OmniSciDB  c0231cc57d
 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 TQueryParsingOption &query_parsing_option, const TOptimizationOption &optimization_option, 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)
 
TQueryParsingOption getCalciteQueryParsingOption (bool legacy_syntax, bool is_explain, bool check_privileges)
 
TOptimizationOption getCalciteOptimizationOption (bool is_view_optimize, bool enable_watchdog, const std::vector< TFilterPushDownInfo > &filter_push_down_info, bool distributed_mode)
 

Static Public Member Functions

static std::string const getInternalSessionProxyUserName ()
 
static 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 TQueryParsingOption &query_parsing_option, const TOptimizationOption &optimization_option, 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 62 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 355 of file Calcite.cpp.

References init().

362  : server_available_(false)
363  , service_timeout_(service_timeout)
364  , service_keepalive_(service_keepalive) {
365  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
366 }
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:368
bool service_keepalive_
Definition: Calcite.h:135
size_t service_timeout_
Definition: Calcite.h:134
bool server_available_
Definition: Calcite.h:133

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

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

393  : service_timeout_(system_parameters.calcite_timeout)
394  , service_keepalive_(system_parameters.calcite_keepalive)
395  , ssl_trust_store_(system_parameters.ssl_trust_store)
396  , ssl_trust_password_(system_parameters.ssl_trust_password)
397  , ssl_key_file_(system_parameters.ssl_key_file)
398  , ssl_keystore_(system_parameters.ssl_keystore)
399  , ssl_keystore_password_(system_parameters.ssl_keystore_password)
400  , ssl_ca_file_(system_parameters.ssl_trust_ca_file)
401  , db_config_file_(system_parameters.config_file) {
402  init(system_parameters.omnisci_server_port,
403  system_parameters.calcite_port,
404  data_dir,
405  system_parameters.calcite_max_mem,
406  udf_filename);
407 }
std::string db_config_file_
Definition: Calcite.h:143
std::string ssl_key_file_
Definition: Calcite.h:139
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:368
std::string ssl_keystore_
Definition: Calcite.h:140
std::string ssl_keystore_password_
Definition: Calcite.h:141
std::string ssl_trust_store_
Definition: Calcite.h:137
bool service_keepalive_
Definition: Calcite.h:135
std::string ssl_ca_file_
Definition: Calcite.h:142
size_t service_timeout_
Definition: Calcite.h:134
std::string ssl_trust_password_
Definition: Calcite.h:138

+ Here is the call graph for this function:

Calcite::~Calcite ( )

Definition at line 664 of file Calcite.cpp.

References close_calcite_server().

664  {
665  close_calcite_server(false);
666 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:640

+ 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 477 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().

479  {
480  AccessPrivileges NOOP;
481  // check the individual tables
482  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
483  checkPermissionForTables(*session_ptr,
484  plan.primary_accessed_objects.tables_selected_from,
487  checkPermissionForTables(*session_ptr,
488  plan.primary_accessed_objects.tables_inserted_into,
490  NOOP);
491  checkPermissionForTables(*session_ptr,
492  plan.primary_accessed_objects.tables_updated_in,
494  NOOP);
495  checkPermissionForTables(*session_ptr,
496  plan.primary_accessed_objects.tables_deleted_from,
498  NOOP);
499 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:160
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::vector< std::string >> tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:422
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:163
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:180
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:162

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

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

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

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

References CHECK.

517  {
518  std::vector<std::string> v_db_obj;
519  Document document;
520  document.Parse(ra.c_str());
521  const Value& rels = document["rels"];
522  CHECK(rels.IsArray());
523  for (auto& v : rels.GetArray()) {
524  std::string relOp(v["relOp"].GetString());
525  if (!relOp.compare("EnumerableTableScan")) {
526  std::string x;
527  auto t = v["table"].GetArray();
528  x = t[1].GetString();
529  v_db_obj.push_back(x);
530  }
531  }
532 
533  return v_db_obj;
534 }
#define CHECK(condition)
Definition: Logger.h:222
TOptimizationOption Calcite::getCalciteOptimizationOption ( bool  is_view_optimize,
bool  enable_watchdog,
const std::vector< TFilterPushDownInfo > &  filter_push_down_info,
bool  distributed_mode 
)

Definition at line 708 of file Calcite.cpp.

712  {
713  TOptimizationOption optimization_option;
714  optimization_option.filter_push_down_info = filter_push_down_info;
715  optimization_option.is_view_optimize = is_view_optimize;
716  optimization_option.enable_watchdog = enable_watchdog;
717  optimization_option.distributed_mode = distributed_mode;
718  return optimization_option;
719 }
TQueryParsingOption Calcite::getCalciteQueryParsingOption ( bool  legacy_syntax,
bool  is_explain,
bool  check_privileges 
)

Definition at line 698 of file Calcite.cpp.

700  {
701  TQueryParsingOption query_parsing_info;
702  query_parsing_info.legacy_syntax = legacy_syntax;
703  query_parsing_info.is_explain = is_explain;
704  query_parsing_info.check_privileges = check_privileges;
705  return query_parsing_info;
706 }
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > Calcite::getClient ( int  port)
private

Definition at line 252 of file Calcite.cpp.

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

252  {
253  const auto transport = connMgr_->open_buffered_client_transport("localhost",
254  port,
255  ssl_ca_file_,
256  true,
261  try {
262  transport->open();
263 
264  } catch (TException& tx) {
265  throw tx;
266  } catch (std::exception& ex) {
267  throw ex;
268  }
269  std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
270  std::shared_ptr<CalciteServerClient> client;
271  client.reset(new CalciteServerClient(protocol));
272  std::pair<std::shared_ptr<CalciteServerClient>, std::shared_ptr<TTransport>> ret;
273  return std::make_pair(client, transport);
274 }
std::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:132
bool service_keepalive_
Definition: Calcite.h:135
std::string ssl_ca_file_
Definition: Calcite.h:142
size_t service_timeout_
Definition: Calcite.h:134

+ 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 501 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.

505  {
506  std::vector<TCompletionHint> hints;
507  auto& cat = session_info.getCatalog();
508  const auto user = session_info.get_currentUser().userName;
509  const auto session = session_info.get_session_id();
510  const auto catalog = cat.getCurrentDB().dbName;
511  auto client = getClient(remote_calcite_port_);
512  client.first->getCompletionHints(
513  hints, user, session, catalog, visible_tables, sql_string, cursor);
514  return hints;
515 }
std::string cat(Ts &&...args)
std::string get_session_id() const
Definition: SessionInfo.h:93
Catalog & getCatalog() const
Definition: SessionInfo.h:75
int remote_calcite_port_
Definition: Calcite.h:136
std::pair< std::shared_ptr< CalciteServerClient >, std::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:252
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88

+ Here is the call graph for this function:

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 604 of file Calcite.cpp.

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

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

+ Here is the call graph for this function:

static std::string const Calcite::getInternalSessionProxyPassword ( )
inlinestatic

Definition at line 97 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserPassword.

97  {
98  return kCalciteUserPassword;
99  }
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:40
static std::string const Calcite::getInternalSessionProxyUserName ( )
inlinestatic

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:39

+ Here is the caller graph for this function:

std::string Calcite::getRuntimeExtensionFunctionWhitelist ( )

Definition at line 668 of file Calcite.cpp.

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

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

+ Here is the call graph for this function:

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 622 of file Calcite.cpp.

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

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

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

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

Referenced by Calcite().

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

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

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

Referenced by close_calcite_server().

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

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

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

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

+ Here is the call graph for this function:

TPlanResult Calcite::process ( query_state::QueryStateProxy  query_state_proxy,
std::string  sql_string,
const TQueryParsingOption &  query_parsing_option,
const TOptimizationOption &  optimization_option,
const std::string &  calcite_session_id = "" 
)

Definition at line 461 of file Calcite.cpp.

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

465  {
466  TPlanResult result = processImpl(query_state_proxy,
467  std::move(sql_string),
468  query_parsing_option,
469  optimization_option,
470  calcite_session_id);
471  if (query_parsing_option.check_privileges && !query_parsing_option.is_explain) {
472  checkAccessedObjectsPrivileges(query_state_proxy, result);
473  }
474  return result;
475 }
TPlanResult processImpl(query_state::QueryStateProxy, std::string sql_string, const TQueryParsingOption &query_parsing_option, const TOptimizationOption &optimization_option, const std::string &calcite_session_id)
Definition: Calcite.cpp:536
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:477

+ Here is the call graph for this function:

TPlanResult Calcite::processImpl ( query_state::QueryStateProxy  query_state_proxy,
std::string  sql_string,
const TQueryParsingOption &  query_parsing_option,
const TOptimizationOption &  optimization_option,
const std::string &  calcite_session_id 
)
private

Definition at line 536 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(), hide_sensitive_data_from_query(), logger::INFO, logger::IR, LOG, logger::PTX, remote_calcite_port_, server_available_, and logger::WARNING.

Referenced by process().

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

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

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

Referenced by init().

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

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

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

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

+ Here is the call graph for this function:

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

Definition at line 409 of file Calcite.cpp.

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

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

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 132 of file Calcite.h.

Referenced by init().

std::string Calcite::db_config_file_
private

Definition at line 143 of file Calcite.h.

bool Calcite::service_keepalive_ = true
private

Definition at line 135 of file Calcite.h.

size_t Calcite::service_timeout_
private

Definition at line 134 of file Calcite.h.

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 144 of file Calcite.h.

Referenced by close_calcite_server().

std::string Calcite::ssl_ca_file_
private

Definition at line 142 of file Calcite.h.

std::string Calcite::ssl_key_file_
private

Definition at line 139 of file Calcite.h.

std::string Calcite::ssl_keystore_
private

Definition at line 140 of file Calcite.h.

std::string Calcite::ssl_keystore_password_
private

Definition at line 141 of file Calcite.h.

std::string Calcite::ssl_trust_password_
private

Definition at line 138 of file Calcite.h.

std::string Calcite::ssl_trust_store_
private

Definition at line 137 of file Calcite.h.


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