Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hdfs-lzo-text-scanner.cc
Go to the documentation of this file.
1 // Copyright (c) 2012 Cloudera, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <hdfs.h>
18 #include <boost/algorithm/string.hpp>
19 #include "common/version.h"
20 #include "exec/hdfs-scan-node.h"
21 #include "exec/read-write-util.h"
22 #include "runtime/runtime-state.h"
23 #include "runtime/hdfs-fs-cache.h"
24 #include "util/debug-util.h"
25 #include "util/hdfs-util.h"
26 #include "util/dynamic-util.h"
27 
28 #include "common/names.h"
29 
30 using namespace impala;
31 
32 DEFINE_bool(skip_lzo_version_check, false, "Disables checking the LZO library version "
33  "against the running Impala version.");
34 
35 const string HdfsLzoTextScanner::LIB_IMPALA_LZO = "libimpalalzo.so";
36 
37 namespace impala {
39 
41 
42 const char* (*GetImpalaBuildVersion)();
43 
44 HdfsScanner* (*HdfsLzoTextScanner::CreateLzoTextScanner)(
45  HdfsScanNode* scan_node, RuntimeState* state);
46 
48  HdfsScanNode* scan_node, const std::vector<HdfsFileDesc*>& files);
49 
51  HdfsScanNode* scan_node, RuntimeState* state) {
52 
53  // If the scanner was not loaded then no scans could be issued so we should
54  // never get here without having loaded the scanner.
55  DCHECK(CreateLzoTextScanner != NULL);
56 
57  return (*CreateLzoTextScanner)(scan_node, state);
58 }
59 
61  const vector<HdfsFileDesc*>& files) {
62  if (LzoIssueInitialRanges == NULL) {
63  lock_guard<mutex> l(lzo_load_lock_);
64  if (library_load_status_.ok()) {
65  // LzoIssueInitialRanges && library_load_status_.ok() means we haven't tried loading
66  // the library yet.
68  if (!library_load_status_.ok()) {
69  stringstream ss;
70  ss << "Error loading impala-lzo library. Check that the impala-lzo library "
71  << "is at version " << IMPALA_BUILD_VERSION;
73  return library_load_status_;
74  }
75  } else {
76  // We only try to load the library once.
77  return library_load_status_;
78  }
79  }
80 
81  return (*LzoIssueInitialRanges)(scan_node, files);
82 }
83 
85  void* handle;
86  RETURN_IF_ERROR(DynamicOpen(LIB_IMPALA_LZO.c_str(), &handle));
88  "GetImpalaBuildVersion", reinterpret_cast<void**>(&GetImpalaBuildVersion)));
89 
90  if (strcmp((*GetImpalaBuildVersion)(), IMPALA_BUILD_VERSION) != 0) {
91  stringstream ss;
92  ss << "Impala LZO library was built against Impala version "
93  << (*GetImpalaBuildVersion)() << ", but the running Impala version is "
95  if (FLAGS_skip_lzo_version_check) {
96  LOG(ERROR) << ss.str();
97  } else {
98  return Status(ss.str());
99  }
100  }
101 
103  "CreateLzoTextScanner", reinterpret_cast<void**>(&CreateLzoTextScanner)));
105  "LzoIssueInitialRangesImpl", reinterpret_cast<void**>(&LzoIssueInitialRanges)));
106 
107  DCHECK(CreateLzoTextScanner != NULL);
108  DCHECK(LzoIssueInitialRanges != NULL);
109  LOG(INFO) << "Loaded impala-lzo library: " << LIB_IMPALA_LZO;
110  return Status::OK;
111 }
112 
113 }
static boost::mutex lzo_load_lock_
Lock to protect loading of the lzo file library.
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Definition: status.h:242
static HdfsScanner *(* CreateLzoTextScanner)(HdfsScanNode *scan_node, RuntimeState *state)
Dynamically linked function to create the Lzo Scanner Object.
static Status(* LzoIssueInitialRanges)(HdfsScanNode *scan_node, const std::vector< HdfsFileDesc * > &files)
Dynamically linked function to set the initial scan ranges.
Status DynamicOpen(const char *library, void **handle)
Definition: dynamic-util.cc:37
void AddDetail(const std::string &msg)
Add a detail string. Calling this method is only defined on a non-OK message.
Definition: status.cc:166
Status DynamicLookup(void *handle, const char *symbol, void **fn_ptr, bool quiet)
Definition: dynamic-util.cc:26
static HdfsScanner * GetHdfsLzoTextScanner(HdfsScanNode *scan_node, RuntimeState *state)
static Status IssueInitialRanges(HdfsScanNode *scan_node, const std::vector< HdfsFileDesc * > &files)
DEFINE_bool(skip_lzo_version_check, false,"Disables checking the LZO library version ""against the running Impala version.")
const char *(* GetImpalaBuildVersion)()
static const Status OK
Definition: status.h:87
static Status library_load_status_
If non-OK, then we have tried and failed to load the LZO library.
static const std::string LIB_IMPALA_LZO
Impala LZO library name – GPL code.
#define IMPALA_BUILD_VERSION
Definition: version.h:21
bool ok() const
Definition: status.h:172