OmniSciDB  04ee39c94c
ThriftWithRetry.h File Reference
#include <cmath>
#include <iostream>
#include "gen-cpp/mapd_types.h"
+ Include dependency graph for ThriftWithRetry.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename SERVICE_ENUM , typename CLIENT_CONTEXT >
bool thrift_with_retry (SERVICE_ENUM which_service, CLIENT_CONTEXT &context, char const *arg, const int try_count=1)
 

Function Documentation

◆ thrift_with_retry()

template<typename SERVICE_ENUM , typename CLIENT_CONTEXT >
bool thrift_with_retry ( SERVICE_ENUM  which_service,
CLIENT_CONTEXT &  context,
char const *  arg,
const int  try_count = 1 
)

Definition at line 9 of file ThriftWithRetry.h.

References kCLEAR_MEMORY_CPU, kCLEAR_MEMORY_GPU, kCONNECT, kDISCONNECT, kGET_COMPLETION_HINTS, kGET_DASHBOARD, kGET_DASHBOARDS, kGET_DATABASES, kGET_HARDWARE_INFO, kGET_LICENSE_CLAIMS, kGET_MEMORY_CPU, kGET_MEMORY_GPU, kGET_MEMORY_SUMMARY, kGET_OBJECT_PRIVS, kGET_OBJECTS_FOR_GRANTEE, kGET_PHYSICAL_TABLES, kGET_ROLES, kGET_ROLES_FOR_USER, kGET_SERVER_STATUS, kGET_TABLE_DETAILS, kGET_TABLE_EPOCH, kGET_TABLE_EPOCH_BY_NAME, kGET_TABLES, kGET_USERS, kGET_VERSION, kGET_VIEWS, kIMPORT_DASHBOARD, kINTERRUPT, kREPORT_DATABASE, kSET_EXECUTION_MODE, kSET_LICENSE_KEY, kSET_TABLE_EPOCH, kSET_TABLE_EPOCH_BY_NAME, kSQL, and kSWITCH_DATABASE.

Referenced by anonymous_namespace{omnisql.cpp}::backchannel(), anonymous_namespace{omnisql.cpp}::completion(), anonymous_namespace{omnisql.cpp}::copy_table(), anonymous_namespace{omnisql.cpp}::get_db_object_privs(), anonymous_namespace{omnisql.cpp}::get_db_objects_for_grantee(), anonymous_namespace{omnisql.cpp}::get_license_claims(), anonymous_namespace{omnisql.cpp}::get_table_epoch(), main(), anonymous_namespace{omnisql.cpp}::set_license_key(), anonymous_namespace{omnisql.cpp}::set_table_epoch(), and thrift_op().

12  {
13  using TException = ::apache::thrift::TException;
14 
15  int max_reconnect = 4;
16  int con_timeout_base = 1;
17  if (try_count > max_reconnect) {
18  std::cerr << "Cannot connect to OmniSci Server." << std::endl;
19  return false;
20  }
21  try {
22  switch (which_service) {
23  case kCONNECT:
24  context.client.connect(
25  context.session, context.user_name, context.passwd, context.db_name);
26  context.client.get_session_info(context.session_info, context.session);
27  context.user_name = context.session_info.user;
28  context.db_name = context.session_info.database;
29  break;
30  case kSWITCH_DATABASE:
31  context.client.switch_database(context.session, context.db_name);
32  context.client.get_session_info(context.session_info, context.session);
33  context.db_name = context.session_info.database;
34  break;
35  case kREPORT_DATABASE:
36  context.client.get_session_info(context.session_info, context.session);
37  context.db_name = context.session_info.database;
38  break;
39  case kDISCONNECT:
40  context.client.disconnect(context.session);
41  break;
42  case kINTERRUPT:
43  context.client.interrupt(context.session);
44  break;
45  case kSQL:
46  context.client.sql_execute(
47  context.query_return, context.session, arg, true, "", -1, -1);
48  break;
49  case kGET_TABLES:
50  context.client.get_tables(context.names_return, context.session);
51  break;
53  context.client.get_physical_tables(context.names_return, context.session);
54  break;
55  case kGET_VIEWS:
56  context.client.get_views(context.names_return, context.session);
57  break;
58  case kGET_DATABASES:
59  context.client.get_databases(context.dbinfos_return, context.session);
60  break;
61  case kGET_USERS:
62  context.client.get_users(context.names_return, context.session);
63  break;
65  context.client.set_execution_mode(context.session, context.execution_mode);
66  break;
67  case kGET_VERSION:
68  context.client.get_version(context.version);
69  break;
70  case kGET_MEMORY_GPU:
71  context.client.get_memory(context.gpu_memory, context.session, "gpu");
72  break;
73  case kGET_MEMORY_CPU:
74  context.client.get_memory(context.cpu_memory, context.session, "cpu");
75  break;
77  context.client.get_memory(context.gpu_memory, context.session, "gpu");
78  context.client.get_memory(context.cpu_memory, context.session, "cpu");
79  break;
80  case kGET_TABLE_DETAILS:
81  context.client.get_table_details(context.table_details, context.session, arg);
82  break;
83  case kCLEAR_MEMORY_GPU:
84  context.client.clear_gpu_memory(context.session);
85  break;
86  case kCLEAR_MEMORY_CPU:
87  context.client.clear_cpu_memory(context.session);
88  break;
89  case kGET_HARDWARE_INFO:
90  context.client.get_hardware_info(context.cluster_hardware_info, context.session);
91  break;
92  case kSET_TABLE_EPOCH:
93  context.client.set_table_epoch(
94  context.session, context.db_id, context.table_id, context.epoch_value);
95  break;
97  context.client.set_table_epoch_by_name(
98  context.session, context.table_name, context.epoch_value);
99  break;
100  case kGET_TABLE_EPOCH:
101  context.epoch_value = context.client.get_table_epoch(
102  context.session, context.db_id, context.table_id);
103  break;
105  context.epoch_value =
106  context.client.get_table_epoch_by_name(context.session, context.table_name);
107  break;
108  case kGET_SERVER_STATUS:
109  context.client.get_status(context.cluster_status, context.session);
110  break;
111  case kIMPORT_DASHBOARD:
112  context.client.create_dashboard(context.session,
113  context.view_name,
114  context.view_state,
115  "",
116  context.view_metadata);
117  break;
118  case kGET_ROLES:
119  context.client.get_roles(context.role_names, context.session);
120  break;
122  context.client.get_db_objects_for_grantee(
123  context.db_objects, context.session, context.privs_role_name);
124  break;
125  case kGET_OBJECT_PRIVS:
126  context.client.get_db_object_privs(context.db_objects,
127  context.session,
128  context.privs_object_name,
129  context.object_type);
130  break;
131  case kGET_ROLES_FOR_USER:
132  context.client.get_all_roles_for_user(
133  context.role_names, context.session, context.privs_user_name);
134  break;
135  case kSET_LICENSE_KEY:
136  context.client.set_license_key(
137  context.license_info, context.session, context.license_key, "");
138  break;
139  case kGET_LICENSE_CLAIMS:
140  context.client.get_license_claims(context.license_info, context.session, "");
141  break;
143  context.client.get_completion_hints(
144  context.completion_hints, context.session, arg, -1);
145  break;
146  case kGET_DASHBOARDS:
147  context.client.get_dashboards(context.dash_names, context.session);
148  break;
149  case kGET_DASHBOARD:
150  context.client.get_dashboard(
151  context.dash_return, context.session, context.dash_id);
152  break;
153  }
154  } catch (TMapDException& e) {
155  std::cerr << e.error_msg << std::endl;
156  return false;
157  } catch (TException& te) {
158  std::cerr << "Thrift error: " << te.what() << std::endl;
159  try {
160  std::cerr << "Thrift connection error: " << te.what() << std::endl;
161  std::cerr << "Retrying connection" << std::endl;
162  context.transport.open();
163  if (which_service == kDISCONNECT) {
164  return false;
165  }
166  sleep(con_timeout_base * pow(2, try_count));
167  if (which_service != kCONNECT) {
168  if (!thrift_with_retry(kCONNECT, context, nullptr, try_count + 1)) {
169  return false;
170  }
171  }
172  return thrift_with_retry(which_service, context, arg, try_count + 1);
173  } catch (TException& te1) {
174  std::cerr << "Thrift error: " << te1.what() << std::endl;
175  return false;
176  }
177  }
178  return true;
179 }
bool thrift_with_retry(SERVICE_ENUM which_service, CLIENT_CONTEXT &context, char const *arg, const int try_count=1)
+ Here is the caller graph for this function: