OmniSciDB  a5dc49c757
 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/heavyai_path.h"
#include "Shared/SysDefinitions.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 anonymous_namespace{Calcite.cpp}::check_db_access (const Catalog_Namespace::SessionInfo &session_info, const Catalog_Namespace::Catalog &accessed_catalog)
 
void anonymous_namespace{Calcite.cpp}::checkPermissionForTables (const Catalog_Namespace::SessionInfo &session_info, std::vector< std::vector< std::string >> tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
 

Function Documentation

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, heavyai::get_root_abs_path(), logger::INFO, join(), shared::kDefaultLogDirName, LOG, to_string(), and anonymous_namespace{Calcite.cpp}::wrapped_execlp().

Referenced by Calcite::runServer().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: