OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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/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::vector< std::string >> tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
 

Function Documentation

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

Definition at line 420 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().

423  {
424  // TODO MAT this needs to be able to check privileges from other catalogs
425  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
426 
427  for (auto tableOrViewName : tableOrViewNames) {
428  const TableDescriptor* tableMeta =
429  catalog.getMetadataForTable(tableOrViewName[0], false);
430 
431  if (!tableMeta) {
432  throw std::runtime_error("unknown table of view: " + tableOrViewName[0]);
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 " +
446  tableOrViewName[0]);
447  }
448 
449  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
450  session_info.get_currentUser(), privObjects)) {
451  throw std::runtime_error("Violation of access privileges: user " +
452  session_info.get_currentUser().userLoggable() +
453  " has no proper privileges for object " +
454  tableOrViewName[0]);
455  }
456  }
457 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:111
bool hasAny() const
Definition: DBObject.h:142
int32_t objectId
Definition: DBObject.h:57
static SysCatalog & instance()
Definition: SysCatalog.h:325
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:221
Catalog & getCatalog() const
Definition: SessionInfo.h:67
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:127
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73

+ 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 71 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().

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