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

#include <Calcite.h>

+ Collaboration diagram for Calcite:

Public Member Functions

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

Private Member Functions

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

Private Attributes

mapd::shared_ptr
< 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 61 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 354 of file Calcite.cpp.

References init().

361  : server_available_(false)
362  , service_timeout_(service_timeout)
363  , service_keepalive_(service_keepalive) {
364  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
365 }
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:367
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 389 of file Calcite.cpp.

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

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

References close_calcite_server().

656  {
657  close_calcite_server(false);
658 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:632

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

481  {
482  AccessPrivileges NOOP;
483  // check the individual tables
484  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
485  checkPermissionForTables(*session_ptr,
486  plan.primary_accessed_objects.tables_selected_from,
489  checkPermissionForTables(*session_ptr,
490  plan.primary_accessed_objects.tables_inserted_into,
492  NOOP);
493  checkPermissionForTables(*session_ptr,
494  plan.primary_accessed_objects.tables_updated_in,
496  NOOP);
497  checkPermissionForTables(*session_ptr,
498  plan.primary_accessed_objects.tables_deleted_from,
500  NOOP);
501 }
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:421

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

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

632  {
633  std::call_once(shutdown_once_flag_,
634  [this, log]() { this->inner_close_calcite_server(log); });
635 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:137
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:637

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

References CHECK.

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

Definition at line 251 of file Calcite.cpp.

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

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

+ Here is the caller graph for this function:

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

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

+ Here is the call graph for this function:

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 596 of file Calcite.cpp.

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

596  {
597  if (server_available_) {
598  TPlanResult ret;
599  std::string whitelist;
600 
601  auto clientP = getClient(remote_calcite_port_);
602  clientP.first->getExtensionFunctionWhitelist(whitelist);
603  clientP.second->close();
604  VLOG(1) << whitelist;
605  return whitelist;
606  } else {
607  LOG(FATAL) << "Not routing to Calcite, server is not up";
608  return "";
609  }
610  CHECK(false);
611  return "";
612 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:197
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:291

+ 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:39
std::string const Calcite::getInternalSessionProxyUserName ( )
inline

Definition at line 97 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

97 { return kCalciteUserName; }
constexpr char const * kCalciteUserName
Definition: Calcite.h:38

+ Here is the caller graph for this function:

std::string Calcite::getRuntimeExtensionFunctionWhitelist ( )

Definition at line 660 of file Calcite.cpp.

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

660  {
661  if (server_available_) {
662  TPlanResult ret;
663  std::string whitelist;
664  auto clientP = getClient(remote_calcite_port_);
665  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
666  clientP.second->close();
667  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
668  return whitelist;
669  } else {
670  LOG(FATAL) << "Not routing to Calcite, server is not up";
671  return "";
672  }
673  UNREACHABLE();
674  return "";
675 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:291

+ Here is the call graph for this function:

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 614 of file Calcite.cpp.

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

614  {
615  if (server_available_) {
616  TPlanResult ret;
617  std::string whitelist;
618 
619  auto clientP = getClient(remote_calcite_port_);
620  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
621  clientP.second->close();
622  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
623  return whitelist;
624  } else {
625  LOG(FATAL) << "Not routing to Calcite, server is not up";
626  return "";
627  }
628  UNREACHABLE();
629  return "";
630 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:291

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

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

Referenced by Calcite().

371  {
372  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
373  << " base data dir is " << data_dir;
374  connMgr_ = std::make_shared<ThriftClientConnection>();
375  if (calcite_port < 0) {
376  CHECK(false) << "JNI mode no longer supported.";
377  }
378  if (calcite_port == 0) {
379  // dummy process for initdb
380  remote_calcite_port_ = calcite_port;
381  server_available_ = false;
382  } else {
383  remote_calcite_port_ = calcite_port;
384  runServer(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
385  server_available_ = true;
386  }
387 }
#define LOG(tag)
Definition: Logger.h:188
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:125
void runServer(const int db_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:275
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Calcite::inner_close_calcite_server ( bool  log)
private

Definition at line 637 of file Calcite.cpp.

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

Referenced by close_calcite_server().

637  {
638  if (server_available_) {
639  LOG_IF(INFO, log) << "Shutting down Calcite server";
640  try {
641  auto clientP = getClient(remote_calcite_port_);
642  clientP.first->shutdown();
643  clientP.second->close();
644  } catch (const std::exception& e) {
645  if (std::string(e.what()) != "connect() failed: Connection refused" &&
646  std::string(e.what()) != "socket open() error: Connection refused" &&
647  std::string(e.what()) != "No more data to read.") {
648  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
649  } // else Calcite already shut down
650  }
651  LOG_IF(INFO, log) << "shut down Calcite";
652  server_available_ = false;
653  }
654 }
#define LOG_IF(severity, condition)
Definition: Logger.h:287
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251

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

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

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

+ 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 457 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  filter_push_down_info,
469  legacy_syntax,
470  is_explain,
471  is_view_optimize,
472  calcite_session_id);
473  if (check_privileges && !is_explain) {
474  checkAccessedObjectsPrivileges(query_state_proxy, result);
475  }
476  return result;
477 }
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:538
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:479

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

545  {
546  query_state::Timer timer = query_state_proxy.createTimer(__func__);
547  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
548  const auto& cat = user_session_info->getCatalog();
549  const std::string user = getInternalSessionProxyUserName();
550  const std::string catalog = cat.getCurrentDB().dbName;
551  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
552  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
553  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
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  filter_push_down_info,
571  legacy_syntax,
572  is_explain,
573  is_view_optimize);
574  clientP.second->close();
575  });
576 
577  // LOG(INFO) << ret.plan_result;
578  LOG(INFO) << "Time in Thrift "
579  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
580  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
581  << " (ms)";
582  } catch (InvalidParseRequest& e) {
583  throw std::invalid_argument(e.whyUp);
584  } catch (const std::exception& ex) {
585  LOG(FATAL)
586  << "Error occurred trying to communicate with Calcite server, the error was: '"
587  << ex.what() << "', omnisci_server restart will be required";
588  return ret; // satisfy return-type warning
589  }
590  } else {
591  LOG(FATAL) << "Not routing to Calcite, server is not up";
592  }
593  return ret;
594 }
std::string cat(Ts &&...args)
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:188
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:113
QueryState & getQueryState()
Definition: QueryState.h:172
int remote_calcite_port_
Definition: Calcite.h:129
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:97
bool server_available_
Definition: Calcite.h:126
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251

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

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

Referenced by init().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 677 of file Calcite.cpp.

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

679  {
680  if (server_available_) {
681  auto clientP = getClient(remote_calcite_port_);
682  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
683  clientP.second->close();
684  } else {
685  LOG(FATAL) << "Not routing to Calcite, server is not up";
686  }
687 }
#define LOG(tag)
Definition: Logger.h:188
int remote_calcite_port_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:126
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251

+ Here is the call graph for this function:

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

Definition at line 408 of file Calcite.cpp.

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

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

+ Here is the call graph for this function:

Member Data Documentation

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