OmniSciDB  ab4938a6a3
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 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_
 
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 std::string &  udf_filename = "" 
)

Definition at line 283 of file Calcite.cpp.

References init().

289  : server_available_(false), service_timeout_(service_timeout) {
290  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
291 }
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:293
size_t service_timeout_
Definition: Calcite.h:126
bool server_available_
Definition: Calcite.h:125
+ 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 315 of file Calcite.cpp.

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

318  : service_timeout_(system_parameters.calcite_timeout)
319  , ssl_trust_store_(system_parameters.ssl_trust_store)
320  , ssl_trust_password_(system_parameters.ssl_trust_password)
321  , ssl_key_file_(system_parameters.ssl_key_file)
322  , ssl_keystore_(system_parameters.ssl_keystore)
323  , ssl_keystore_password_(system_parameters.ssl_keystore_password)
324  , ssl_ca_file_(system_parameters.ssl_trust_ca_file)
325  , db_config_file_(system_parameters.config_file) {
326  init(system_parameters.omnisci_server_port,
327  system_parameters.calcite_port,
328  data_dir,
329  system_parameters.calcite_max_mem,
330  udf_filename);
331 }
std::string db_config_file_
Definition: Calcite.h:134
std::string ssl_key_file_
Definition: Calcite.h:130
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:293
std::string ssl_keystore_
Definition: Calcite.h:131
std::string ssl_keystore_password_
Definition: Calcite.h:132
std::string ssl_trust_store_
Definition: Calcite.h:128
std::string ssl_ca_file_
Definition: Calcite.h:133
size_t service_timeout_
Definition: Calcite.h:126
std::string ssl_trust_password_
Definition: Calcite.h:129
+ Here is the call graph for this function:

◆ ~Calcite()

Calcite::~Calcite ( )

Definition at line 581 of file Calcite.cpp.

References close_calcite_server().

