OmniSciDB  addbbd5075
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Calcite Class Referencefinal

#include <Calcite.h>

+ Collaboration diagram for Calcite:

Public Member Functions

 Calcite (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename="")
 
 Calcite (const MapDParameters &mapd_parameter, const std::string &data_dir, const std::string &udf_filename="")
 
TPlanResult process (query_state::QueryStateProxy, std::string sql_string, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool legacy_syntax, const bool is_explain, const bool is_view_optimize, const std::string &calcite_session_id="")
 
std::vector< TCompletionHint > getCompletionHints (const Catalog_Namespace::SessionInfo &session_info, const std::vector< std::string > &visible_tables, const std::string sql_string, const int cursor)
 
std::string getExtensionFunctionWhitelist ()
 
std::string getUserDefinedFunctionWhitelist ()
 
void updateMetadata (std::string catalog, std::string table)
 
void close_calcite_server (bool log=true)
 
 ~Calcite ()
 
std::string getRuntimeExtensionFunctionWhitelist ()
 
void setRuntimeExtensionFunctions (const std::vector< TUserDefinedFunction > &udfs, const std::vector< TUserDefinedTableFunction > &udtfs)
 
std::string const getInternalSessionProxyUserName ()
 
std::string const getInternalSessionProxyPassword ()
 

Private Member Functions

