OmniSciDB  a667adc9c8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Calcite.cpp File Reference
#include "Calcite.h"
#include "Catalog/Catalog.h"
#include "Logger/Logger.h"
#include "OSDependent/omnisci_path.h"
#include "Shared/SystemParameters.h"
#include "Shared/ThriftClient.h"
#include "Shared/fixautotools.h"
#include "Shared/mapd_shared_ptr.h"
#include "Shared/measure.h"
#include "ThriftHandler/QueryState.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <type_traits>
#include "gen-cpp/CalciteServer.h"
#include "rapidjson/document.h"
#include <utility>
+ Include dependency graph for Calcite.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{Calcite.cpp}
 

Functions

template<typename XDEBUG_OPTION , typename REMOTE_DEBUG_OPTION , typename... REMAINING_ARGS>
int anonymous_namespace{Calcite.cpp}::wrapped_execlp (char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
 
static void start_calcite_server_as_daemon (const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &ssl_trust_store, const std::string &ssl_trust_password_X, const std::string &ssl_keystore, const std::string &ssl_keystore_password_X, const std::string &ssl_key_file, const std::string &db_config_file, const std::string &udf_filename)
 
void checkPermissionForTables (const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
 

Function Documentation

void checkPermissionForTables ( const Catalog_Namespace::SessionInfo session_info,
std::vector< std::string >  tableOrViewNames,
AccessPrivileges  tablePrivs,
AccessPrivileges  viewPrivs 
)

Definition at line 421 of file Calcite.cpp.

References DBObjectKey::dbId, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::Catalog::getCurrentDB(), Catalog_Namespace::Catalog::getMetadataForTable(), AccessPrivileges::hasAny(), Catalog_Namespace::SysCatalog::instance(), TableDescriptor::isView, DBObjectKey::objectId, DBObjectKey::permissionType, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userLoggable(), and ViewDBObjectType.

Referenced by Calcite::checkAccessedObjectsPrivileges().

424  {
425  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
426 
427  for (auto tableOrViewName : tableOrViewNames) {
428  const TableDescriptor* tableMeta =
429  catalog.getMetadataForTable(tableOrViewName, false);
430 
431  if (!tableMeta) {
432  throw std::runtime_error("unknown table of view: " + tableOrViewName);
433  }
434 
435  DBObjectKey key;
436  key.dbId = catalog.getCurrentDB().dbId;
439  key.objectId = tableMeta->tableId;
440  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
441  DBObject dbobject(key, privs, tableMeta->userId);
442  std::vector<DBObject> privObjects{dbobject};
443 
444  if (!privs.hasAny()) {
445  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
446  }
447 
448  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
449  session_info.get_currentUser(), privObjects)) {
450  throw std::runtime_error("Violation of access privileges: user " +
451  session_info.get_currentUser().userLoggable() +
452  " has no proper privileges for object " + tableOrViewName);
453  }
454  }
455 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:101
bool hasAny() const
Definition: DBObject.h:142
int32_t objectId
Definition: DBObject.h:57
static SysCatalog & instance()
Definition: SysCatalog.h:292
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:221
Catalog & getCatalog() const
Definition: SessionInfo.h:66
int32_t dbId
Definition: DBObject.h:56
int32_t permissionType
Definition: DBObject.h:55
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::string userLoggable() const
Definition: SysCatalog.cpp:125
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void start_calcite_server_as_daemon ( const int  db_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  ssl_trust_store,
const std::string &  ssl_trust_password_X,
const std::string &  ssl_keystore,
const std::string &  ssl_keystore_password_X,
const std::string &  ssl_key_file,
const std::string &  db_config_file,
const std::string &  udf_filename 
)
static

Definition at line 72 of file Calcite.cpp.

References run_benchmark_import::args, logger::FATAL, omnisci::get_root_abs_path(), i, logger::INFO, join(), LOG, to_string(), and anonymous_namespace{Calcite.cpp}::wrapped_execlp().

Referenced by Calcite::runServer().

82  {
83  auto root_abs_path = omnisci::get_root_abs_path();
84  std::string const xDebug = "-Xdebug";
85  std::string const remoteDebug =
86  "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005";
87  std::string xmxP = "-Xmx" + std::to_string(calcite_max_mem) + "m";
88  std::string jarP = "-jar";
89  std::string jarD =
90  root_abs_path + "/bin/calcite-1.0-SNAPSHOT-jar-with-dependencies.jar";
91  std::string extensionsP = "-e";
92  std::string extensionsD = root_abs_path + "/QueryEngine/";
93  std::string dataP = "-d";
94  std::string dataD = data_dir;
95  std::string localPortP = "-p";
96  std::string localPortD = std::to_string(port);
97  std::string dbPortP = "-m";
98  std::string dbPortD = std::to_string(db_port);
99  std::string TrustStoreP = "-T";
100  std::string TrustPasswdP = "-P";
101  std::string ConfigFileP = "-c";
102  std::string KeyStoreP = "-Y";
103  std::string KeyStorePasswdP = "-Z";
104  std::string logDirectory = "-DMAPD_LOG_DIR=" + data_dir;
105  std::string userDefinedFunctionsP = "";
106  std::string userDefinedFunctionsD = "";
107 
108  if (!udf_filename.empty()) {
109  userDefinedFunctionsP += "-u";
110  userDefinedFunctionsD += udf_filename;
111  }
112 
113  // If a config file hasn't been supplied then put the password in the params
114  // otherwise send an empty string and Calcite should get it from the config file.
115  std::string key_store_password = (db_config_file == "") ? ssl_keystore_password_X : "";
116  std::string trust_store_password = (db_config_file == "") ? ssl_trust_password_X : "";
117 #ifdef _MSC_VER
118  // TODO: enable UDF support
119  std::vector<std::string> args_vec;
120  args_vec.push_back("java");
121  args_vec.push_back(xDebug);
122  args_vec.push_back(remoteDebug);
123  args_vec.push_back(xmxP);
124  args_vec.push_back(logDirectory);
125  args_vec.push_back(jarP);
126  args_vec.push_back(jarD);
127  args_vec.push_back(extensionsP);
128  args_vec.push_back(extensionsD);
129  args_vec.push_back(dataP);
130  args_vec.push_back(dataD);
131  args_vec.push_back(localPortP);
132  args_vec.push_back(localPortD);
133  args_vec.push_back(dbPortP);
134  args_vec.push_back(dbPortD);
135  if (!ssl_trust_store.empty()) {
136  args_vec.push_back(TrustStoreP);
137  args_vec.push_back(ssl_trust_store);
138  }
139  if (!trust_store_password.empty()) {
140  args_vec.push_back(TrustPasswdP);
141  args_vec.push_back(trust_store_password);
142  }
143  if (!ssl_keystore.empty()) {
144  args_vec.push_back(KeyStoreP);
145  args_vec.push_back(ssl_keystore);
146  }
147  if (!key_store_password.empty()) {
148  args_vec.push_back(KeyStorePasswdP);
149  args_vec.push_back(key_store_password);
150  }
151  if (!db_config_file.empty()) {
152  args_vec.push_back(ConfigFileP);
153  args_vec.push_back(db_config_file);
154  }
155  std::string args{boost::algorithm::join(args_vec, " ")};
156  STARTUPINFO startup_info;
157  PROCESS_INFORMATION proc_info;
158  ZeroMemory(&startup_info, sizeof(startup_info));
159  startup_info.cb = sizeof(startup_info);
160  ZeroMemory(&proc_info, sizeof(proc_info));
161  LOG(INFO) << "Startup command: " << args;
162  std::wstring wargs = std::wstring(args.begin(), args.end());
163  const auto ret = CreateProcess(NULL,
164  (LPWSTR)wargs.c_str(),
165  NULL,
166  NULL,
167  false,
168  0,
169  NULL,
170  NULL,
171  &startup_info,
172  &proc_info);
173  if (ret == 0) {
174  LOG(FATAL) << "Failed to start Calcite server " << GetLastError();
175  }
176 #else
177  int pid = fork();
178  if (pid == 0) {
179  int i;
180 
181  if (udf_filename.empty()) {
182  i = wrapped_execlp("java",
183  xDebug.c_str(),
184  remoteDebug.c_str(),
185  xmxP.c_str(),
186  logDirectory.c_str(),
187  jarP.c_str(),
188  jarD.c_str(),
189  extensionsP.c_str(),
190  extensionsD.c_str(),
191  dataP.c_str(),
192  dataD.c_str(),
193  localPortP.c_str(),
194  localPortD.c_str(),
195  dbPortP.c_str(),
196  dbPortD.c_str(),
197  TrustStoreP.c_str(),
198  ssl_trust_store.c_str(),
199  TrustPasswdP.c_str(),
200  trust_store_password.c_str(),
201  KeyStoreP.c_str(),
202  ssl_keystore.c_str(),
203  KeyStorePasswdP.c_str(),
204  key_store_password.c_str(),
205  ConfigFileP.c_str(),
206  db_config_file.c_str(),
207  (char*)0);
208  } else {
209  i = wrapped_execlp("java",
210  xDebug.c_str(),
211  remoteDebug.c_str(),
212  xmxP.c_str(),
213  logDirectory.c_str(),
214  jarP.c_str(),
215  jarD.c_str(),
216  extensionsP.c_str(),
217  extensionsD.c_str(),
218  dataP.c_str(),
219  dataD.c_str(),
220  localPortP.c_str(),
221  localPortD.c_str(),
222  dbPortP.c_str(),
223  dbPortD.c_str(),
224  TrustStoreP.c_str(),
225  ssl_trust_store.c_str(),
226  TrustPasswdP.c_str(),
227  trust_store_password.c_str(),
228  KeyStoreP.c_str(),
229  ssl_keystore.c_str(),
230  KeyStorePasswdP.c_str(),
231  key_store_password.c_str(),
232  ConfigFileP.c_str(),
233  db_config_file.c_str(),
234  userDefinedFunctionsP.c_str(),
235  userDefinedFunctionsD.c_str(),
236  (char*)0);
237  }
238 
239  if (i) {
240  int errsv = errno;
241  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
242  << "]: " << strerror(errsv);
243  } else {
244  LOG(INFO) << "Successfully started Calcite server";
245  }
246  }
247 #endif
248 }
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
Definition: Calcite.cpp:59
#define LOG(tag)
Definition: Logger.h:188
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
std::string get_root_abs_path()

+ Here is the call graph for this function:

+ Here is the caller graph for this function: