OmniSciDB  8a228a1076
Calcite Class Referencefinal

#include <Calcite.h>

+ Collaboration diagram for Calcite:

Public Member Functions

 Calcite (const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const size_t service_timeout, const bool service_keepalive, const std::string &udf_filename="")
 
 Calcite (const SystemParameters &db_parameters, 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 bool check_privileges, const std::string &calcite_session_id="")
 
void checkAccessedObjectsPrivileges (query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
 
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 db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
 
void runServer (const int db_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< ThriftClientConnectionconnMgr_
 
bool server_available_
 
size_t service_timeout_
 
bool service_keepalive_ = true
 
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 db_config_file_
 
std::once_flag shutdown_once_flag_
 

Detailed Description

Definition at line 61 of file Calcite.h.

Constructor & Destructor Documentation

◆ Calcite() [1/2]

Calcite::Calcite ( const int  db_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const size_t  service_timeout,
const bool  service_keepalive,
const std::string &  udf_filename = "" 
)

Definition at line 289 of file Calcite.cpp.

References init().

296  : server_available_(false)
297  , service_timeout_(service_timeout)
298  , service_keepalive_(service_keepalive) {
299  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
300 }
void init(const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:302
bool service_keepalive_
Definition: Calcite.h:128
size_t service_timeout_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:126
+ Here is the call graph for this function:

◆ Calcite() [2/2]

Calcite::Calcite ( const SystemParameters db_parameters,
const std::string &  data_dir,
const std::string &  udf_filename = "" 
)

Definition at line 324 of file Calcite.cpp.

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

327  : service_timeout_(system_parameters.calcite_timeout)
328  , service_keepalive_(system_parameters.calcite_keepalive)
329  , ssl_trust_store_(system_parameters.ssl_trust_store)
330  , ssl_trust_password_(system_parameters.ssl_trust_password)
331  , ssl_key_file_(system_parameters.ssl_key_file)
332  , ssl_keystore_(system_parameters.ssl_keystore)
333  , ssl_keystore_password_(system_parameters.ssl_keystore_password)
334  , ssl_ca_file_(system_parameters.ssl_trust_ca_file)
335  , db_config_file_(system_parameters.config_file) {
336  init(system_parameters.omnisci_server_port,
337  system_parameters.calcite_port,
338  data_dir,
339  system_parameters.calcite_max_mem,
340  udf_filename);
341 }
std::string db_config_file_
Definition: Calcite.h:136
std::string ssl_key_file_
Definition: Calcite.h:132
void init(const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:302
std::string ssl_keystore_
Definition: Calcite.h:133
std::string ssl_keystore_password_
Definition: Calcite.h:134
std::string ssl_trust_store_
Definition: Calcite.h:130
bool service_keepalive_
Definition: Calcite.h:128
std::string ssl_ca_file_
Definition: Calcite.h:135
size_t service_timeout_
Definition: Calcite.h:127
std::string ssl_trust_password_
Definition: Calcite.h:131
+ Here is the call graph for this function:

◆ ~Calcite()

Calcite::~Calcite ( )

Definition at line 591 of file Calcite.cpp.

References close_calcite_server().

591  {
592  close_calcite_server(false);
593 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:567
+ Here is the call graph for this function:

Member Function Documentation

◆ checkAccessedObjectsPrivileges()

void Calcite::checkAccessedObjectsPrivileges ( query_state::QueryStateProxy  query_state_prox,
TPlanResult  plan 
) const

Definition at line 414 of file Calcite.cpp.

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

Referenced by process().

416  {
417  AccessPrivileges NOOP;
418  // check the individual tables
419  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
420  checkPermissionForTables(*session_ptr,
421  plan.primary_accessed_objects.tables_selected_from,
424  checkPermissionForTables(*session_ptr,
425  plan.primary_accessed_objects.tables_inserted_into,
427  NOOP);
428  checkPermissionForTables(*session_ptr,
429  plan.primary_accessed_objects.tables_updated_in,
431  NOOP);
432  checkPermissionForTables(*session_ptr,
433  plan.primary_accessed_objects.tables_deleted_from,
435  NOOP);
436 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:162
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:161
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:164
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:181
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:163
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:356
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close_calcite_server()

void Calcite::close_calcite_server ( bool  log = true)

Definition at line 567 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

567  {
568  std::call_once(shutdown_once_flag_,
569  [this, log]() { this->inner_close_calcite_server(log); });
570 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:137
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:572
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_db_objects()

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

Definition at line 454 of file Calcite.cpp.

References CHECK.

454  {
455  std::vector<std::string> v_db_obj;
456  Document document;
457  document.Parse(ra.c_str());
458  const Value& rels = document["rels"];
459  CHECK(rels.IsArray());
460  for (auto& v : rels.GetArray()) {
461  std::string relOp(v["relOp"].GetString());
462  if (!relOp.compare("EnumerableTableScan")) {
463  std::string x;
464  auto t = v["table"].GetArray();
465  x = t[1].GetString();
466  v_db_obj.push_back(x);
467  }
468  }
469 
470  return v_db_obj;
471 }
#define CHECK(condition)
Definition: Logger.h:197

◆ getClient()

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

Definition at line 186 of file Calcite.cpp.

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

186  {
187  const auto transport = connMgr_->open_buffered_client_transport("localhost",
188  port,
189  ssl_ca_file_,
190  true,
192  2000,
195  try {
196  transport->open();
197 
198  } catch (TException& tx) {
199  throw tx;
200  } catch (std::exception& ex) {
201  throw ex;
202  }
203  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
204  mapd::shared_ptr<CalciteServerClient> client;
205  client.reset(new CalciteServerClient(protocol));
206  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
207  return std::make_pair(client, transport);
208 }
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:125
bool service_keepalive_
Definition: Calcite.h:128
std::string ssl_ca_file_
Definition: Calcite.h:135
size_t service_timeout_
Definition: Calcite.h:127
+ Here is the caller graph for this function:

◆ getCompletionHints()

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

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

442  {
443  std::vector<TCompletionHint> hints;
444  auto& cat = session_info.getCatalog();
445  const auto user = session_info.get_currentUser().userName;
446  const auto session = session_info.get_session_id();
447  const auto catalog = cat.getCurrentDB().dbName;
448  auto client = getClient(remote_calcite_port_);
449  client.first->getCompletionHints(
450  hints, user, session, catalog, visible_tables, sql_string, cursor);
451  return hints;
452 }
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
std::string get_session_id() const
Definition: SessionInfo.h:73
std::string cat(Ts &&... args)
Catalog & getCatalog() const
Definition: SessionInfo.h:65
int remote_calcite_port_
Definition: Calcite.h:129
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:

◆ getExtensionFunctionWhitelist()

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 531 of file Calcite.cpp.

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

531  {
532  if (server_available_) {
533  TPlanResult ret;
534  std::string whitelist;
535 
536  auto clientP = getClient(remote_calcite_port_);
537  clientP.first->getExtensionFunctionWhitelist(whitelist);
538  clientP.second->close();
539  VLOG(1) << whitelist;
540  return whitelist;
541  } else {
542  LOG(FATAL) << "Not routing to Calcite, server is not up";
543  return "";
544  }
545  CHECK(false);
546  return "";
547 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:197
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
#define VLOG(n)
Definition: Logger.h:291
+ Here is the call graph for this function:

◆ getInternalSessionProxyPassword()

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

Definition at line 98 of file Calcite.h.

References logger::init(), and anonymous_namespace{Calcite.h}::kCalciteUserPassword.

98 { return kCalciteUserPassword; }
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:39
+ Here is the call graph for this function:

◆ getInternalSessionProxyUserName()

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

Definition at line 97 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

97 { return kCalciteUserName; }
constexpr char const * kCalciteUserName
Definition: Calcite.h:38
+ Here is the caller graph for this function:

◆ getRuntimeExtensionFunctionWhitelist()

std::string Calcite::getRuntimeExtensionFunctionWhitelist ( )

Definition at line 595 of file Calcite.cpp.

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

595  {
596  if (server_available_) {
597  TPlanResult ret;
598  std::string whitelist;
599  auto clientP = getClient(remote_calcite_port_);
600  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
601  clientP.second->close();
602  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
603  return whitelist;
604  } else {
605  LOG(FATAL) << "Not routing to Calcite, server is not up";
606  return "";
607  }
608  UNREACHABLE();
609  return "";
610 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
#define VLOG(n)
Definition: Logger.h:291
+ Here is the call graph for this function:

◆ getUserDefinedFunctionWhitelist()

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 549 of file Calcite.cpp.

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

549  {
550  if (server_available_) {
551  TPlanResult ret;
552  std::string whitelist;
553 
554  auto clientP = getClient(remote_calcite_port_);
555  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
556  clientP.second->close();
557  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
558  return whitelist;
559  } else {
560  LOG(FATAL) << "Not routing to Calcite, server is not up";
561  return "";
562  }
563  UNREACHABLE();
564  return "";
565 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
#define VLOG(n)
Definition: Logger.h:291
+ Here is the call graph for this function:

◆ init()

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

Definition at line 302 of file Calcite.cpp.

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

Referenced by Calcite().

306  {
307  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
308  << " base data dir is " << data_dir;
309  connMgr_ = std::make_shared<ThriftClientConnection>();
310  if (calcite_port < 0) {
311  CHECK(false) << "JNI mode no longer supported.";
312  }
313  if (calcite_port == 0) {
314  // dummy process for initdb
315  remote_calcite_port_ = calcite_port;
316  server_available_ = false;
317  } else {
318  remote_calcite_port_ = calcite_port;
319  runServer(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
320  server_available_ = true;
321  }
322 }
#define LOG(tag)
Definition: Logger.h:188
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:125
void runServer(const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:210
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inner_close_calcite_server()

void Calcite::inner_close_calcite_server ( bool  log)
private

Definition at line 572 of file Calcite.cpp.

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

Referenced by close_calcite_server().

572  {
573  if (server_available_) {
574  LOG_IF(INFO, log) << "Shutting down Calcite server";
575  try {
576  auto clientP = getClient(remote_calcite_port_);
577  clientP.first->shutdown();
578  clientP.second->close();
579  } catch (const std::exception& e) {
580  if (std::string(e.what()) != "connect() failed: Connection refused" &&
581  std::string(e.what()) != "socket open() error: Connection refused" &&
582  std::string(e.what()) != "No more data to read.") {
583  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
584  } // else Calcite already shut down
585  }
586  LOG_IF(INFO, log) << "shut down Calcite";
587  server_available_ = false;
588  }
589 }
#define LOG_IF(severity, condition)
Definition: Logger.h:287
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ping()

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

Definition at line 272 of file Calcite.cpp.

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

272  {
273  try {
274  auto ms = measure<>::execution([&]() {
275  auto clientP = getClient(remote_calcite_port_);
276  clientP.first->ping();
277  clientP.second->close();
278  });
279  return ms;
280 
281  } catch (TException& tx) {
282  if (retry_num >= max_retry) {
283  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
284  }
285  return -1;
286  }
287 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:

◆ process()

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 bool  check_privileges,
const std::string &  calcite_session_id = "" 
)

Definition at line 392 of file Calcite.cpp.

References checkAccessedObjectsPrivileges(), processImpl(), and run_benchmark_import::result.

400  {
401  TPlanResult result = processImpl(query_state_proxy,
402  std::move(sql_string),
403  filter_push_down_info,
404  legacy_syntax,
405  is_explain,
406  is_view_optimize,
407  calcite_session_id);
408  if (check_privileges && !is_explain) {
409  checkAccessedObjectsPrivileges(query_state_proxy, result);
410  }
411  return result;
412 }
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:473
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:414
+ Here is the call graph for this function:

◆ processImpl()

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

References cat(), 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().

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

◆ runServer()

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

Definition at line 210 of file Calcite.cpp.

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

Referenced by init().

214  {
215  LOG(INFO) << "Running Calcite server as a daemon";
216 
217  // ping server to see if for any reason there is an orphaned one
218  int ping_time = ping();
219  if (ping_time > -1) {
220  // we have an orphaned server shut it down
221  LOG(ERROR)
222  << "Appears to be orphaned Calcite server already running, shutting it down";
223  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
224  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
225  try {
226  auto clientP = getClient(remote_calcite_port_);
227  clientP.first->shutdown();
228  clientP.second->close();
229  LOG(ERROR) << "orphaned Calcite server shutdown";
230 
231  } catch (TException& tx) {
232  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
233  }
234  }
235 
236  // start the calcite server as a seperate process
238  port,
239  data_dir,
240  calcite_max_mem,
247  udf_filename);
248 
249  // check for new server for 30 seconds max
250  std::this_thread::sleep_for(std::chrono::milliseconds(200));
251  int retry_max = 300;
252  for (int i = 2; i <= retry_max; i++) {
253  int ping_time = ping(i, retry_max);
254  if (ping_time > -1) {
255  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
256  LOG(INFO) << "ping took " << ping_time << " ms ";
257  server_available_ = true;
258  return;
259  } else {
260  // wait 100 ms
261  std::this_thread::sleep_for(std::chrono::milliseconds(100));
262  }
263  }
264  server_available_ = false;
265  LOG(FATAL) << "Could not connect to Calcite remote server running on port [" << port
266  << "]";
267 }
std::string db_config_file_
Definition: Calcite.h:136
std::string ssl_key_file_
Definition: Calcite.h:132
#define LOG(tag)
Definition: Logger.h:188
std::string ssl_keystore_
Definition: Calcite.h:133
std::string ssl_keystore_password_
Definition: Calcite.h:134
std::string ssl_trust_store_
Definition: Calcite.h:130
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)
Definition: Calcite.cpp:68
int ping(int retry_num=0, int max_retry=50)
Definition: Calcite.cpp:272
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::string ssl_trust_password_
Definition: Calcite.h:131
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRuntimeExtensionFunctions()

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

Definition at line 612 of file Calcite.cpp.

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

614  {
615  if (server_available_) {
616  auto clientP = getClient(remote_calcite_port_);
617  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
618  clientP.second->close();
619  } else {
620  LOG(FATAL) << "Not routing to Calcite, server is not up";
621  }
622 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:

◆ updateMetadata()

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

Definition at line 343 of file Calcite.cpp.

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

343  {
344  if (server_available_) {
345  auto ms = measure<>::execution([&]() {
346  auto clientP = getClient(remote_calcite_port_);
347  clientP.first->updateMetadata(catalog, table);
348  clientP.second->close();
349  });
350  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
351  } else {
352  LOG(INFO) << "Not routing to Calcite, server is not up";
353  }
354 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:186
+ Here is the call graph for this function:

Member Data Documentation

◆ connMgr_

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

Definition at line 125 of file Calcite.h.

Referenced by init().

◆ db_config_file_

std::string Calcite::db_config_file_
private

Definition at line 136 of file Calcite.h.

◆ remote_calcite_port_

◆ server_available_

◆ service_keepalive_

bool Calcite::service_keepalive_ = true
private

Definition at line 128 of file Calcite.h.

◆ service_timeout_

size_t Calcite::service_timeout_
private

Definition at line 127 of file Calcite.h.

◆ shutdown_once_flag_

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 137 of file Calcite.h.

Referenced by close_calcite_server().

◆ ssl_ca_file_

std::string Calcite::ssl_ca_file_
private

Definition at line 135 of file Calcite.h.

◆ ssl_key_file_

std::string Calcite::ssl_key_file_
private

Definition at line 132 of file Calcite.h.

◆ ssl_keystore_

std::string Calcite::ssl_keystore_
private

Definition at line 133 of file Calcite.h.

◆ ssl_keystore_password_

std::string Calcite::ssl_keystore_password_
private

Definition at line 134 of file Calcite.h.

◆ ssl_trust_password_

std::string Calcite::ssl_trust_password_
private

Definition at line 131 of file Calcite.h.

◆ ssl_trust_store_

std::string Calcite::ssl_trust_store_
private

Definition at line 130 of file Calcite.h.


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