581  {
582  close_calcite_server(false);
583 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:557
+ 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 404 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().

406  {
407  AccessPrivileges NOOP;
408  // check the individual tables
409  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
410  checkPermissionForTables(*session_ptr,
411  plan.primary_accessed_objects.tables_selected_from,
414  checkPermissionForTables(*session_ptr,
415  plan.primary_accessed_objects.tables_inserted_into,
417  NOOP);
418  checkPermissionForTables(*session_ptr,
419  plan.primary_accessed_objects.tables_updated_in,
421  NOOP);
422  checkPermissionForTables(*session_ptr,
423  plan.primary_accessed_objects.tables_deleted_from,
425  NOOP);
426 }
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:346
+ 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 557 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

557  {
558  std::call_once(shutdown_once_flag_,
559  [this, log]() { this->inner_close_calcite_server(log); });
560 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:135
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:562
+ 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 444 of file Calcite.cpp.

References CHECK.

444  {
445  std::vector<std::string> v_db_obj;
446  Document document;
447  document.Parse(ra.c_str());
448  const Value& rels = document["rels"];
449  CHECK(rels.IsArray());
450  for (auto& v : rels.GetArray()) {
451  std::string relOp(v["relOp"].GetString());
452  if (!relOp.compare("EnumerableTableScan")) {
453  std::string x;
454  auto t = v["table"].GetArray();
455  x = t[1].GetString();
456  v_db_obj.push_back(x);
457  }
458  }
459 
460  return v_db_obj;
461 }
#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(
188  "localhost", port, ssl_ca_file_, true, 2000, service_timeout_, service_timeout_);
189  try {
190  transport->open();
191 
192  } catch (TException& tx) {
193  throw tx;
194  } catch (std::exception& ex) {
195  throw ex;
196  }
197  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
198  mapd::shared_ptr<CalciteServerClient> client;
199  client.reset(new CalciteServerClient(protocol));
200  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
201  return std::make_pair(client, transport);
202 }
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:124
std::string ssl_ca_file_
Definition: Calcite.h:133
size_t service_timeout_
Definition: Calcite.h:126
+ 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 428 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.

432  {
433  std::vector<TCompletionHint> hints;
434  auto& cat = session_info.getCatalog();
435  const auto user = session_info.get_currentUser().userName;
436  const auto session = session_info.get_session_id();
437  const auto catalog = cat.getCurrentDB().dbName;
438  auto client = getClient(remote_calcite_port_);
439  client.first->getCompletionHints(
440  hints, user, session, catalog, visible_tables, sql_string, cursor);
441  return hints;
442 }
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:127
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 521 of file Calcite.cpp.

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

521  {
522  if (server_available_) {
523  TPlanResult ret;
524  std::string whitelist;
525 
526  auto clientP = getClient(remote_calcite_port_);
527  clientP.first->getExtensionFunctionWhitelist(whitelist);
528  clientP.second->close();
529  VLOG(1) << whitelist;
530  return whitelist;
531  } else {
532  LOG(FATAL) << "Not routing to Calcite, server is not up";
533  return "";
534  }
535  CHECK(false);
536  return "";
537 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
#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 97 of file Calcite.h.

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

97 { 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 96 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

96 { 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 585 of file Calcite.cpp.

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

585  {
586  if (server_available_) {
587  TPlanResult ret;
588  std::string whitelist;
589  auto clientP = getClient(remote_calcite_port_);
590  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
591  clientP.second->close();
592  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
593  return whitelist;
594  } else {
595  LOG(FATAL) << "Not routing to Calcite, server is not up";
596  return "";
597  }
598  UNREACHABLE();
599  return "";
600 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
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 539 of file Calcite.cpp.

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

539  {
540  if (server_available_) {
541  TPlanResult ret;
542  std::string whitelist;
543 
544  auto clientP = getClient(remote_calcite_port_);
545  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
546  clientP.second->close();
547  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
548  return whitelist;
549  } else {
550  LOG(FATAL) << "Not routing to Calcite, server is not up";
551  return "";
552  }
553  UNREACHABLE();
554  return "";
555 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
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 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(db_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:124
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:204
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
#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 562 of file Calcite.cpp.

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

Referenced by close_calcite_server().

562  {
563  if (server_available_) {
564  LOG_IF(INFO, log) << "Shutting down Calcite server";
565  try {
566  auto clientP = getClient(remote_calcite_port_);
567  clientP.first->shutdown();
568  clientP.second->close();
569  } catch (const std::exception& e) {
570  if (std::string(e.what()) != "connect() failed: Connection refused" &&
571  std::string(e.what()) != "socket open() error: Connection refused" &&
572  std::string(e.what()) != "No more data to read.") {
573  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
574  } // else Calcite already shut down
575  }
576  LOG_IF(INFO, log) << "shut down Calcite";
577  server_available_ = false;
578  }
579 }
#define LOG_IF(severity, condition)
Definition: Logger.h:287
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
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 266 of file Calcite.cpp.

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

266  {
267  try {
268  auto ms = measure<>::execution([&]() {
269  auto clientP = getClient(remote_calcite_port_);
270  clientP.first->ping();
271  clientP.second->close();
272  });
273  return ms;
274 
275  } catch (TException& tx) {
276  if (retry_num >= max_retry) {
277  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
278  }
279  return -1;
280  }
281 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:127
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 382 of file Calcite.cpp.

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

390  {
391  TPlanResult result = processImpl(query_state_proxy,
392  std::move(sql_string),
393  filter_push_down_info,
394  legacy_syntax,
395  is_explain,
396  is_view_optimize,
397  calcite_session_id);
398  if (check_privileges && !is_explain) {
399  checkAccessedObjectsPrivileges(query_state_proxy, result);
400  }
401  return result;
402 }
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:463
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:404
+ 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 463 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().

470  {
471  query_state::Timer timer = query_state_proxy.createTimer(__func__);
472  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
473  const auto& cat = user_session_info->getCatalog();
474  const std::string user = getInternalSessionProxyUserName();
475  const std::string catalog = cat.getCurrentDB().dbName;
476  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
477  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
478  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
479 
480  TPlanResult ret;
481  if (server_available_) {
482  try {
483  // calcite_session_id would be an empty string when accessed by internal resources
484  // that would not access `process` through handler instance, like for eg: Unit
485  // Tests. In these cases we would use the session_id from query state.
486  auto ms = measure<>::execution([&]() {
487  auto clientP = getClient(remote_calcite_port_);
488  clientP.first->process(ret,
489  user,
490  calcite_session_id.empty()
491  ? user_session_info->get_session_id()
492  : calcite_session_id,
493  catalog,
494  sql_string,
495  filter_push_down_info,
496  legacy_syntax,
497  is_explain,
498  is_view_optimize);
499  clientP.second->close();
500  });
501 
502  // LOG(INFO) << ret.plan_result;
503  LOG(INFO) << "Time in Thrift "
504  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
505  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
506  << " (ms)";
507  } catch (InvalidParseRequest& e) {
508  throw std::invalid_argument(e.whyUp);
509  } catch (const std::exception& ex) {
510  LOG(FATAL)
511  << "Error occurred trying to communicate with Calcite server, the error was: '"
512  << ex.what() << "', omnisci_server restart will be required";
513  return ret; // satisfy return-type warning
514  }
515  } else {
516  LOG(FATAL) << "Not routing to Calcite, server is not up";
517  }
518  return ret;
519 }
#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:127
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:96
bool server_available_
Definition: Calcite.h:125
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 204 of file Calcite.cpp.

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

Referenced by init().

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

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

604  {
605  if (server_available_) {
606  auto clientP = getClient(remote_calcite_port_);
607  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
608  clientP.second->close();
609  } else {
610  LOG(FATAL) << "Not routing to Calcite, server is not up";
611  }
612 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
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 333 of file Calcite.cpp.

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

333  {
334  if (server_available_) {
335  auto ms = measure<>::execution([&]() {
336  auto clientP = getClient(remote_calcite_port_);
337  clientP.first->updateMetadata(catalog, table);
338  clientP.second->close();
339  });
340  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
341  } else {
342  LOG(INFO) << "Not routing to Calcite, server is not up";
343  }
344 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:127
bool server_available_
Definition: Calcite.h:125
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 124 of file Calcite.h.

Referenced by init().

◆ db_config_file_

std::string Calcite::db_config_file_
private

Definition at line 134 of file Calcite.h.

◆ remote_calcite_port_

◆ server_available_

◆ service_timeout_

size_t Calcite::service_timeout_
private

Definition at line 126 of file Calcite.h.

◆ shutdown_once_flag_

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 135 of file Calcite.h.

Referenced by close_calcite_server().

◆ ssl_ca_file_

std::string Calcite::ssl_ca_file_
private

Definition at line 133 of file Calcite.h.

◆ ssl_key_file_

std::string Calcite::ssl_key_file_
private

Definition at line 130 of file Calcite.h.

◆ ssl_keystore_

std::string Calcite::ssl_keystore_
private

Definition at line 131 of file Calcite.h.

◆ ssl_keystore_password_

std::string Calcite::ssl_keystore_password_
private

Definition at line 132 of file Calcite.h.

◆ ssl_trust_password_

std::string Calcite::ssl_trust_password_
private

Definition at line 129 of file Calcite.h.

◆ ssl_trust_store_

std::string Calcite::ssl_trust_store_
private

Definition at line 128 of file Calcite.h.


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