OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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, bool isruntime=true)
 
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< std::shared_ptr
< CalciteServerClient >
, std::shared_ptr< TTransport > > 
getClient (int port)
 
int ping (int retry_num=0, int max_retry=50)
 

Private Attributes

std::shared_ptr
< ThriftClientConnection
connMgr_
 
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 60 of file Calcite.h.

Constructor & Destructor Documentation

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

References init().

360  : server_available_(false)
361  , service_timeout_(service_timeout)
362  , service_keepalive_(service_keepalive) {
363  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
364 }
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:366
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::Calcite ( const SystemParameters db_parameters,
const std::string &  data_dir,
const std::string &  udf_filename = "" 
)

Definition at line 388 of file Calcite.cpp.

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

391  : service_timeout_(system_parameters.calcite_timeout)
392  , service_keepalive_(system_parameters.calcite_keepalive)
393  , ssl_trust_store_(system_parameters.ssl_trust_store)
394  , ssl_trust_password_(system_parameters.ssl_trust_password)
395  , ssl_key_file_(system_parameters.ssl_key_file)
396  , ssl_keystore_(system_parameters.ssl_keystore)
397  , ssl_keystore_password_(system_parameters.ssl_keystore_password)
398  , ssl_ca_file_(system_parameters.ssl_trust_ca_file)
399  , db_config_file_(system_parameters.config_file) {
400  init(system_parameters.omnisci_server_port,
401  system_parameters.calcite_port,
402  data_dir,
403  system_parameters.calcite_max_mem,
404  udf_filename);
405 }
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:366
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 ( )

Definition at line 666 of file Calcite.cpp.

References close_calcite_server().

666  {
667  close_calcite_server(false);
668 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:642

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 481 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().

483  {
484  AccessPrivileges NOOP;
485  // check the individual tables
486  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
487  checkPermissionForTables(*session_ptr,
488  plan.primary_accessed_objects.tables_selected_from,
491  checkPermissionForTables(*session_ptr,
492  plan.primary_accessed_objects.tables_inserted_into,
494  NOOP);
495  checkPermissionForTables(*session_ptr,
496  plan.primary_accessed_objects.tables_updated_in,
498  NOOP);
499  checkPermissionForTables(*session_ptr,
500  plan.primary_accessed_objects.tables_deleted_from,
502  NOOP);
503 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:163
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:162
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::vector< std::string >> tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:420
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:165
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:182
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:164

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Calcite::close_calcite_server ( bool  log = true)

Definition at line 642 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

642  {
643  std::call_once(shutdown_once_flag_,
644  [this, log]() { this->inner_close_calcite_server(log); });
645 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:137
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:647

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

References CHECK, and t.

521  {
522  std::vector<std::string> v_db_obj;
523  Document document;
524  document.Parse(ra.c_str());
525  const Value& rels = document["rels"];
526  CHECK(rels.IsArray());
527  for (auto& v : rels.GetArray()) {
528  std::string relOp(v["relOp"].GetString());
529  if (!relOp.compare("EnumerableTableScan")) {
530  std::string x;
531  auto t = v["table"].GetArray();
532  x = t[1].GetString();
533  v_db_obj.push_back(x);
534  }
535  }
536 
537  return v_db_obj;
538 }
#define CHECK(condition)
Definition: Logger.h:211
char * t
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > Calcite::getClient ( int  port)
private

Definition at line 250 of file Calcite.cpp.

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

250  {
251  const auto transport = connMgr_->open_buffered_client_transport("localhost",
252  port,
253  ssl_ca_file_,
254  true,
259  try {
260  transport->open();
261 
262  } catch (TException& tx) {
263  throw tx;
264  } catch (std::exception& ex) {
265  throw ex;
266  }
267  std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
268  std::shared_ptr<CalciteServerClient> client;
269  client.reset(new CalciteServerClient(protocol));
270  std::pair<std::shared_ptr<CalciteServerClient>, std::shared_ptr<TTransport>> ret;
271  return std::make_pair(client, transport);
272 }
std::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:

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 505 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.

509  {
510  std::vector<TCompletionHint> hints;
511  auto& cat = session_info.getCatalog();
512  const auto user = session_info.get_currentUser().userName;
513  const auto session = session_info.get_session_id();
514  const auto catalog = cat.getCurrentDB().dbName;
515  auto client = getClient(remote_calcite_port_);
516  client.first->getCompletionHints(
517  hints, user, session, catalog, visible_tables, sql_string, cursor);
518  return hints;
519 }
std::string cat(Ts &&...args)
std::string get_session_id() const
Definition: SessionInfo.h:78
Catalog & getCatalog() const
Definition: SessionInfo.h:67
int remote_calcite_port_
Definition: Calcite.h:129
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73

+ Here is the call graph for this function:

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 606 of file Calcite.cpp.

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

606  {
607  if (server_available_) {
608  TPlanResult ret;
609  std::string whitelist;
610 
611  auto clientP = getClient(remote_calcite_port_);
612  clientP.first->getExtensionFunctionWhitelist(whitelist);
613  clientP.second->close();
614  VLOG(1) << whitelist;
615  return whitelist;
616  } else {
617  LOG(FATAL) << "Not routing to Calcite, server is not up";
618  return "";
619  }
620  CHECK(false);
621  return "";
622 }
#define LOG(tag)
Definition: Logger.h:205
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:211
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
#define VLOG(n)
Definition: Logger.h:305

+ Here is the call graph for this function:

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

Definition at line 98 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserPassword.

98 { return kCalciteUserPassword; }
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:38
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:37

+ Here is the caller graph for this function:

std::string Calcite::getRuntimeExtensionFunctionWhitelist ( )

Definition at line 670 of file Calcite.cpp.

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

670  {
671  if (server_available_) {
672  TPlanResult ret;
673  std::string whitelist;
674  auto clientP = getClient(remote_calcite_port_);
675  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
676  clientP.second->close();
677  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
678  return whitelist;
679  } else {
680  LOG(FATAL) << "Not routing to Calcite, server is not up";
681  return "";
682  }
683  UNREACHABLE();
684  return "";
685 }
#define LOG(tag)
Definition: Logger.h:205
#define UNREACHABLE()
Definition: Logger.h:255
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
#define VLOG(n)
Definition: Logger.h:305

+ Here is the call graph for this function:

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 624 of file Calcite.cpp.

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

624  {
625  if (server_available_) {
626  TPlanResult ret;
627  std::string whitelist;
628 
629  auto clientP = getClient(remote_calcite_port_);
630  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
631  clientP.second->close();
632  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
633  return whitelist;
634  } else {
635  LOG(FATAL) << "Not routing to Calcite, server is not up";
636  return "";
637  }
638  UNREACHABLE();
639  return "";
640 }
#define LOG(tag)
Definition: Logger.h:205
#define UNREACHABLE()
Definition: Logger.h:255
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
#define VLOG(n)
Definition: Logger.h:305

+ Here is the call graph for this function:

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

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

Referenced by Calcite().

370  {
371  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
372  << " base data dir is " << data_dir;
373  connMgr_ = std::make_shared<ThriftClientConnection>();
374  if (calcite_port < 0) {
375  CHECK(false) << "JNI mode no longer supported.";
376  }
377  if (calcite_port == 0) {
378  // dummy process for initdb
379  remote_calcite_port_ = calcite_port;
380  server_available_ = false;
381  } else {
382  remote_calcite_port_ = calcite_port;
383  runServer(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
384  server_available_ = true;
385  }
386 }
#define LOG(tag)
Definition: Logger.h:205
std::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:274
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:211

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

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

Referenced by close_calcite_server().

647  {
648  if (server_available_) {
649  LOG_IF(INFO, log) << "Shutting down Calcite server";
650  try {
651  auto clientP = getClient(remote_calcite_port_);
652  clientP.first->shutdown();
653  clientP.second->close();
654  } catch (const std::exception& e) {
655  if (std::string(e.what()) != "connect() failed: Connection refused" &&
656  std::string(e.what()) != "socket open() error: Connection refused" &&
657  std::string(e.what()) != "No more data to read.") {
658  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
659  } // else Calcite already shut down
660  }
661  LOG_IF(INFO, log) << "shut down Calcite";
662  server_available_ = false;
663  }
664 }
#define LOG_IF(severity, condition)
Definition: Logger.h:301
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250

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

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

336  {
337  try {
338  auto ms = measure<>::execution([&]() {
339  auto clientP = getClient(remote_calcite_port_);
340  clientP.first->ping();
341  clientP.second->close();
342  });
343  return ms;
344 
345  } catch (TException& tx) {
346  if (retry_num >= max_retry) {
347  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
348  }
349  return -1;
350  }
351 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:205
int remote_calcite_port_
Definition: Calcite.h:129
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250

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

Definition at line 459 of file Calcite.cpp.

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

467  {
468  TPlanResult result = processImpl(query_state_proxy,
469  std::move(sql_string),
470  filter_push_down_info,
471  legacy_syntax,
472  is_explain,
473  is_view_optimize,
474  calcite_session_id);
475  if (check_privileges && !is_explain) {
476  checkAccessedObjectsPrivileges(query_state_proxy, result);
477  }
478  return result;
479 }
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:540
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:481

+ 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 540 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_, server_available_, and VLOG.

Referenced by process().

547  {
548  query_state::Timer timer = query_state_proxy.createTimer(__func__);
549  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
550  const auto& cat = user_session_info->getCatalog();
551  const std::string user = getInternalSessionProxyUserName();
552  const std::string catalog = cat.getCurrentDB().dbName;
553  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
554  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
555  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
556 
557  TRestriction restriction;
558  auto rest = user_session_info->get_restriction_ptr();
559  if (rest != nullptr && !rest->column.empty()) {
560  VLOG(1) << "This users session has a restriction : " << *rest;
561  restriction.column = rest->column;
562  restriction.values = rest->values;
563  }
564  TPlanResult ret;
565  if (server_available_) {
566  try {
567  // calcite_session_id would be an empty string when accessed by internal resources
568  // that would not access `process` through handler instance, like for eg: Unit
569  // Tests. In these cases we would use the session_id from query state.
570  auto ms = measure<>::execution([&]() {
571  auto clientP = getClient(remote_calcite_port_);
572  clientP.first->process(ret,
573  user,
574  calcite_session_id.empty()
575  ? user_session_info->get_session_id()
576  : calcite_session_id,
577  catalog,
578  sql_string,
579  filter_push_down_info,
580  legacy_syntax,
581  is_explain,
582  is_view_optimize,
583  restriction);
584  clientP.second->close();
585  });
586 
587  // LOG(INFO) << ret.plan_result;
588  LOG(INFO) << "Time in Thrift "
589  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
590  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
591  << " (ms)";
592  } catch (InvalidParseRequest& e) {
593  throw std::invalid_argument(e.whyUp);
594  } catch (const std::exception& ex) {
595  LOG(FATAL)
596  << "Error occurred trying to communicate with Calcite server, the error was: '"
597  << ex.what() << "', omnisci_server restart will be required";
598  return ret; // satisfy return-type warning
599  }
600  } else {
601  LOG(FATAL) << "Not routing to Calcite, server is not up";
602  }
603  return ret;
604 }
std::string cat(Ts &&...args)
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:205
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:138
QueryState & getQueryState()
Definition: QueryState.h:181
int remote_calcite_port_
Definition: Calcite.h:129
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:97
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:88
#define VLOG(n)
Definition: Logger.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

Referenced by init().

278  {
279  LOG(INFO) << "Running Calcite server as a daemon";
280 
281  // ping server to see if for any reason there is an orphaned one
282  int ping_time = ping();
283  if (ping_time > -1) {
284  // we have an orphaned server shut it down
285  LOG(ERROR)
286  << "Appears to be orphaned Calcite server already running, shutting it down";
287  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
288  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
289  try {
290  auto clientP = getClient(remote_calcite_port_);
291  clientP.first->shutdown();
292  clientP.second->close();
293  LOG(ERROR) << "orphaned Calcite server shutdown";
294 
295  } catch (TException& tx) {
296  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
297  }
298  }
299 
300  // start the calcite server as a seperate process
302  port,
303  data_dir,
304  calcite_max_mem,
311  udf_filename);
312 
313  // check for new server for 30 seconds max
314  std::this_thread::sleep_for(std::chrono::milliseconds(200));
315  int retry_max = 300;
316  for (int i = 2; i <= retry_max; i++) {
317  int ping_time = ping(i, retry_max);
318  if (ping_time > -1) {
319  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
320  LOG(INFO) << "ping took " << ping_time << " ms ";
321  server_available_ = true;
322  return;
323  } else {
324  // wait 100 ms
325  std::this_thread::sleep_for(std::chrono::milliseconds(100));
326  }
327  }
328  server_available_ = false;
329  LOG(FATAL) << "Could not connect to Calcite remote server running on port [" << port
330  << "]";
331 }
std::string db_config_file_
Definition: Calcite.h:136
std::string ssl_key_file_
Definition: Calcite.h:132
#define LOG(tag)
Definition: Logger.h:205
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:71
int ping(int retry_num=0, int max_retry=50)
Definition: Calcite.cpp:336
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250
std::string ssl_trust_password_
Definition: Calcite.h:131

+ 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,
bool  isruntime = true 
)

Definition at line 687 of file Calcite.cpp.

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

690  {
691  if (server_available_) {
692  auto clientP = getClient(remote_calcite_port_);
693  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs, isruntime);
694  clientP.second->close();
695  } else {
696  LOG(FATAL) << "Not routing to Calcite, server is not up";
697  }
698 }
#define LOG(tag)
Definition: Logger.h:205
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250

+ Here is the call graph for this function:

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

Definition at line 407 of file Calcite.cpp.

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

407  {
408  if (server_available_) {
409  auto ms = measure<>::execution([&]() {
410  auto clientP = getClient(remote_calcite_port_);
411  clientP.first->updateMetadata(catalog, table);
412  clientP.second->close();
413  });
414  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
415  } else {
416  LOG(INFO) << "Not routing to Calcite, server is not up";
417  }
418 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:205
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:250

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 125 of file Calcite.h.

Referenced by init().

std::string Calcite::db_config_file_
private

Definition at line 136 of file Calcite.h.

bool Calcite::service_keepalive_ = true
private

Definition at line 128 of file Calcite.h.

size_t Calcite::service_timeout_
private

Definition at line 127 of file Calcite.h.

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 137 of file Calcite.h.

Referenced by close_calcite_server().

std::string Calcite::ssl_ca_file_
private

Definition at line 135 of file Calcite.h.

std::string Calcite::ssl_key_file_
private

Definition at line 132 of file Calcite.h.

std::string Calcite::ssl_keystore_
private

Definition at line 133 of file Calcite.h.

std::string Calcite::ssl_keystore_password_
private

Definition at line 134 of file Calcite.h.

std::string Calcite::ssl_trust_password_
private

Definition at line 131 of file Calcite.h.

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: