OmniSciDB  b24e664e58
 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 mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename="")
 
 Calcite (const MapDParameters &mapd_parameter, 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 std::string &calcite_session_id="")
 
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 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 (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 ()
 

Private Attributes

mapd::shared_ptr
< ThriftClientConnection
connMgr_
 
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_ca_file_
 
std::once_flag shutdown_once_flag_
 

Detailed Description

Definition at line 62 of file Calcite.h.

Constructor & Destructor Documentation

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 = "" 
)

Definition at line 265 of file Calcite.cpp.

References init().

270  : server_available_(false) {
271  init(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
272 }
bool server_available_
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:274

+ Here is the call graph for this function:

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

Definition at line 296 of file Calcite.cpp.

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

299  : ssl_trust_store_(mapd_parameter.ssl_trust_store)
300  , ssl_trust_password_(mapd_parameter.ssl_trust_password)
301  , ssl_key_file_(mapd_parameter.ssl_key_file)
302  , ssl_keystore_(mapd_parameter.ssl_keystore)
304  , ssl_ca_file_(mapd_parameter.ssl_trust_ca_file) {
305  init(mapd_parameter.omnisci_server_port,
306  mapd_parameter.calcite_port,
307  data_dir,
308  mapd_parameter.calcite_max_mem,
309  udf_filename);
310 }
std::string ssl_key_file
std::string ssl_key_file_
Definition: Calcite.h:126
std::string ssl_keystore_
Definition: Calcite.h:127
std::string ssl_keystore_password_
Definition: Calcite.h:128
std::string ssl_trust_store
std::string ssl_trust_ca_file
std::string ssl_trust_store_
Definition: Calcite.h:124
std::string ssl_keystore
std::string ssl_keystore_password
std::string ssl_ca_file_
Definition: Calcite.h:129
std::string ssl_trust_password
size_t calcite_max_mem
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:274
std::string ssl_trust_password_
Definition: Calcite.h:125

+ Here is the call graph for this function:

Calcite::~Calcite ( )

Definition at line 557 of file Calcite.cpp.

References close_calcite_server().

557  {
558  close_calcite_server(false);
559 }
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:533

+ Here is the call graph for this function:

Member Function Documentation

void Calcite::close_calcite_server ( bool  log = true)

Definition at line 533 of file Calcite.cpp.

References inner_close_calcite_server(), and shutdown_once_flag_.

Referenced by ~Calcite().

533  {
534  std::call_once(shutdown_once_flag_,
535  [this, log]() { this->inner_close_calcite_server(log); });
536 }
std::once_flag shutdown_once_flag_
Definition: Calcite.h:130
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:538

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

References CHECK().

419  {
420  std::vector<std::string> v_db_obj;
421  Document document;
422  document.Parse(ra.c_str());
423  const Value& rels = document["rels"];
424  CHECK(rels.IsArray());
425  for (auto& v : rels.GetArray()) {
426  std::string relOp(v["relOp"].GetString());
427  if (!relOp.compare("EnumerableTableScan")) {
428  std::string x;
429  auto t = v["table"].GetArray();
430  x = t[1].GetString();
431  v_db_obj.push_back(x);
432  }
433  }
434 
435  return v_db_obj;
436 }
CHECK(cgen_state)

+ Here is the call graph for this function:

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

Definition at line 175 of file Calcite.cpp.

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

175  {
176  const auto transport = connMgr_->open_buffered_client_transport(
177  "localhost", port, ssl_ca_file_, true, 2000, 5000, 5000);
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:121
std::string ssl_ca_file_
Definition: Calcite.h:129

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

References Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::get_session_id(), Catalog_Namespace::SessionInfo::getCatalog(), getClient(), remote_calcite_port_, and Catalog_Namespace::UserMetadata::userName.

407  {
408  std::vector<TCompletionHint> hints;
409  auto& cat = session_info.getCatalog();
410  const auto user = session_info.get_currentUser().userName;
411  const auto session = session_info.get_session_id();
412  const auto catalog = cat.getCurrentDB().dbName;
413  auto client = getClient(remote_calcite_port_);
414  client.first->getCompletionHints(
415  hints, user, session, catalog, visible_tables, sql_string, cursor);
416  return hints;
417 }
std::string get_session_id() const
Definition: SessionInfo.h:98
Catalog & getCatalog() const
Definition: SessionInfo.h:90
int remote_calcite_port_
Definition: Calcite.h:123
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

+ Here is the call graph for this function:

std::string Calcite::getExtensionFunctionWhitelist ( )

Definition at line 497 of file Calcite.cpp.

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

497  {
498  if (server_available_) {
499  TPlanResult ret;
500  std::string whitelist;
501 
502  auto clientP = getClient(remote_calcite_port_);
503  clientP.first->getExtensionFunctionWhitelist(whitelist);
504  clientP.second->close();
505  VLOG(1) << whitelist;
506  return whitelist;
507  } else {
508  LOG(FATAL) << "Not routing to Calcite, server is not up";
509  return "";
510  }
511  CHECK(false);
512  return "";
513 }
#define LOG(tag)
Definition: Logger.h:185
CHECK(cgen_state)
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175
#define VLOG(n)
Definition: Logger.h:280

+ Here is the call graph for this function:

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

Definition at line 94 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserPassword.

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

Definition at line 93 of file Calcite.h.

References anonymous_namespace{Calcite.h}::kCalciteUserName.

Referenced by processImpl().

93 { 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 561 of file Calcite.cpp.

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

561  {
562  if (server_available_) {
563  TPlanResult ret;
564  std::string whitelist;
565  auto clientP = getClient(remote_calcite_port_);
566  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
567  clientP.second->close();
568  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
569  return whitelist;
570  } else {
571  LOG(FATAL) << "Not routing to Calcite, server is not up";
572  return "";
573  }
574  UNREACHABLE();
575  return "";
576 }
#define LOG(tag)
Definition: Logger.h:185
#define UNREACHABLE()
Definition: Logger.h:234
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175
#define VLOG(n)
Definition: Logger.h:280

+ Here is the call graph for this function:

std::string Calcite::getUserDefinedFunctionWhitelist ( )

Definition at line 515 of file Calcite.cpp.

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

515  {
516  if (server_available_) {
517  TPlanResult ret;
518  std::string whitelist;
519 
520  auto clientP = getClient(remote_calcite_port_);
521  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
522  clientP.second->close();
523  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
524  return whitelist;
525  } else {
526  LOG(FATAL) << "Not routing to Calcite, server is not up";
527  return "";
528  }
529  UNREACHABLE();
530  return "";
531 }
#define LOG(tag)
Definition: Logger.h:185
#define UNREACHABLE()
Definition: Logger.h:234
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175
#define VLOG(n)
Definition: Logger.h:280

+ Here is the call graph for this function:

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

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

Referenced by Calcite().

278  {
279  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
280  << " base data dir is " << data_dir;
281  connMgr_ = std::make_shared<ThriftClientConnection>();
282  if (calcite_port < 0) {
283  CHECK(false) << "JNI mode no longer supported.";
284  }
285  if (calcite_port == 0) {
286  // dummy process for initdb
287  remote_calcite_port_ = calcite_port;
288  server_available_ = false;
289  } else {
290  remote_calcite_port_ = calcite_port;
291  runServer(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
292  server_available_ = true;
293  }
294 }
#define LOG(tag)
Definition: Logger.h:185
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:121
CHECK(cgen_state)
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
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:

void Calcite::inner_close_calcite_server ( bool  log)
private

Definition at line 538 of file Calcite.cpp.

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

Referenced by close_calcite_server().

538  {
539  if (server_available_) {
540  LOG_IF(INFO, log) << "Shutting down Calcite server";
541  try {
542  auto clientP = getClient(remote_calcite_port_);
543  clientP.first->shutdown();
544  clientP.second->close();
545  } catch (const std::exception& e) {
546  if (std::string(e.what()) != "connect() failed: Connection refused" &&
547  std::string(e.what()) != "socket open() error: Connection refused" &&
548  std::string(e.what()) != "No more data to read.") {
549  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
550  } // else Calcite already shut down
551  }
552  LOG_IF(INFO, log) << "shut down Calcite";
553  server_available_ = false;
554  }
555 }
#define LOG_IF(severity, condition)
Definition: Logger.h:276
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int Calcite::ping ( )
private

Definition at line 251 of file Calcite.cpp.

References measure< TimeT >::execution().

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

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

Definition at line 361 of file Calcite.cpp.

References checkPermissionForTables(), AccessPrivileges::DELETE_FROM_TABLE, query_state::QueryState::getConstSessionInfo(), query_state::QueryStateProxy::getQueryState(), AccessPrivileges::INSERT_INTO_TABLE, processImpl(), run_benchmark_import::result, AccessPrivileges::SELECT_FROM_TABLE, AccessPrivileges::SELECT_FROM_VIEW, and AccessPrivileges::UPDATE_IN_TABLE.

368  {
369  TPlanResult result = processImpl(query_state_proxy,
370  std::move(sql_string),
371  filter_push_down_info,
372  legacy_syntax,
373  is_explain,
374  is_view_optimize,
375  calcite_session_id);
376 
377  AccessPrivileges NOOP;
378 
379  if (!is_explain) {
380  // check the individual tables
381  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
382  checkPermissionForTables(*session_ptr,
383  result.primary_accessed_objects.tables_selected_from,
386  checkPermissionForTables(*session_ptr,
387  result.primary_accessed_objects.tables_inserted_into,
389  NOOP);
390  checkPermissionForTables(*session_ptr,
391  result.primary_accessed_objects.tables_updated_in,
393  NOOP);
394  checkPermissionForTables(*session_ptr,
395  result.primary_accessed_objects.tables_deleted_from,
397  NOOP);
398  }
399 
400  return result;
401 }
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
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:438
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:153
QueryState & getQueryState()
Definition: QueryState.h:172
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
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:325

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

References 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().

445  {
446  query_state::Timer timer = query_state_proxy.createTimer(__func__);
447  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
448  const auto& cat = user_session_info->getCatalog();
449  const std::string user = getInternalSessionProxyUserName();
450  const std::string catalog = cat.getCurrentDB().dbName;
451  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
452  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
453  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
454 
455  TPlanResult ret;
456  if (server_available_) {
457  try {
458  // calcite_session_id would be an empty string when accessed by internal resources
459  // that would not access `process` through handler instance, like for eg: Unit
460  // Tests. In these cases we would use the session_id from query state.
461  auto ms = measure<>::execution([&]() {
462  auto clientP = getClient(remote_calcite_port_);
463  clientP.first->process(ret,
464  user,
465  calcite_session_id.empty()
466  ? user_session_info->get_session_id()
467  : calcite_session_id,
468  catalog,
469  sql_string,
470  filter_push_down_info,
471  legacy_syntax,
472  is_explain,
473  is_view_optimize);
474  clientP.second->close();
475  });
476 
477  // LOG(INFO) << ret.plan_result;
478  LOG(INFO) << "Time in Thrift "
479  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
480  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
481  << " (ms)";
482  } catch (InvalidParseRequest& e) {
483  throw std::invalid_argument(e.whyUp);
484  } catch (const std::exception& ex) {
485  LOG(FATAL)
486  << "Error occurred trying to communicate with calcite server, the error was: '"
487  << ex.what() << "', omnisci_server restart will be required";
488  return ret; // satisfy return-type warning
489  }
490  } else {
491  LOG(INFO) << "Not routing to Calcite, server is not up";
492  ret.plan_result = "";
493  }
494  return ret;
495 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:111
QueryState & getQueryState()
Definition: QueryState.h:172
int remote_calcite_port_
Definition: Calcite.h:123
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:93
bool server_available_
Definition: Calcite.h:122
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 server 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,
229  udf_filename);
230 
231  // check for new server for 5 seconds max
232  std::this_thread::sleep_for(std::chrono::milliseconds(200));
233  for (int i = 2; i < 50; i++) {
234  int ping_time = ping();
235  if (ping_time > -1) {
236  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
237  LOG(INFO) << "ping took " << ping_time << " ms ";
238  server_available_ = true;
239  return;
240  } else {
241  // wait 100 ms
242  std::this_thread::sleep_for(std::chrono::milliseconds(100));
243  }
244  }
245  server_available_ = false;
246  LOG(FATAL) << "Could not connect to calcite remote server running on port " << port;
247 }
std::string ssl_key_file_
Definition: Calcite.h:126
#define LOG(tag)
Definition: Logger.h:185
std::string ssl_keystore_
Definition: Calcite.h:127
std::string ssl_keystore_password_
Definition: Calcite.h:128
std::string ssl_trust_store_
Definition: Calcite.h:124
int ping()
Definition: Calcite.cpp:251
int remote_calcite_port_
Definition: Calcite.h:123
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 &udf_filename)
Definition: Calcite.cpp:68
bool server_available_
Definition: Calcite.h:122
std::string ssl_trust_password_
Definition: Calcite.h:125
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

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

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

580  {
581  if (server_available_) {
582  auto clientP = getClient(remote_calcite_port_);
583  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
584  clientP.second->close();
585  } else {
586  LOG(FATAL) << "Not routing to Calcite, server is not up";
587  }
588 }
#define LOG(tag)
Definition: Logger.h:185
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

+ Here is the call graph for this function:

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

Definition at line 312 of file Calcite.cpp.

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

312  {
313  if (server_available_) {
314  auto ms = measure<>::execution([&]() {
315  auto clientP = getClient(remote_calcite_port_);
316  clientP.first->updateMetadata(catalog, table);
317  clientP.second->close();
318  });
319  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
320  } else {
321  LOG(INFO) << "Not routing to Calcite, server is not up";
322  }
323 }
static TimeT::rep execution(F func, Args &&...args)
Definition: sample.cpp:29
#define LOG(tag)
Definition: Logger.h:185
int remote_calcite_port_
Definition: Calcite.h:123
bool server_available_
Definition: Calcite.h:122
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:175

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 121 of file Calcite.h.

Referenced by init().

std::once_flag Calcite::shutdown_once_flag_
private

Definition at line 130 of file Calcite.h.

Referenced by close_calcite_server().

std::string Calcite::ssl_ca_file_
private

Definition at line 129 of file Calcite.h.

std::string Calcite::ssl_key_file_
private

Definition at line 126 of file Calcite.h.

std::string Calcite::ssl_keystore_
private

Definition at line 127 of file Calcite.h.

std::string Calcite::ssl_keystore_password_
private

Definition at line 128 of file Calcite.h.

std::string Calcite::ssl_trust_password_
private

Definition at line 125 of file Calcite.h.

std::string Calcite::ssl_trust_store_
private

Definition at line 124 of file Calcite.h.


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