OmniSciDB  fe05a0c208
 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, 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< 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:129
size_t service_timeout_
Definition: Calcite.h:128
bool server_available_
Definition: Calcite.h:127

+ 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:137
std::string ssl_key_file_
Definition: Calcite.h:133
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:134
std::string ssl_keystore_password_
Definition: Calcite.h:135
std::string ssl_trust_store_
Definition: Calcite.h:131
bool service_keepalive_
Definition: Calcite.h:129
std::string ssl_ca_file_
Definition: Calcite.h:136
size_t service_timeout_
Definition: Calcite.h:128
std::string ssl_trust_password_
Definition: Calcite.h:132

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

484  {
485  AccessPrivileges NOOP;
486  // check the individual tables
487  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
488  checkPermissionForTables(*session_ptr,
489  plan.primary_accessed_objects.tables_selected_from,
492  checkPermissionForTables(*session_ptr,
493  plan.primary_accessed_objects.tables_inserted_into,
495  NOOP);
496  checkPermissionForTables(*session_ptr,
497  plan.primary_accessed_objects.tables_updated_in,
499  NOOP);
500  checkPermissionForTables(*session_ptr,
501  plan.primary_accessed_objects.tables_deleted_from,
503  NOOP);
504 }
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:421
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:138
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 522 of file Calcite.cpp.

References CHECK, and t.

522  {
523  std::vector<std::string> v_db_obj;
524  Document document;
525  document.Parse(ra.c_str());
526  const Value& rels = document["rels"];
527  CHECK(rels.IsArray());
528  for (auto& v : rels.GetArray()) {
529  std::string relOp(v["relOp"].GetString());
530  if (!relOp.compare("EnumerableTableScan")) {
531  std::string x;
532  auto t = v["table"].GetArray();
533  x = t[1].GetString();
534  v_db_obj.push_back(x);
535  }
536  }
537 
538  return v_db_obj;
539 }
#define CHECK(condition)
Definition: Logger.h:203
char * t
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:126
bool service_keepalive_
Definition: Calcite.h:129
std::string ssl_ca_file_
Definition: Calcite.h:136
size_t service_timeout_
Definition: Calcite.h:128

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

510  {
511  std::vector<TCompletionHint> hints;
512  auto& cat = session_info.getCatalog();
513  const auto user = session_info.get_currentUser().userName;
514  const auto session = session_info.get_session_id();
515  const auto catalog = cat.getCurrentDB().dbName;
516  auto client = getClient(remote_calcite_port_);
517  client.first->getCompletionHints(
518  hints, user, session, catalog, visible_tables, sql_string, cursor);
519  return hints;
520 }
std::string cat(Ts &&...args)
std::string get_session_id() const
Definition: SessionInfo.h:77
Catalog & getCatalog() const
Definition: SessionInfo.h:66
int remote_calcite_port_
Definition: Calcite.h:130
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:72
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 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:194
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
#define CHECK(condition)
Definition: Logger.h:203
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:297

+ Here is the call graph for this function:

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

Definition at line 99 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserPassword.

99 { return kCalciteUserPassword; }
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:39
std::string const Calcite::getInternalSessionProxyUserName ( )
inline

Definition at line 98 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

98 { 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 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:194
#define UNREACHABLE()
Definition: Logger.h:247
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:297

+ 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:194
#define UNREACHABLE()
Definition: Logger.h:247
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:251
#define VLOG(n)
Definition: Logger.h:297

+ 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:194
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:126
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:130
bool server_available_
Definition: Calcite.h:127
#define CHECK(condition)
Definition: Logger.h:203

+ 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:293
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
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:194
int remote_calcite_port_
Definition: Calcite.h:130
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 460 of file Calcite.cpp.

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

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

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

548  {
549  query_state::Timer timer = query_state_proxy.createTimer(__func__);
550  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
551  const auto& cat = user_session_info->getCatalog();
552  const std::string user = getInternalSessionProxyUserName();
553  const std::string catalog = cat.getCurrentDB().dbName;
554  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
555  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
556  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
557 
558  TRestriction restriction;
559  auto rest = user_session_info->get_restriction_ptr();
560  if (rest != nullptr) {
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:194
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:124
QueryState & getQueryState()
Definition: QueryState.h:175
int remote_calcite_port_
Definition: Calcite.h:130
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:98
bool server_available_
Definition: Calcite.h:127
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:79
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, i, 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:137
std::string ssl_key_file_
Definition: Calcite.h:133
#define LOG(tag)
Definition: Logger.h:194
std::string ssl_keystore_
Definition: Calcite.h:134
std::string ssl_keystore_password_
Definition: Calcite.h:135
std::string ssl_trust_store_
Definition: Calcite.h:131
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:130
bool server_available_
Definition: Calcite.h:127
std::string ssl_trust_password_
Definition: Calcite.h:132
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,
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:194
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
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:194
int remote_calcite_port_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:127
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 126 of file Calcite.h.

Referenced by init().

std::string Calcite::db_config_file_
private

Definition at line 137 of file Calcite.h.

bool Calcite::service_keepalive_ = true
private

Definition at line 129 of file Calcite.h.

size_t Calcite::service_timeout_
private

Definition at line 128 of file Calcite.h.

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 138 of file Calcite.h.

Referenced by close_calcite_server().

std::string Calcite::ssl_ca_file_
private

Definition at line 136 of file Calcite.h.

std::string Calcite::ssl_key_file_
private

Definition at line 133 of file Calcite.h.

std::string Calcite::ssl_keystore_
private

Definition at line 134 of file Calcite.h.

std::string Calcite::ssl_keystore_password_
private

Definition at line 135 of file Calcite.h.

std::string Calcite::ssl_trust_password_
private

Definition at line 132 of file Calcite.h.

std::string Calcite::ssl_trust_store_
private

Definition at line 131 of file Calcite.h.


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