void init (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
 
void runServer (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
 
TPlanResult processImpl (query_state::QueryStateProxy, std::string sql_string, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool legacy_syntax, const bool is_explain, const bool is_view_optimize, const std::string &calcite_session_id)
 
std::vector< std::string > get_db_objects (const std::string ra)
 
void inner_close_calcite_server (bool log)
 
std::pair< mapd::shared_ptr
< CalciteServerClient >
, mapd::shared_ptr< TTransport > > 
getClient (int port)
 
int ping (int retry_num=0, int max_retry=50)
 

Private Attributes

mapd::shared_ptr
< ThriftClientConnection
connMgr_
 
bool server_available_
 
int remote_calcite_port_ = -1
 
std::string ssl_trust_store_
 
std::string ssl_trust_password_
 
std::string ssl_key_file_
 
std::string ssl_keystore_
 
std::string ssl_keystore_password_
 
std::string ssl_ca_file_
 
std::string mapd_config_file_
 
std::once_flag shutdown_once_flag_
 

Detailed Description

Definition at line 62 of file Calcite.h.

Constructor & Destructor Documentation

Calcite::Calcite ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  udf_filename = "" 
)

Definition at line 284 of file Calcite.cpp.

References init().

289  : server_available_(false) {
290  init(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
291 }
bool server_available_
Definition: Calcite.h:122
void init(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:293

+ Here is the call graph for this function:

Calcite::Calcite ( const MapDParameters mapd_parameter,
const std::string &  data_dir,
const std::string &  udf_filename = "" 
)

Definition at line 315 of file Calcite.cpp.

References MapDParameters::calcite_max_mem, MapDParameters::calcite_port, init(), and MapDParameters::omnisci_server_port.

318  : ssl_trust_store_(mapd_parameter.ssl_trust_store)
319  , ssl_trust_password_(mapd_parameter.ssl_trust_password)
320  , ssl_key_file_(mapd_parameter.ssl_key_file)
321  , ssl_keystore_(mapd_parameter.ssl_keystore)
323  , ssl_ca_file_(mapd_parameter.ssl_trust_ca_file)
324  , mapd_config_file_(mapd_parameter.config_file) {
325  init(mapd_parameter.omnisci_server_port,
326  mapd_parameter.calcite_port,
327  data_dir,
328  mapd_parameter.calcite_max_mem,
329  udf_filename);
330 }
std::string ssl_key_file
std::string ssl_key_file_
Definition: Calcite.h:126
std::string ssl_keystore_
Definition: Calcite.h:127
std::string ssl_keystore_password_
Definition: Calcite.h:128
std::string ssl_trust_store
std::string ssl_trust_ca_file
std::string ssl_trust_store_
Definition: Calcite.h:124
std::string ssl_keystore
std::string config_file
std::string ssl_keystore_password
std::string ssl_ca_file_
Definition: Calcite.h:129
std::string ssl_trust_password
size_t calcite_max_mem
std::string mapd_config_file_
Definition: Calcite.h:130
void init(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:293
std::string ssl_trust_password_
Definition: Calcite.h:125

+ Here is the call graph for this function:

Calcite::~Calcite ( )

Definition at line 577 of file Calcite.cpp.

References close_calcite_server().

577  {
578  close_calcite_server(false);
579 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:553

+ Here is the call graph for this function:

Member Function Documentation

void Calcite::close_calcite_server ( bool  log = true)

Definition at line 553 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

553  {
554  std::call_once(shutdown_once_flag_,
555  [this, log]() { this->inner_close_calcite_server(log); });
556 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:131
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:558

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< std::string > Calcite::get_db_objects ( const std::string  ra)
private

Definition at line 439 of file Calcite.cpp.

References CHECK().

439  {
440  std::vector<std::string> v_db_obj;
441  Document document;
442  document.Parse(ra.c_str());
443  const Value& rels = document["rels"];
444  CHECK(rels.IsArray());
445  for (auto& v : rels.GetArray()) {
446  std::string relOp(v["relOp"].GetString());
447  if (!relOp.compare("EnumerableTableScan")) {
448  std::string x;
449  auto t = v["table"].GetArray();
450  x = t[1].GetString();
451  v_db_obj.push_back(x);
452  }
453  }
454 
455  return v_db_obj;
456 }
CHECK(cgen_state)

+ Here is the call graph for this function:

std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > Calcite::getClient ( int  port)
private

Definition at line 187 of file Calcite.cpp.

Referenced by getCompletionHints(), getExtensionFunctionWhitelist(), getRuntimeExtensionFunctionWhitelist(), getUserDefinedFunctionWhitelist(), inner_close_calcite_server(), processImpl(), setRuntimeExtensionFunctions(), and updateMetadata().

187  {
188  const auto transport = connMgr_->open_buffered_client_transport(
189  "localhost", port, ssl_ca_file_, true, 2000, 5000, 5000);
190  try {
191  transport->open();
192 
193  } catch (TException& tx) {
194  throw tx;
195  } catch (std::exception& ex) {
196  throw ex;
197  }
198  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
199  mapd::shared_ptr<CalciteServerClient> client;
200  client.reset(new CalciteServerClient(protocol));
201  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
202  return std::make_pair(client, transport);
203 }
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:121
std::string ssl_ca_file_
Definition: Calcite.h:129

+ Here is the caller graph for this function:

std::vector< TCompletionHint > Calcite::getCompletionHints ( const Catalog_Namespace::SessionInfo session_info,
const std::vector< std::string > &  visible_tables,
const std::string  sql_string,
const int  cursor 
)

Definition at line 423 of file Calcite.cpp.

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::get_session_id(), Catalog_Namespace::SessionInfo::getCatalog(), getClient(), remote_calcite_port_, and Catalog_Namespace::UserMetadata::userName.

427  {
428  std::vector<TCompletionHint> hints;
429  auto& cat = session_info.getCatalog();
430  const auto user = session_info.get_currentUser().userName;
431  const auto session = session_info.get_session_id();
432  const auto catalog = cat.getCurrentDB().dbName;
433  auto client = getClient(remote_calcite_port_);
434  client.first->getCompletionHints(
435  hints, user, session, catalog, visible_tables, sql_string, cursor);
436  return hints;
437 }
std::string get_session_id() const
Definition: SessionInfo.h:98
Catalog & getCatalog() const
Definition: SessionInfo.h:90
int remote_calcite_port_
Definition: Calcite.h:123
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 517 of file Calcite.cpp.

References CHECK(), logger::FATAL, getClient(), LOG, remote_calcite_port_, server_available_, and VLOG.

517  {
518  if (server_available_) {
519  TPlanResult ret;
520  std::string whitelist;
521 
522  auto clientP = getClient(remote_calcite_port_);
523  clientP.first->getExtensionFunctionWhitelist(whitelist);
524  clientP.second->close();
525  VLOG(1) << whitelist;
526  return whitelist;
527  } else {
528  LOG(FATAL) << "Not routing to Calcite, server is not up";
529  return "";
530  }
531  CHECK(false);
532  return "";
533 }
#define LOG(tag)
Definition: Logger.h:188
CHECK(cgen_state)
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187
#define VLOG(n)
Definition: Logger.h:283

+ Here is the call graph for this function:

std::string const Calcite::getInternalSessionProxyPassword ( )
inline

Definition at line 94 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserPassword.

94 { return kCalciteUserPassword; }
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:40
std::string const Calcite::getInternalSessionProxyUserName ( )
inline

Definition at line 93 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

93 { return kCalciteUserName; }
constexpr char const * kCalciteUserName
Definition: Calcite.h:39

+ Here is the caller graph for this function:

std::string Calcite::getRuntimeExtensionFunctionWhitelist ( )

Definition at line 581 of file Calcite.cpp.

References logger::FATAL, getClient(), LOG, remote_calcite_port_, server_available_, UNREACHABLE, and VLOG.

581  {
582  if (server_available_) {
583  TPlanResult ret;
584  std::string whitelist;
585  auto clientP = getClient(remote_calcite_port_);
586  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
587  clientP.second->close();
588  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
589  return whitelist;
590  } else {
591  LOG(FATAL) << "Not routing to Calcite, server is not up";
592  return "";
593  }
594  UNREACHABLE();
595  return "";
596 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:237
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187
#define VLOG(n)
Definition: Logger.h:283

+ Here is the call graph for this function:

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 535 of file Calcite.cpp.

References logger::FATAL, getClient(), LOG, remote_calcite_port_, server_available_, UNREACHABLE, and VLOG.

535  {
536  if (server_available_) {
537  TPlanResult ret;
538  std::string whitelist;
539 
540  auto clientP = getClient(remote_calcite_port_);
541  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
542  clientP.second->close();
543  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
544  return whitelist;
545  } else {
546  LOG(FATAL) << "Not routing to Calcite, server is not up";
547  return "";
548  }
549  UNREACHABLE();
550  return "";
551 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:237
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187
#define VLOG(n)
Definition: Logger.h:283

+ Here is the call graph for this function:

void Calcite::init ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  udf_filename 
)
private

Definition at line 293 of file Calcite.cpp.

References CHECK(), connMgr_, logger::INFO, LOG, remote_calcite_port_, runServer(), and server_available_.

Referenced by Calcite().

297  {
298  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
299  << " base data dir is " << data_dir;
300  connMgr_ = std::make_shared<ThriftClientConnection>();
301  if (calcite_port < 0) {
302  CHECK(false) << "JNI mode no longer supported.";
303  }
304  if (calcite_port == 0) {
305  // dummy process for initdb
306  remote_calcite_port_ = calcite_port;
307  server_available_ = false;
308  } else {
309  remote_calcite_port_ = calcite_port;
310  runServer(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
311  server_available_ = true;
312  }
313 }
#define LOG(tag)
Definition: Logger.h:188
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:121
CHECK(cgen_state)
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
void runServer(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:205

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Calcite::inner_close_calcite_server ( bool  log)
private

Definition at line 558 of file Calcite.cpp.

References getClient(), logger::INFO, LOG_IF, remote_calcite_port_, and server_available_.

Referenced by close_calcite_server().

558  {
559  if (server_available_) {
560  LOG_IF(INFO, log) << "Shutting down Calcite server";
561  try {
562  auto clientP = getClient(remote_calcite_port_);
563  clientP.first->shutdown();
564  clientP.second->close();
565  } catch (const std::exception& e) {
566  if (std::string(e.what()) != "connect() failed: Connection refused" &&
567  std::string(e.what()) != "socket open() error: Connection refused" &&
568  std::string(e.what()) != "No more data to read.") {
569  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
570  } // else Calcite already shut down
571  }
572  LOG_IF(INFO, log) << "shut down Calcite";
573  server_available_ = false;
574  }
575 }
#define LOG_IF(severity, condition)
Definition: Logger.h:279
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Calcite::ping ( int  retry_num = 0,
int  max_retry = 50 
)
private

Definition at line 267 of file Calcite.cpp.

References logger::ERROR, measure< TimeT >::execution(), and LOG.

267  {
268  try {
269  auto ms = measure<>::execution([&]() {
270  auto clientP = getClient(remote_calcite_port_);
271  clientP.first->ping();
272  clientP.second->close();
273  });
274  return ms;
275 
276  } catch (TException& tx) {
277  if (retry_num >= max_retry) {
278  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
279  }
280  return -1;
281  }
282 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:123
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

TPlanResult Calcite::process ( query_state::QueryStateProxy  query_state_proxy,
std::string  sql_string,
const std::vector< TFilterPushDownInfo > &  filter_push_down_info,
const bool  legacy_syntax,
const bool  is_explain,
const bool  is_view_optimize,
const std::string &  calcite_session_id = "" 
)

Definition at line 381 of file Calcite.cpp.

References checkPermissionForTables(), AccessPrivileges::DELETE_FROM_TABLE, query_state::QueryState::getConstSessionInfo(), query_state::QueryStateProxy::getQueryState(), AccessPrivileges::INSERT_INTO_TABLE, processImpl(), run_benchmark_import::result, AccessPrivileges::SELECT_FROM_TABLE, AccessPrivileges::SELECT_FROM_VIEW, and AccessPrivileges::UPDATE_IN_TABLE.

388  {
389  TPlanResult result = processImpl(query_state_proxy,
390  std::move(sql_string),
391  filter_push_down_info,
392  legacy_syntax,
393  is_explain,
394  is_view_optimize,
395  calcite_session_id);
396 
397  AccessPrivileges NOOP;
398 
399  if (!is_explain) {
400  // check the individual tables
401  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
402  checkPermissionForTables(*session_ptr,
403  result.primary_accessed_objects.tables_selected_from,
406  checkPermissionForTables(*session_ptr,
407  result.primary_accessed_objects.tables_inserted_into,
409  NOOP);
410  checkPermissionForTables(*session_ptr,
411  result.primary_accessed_objects.tables_updated_in,
413  NOOP);
414  checkPermissionForTables(*session_ptr,
415  result.primary_accessed_objects.tables_deleted_from,
417  NOOP);
418  }
419 
420  return result;
421 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
TPlanResult processImpl(query_state::QueryStateProxy, std::string sql_string, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool legacy_syntax, const bool is_explain, const bool is_view_optimize, const std::string &calcite_session_id)
Definition: Calcite.cpp:458
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:153
QueryState & getQueryState()
Definition: QueryState.h:172
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:156
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:173
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:155
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:345

+ Here is the call graph for this function:

TPlanResult Calcite::processImpl ( query_state::QueryStateProxy  query_state_proxy,
std::string  sql_string,
const std::vector< TFilterPushDownInfo > &  filter_push_down_info,
const bool  legacy_syntax,
const bool  is_explain,
const bool  is_view_optimize,
const std::string &  calcite_session_id 
)
private

Definition at line 458 of file Calcite.cpp.

References query_state::QueryStateProxy::createTimer(), measure< TimeT >::execution(), logger::FATAL, getClient(), query_state::QueryState::getConstSessionInfo(), getInternalSessionProxyUserName(), query_state::QueryStateProxy::getQueryState(), logger::INFO, logger::IR, LOG, logger::PTX, remote_calcite_port_, and server_available_.

Referenced by process().

465  {
466  query_state::Timer timer = query_state_proxy.createTimer(__func__);
467  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
468  const auto& cat = user_session_info->getCatalog();
469  const std::string user = getInternalSessionProxyUserName();
470  const std::string catalog = cat.getCurrentDB().dbName;
471  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
472  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
473  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
474 
475  TPlanResult ret;
476  if (server_available_) {
477  try {
478  // calcite_session_id would be an empty string when accessed by internal resources
479  // that would not access `process` through handler instance, like for eg: Unit
480  // Tests. In these cases we would use the session_id from query state.
481  auto ms = measure<>::execution([&]() {
482  auto clientP = getClient(remote_calcite_port_);
483  clientP.first->process(ret,
484  user,
485  calcite_session_id.empty()
486  ? user_session_info->get_session_id()
487  : calcite_session_id,
488  catalog,
489  sql_string,
490  filter_push_down_info,
491  legacy_syntax,
492  is_explain,
493  is_view_optimize);
494  clientP.second->close();
495  });
496 
497  // LOG(INFO) << ret.plan_result;
498  LOG(INFO) << "Time in Thrift "
499  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
500  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
501  << " (ms)";
502  } catch (InvalidParseRequest& e) {
503  throw std::invalid_argument(e.whyUp);
504  } catch (const std::exception& ex) {
505  LOG(FATAL)
506  << "Error occurred trying to communicate with Calcite server, the error was: '"
507  << ex.what() << "', omnisci_server restart will be required";
508  return ret; // satisfy return-type warning
509  }
510  } else {
511  LOG(INFO) << "Not routing to Calcite, server is not up";
512  ret.plan_result = "";
513  }
514  return ret;
515 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
QueryState & getQueryState()
Definition: QueryState.h:172
int remote_calcite_port_
Definition: Calcite.h:123
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:93
bool server_available_
Definition: Calcite.h:122
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Calcite::runServer ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  udf_filename 
)
private

Definition at line 205 of file Calcite.cpp.

References logger::ERROR, logger::FATAL, logger::INFO, LOG, and start_calcite_server_as_daemon().

Referenced by init().

209  {
210  LOG(INFO) << "Running Calcite server as a daemon";
211 
212  // ping server to see if for any reason there is an orphaned one
213  int ping_time = ping();
214  if (ping_time > -1) {
215  // we have an orphaned server shut it down
216  LOG(ERROR)
217  << "Appears to be orphaned Calcite server already running, shutting it down";
218  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
219  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
220  try {
221  auto clientP = getClient(remote_calcite_port_);
222  clientP.first->shutdown();
223  clientP.second->close();
224  LOG(ERROR) << "orphaned Calcite server shutdown";
225 
226  } catch (TException& tx) {
227  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
228  }
229  }
230 
231  // start the calcite server as a seperate process
233  port,
234  data_dir,
235  calcite_max_mem,
242  udf_filename);
243 
244  // check for new server for 5 seconds max
245  std::this_thread::sleep_for(std::chrono::milliseconds(200));
246  int retry_max = 50;
247  for (int i = 2; i <= retry_max; i++) {
248  int ping_time = ping(i, retry_max);
249  if (ping_time > -1) {
250  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
251  LOG(INFO) << "ping took " << ping_time << " ms ";
252  server_available_ = true;
253  return;
254  } else {
255  // wait 100 ms
256  std::this_thread::sleep_for(std::chrono::milliseconds(100));
257  }
258  }
259  server_available_ = false;
260  LOG(FATAL) << "Could not connect to Calcite remote server running on port [" << port
261  << "]";
262 }
std::string ssl_key_file_
Definition: Calcite.h:126
#define LOG(tag)
Definition: Logger.h:188
std::string ssl_keystore_
Definition: Calcite.h:127
std::string ssl_keystore_password_
Definition: Calcite.h:128
std::string ssl_trust_store_
Definition: Calcite.h:124
int ping(int retry_num=0, int max_retry=50)
Definition: Calcite.cpp:267
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_X, const std::string &ssl_keystore, const std::string &ssl_keystore_password_X, const std::string &ssl_key_file, const std::string &mapd_config_file, const std::string &udf_filename)
Definition: Calcite.cpp:68
int remote_calcite_port_
Definition: Calcite.h:123
std::string mapd_config_file_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:122
std::string ssl_trust_password_
Definition: Calcite.h:125
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Calcite::setRuntimeExtensionFunctions ( const std::vector< TUserDefinedFunction > &  udfs,
const std::vector< TUserDefinedTableFunction > &  udtfs 
)

Definition at line 598 of file Calcite.cpp.

References logger::FATAL, getClient(), LOG, remote_calcite_port_, and server_available_.

600  {
601  if (server_available_) {
602  auto clientP = getClient(remote_calcite_port_);
603  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
604  clientP.second->close();
605  } else {
606  LOG(FATAL) << "Not routing to Calcite, server is not up";
607  }
608 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

void Calcite::updateMetadata ( std::string  catalog,
std::string  table 
)

Definition at line 332 of file Calcite.cpp.

References measure< TimeT >::execution(), getClient(), logger::INFO, LOG, remote_calcite_port_, and server_available_.

332  {
333  if (server_available_) {
334  auto ms = measure<>::execution([&]() {
335  auto clientP = getClient(remote_calcite_port_);
336  clientP.first->updateMetadata(catalog, table);
337  clientP.second->close();
338  });
339  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
340  } else {
341  LOG(INFO) << "Not routing to Calcite, server is not up";
342  }
343 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187

+ Here is the call graph for this function:

Member Data Documentation

mapd::shared_ptr<ThriftClientConnection> Calcite::connMgr_
private

Definition at line 121 of file Calcite.h.

Referenced by init().

std::string Calcite::mapd_config_file_
private

Definition at line 130 of file Calcite.h.

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 131 of file Calcite.h.

Referenced by close_calcite_server().

std::string Calcite::ssl_ca_file_
private

Definition at line 129 of file Calcite.h.

std::string Calcite::ssl_key_file_
private

Definition at line 126 of file Calcite.h.

std::string Calcite::ssl_keystore_
private

Definition at line 127 of file Calcite.h.

std::string Calcite::ssl_keystore_password_
private

Definition at line 128 of file Calcite.h.

std::string Calcite::ssl_trust_password_
private

Definition at line 125 of file Calcite.h.

std::string Calcite::ssl_trust_store_
private

Definition at line 124 of file Calcite.h.


The documentation for this class was generated from the following files: