OmniSciDB  04ee39c94c
Calcite.cpp File Reference
#include "Calcite.h"
#include <thread>
#include <utility>
#include "Catalog/Catalog.h"
#include "Shared/ConfigResolve.h"
#include "Shared/Logger.h"
#include "Shared/ThriftClient.h"
#include "Shared/mapd_shared_ptr.h"
#include "Shared/mapdpath.h"
#include "Shared/measure.h"
#include "Shared/fixautotools.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include "gen-cpp/CalciteServer.h"
+ 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 mapd_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, const std::string &ssl_keystore, const std::string &ssl_keystore_password, const std::string &ssl_key_file, const std::string &ssl_cert_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

◆ checkPermissionForTables()

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

Definition at line 329 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, anonymous_namespace{DBObjectPrivilegesTest.cpp}::privObjects, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userName, and ViewDBObjectType.

Referenced by Calcite::process().

332  {
333  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
334 
335  for (auto tableOrViewName : tableOrViewNames) {
336  const TableDescriptor* tableMeta =
337  catalog.getMetadataForTable(tableOrViewName, false);
338 
339  if (!tableMeta) {
340  throw std::runtime_error("unknown table of view: " + tableOrViewName);
341  }
342 
343  DBObjectKey key;
344  key.dbId = catalog.getCurrentDB().dbId;
347  key.objectId = tableMeta->tableId;
348  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
349  DBObject dbobject(key, privs, tableMeta->userId);
350  std::vector<DBObject> privObjects{dbobject};
351 
352  if (!privs.hasAny()) {
353  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
354  }
355 
356  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
357  session_info.get_currentUser(), privObjects)) {
358  throw std::runtime_error("Violation of access privileges: user " +
359  session_info.get_currentUser().userName +
360  " has no proper privileges for object " + tableOrViewName);
361  }
362  }
363 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
int32_t objectId
Definition: DBObject.h:56
bool hasAny() const
Definition: DBObject.h:133
static SysCatalog & instance()
Definition: SysCatalog.h:240
Catalog & getCatalog() const
Definition: SessionInfo.h:90
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
int32_t dbId
Definition: DBObject.h:55
int32_t permissionType
Definition: DBObject.h:54
specifies the content in-memory of a row in the table metadata table
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start_calcite_server_as_daemon()

static void start_calcite_server_as_daemon ( const int  mapd_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,
const std::string &  ssl_keystore,
const std::string &  ssl_keystore_password,
const std::string &  ssl_key_file,
const std::string &  ssl_cert_file,
const std::string &  udf_filename 
)
static

Definition at line 66 of file Calcite.cpp.

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

Referenced by Calcite::runServer().

76  {
77  std::string const xDebug = "-Xdebug";
78  std::string const remoteDebug =
79  "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005";
80  std::string xmxP = "-Xmx" + std::to_string(calcite_max_mem) + "m";
81  std::string jarP = "-jar";
82  std::string jarD =
83  mapd_root_abs_path() + "/bin/calcite-1.0-SNAPSHOT-jar-with-dependencies.jar";
84  std::string extensionsP = "-e";
85  std::string extensionsD = mapd_root_abs_path() + "/QueryEngine/";
86  std::string dataP = "-d";
87  std::string dataD = data_dir;
88  std::string localPortP = "-p";
89  std::string localPortD = std::to_string(port);
90  std::string mapdPortP = "-m";
91  std::string mapdPortD = std::to_string(mapd_port);
92  std::string mapdTrustStoreP = "-T";
93  std::string mapdTrustPasswdP = "-P";
94  std::string mapdKeyStoreP = "-Y";
95  std::string mapdKeyStorePasswdP = "-Z";
96  std::string mapdLogDirectory = "-DMAPD_LOG_DIR=" + data_dir;
97  std::string userDefinedFunctionsP = "";
98  std::string userDefinedFunctionsD = "";
99 
100  if (!udf_filename.empty()) {
101  userDefinedFunctionsP += "-u";
102  userDefinedFunctionsD += udf_filename;
103  }
104 
105  int pid = fork();
106  if (pid == 0) {
107  int i;
108 
109  if (udf_filename.empty()) {
110  i = wrapped_execlp("java",
111  xDebug.c_str(),
112  remoteDebug.c_str(),
113  xmxP.c_str(),
114  mapdLogDirectory.c_str(),
115  jarP.c_str(),
116  jarD.c_str(),
117  extensionsP.c_str(),
118  extensionsD.c_str(),
119  dataP.c_str(),
120  dataD.c_str(),
121  localPortP.c_str(),
122  localPortD.c_str(),
123  mapdPortP.c_str(),
124  mapdPortD.c_str(),
125  mapdTrustStoreP.c_str(),
126  ssl_trust_store.c_str(),
127  mapdTrustPasswdP.c_str(),
128  ssl_trust_password.c_str(),
129  mapdKeyStoreP.c_str(),
130  ssl_keystore.c_str(),
131  mapdKeyStorePasswdP.c_str(),
132  ssl_keystore_password.c_str(),
133  (char*)0);
134  } else {
135  i = wrapped_execlp("java",
136  xDebug.c_str(),
137  remoteDebug.c_str(),
138  xmxP.c_str(),
139  mapdLogDirectory.c_str(),
140  jarP.c_str(),
141  jarD.c_str(),
142  extensionsP.c_str(),
143  extensionsD.c_str(),
144  dataP.c_str(),
145  dataD.c_str(),
146  localPortP.c_str(),
147  localPortD.c_str(),
148  mapdPortP.c_str(),
149  mapdPortD.c_str(),
150  mapdTrustStoreP.c_str(),
151  ssl_trust_store.c_str(),
152  mapdTrustPasswdP.c_str(),
153  ssl_trust_password.c_str(),
154  mapdKeyStoreP.c_str(),
155  ssl_keystore.c_str(),
156  mapdKeyStorePasswdP.c_str(),
157  ssl_keystore_password.c_str(),
158  userDefinedFunctionsP.c_str(),
159  userDefinedFunctionsD.c_str(),
160  (char*)0);
161  }
162 
163  if (i) {
164  int errsv = errno;
165  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
166  << "]: " << strerror(errsv);
167  } else {
168  LOG(INFO) << "Successfully started Calcite server";
169  }
170  }
171 }
#define LOG(tag)
Definition: Logger.h:182
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
std::string to_string(char const *&&v)
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&... standard_args)
Definition: Calcite.cpp:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function: