Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
catalog.cc
Go to the documentation of this file.
1 // Copyright 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 
15 #include "catalog/catalog.h"
16 
17 #include <list>
18 #include <string>
19 
20 #include "common/logging.h"
21 #include "rpc/jni-thrift-util.h"
22 #include "util/logging-support.h"
23 
24 #include "common/names.h"
25 
26 using namespace impala;
27 
28 DEFINE_bool(load_catalog_in_background, false,
29  "If true, loads catalog metadata in the background. If false, metadata is loaded "
30  "lazily (on access).");
31 DEFINE_int32(num_metadata_loading_threads, 16,
32  "(Advanced) The number of metadata loading threads (degree of parallelism) to use "
33  "when loading catalog metadata.");
34 DEFINE_string(sentry_config, "", "Local path to a sentry-site.xml configuration "
35  "file. If set, authorization will be enabled.");
36 
37 DECLARE_int32(non_impala_java_vlog);
38 
40  JniMethodDescriptor methods[] = {
41  {"<init>", "(ZILjava/lang/String;II)V", &catalog_ctor_},
42  {"updateCatalog", "([B)[B", &update_metastore_id_},
43  {"execDdl", "([B)[B", &exec_ddl_id_},
44  {"resetMetadata", "([B)[B", &reset_metadata_id_},
45  {"getTableNames", "([B)[B", &get_table_names_id_},
46  {"getDbNames", "([B)[B", &get_db_names_id_},
47  {"getFunctions", "([B)[B", &get_functions_id_},
48  {"checkUserSentryAdmin", "([B)V", &sentry_admin_check_id_},
49  {"getCatalogObject", "([B)[B", &get_catalog_object_id_},
50  {"getCatalogObjects", "(J)[B", &get_catalog_objects_id_},
51  {"getCatalogVersion", "()J", &get_catalog_version_id_},
52  {"prioritizeLoad", "([B)V", &prioritize_load_id_}};
53 
54  JNIEnv* jni_env = getJNIEnv();
55  // Create an instance of the java class JniCatalog
56  catalog_class_ = jni_env->FindClass("com/cloudera/impala/service/JniCatalog");
57  EXIT_IF_EXC(jni_env);
58 
59  uint32_t num_methods = sizeof(methods) / sizeof(methods[0]);
60  for (int i = 0; i < num_methods; ++i) {
61  EXIT_IF_ERROR(JniUtil::LoadJniMethod(jni_env, catalog_class_, &(methods[i])));
62  }
63 
64  jboolean load_in_background = FLAGS_load_catalog_in_background;
65  jint num_metadata_loading_threads = FLAGS_num_metadata_loading_threads;
66  jstring sentry_config = jni_env->NewStringUTF(FLAGS_sentry_config.c_str());
67  jobject catalog = jni_env->NewObject(catalog_class_, catalog_ctor_,
68  load_in_background, num_metadata_loading_threads, sentry_config,
69  FlagToTLogLevel(FLAGS_v), FlagToTLogLevel(FLAGS_non_impala_java_vlog));
70  EXIT_IF_EXC(jni_env);
72 }
73 
74 Status Catalog::GetCatalogObject(const TCatalogObject& req,
75  TCatalogObject* resp) {
77 }
78 
80  JNIEnv* jni_env = getJNIEnv();
81  JniLocalFrame jni_frame;
82  RETURN_IF_ERROR(jni_frame.push(jni_env));
83  *version = jni_env->CallLongMethod(catalog_, get_catalog_version_id_);
84  return Status::OK;
85 }
86 
88  TGetAllCatalogObjectsResponse* resp) {
89  JNIEnv* jni_env = getJNIEnv();
90  JniLocalFrame jni_frame;
91  RETURN_IF_ERROR(jni_frame.push(jni_env));
92  jvalue requested_from_version;
93  requested_from_version.j = from_version;
94  jbyteArray result_bytes = static_cast<jbyteArray>(
95  jni_env->CallObjectMethod(catalog_, get_catalog_objects_id_,
96  requested_from_version));
97  RETURN_ERROR_IF_EXC(jni_env);
98  RETURN_IF_ERROR(DeserializeThriftMsg(jni_env, result_bytes, resp));
99  return Status::OK;
100 }
101 
102 Status Catalog::ExecDdl(const TDdlExecRequest& req, TDdlExecResponse* resp) {
103  return JniUtil::CallJniMethod(catalog_, exec_ddl_id_, req, resp);
104 }
105 
106 Status Catalog::ResetMetadata(const TResetMetadataRequest& req,
107  TResetMetadataResponse* resp) {
109 }
110 
111 Status Catalog::UpdateCatalog(const TUpdateCatalogRequest& req,
112  TUpdateCatalogResponse* resp) {
114 }
115 
116 Status Catalog::GetDbNames(const string* pattern, TGetDbsResult* db_names) {
117  TGetDbsParams params;
118  if (pattern != NULL) params.__set_pattern(*pattern);
119  return JniUtil::CallJniMethod(catalog_, get_db_names_id_, params, db_names);
120 }
121 
122 Status Catalog::GetTableNames(const string& db, const string* pattern,
123  TGetTablesResult* table_names) {
124  TGetTablesParams params;
125  params.__set_db(db);
126  if (pattern != NULL) params.__set_pattern(*pattern);
127  return JniUtil::CallJniMethod(catalog_, get_table_names_id_, params, table_names);
128 }
129 
130 Status Catalog::GetFunctions(const TGetFunctionsRequest& request,
131  TGetFunctionsResponse *response) {
132  return JniUtil::CallJniMethod(catalog_, get_functions_id_, request, response);
133 }
134 
135 Status Catalog::PrioritizeLoad(const TPrioritizeLoadRequest& req) {
137 }
138 
139 Status Catalog::SentryAdminCheck(const TSentryAdminCheckRequest& req) {
141 }
jmethodID get_catalog_object_id_
Definition: catalog.h:108
jmethodID get_functions_id_
Definition: catalog.h:113
jmethodID get_table_names_id_
Definition: catalog.h:112
DEFINE_bool(load_catalog_in_background, false,"If true, loads catalog metadata in the background. If false, metadata is loaded ""lazily (on access).")
Status ExecDdl(const TDdlExecRequest &req, TDdlExecResponse *resp)
Definition: catalog.cc:102
Status PrioritizeLoad(const TPrioritizeLoadRequest &req)
Definition: catalog.cc:135
TLogLevel::type FlagToTLogLevel(int flag)
jmethodID sentry_admin_check_id_
Definition: catalog.h:115
jmethodID update_metastore_id_
Definition: catalog.h:105
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Definition: status.h:242
static Status LoadJniMethod(JNIEnv *jni_env, const jclass &jni_class, JniMethodDescriptor *descriptor)
Definition: jni-util.cc:193
Status GetDbNames(const std::string *pattern, TGetDbsResult *table_names)
Definition: catalog.cc:116
#define EXIT_IF_EXC(env)
Definition: jni-util.h:85
jobject catalog_
Definition: catalog.h:104
Status GetAllCatalogObjects(long from_version, TGetAllCatalogObjectsResponse *resp)
Definition: catalog.cc:87
DECLARE_int32(non_impala_java_vlog)
Status SentryAdminCheck(const TSentryAdminCheckRequest &req)
Definition: catalog.cc:139
Status UpdateCatalog(const TUpdateCatalogRequest &req, TUpdateCatalogResponse *resp)
Definition: catalog.cc:111
jmethodID catalog_ctor_
Definition: catalog.h:116
static Status LocalToGlobalRef(JNIEnv *env, jobject local_ref, jobject *global_ref)
Definition: jni-util.cc:67
jmethodID get_catalog_version_id_
Definition: catalog.h:110
Status GetCatalogObject(const TCatalogObject &request, TCatalogObject *response)
Definition: catalog.cc:74
jmethodID reset_metadata_id_
Definition: catalog.h:107
#define EXIT_IF_ERROR(stmt)
Definition: status.h:248
jmethodID prioritize_load_id_
Definition: catalog.h:114
Status push(JNIEnv *env, int max_local_ref=10)
Definition: jni-util.cc:34
Describes one method to look up in a Java object.
Definition: jni-util.h:149
#define RETURN_ERROR_IF_EXC(env)
Definition: jni-util.h:99
Status GetFunctions(const TGetFunctionsRequest &request, TGetFunctionsResponse *response)
Definition: catalog.cc:130
Status GetTableNames(const std::string &db, const std::string *pattern, TGetTablesResult *table_names)
Definition: catalog.cc:122
jclass catalog_class_
Descriptor of Java Catalog class itself, used to create a new instance.
Definition: catalog.h:102
jmethodID exec_ddl_id_
Definition: catalog.h:106
jmethodID get_catalog_objects_id_
Definition: catalog.h:109
static const Status OK
Definition: status.h:87
Status ResetMetadata(const TResetMetadataRequest &req, TResetMetadataResponse *resp)
Definition: catalog.cc:106
Status DeserializeThriftMsg(JNIEnv *env, jbyteArray serialized_msg, T *deserialized_msg)
DEFINE_int32(periodic_counter_update_period_ms, 500,"Period to update rate counters and"" sampling counters in ms")
static Status CallJniMethod(const jobject &obj, const jmethodID &method, const T &arg)
Definition: jni-util.h:231
DEFINE_string(sentry_config,"","Local path to a sentry-site.xml configuration ""file. If set, authorization will be enabled.")
jmethodID get_db_names_id_
Definition: catalog.h:111
Status GetCatalogVersion(long *version)
Definition: catalog.cc:79
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.