OmniSciDB  95562058bd
 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 357 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::userName, and ViewDBObjectType.

Referenced by Calcite::checkAccessedObjectsPrivileges().

360  {
361  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
362 
363  for (auto tableOrViewName : tableOrViewNames) {
364  const TableDescriptor* tableMeta =
365  catalog.getMetadataForTable(tableOrViewName, false);
366 
367  if (!tableMeta) {
368  throw std::runtime_error("unknown table of view: " + tableOrViewName);
369  }
370 
371  DBObjectKey key;
372  key.dbId = catalog.getCurrentDB().dbId;
375  key.objectId = tableMeta->tableId;
376  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
377  DBObject dbobject(key, privs, tableMeta->userId);
378  std::vector<DBObject> privObjects{dbobject};
379 
380  if (!privs.hasAny()) {
381  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
382  }
383 
384  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
385  session_info.get_currentUser(), privObjects)) {
386  throw std::runtime_error("Violation of access privileges: user " +
387  session_info.get_currentUser().userName +
388  " has no proper privileges for object " + tableOrViewName);
389  }
390  }
391 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
bool hasAny() const
Definition: DBObject.h:141
int32_t objectId
Definition: DBObject.h:57
static SysCatalog & instance()
Definition: SysCatalog.h:286
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:208
Catalog & getCatalog() const
Definition: SessionInfo.h:65
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.
specifies the content in-memory of a row in the table metadata table
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68

+ 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 68 of file Calcite.cpp.

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

Referenced by Calcite::runServer().

78  {
79  auto root_abs_path = omnisci::get_root_abs_path();
80  std::string const xDebug = "-Xdebug";
81  std::string const remoteDebug =
82  "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005";
83  std::string xmxP = "-Xmx" + std::to_string(calcite_max_mem) + "m";
84  std::string jarP = "-jar";
85  std::string jarD =
86  root_abs_path + "/bin/calcite-1.0-SNAPSHOT-jar-with-dependencies.jar";
87  std::string extensionsP = "-e";
88  std::string extensionsD = root_abs_path + "/QueryEngine/";
89  std::string dataP = "-d";
90  std::string dataD = data_dir;
91  std::string localPortP = "-p";
92  std::string localPortD = std::to_string(port);
93  std::string dbPortP = "-m";
94  std::string dbPortD = std::to_string(db_port);
95  std::string TrustStoreP = "-T";
96  std::string TrustPasswdP = "-P";
97  std::string ConfigFileP = "-c";
98  std::string KeyStoreP = "-Y";
99  std::string KeyStorePasswdP = "-Z";
100  std::string logDirectory = "-DMAPD_LOG_DIR=" + data_dir;
101  std::string userDefinedFunctionsP = "";
102  std::string userDefinedFunctionsD = "";
103 
104  if (!udf_filename.empty()) {
105  userDefinedFunctionsP += "-u";
106  userDefinedFunctionsD += udf_filename;
107  }
108 
109  // If a config file hasn't been supplied then put the password in the params
110  // otherwise send an empty string and Calcite should get it from the config file.
111  std::string key_store_password = (db_config_file == "") ? ssl_keystore_password_X : "";
112  std::string trust_store_password = (db_config_file == "") ? ssl_trust_password_X : "";
113 
114  int pid = fork();
115  if (pid == 0) {
116  int i;
117 
118  if (udf_filename.empty()) {
119  i = wrapped_execlp("java",
120  xDebug.c_str(),
121  remoteDebug.c_str(),
122  xmxP.c_str(),
123  logDirectory.c_str(),
124  jarP.c_str(),
125  jarD.c_str(),
126  extensionsP.c_str(),
127  extensionsD.c_str(),
128  dataP.c_str(),
129  dataD.c_str(),
130  localPortP.c_str(),
131  localPortD.c_str(),
132  dbPortP.c_str(),
133  dbPortD.c_str(),
134  TrustStoreP.c_str(),
135  ssl_trust_store.c_str(),
136  TrustPasswdP.c_str(),
137  trust_store_password.c_str(),
138  KeyStoreP.c_str(),
139  ssl_keystore.c_str(),
140  KeyStorePasswdP.c_str(),
141  key_store_password.c_str(),
142  ConfigFileP.c_str(),
143  db_config_file.c_str(),
144  (char*)0);
145  } else {
146  i = wrapped_execlp("java",
147  xDebug.c_str(),
148  remoteDebug.c_str(),
149  xmxP.c_str(),
150  logDirectory.c_str(),
151  jarP.c_str(),
152  jarD.c_str(),
153  extensionsP.c_str(),
154  extensionsD.c_str(),
155  dataP.c_str(),
156  dataD.c_str(),
157  localPortP.c_str(),
158  localPortD.c_str(),
159  dbPortP.c_str(),
160  dbPortD.c_str(),
161  TrustStoreP.c_str(),
162  ssl_trust_store.c_str(),
163  TrustPasswdP.c_str(),
164  trust_store_password.c_str(),
165  KeyStoreP.c_str(),
166  ssl_keystore.c_str(),
167  KeyStorePasswdP.c_str(),
168  key_store_password.c_str(),
169  ConfigFileP.c_str(),
170  db_config_file.c_str(),
171  userDefinedFunctionsP.c_str(),
172  userDefinedFunctionsD.c_str(),
173  (char*)0);
174  }
175 
176  if (i) {
177  int errsv = errno;
178  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
179  << "]: " << strerror(errsv);
180  } else {
181  LOG(INFO) << "Successfully started Calcite server";
182  }
183  }
184 }
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
Definition: Calcite.cpp:55
#define LOG(tag)
Definition: Logger.h:188
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: