OmniSciDB  04ee39c94c
Calcite Class Reference

#include <Calcite.h>

+ Collaboration diagram for Calcite:

Public Member Functions

 Calcite (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename="")
 
 Calcite (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &session_prefix, const std::string &udf_filename="")
 
 Calcite (const MapDParameters &mapd_parameter, const std::string &data_dir, const std::string &session_prefix, const std::string &udf_filename="")
 
TPlanResult process (const Catalog_Namespace::SessionInfo &session_info, const 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)
 
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)
 
virtual ~Calcite ()
 
std::string getRuntimeUserDefinedFunctionWhitelist ()
 
void setRuntimeUserDefinedFunction (std::string udf_string)
 
std::string & get_session_prefix ()
 

Private Member Functions

void init (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
 
void runServer (const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
 
TPlanResult processImpl (const Catalog_Namespace::SessionInfo &session_info, const 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)
 
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 ()
 

Private Attributes

std::thread calcite_server_thread_
 
mapd::shared_ptr< ThriftClientConnectionconnMgr_
 
bool server_available_
 
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_cert_file_
 
std::string session_prefix_
 
std::once_flag shutdown_once_flag_
 

Detailed Description

Definition at line 51 of file Calcite.h.

Constructor & Destructor Documentation

◆ Calcite() [1/3]

Calcite::Calcite ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  udf_filename = "" 
)
inline

Definition at line 53 of file Calcite.h.

58  : Calcite(mapd_port, port, data_dir, calcite_max_mem, "", udf_filename){};
Calcite(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename="")
Definition: Calcite.h:53

◆ Calcite() [2/3]

Calcite::Calcite ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  session_prefix,
const std::string &  udf_filename = "" 
)

Definition at line 266 of file Calcite.cpp.

References init().

272  : server_available_(false), session_prefix_(session_prefix) {
273  init(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
274 }
std::string session_prefix_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:115
void init(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:276
+ Here is the call graph for this function:

◆ Calcite() [3/3]

Calcite::Calcite ( const MapDParameters mapd_parameter,
const std::string &  data_dir,
const std::string &  session_prefix,
const std::string &  udf_filename = "" 
)

Definition at line 298 of file Calcite.cpp.

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

302  : ssl_trust_store_(mapd_parameter.ssl_trust_store)
303  , ssl_trust_password_(mapd_parameter.ssl_trust_password)
304  , ssl_key_file_(mapd_parameter.ssl_key_file)
305  , ssl_keystore_(mapd_parameter.ssl_keystore)
307  , ssl_cert_file_(mapd_parameter.ssl_cert_file)
308  , session_prefix_(session_prefix) {
309  init(mapd_parameter.omnisci_server_port,
310  mapd_parameter.calcite_port,
311  data_dir,
312  mapd_parameter.calcite_max_mem,
313  udf_filename);
314 }
std::string ssl_key_file
std::string ssl_key_file_
Definition: Calcite.h:119
std::string ssl_keystore_
Definition: Calcite.h:120
std::string ssl_keystore_password_
Definition: Calcite.h:121
std::string ssl_trust_store
std::string ssl_trust_store_
Definition: Calcite.h:117
std::string ssl_keystore
std::string ssl_keystore_password
std::string ssl_trust_password
std::string ssl_cert_file
std::string session_prefix_
Definition: Calcite.h:123
size_t calcite_max_mem
std::string ssl_cert_file_
Definition: Calcite.h:122
void init(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:276
std::string ssl_trust_password_
Definition: Calcite.h:118
+ Here is the call graph for this function:

◆ ~Calcite()

Calcite::~Calcite ( )
virtual

Definition at line 555 of file Calcite.cpp.

References close_calcite_server().

555  {
556  close_calcite_server(false);
557 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:532
+ Here is the call graph for this function:

Member Function Documentation

◆ close_calcite_server()

void Calcite::close_calcite_server ( bool  log = true)

Definition at line 532 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

532  {
533  std::call_once(shutdown_once_flag_,
534  [this, log]() { this->inner_close_calcite_server(log); });
535 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:124
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:537
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_db_objects()

std::vector< std::string > Calcite::get_db_objects ( const std::string  ra)
private

Definition at line 420 of file Calcite.cpp.

References CHECK, and v().

420  {
421  std::vector<std::string> v_db_obj;
422  Document document;
423  document.Parse(ra.c_str());
424  const Value& rels = document["rels"];
425  CHECK(rels.IsArray());
426  for (auto& v : rels.GetArray()) {
427  std::string relOp(v["relOp"].GetString());
428  if (!relOp.compare("EnumerableTableScan")) {
429  std::string x;
430  auto t = v["table"].GetArray();
431  x = t[1].GetString();
432  v_db_obj.push_back(x);
433  }
434  }
435 
436  return v_db_obj;
437 }
T v(const TargetValue &r)
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ get_session_prefix()

std::string& Calcite::get_session_prefix ( )
inline

Definition at line 87 of file Calcite.h.

References logger::init().

87 { return session_prefix_; }
std::string session_prefix_
Definition: Calcite.h:123
+ Here is the call graph for this function:

◆ getClient()

std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > Calcite::getClient ( int  port)
private

Definition at line 174 of file Calcite.cpp.

References client.

Referenced by getCompletionHints(), getExtensionFunctionWhitelist(), getRuntimeUserDefinedFunctionWhitelist(), getUserDefinedFunctionWhitelist(), inner_close_calcite_server(), processImpl(), setRuntimeUserDefinedFunction(), and updateMetadata().

174  {
175  const auto transport = connMgr_->open_buffered_client_transport(
176  "localhost", port, ssl_cert_file_, true, 2000, 5000, 5000);
177 
178  try {
179  transport->open();
180 
181  } catch (TException& tx) {
182  throw tx;
183  } catch (std::exception& ex) {
184  throw ex;
185  }
186  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
187  mapd::shared_ptr<CalciteServerClient> client;
188  client.reset(new CalciteServerClient(protocol));
189  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
190  return std::make_pair(client, transport);
191 }
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:114
mapd::shared_ptr< MapDClient > client
std::string ssl_cert_file_
Definition: Calcite.h:122
+ Here is the caller graph for this function:

◆ getCompletionHints()

std::vector< TCompletionHint > Calcite::getCompletionHints ( const Catalog_Namespace::SessionInfo session_info,
const std::vector< std::string > &  visible_tables,
const std::string  sql_string,
const int  cursor 
)

Definition at line 404 of file Calcite.cpp.

References client, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::get_session_id(), Catalog_Namespace::SessionInfo::getCatalog(), getClient(), remote_calcite_port_, session, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userName.

408  {
409  std::vector<TCompletionHint> hints;
410  auto& cat = session_info.getCatalog();
411  const auto user = session_info.get_currentUser().userName;
412  const auto session = session_info.get_session_id();
413  const auto catalog = cat.getCurrentDB().dbName;
415  client.first->getCompletionHints(
416  hints, user, session, catalog, visible_tables, sql_string, cursor);
417  return hints;
418 }
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::string get_session_id() const
Definition: SessionInfo.h:98
mapd::shared_ptr< MapDClient > client
Catalog & getCatalog() const
Definition: SessionInfo.h:90
int remote_calcite_port_
Definition: Calcite.h:116
TSessionId session
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:

◆ getExtensionFunctionWhitelist()

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 496 of file Calcite.cpp.

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

496  {
497  if (server_available_) {
498  TPlanResult ret;
499  std::string whitelist;
500 
501  auto clientP = getClient(remote_calcite_port_);
502  clientP.first->getExtensionFunctionWhitelist(whitelist);
503  clientP.second->close();
504  VLOG(1) << whitelist;
505  return whitelist;
506  } else {
507  LOG(FATAL) << "Not routing to Calcite, server is not up";
508  return "";
509  }
510  CHECK(false);
511  return "";
512 }
#define LOG(tag)
Definition: Logger.h:182
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
#define CHECK(condition)
Definition: Logger.h:187
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
#define VLOG(n)
Definition: Logger.h:277
+ Here is the call graph for this function:

◆ getRuntimeUserDefinedFunctionWhitelist()

std::string Calcite::getRuntimeUserDefinedFunctionWhitelist ( )

Definition at line 559 of file Calcite.cpp.

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

559  {
560  if (server_available_) {
561  TPlanResult ret;
562  std::string whitelist;
563  auto clientP = getClient(remote_calcite_port_);
564  clientP.first->getRuntimeUserDefinedFunctionWhitelist(whitelist);
565  clientP.second->close();
566  VLOG(1) << "Runtime user defined functions whitelist loaded from Calcite: "
567  << whitelist;
568  return whitelist;
569  } else {
570  LOG(FATAL) << "Not routing to Calcite, server is not up";
571  return "";
572  }
573  UNREACHABLE();
574  return "";
575 }
#define LOG(tag)
Definition: Logger.h:182
#define UNREACHABLE()
Definition: Logger.h:231
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
#define VLOG(n)
Definition: Logger.h:277
+ Here is the call graph for this function:

◆ getUserDefinedFunctionWhitelist()

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 514 of file Calcite.cpp.

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

514  {
515  if (server_available_) {
516  TPlanResult ret;
517  std::string whitelist;
518 
519  auto clientP = getClient(remote_calcite_port_);
520  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
521  clientP.second->close();
522  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
523  return whitelist;
524  } else {
525  LOG(FATAL) << "Not routing to Calcite, server is not up";
526  return "";
527  }
528  UNREACHABLE();
529  return "";
530 }
#define LOG(tag)
Definition: Logger.h:182
#define UNREACHABLE()
Definition: Logger.h:231
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
#define VLOG(n)
Definition: Logger.h:277
+ Here is the call graph for this function:

◆ init()

void Calcite::init ( const int  mapd_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 CHECK, connMgr_, logger::INFO, LOG, remote_calcite_port_, runServer(), and server_available_.

Referenced by Calcite().

280  {
281  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
282  << " base data dir is " << data_dir;
283  connMgr_ = std::make_shared<ThriftClientConnection>();
284  if (calcite_port < 0) {
285  CHECK(false) << "JNI mode no longer supported.";
286  }
287  if (calcite_port == 0) {
288  // dummy process for initdb
289  remote_calcite_port_ = calcite_port;
290  server_available_ = false;
291  } else {
292  remote_calcite_port_ = calcite_port;
293  runServer(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
294  server_available_ = true;
295  }
296 }
#define LOG(tag)
Definition: Logger.h:182
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:114
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
#define CHECK(condition)
Definition: Logger.h:187
void runServer(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename)
Definition: Calcite.cpp:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inner_close_calcite_server()

void Calcite::inner_close_calcite_server ( bool  log)
private

Definition at line 537 of file Calcite.cpp.

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

Referenced by close_calcite_server().

537  {
538  if (server_available_) {
539  LOG_IF(INFO, log) << "Shutting down Calcite server";
540  try {
541  auto clientP = getClient(remote_calcite_port_);
542  clientP.first->shutdown();
543  clientP.second->close();
544  } catch (const std::exception& e) {
545  if (std::string(e.what()) != "connect() failed: Connection refused" &&
546  std::string(e.what()) != "No more data to read.") {
547  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
548  } // else Calcite already shut down
549  }
550  LOG_IF(INFO, log) << "shut down Calcite";
551  server_available_ = false;
552  }
553 }
#define LOG_IF(severity, condition)
Definition: Logger.h:273
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ping()

int Calcite::ping ( )
private

Definition at line 252 of file Calcite.cpp.

References measure< TimeT >::execution().

252  {
253  try {
254  auto ms = measure<>::execution([&]() {
255  auto clientP = getClient(remote_calcite_port_);
256  clientP.first->ping();
257  clientP.second->close();
258  });
259  return ms;
260 
261  } catch (TException& tx) {
262  return -1;
263  }
264 }
int remote_calcite_port_
Definition: Calcite.h:116
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:

◆ process()

TPlanResult Calcite::process ( const Catalog_Namespace::SessionInfo session_info,
const 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 
)

Definition at line 365 of file Calcite.cpp.

References checkPermissionForTables(), AccessPrivileges::DELETE_FROM_TABLE, AccessPrivileges::INSERT_INTO_TABLE, processImpl(), run-benchmark-import::result, AccessPrivileges::SELECT_FROM_TABLE, AccessPrivileges::SELECT_FROM_VIEW, and AccessPrivileges::UPDATE_IN_TABLE.

371  {
372  TPlanResult result = processImpl(session_info,
373  sql_string,
374  filter_push_down_info,
375  legacy_syntax,
376  is_explain,
377  is_view_optimize);
378 
379  AccessPrivileges NOOP;
380 
381  if (!is_explain) {
382  // check the individual tables
383  checkPermissionForTables(session_info,
384  result.primary_accessed_objects.tables_selected_from,
387  checkPermissionForTables(session_info,
388  result.primary_accessed_objects.tables_inserted_into,
390  NOOP);
391  checkPermissionForTables(session_info,
392  result.primary_accessed_objects.tables_updated_in,
394  NOOP);
395  checkPermissionForTables(session_info,
396  result.primary_accessed_objects.tables_deleted_from,
398  NOOP);
399  }
400 
401  return result;
402 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:153
TPlanResult processImpl(const Catalog_Namespace::SessionInfo &session_info, const 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)
Definition: Calcite.cpp:439
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:156
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:173
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:155
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:329
+ Here is the call graph for this function:

◆ processImpl()

TPlanResult Calcite::processImpl ( const Catalog_Namespace::SessionInfo session_info,
const 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 
)
private

Definition at line 439 of file Calcite.cpp.

References measure< TimeT >::execution(), logger::FATAL, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::get_session_id(), Catalog_Namespace::SessionInfo::getCatalog(), getClient(), logger::INFO, logger::IR, LOG, logger::PTX, remote_calcite_port_, server_available_, session, session_prefix_, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userName.

Referenced by process().

445  {
446  auto& cat = session_info.getCatalog();
447  std::string user = session_info.get_currentUser().userName;
448  std::string session = session_info.get_session_id();
449  if (!session_prefix_.empty()) {
450  // preprend session prefix, if present
451  session = session_prefix_ + "/" + session;
452  }
453  std::string catalog = cat.getCurrentDB().dbName;
454 
455  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
456  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
457  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
458 
459  TPlanResult ret;
460  if (server_available_) {
461  try {
462  auto ms = measure<>::execution([&]() {
463  auto clientP = getClient(remote_calcite_port_);
464  clientP.first->process(ret,
465  user,
466  session,
467  catalog,
468  sql_string,
469  filter_push_down_info,
470  legacy_syntax,
471  is_explain,
472  is_view_optimize);
473  clientP.second->close();
474  });
475 
476  // LOG(INFO) << ret.plan_result;
477  LOG(INFO) << "Time in Thrift "
478  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
479  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
480  << " (ms)";
481  } catch (InvalidParseRequest& e) {
482  throw std::invalid_argument(e.whyUp);
483  } catch (const std::exception& ex) {
484  LOG(FATAL)
485  << "Error occurred trying to communicate with calcite server, the error was: '"
486  << ex.what() << "', omnisci_server restart will be required";
487  return ret; // satisfy return-type warning
488  }
489  } else {
490  LOG(INFO) << "Not routing to Calcite, server is not up";
491  ret.plan_result = "";
492  }
493  return ret;
494 }
#define LOG(tag)
Definition: Logger.h:182
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::string get_session_id() const
Definition: SessionInfo.h:98
Catalog & getCatalog() const
Definition: SessionInfo.h:90
std::string session_prefix_
Definition: Calcite.h:123
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
TSessionId session
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runServer()

void Calcite::runServer ( const int  mapd_port,
const int  port,
const std::string &  data_dir,
const size_t  calcite_max_mem,
const std::string &  udf_filename 
)
private

Definition at line 193 of file Calcite.cpp.

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

Referenced by init().

197  {
198  LOG(INFO) << "Running calcite server as a daemon";
199 
200  // ping server to see if for any reason there is an orphaned one
201  int ping_time = ping();
202  if (ping_time > -1) {
203  // we have an orphaned server shut it down
204  LOG(ERROR)
205  << "Appears to be orphaned Calcite serve already running, shutting it down";
206  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
207  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
208  try {
209  auto clientP = getClient(remote_calcite_port_);
210  clientP.first->shutdown();
211  clientP.second->close();
212  LOG(ERROR) << "orphaned Calcite server shutdown";
213 
214  } catch (TException& tx) {
215  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
216  }
217  }
218 
219  // start the calcite server as a seperate process
221  port,
222  data_dir,
223  calcite_max_mem,
230  udf_filename);
231 
232  // check for new server for 5 seconds max
233  std::this_thread::sleep_for(std::chrono::milliseconds(200));
234  for (int i = 2; i < 50; i++) {
235  int ping_time = ping();
236  if (ping_time > -1) {
237  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
238  LOG(INFO) << "ping took " << ping_time << " ms ";
239  server_available_ = true;
240  return;
241  } else {
242  // wait 100 ms
243  std::this_thread::sleep_for(std::chrono::milliseconds(100));
244  }
245  }
246  server_available_ = false;
247  LOG(FATAL) << "Could not connect to calcite remote server running on port " << port;
248 }
std::string ssl_key_file_
Definition: Calcite.h:119
#define LOG(tag)
Definition: Logger.h:182
std::string ssl_keystore_
Definition: Calcite.h:120
std::string ssl_keystore_password_
Definition: Calcite.h:121
std::string ssl_trust_store_
Definition: Calcite.h:117
static void start_calcite_server_as_daemon(const int mapd_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, const std::string &ssl_keystore, const std::string &ssl_keystore_password, const std::string &ssl_key_file, const std::string &ssl_cert_file, const std::string &udf_filename)
Definition: Calcite.cpp:66
int ping()
Definition: Calcite.cpp:252
int remote_calcite_port_
Definition: Calcite.h:116
std::string ssl_cert_file_
Definition: Calcite.h:122
bool server_available_
Definition: Calcite.h:115
std::string ssl_trust_password_
Definition: Calcite.h:118
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRuntimeUserDefinedFunction()

void Calcite::setRuntimeUserDefinedFunction ( std::string  udf_string)

Definition at line 577 of file Calcite.cpp.

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

577  {
578  if (server_available_) {
579  auto clientP = getClient(remote_calcite_port_);
580  clientP.first->setRuntimeUserDefinedFunction(udf_string);
581  clientP.second->close();
582  } else {
583  LOG(FATAL) << "Not routing to Calcite, server is not up";
584  }
585 }
#define LOG(tag)
Definition: Logger.h:182
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:

◆ updateMetadata()

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

Definition at line 316 of file Calcite.cpp.

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

316  {
317  if (server_available_) {
318  auto ms = measure<>::execution([&]() {
319  auto clientP = getClient(remote_calcite_port_);
320  clientP.first->updateMetadata(catalog, table);
321  clientP.second->close();
322  });
323  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
324  } else {
325  LOG(INFO) << "Not routing to Calcite, server is not up";
326  }
327 }
#define LOG(tag)
Definition: Logger.h:182
int remote_calcite_port_
Definition: Calcite.h:116
bool server_available_
Definition: Calcite.h:115
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:174
+ Here is the call graph for this function:

Member Data Documentation

◆ calcite_server_thread_

std::thread Calcite::calcite_server_thread_
private

Definition at line 111 of file Calcite.h.

◆ connMgr_

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

Definition at line 114 of file Calcite.h.

Referenced by init().

◆ remote_calcite_port_

◆ server_available_

◆ session_prefix_

std::string Calcite::session_prefix_
private

Definition at line 123 of file Calcite.h.

Referenced by processImpl().

◆ shutdown_once_flag_

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 124 of file Calcite.h.

Referenced by close_calcite_server().

◆ ssl_cert_file_

std::string Calcite::ssl_cert_file_
private

Definition at line 122 of file Calcite.h.

◆ ssl_key_file_

std::string Calcite::ssl_key_file_
private

Definition at line 119 of file Calcite.h.

◆ ssl_keystore_

std::string Calcite::ssl_keystore_
private

Definition at line 120 of file Calcite.h.

◆ ssl_keystore_password_

std::string Calcite::ssl_keystore_password_
private

Definition at line 121 of file Calcite.h.

◆ ssl_trust_password_

std::string Calcite::ssl_trust_password_
private

Definition at line 118 of file Calcite.h.

◆ ssl_trust_store_

std::string Calcite::ssl_trust_store_
private

Definition at line 117 of file Calcite.h.


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