transactd 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CMakeLists.txt +2 -2
  3. data/bin/common/tdclc_32_3_5.dll +0 -0
  4. data/bin/common/tdclc_64_3_5.dll +0 -0
  5. data/build/common/options.cmake +12 -0
  6. data/build/common/transactd_cl_common.cmake +1 -0
  7. data/build/common/transactd_required.cmake +5 -0
  8. data/build/swig/ruby/tdclrb_wrap.cpp +1029 -130
  9. data/build/swig/tdcl.i +60 -5
  10. data/build/tdclc/CMakeLists.txt +30 -32
  11. data/build/tdclc/libtdclcm.map +1 -1
  12. data/build/tdclc/tdclc.cbproj +1 -1
  13. data/build/tdclc/tdclc.rc +4 -4
  14. data/build/tdclcpp/CMakeLists.txt +39 -48
  15. data/build/tdclcpp/tdclcpp.rc +4 -4
  16. data/build/tdclcpp/tdclcpp_bc.cbproj +4 -1
  17. data/build/tdclrb/CMakeLists.txt +5 -4
  18. data/build/tdclrb/tdclrb.rc +4 -4
  19. data/source/bzs/db/engine/mysql/database.cpp +45 -35
  20. data/source/bzs/db/engine/mysql/database.h +6 -8
  21. data/source/bzs/db/engine/mysql/dbManager.cpp +11 -0
  22. data/source/bzs/db/engine/mysql/dbManager.h +1 -0
  23. data/source/bzs/db/engine/mysql/ha.cpp +174 -0
  24. data/source/bzs/db/engine/mysql/ha.h +50 -0
  25. data/source/bzs/db/engine/mysql/mysqlInternal.h +18 -1
  26. data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +222 -9
  27. data/source/bzs/db/engine/mysql/mysqlProtocol.h +5 -0
  28. data/source/bzs/db/protocol/tdap/client/client.cpp +23 -9
  29. data/source/bzs/db/protocol/tdap/client/client.h +125 -94
  30. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +139 -30
  31. data/source/bzs/db/protocol/tdap/client/connMgr.h +40 -8
  32. data/source/bzs/db/protocol/tdap/client/database.cpp +17 -17
  33. data/source/bzs/db/protocol/tdap/client/database.h +15 -0
  34. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +10 -4
  35. data/source/bzs/db/protocol/tdap/client/haNameResolver.cpp +486 -0
  36. data/source/bzs/db/protocol/tdap/client/haNameResolver.h +74 -0
  37. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +102 -71
  38. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +15 -3
  39. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +2 -5
  40. data/source/bzs/db/protocol/tdap/client/nsTable.h +2 -1
  41. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +2 -2
  42. data/source/bzs/db/protocol/tdap/client/table.cpp +1 -2
  43. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +13 -0
  44. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +1 -0
  45. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +9 -7
  46. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +2 -2
  47. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +328 -117
  48. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +7 -8
  49. data/source/bzs/db/protocol/tdap/tdapcapi.h +81 -41
  50. data/source/bzs/db/transactd/connManager.cpp +118 -93
  51. data/source/bzs/db/transactd/connManager.h +6 -1
  52. data/source/bzs/db/transactd/connectionRecord.h +27 -7
  53. data/source/bzs/db/transactd/transactd.cpp +24 -13
  54. data/source/bzs/env/crosscompile.h +2 -0
  55. data/source/bzs/netsvc/client/iconnection.h +2 -0
  56. data/source/bzs/netsvc/client/tcpClient.cpp +45 -14
  57. data/source/bzs/netsvc/client/tcpClient.h +21 -4
  58. data/source/bzs/netsvc/server/IAppModule.h +1 -0
  59. data/source/bzs/netsvc/server/serverCpt.cpp +1 -1
  60. data/source/bzs/netsvc/server/serverPipe.cpp +2 -0
  61. data/source/bzs/netsvc/server/serverTpool.cpp +3 -5
  62. data/source/bzs/test/tdclatl/test_v3.js +91 -3
  63. data/source/bzs/test/tdclphp/transactd_v3_Test.php +89 -3
  64. data/source/bzs/test/tdclrb/transactd_v3_spec.rb +69 -2
  65. data/source/bzs/test/trdclengn/testField.h +19 -1
  66. data/source/bzs/test/trdclengn/test_tdclcpp_ha.cpp +388 -0
  67. data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +6 -1
  68. data/source/bzs/test/trdclengn/test_trdclengn.cpp +1 -0
  69. data/source/bzs/test/trdclengn/testbase.h +7 -1
  70. data/source/global/replication/haCommand.cpp +843 -0
  71. data/source/global/replication/haCommand.h +78 -0
  72. data/source/global/replication/haMgr.cpp +321 -0
  73. data/source/global/replication/replCommand.cpp +696 -0
  74. data/source/global/replication/replCommand.h +161 -0
  75. data/source/global/tdclatl/BinlogPos.cpp +10 -0
  76. data/source/global/tdclatl/BinlogPos.h +1 -0
  77. data/source/global/tdclatl/ConnMgr.cpp +89 -2
  78. data/source/global/tdclatl/ConnMgr.h +13 -1
  79. data/source/global/tdclatl/ConnRecord.cpp +8 -2
  80. data/source/global/tdclatl/ConnRecord.h +4 -3
  81. data/source/global/tdclatl/Database.cpp +13 -0
  82. data/source/global/tdclatl/Database.h +2 -0
  83. data/source/global/tdclatl/HaNameREsolver.cpp +54 -0
  84. data/source/global/tdclatl/HaNameREsolver.h +68 -0
  85. data/source/global/tdclatl/resource.h +0 -0
  86. data/source/global/tdclatl/tdclatl.idl +76 -5
  87. metadata +16 -6
  88. data/bin/common/tdclc_32_3_4.dll +0 -0
  89. data/bin/common/tdclc_64_3_4.dll +0 -0
  90. data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +0 -423
  91. data/source/bzs/db/protocol/tdap/mysql/debuglog.h +0 -116
@@ -69,7 +69,7 @@ class dbExecuter : public engine::mysql::dbManager
69
69
  void releaseDatabase(request& req, int op);
70
70
  std::string makeSQLcreateTable(const request& req);
71
71
  bool connect(request& req);
72
- inline bool doCreateTable(request& req);
72
+ inline void doCreateTable(request& req);
73
73
  inline bool doOpenTable(request& req, char* buf, bool reconnect=false);
74
74
  inline void doSeekKey(request& req, int op, engine::mysql::rowLockMode* lock);
75
75
  inline void doMoveFirst(request& req, engine::mysql::rowLockMode* lock);
@@ -106,6 +106,7 @@ public:
106
106
  */
107
107
  class connMgrExecuter
108
108
  {
109
+ friend class safeLockReadChannels;
109
110
  request& m_req;
110
111
  __int64 m_modHandle;
111
112
  blobBuffer* m_blobBuffer;
@@ -114,11 +115,15 @@ class connMgrExecuter
114
115
  int definedTables(char* buf, size_t& size);
115
116
  int definedViews(char* buf, size_t& size);
116
117
  int slaveStatus(netsvc::server::netWriter* nw);
118
+ int channels(char* buf, size_t& size);
119
+ int slaveHosts(netsvc::server::netWriter* nw);
117
120
  int systemVariables(char* buf, size_t& size);
118
121
  int statusVariables(char* buf, size_t& size);
122
+ int extendedVariables(netsvc::server::netWriter* nw);
119
123
  int read(char* buf, size_t& size);
120
124
  int disconnectOne(char* buf, size_t& size);
121
125
  int disconnectAll(char* buf, size_t& size);
126
+ void execHaCommand();
122
127
  public:
123
128
  connMgrExecuter(request& req, unsigned __int64 parent, blobBuffer* bb);
124
129
  int commandExec(netsvc::server::netWriter* nw);
@@ -145,13 +150,7 @@ public:
145
150
 
146
151
  bool parse(const char* p, size_t size);
147
152
 
148
- int execute(netsvc::server::netWriter* nw)
149
- {
150
- if (m_req.op == TD_STASTISTICS)
151
- return connMgrExecuter(m_req, (unsigned __int64)m_dbExec->mod(),
152
- m_dbExec->m_blobBuffer).commandExec(nw);
153
- return m_dbExec->commandExec(m_req, nw);
154
- }
153
+ int execute(netsvc::server::netWriter* nw);
155
154
 
156
155
  bool isShutDown() { return m_dbExec->isShutDown(); }
157
156
 
@@ -46,25 +46,12 @@ struct BOOKMARK
46
46
  };
47
47
  typedef BOOKMARK bookmark_td;
48
48
 
49
- /** tdap c interface
50
- */
51
- #if (defined(__BORLANDC__) && !defined(__clang__))
52
- typedef short __stdcall (*dllUnloadCallback)();
53
- #else
54
- /** @cond INTERNAL */
55
- /** Callback function on a record was deleted. */
56
- typedef short(__STDCALL* dllUnloadCallback)();
57
- /** @endcond */
58
- #endif
59
-
49
+ /* tdap c interface */
60
50
  #ifdef LIB_TDCLCPP
61
51
  extern __declspec(dllimport) short_td
62
52
  __stdcall BTRCALLID(ushort_td op, void* posb, void* data, uint_td* datalen,
63
53
  void* keybuf, keylen_td keylen, char_td keyNum,
64
54
  uchar_td* clientID);
65
-
66
- extern __declspec(dllimport) short_td
67
- __stdcall CallbackRegist(dllUnloadCallback func);
68
55
  #endif
69
56
 
70
57
  typedef short_td(__STDCALL* BTRCALLID_PTR)(ushort_td, void*, void*, uint_td*,
@@ -73,6 +60,19 @@ typedef short_td(__STDCALL* BTRCALLID_PTR)(ushort_td, void*, void*, uint_td*,
73
60
 
74
61
  typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
75
62
 
63
+ /* HA hostname resolver */
64
+ #if (defined(__BORLANDC__) && !defined(__clang__))
65
+ typedef const char* __STDCALL (*HANAME_RESOLVER_PTR)(const char* vhost, const char* port, char* retBuf, unsigned int& opt);
66
+ typedef void __STDCALL (*REGISTER_RESOLVER_PTR)(HANAME_RESOLVER_PTR func);
67
+
68
+ #else
69
+ /* @cond INTERNAL */
70
+ typedef const char* (__STDCALL* HANAME_RESOLVER_PTR)(const char* vhost, const char* port, char* retBuf, unsigned int& opt);
71
+ typedef void (__STDCALL* REGISTER_RESOLVER_PTR)(HANAME_RESOLVER_PTR func);
72
+
73
+ /* @endcond */
74
+ #endif
75
+
76
76
  /** buffer size
77
77
  */
78
78
  #define POS_BLOCK_SIZE 128
@@ -202,6 +202,20 @@ typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
202
202
  #define TD_STSTCS_VIEW_LIST 7
203
203
  #define TD_STSTCS_SLAVE_STATUS 8
204
204
  #define TD_STSTCS_STATUS_VARIABLES 9
205
+ #define TD_STSTCS_SLAVE_HOSTS 10
206
+ #define TD_STSTCS_EXTENDED_VARIABLES 11
207
+ #define TD_STSTCS_SLAVE_CHANNELS 12
208
+ #define TD_STSTCS_SLAVE_CHANNELS_LOCK 13
209
+ #define TD_STSTCS_HA_LOCK 14
210
+ #define TD_STSTCS_HA_UNLOCK 15
211
+ #define TD_STSTCS_HA_SET_ROLEMASTER 16
212
+ #define TD_STSTCS_HA_SET_ROLESLAVE 17
213
+ #define TD_STSTCS_HA_SET_ROLENONE 18
214
+ #define TD_STSTCS_HA_SET_TRXBLOCK 19
215
+ #define TD_STSTCS_HA_SET_TRXNOBLOCK 20
216
+ #define TD_STSTCS_HA_ENABLE_FO 21
217
+ #define TD_STSTCS_HA_DISBLE_FO 22
218
+
205
219
 
206
220
  /** connect sub operation
207
221
  */
@@ -282,27 +296,27 @@ typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
282
296
  #define ft_mydecimal 62
283
297
  #define ft_nullindicator 255
284
298
 
285
- /* compair types */
286
- enum eCompType
287
- {
288
- eEqual = 1,
289
- eGreater = 2,
290
- eLess = 3,
291
- eNotEq = 4,
292
- eGreaterEq = 5,
293
- eLessEq = 6,
299
+ /* compair types */
300
+ enum eCompType
301
+ {
302
+ eEqual = 1,
303
+ eGreater = 2,
304
+ eLess = 3,
305
+ eNotEq = 4,
306
+ eGreaterEq = 5,
307
+ eLessEq = 6,
294
308
  eBitAnd = 8,
295
- eNotBitAnd = 9,
296
- eIsNull = 10,
297
- eIsNotNull = 11
309
+ eNotBitAnd = 9,
310
+ eIsNull = 10,
311
+ eIsNotNull = 11
298
312
  };
299
313
 
300
- /* filter cobine type */
301
- enum combineType
302
- {
303
- eCend,
304
- eCand,
305
- eCor
314
+ /* filter cobine type */
315
+ enum combineType
316
+ {
317
+ eCend,
318
+ eCand,
319
+ eCor
306
320
  };
307
321
 
308
322
  /** extruct row comp bias
@@ -484,13 +498,15 @@ enum combineType
484
498
  #define ERROR_TD_NET_TOO_BIGDATA 3802
485
499
  #define ERROR_TD_NET_OTHER 3810
486
500
  #define ERROR_TD_C_CLIENT_UNKNOWN 3811
501
+ #define ERROR_TD_INVALID_SERVER_ROLE 3812
487
502
  #define ERROR_TD_RECONNECTED 3900
488
503
 
504
+ #define ERROR_TD_RECONNECTED_OFFSET 1000
489
505
  #define MYSQL_ERROR_OFFSET 25000
490
506
 
491
507
  inline bool canRecoverNetError(short code)
492
508
  {
493
- return (code >= ERROR_TD_CONNECTION_FAILURE) &&
509
+ return (code >= ERROR_TD_HOSTNAME_NOT_FOUND) &&
494
510
  (code < ERROR_TD_RECONNECTED) &&
495
511
  (code != ERROR_TD_NET_TOO_BIGDATA);
496
512
  }
@@ -588,6 +604,12 @@ struct handshale_t
588
604
  };
589
605
 
590
606
  #define HST_OPTION_NO_SCRAMBLE 1
607
+ #define HST_OPTION_ROLE_MASTER 2
608
+ #define HST_OPTION_ROLE_SLAVE 4
609
+ #define HST_OPTION_CLEAR_CACHE 8
610
+
611
+
612
+ #define CL_OPTION_CHECK_ROLE 1
591
613
 
592
614
  /* server system variables index */
593
615
  #define TD_VER_DB 0
@@ -608,7 +630,8 @@ struct handshale_t
608
630
  #define TD_VAR_HSLISTENPORT 15
609
631
  #define TD_VAR_USEHS 16
610
632
  #define TD_VAR_TIMESTAMPMODE 17
611
- #define TD_VAR_SIZE 18
633
+ #define TD_VAR_STARTUP_HA 18
634
+ #define TD_VAR_SIZE 19
612
635
 
613
636
  /* server status variables index */
614
637
  #define TD_SVAR_TCP_CONNECTIONS 0
@@ -618,14 +641,31 @@ struct handshale_t
618
641
  #define TD_SVAR_PIPE_CONNECTIONS 4
619
642
  #define TD_SVAR_PIPE_WAIT_THREADS 5
620
643
  #define TD_SVAR_OPEN_DBS 6
621
- #define TD_SVAR_SIZE 7
622
- /** @endcond */
644
+ #define TD_SVAR_HA 7
645
+ #define TD_SVAR_SIZE 8
646
+
647
+ #define HA_ROLE_SLAVE 0
648
+ #define HA_ROLE_MASTER 1
649
+ #define HA_ROLE_NONE 2
650
+ #define HA_RESTORE_ROLE 4
651
+ #define HA_ENABLE_FAILOVER 8
652
+
653
+ /* server sql variables index */
654
+ #define TD_EXTENDED_VAR_MYSQL_GTID_MODE 0
655
+ #define TD_EXTENDED_VAR_BINLOG_FILE 1
656
+ #define TD_EXTENDED_VAR_BINLOG_POS 2
657
+ #define TD_EXTENDED_VAR_BINLOG_GTID 3
658
+ #define TD_EXTENDED_VAR_SIZE 4
623
659
 
660
+
661
+ #define TD_CLINET_LOGNAME "transactd_clinet_err.log"
662
+
663
+ /** @endcond */
624
664
  /* In the case of "tdclcppxxx" library of msvc, The ($TargetName) is not changed automatically.
625
665
  If you change this version then you need change The ($TargetName) project options too.
626
666
  */
627
667
  #define C_INTERFACE_VER_MAJOR "3"//##1 Build marker! Don't remove
628
- #define C_INTERFACE_VER_MINOR "4"//##2 Build marker! Don't remove
668
+ #define C_INTERFACE_VER_MINOR "5"//##2 Build marker! Don't remove
629
669
  #define C_INTERFACE_VER_RELEASE "0"//##3 Build marker! Don't remove
630
670
 
631
671
  /* dnamic load library name.
@@ -689,8 +729,8 @@ struct handshale_t
689
729
  */
690
730
 
691
731
  #define CPP_INTERFACE_VER_MAJOR "3"//##4 Build marker! Don't remove
692
- #define CPP_INTERFACE_VER_MINOR "4"//##5 Build marker! Don't remove
693
- #define CPP_INTERFACE_VER_RELEASE "1"//##6 Build marker! Don't remove
732
+ #define CPP_INTERFACE_VER_MINOR "5"//##5 Build marker! Don't remove
733
+ #define CPP_INTERFACE_VER_RELEASE "0"//##6 Build marker! Don't remove
694
734
 
695
735
  /* use autolink tdclcpp */
696
736
  #if (__BCPLUSPLUS__ || _MSC_VER)
@@ -726,7 +766,7 @@ struct handshale_t
726
766
 
727
767
 
728
768
  #define TRANSACTD_VER_MAJOR 3//##7 Build marker! Don't remove
729
- #define TRANSACTD_VER_MINOR 4//##8 Build marker! Don't remove
730
- #define TRANSACTD_VER_RELEASE 1//##9 Build marker! Don't remove
769
+ #define TRANSACTD_VER_MINOR 5//##8 Build marker! Don't remove
770
+ #define TRANSACTD_VER_RELEASE 0//##9 Build marker! Don't remove
731
771
 
732
772
  #endif // BZS_DB_PROTOCOL_TDAP_TDAPCAPI_H
@@ -33,8 +33,13 @@ extern const char* get_trd_sys_var(int index);
33
33
  extern const unsigned int* get_trd_status_var(int index);
34
34
 
35
35
  /* implemnts in mysqlProtocol.cpp */
36
- extern int getSlaveStatus(THD* thd, bzs::db::transactd::connection::records& recs,
37
- bzs::db::IblobBuffer* bb);
36
+ extern int getSlaveStatus(THD* thd, const char* channel,
37
+ bzs::db::transactd::connection::records& recs, bzs::db::IblobBuffer* bb);
38
+ extern int getSlaveHosts(THD* thd, bzs::db::transactd::connection::records& recs,
39
+ bzs::db::IblobBuffer* bb);
40
+ extern int getChannels(THD* thd, bzs::db::transactd::connection::records& recs);
41
+
42
+ extern short getBinlogPos(THD* thd, binlogPos* bpos, THD* tmpThd, bzs::db::IblobBuffer* bb);
38
43
 
39
44
  namespace bzs
40
45
  {
@@ -47,9 +52,7 @@ using namespace engine::mysql;
47
52
  namespace transactd
48
53
  {
49
54
 
50
- connManager::~connManager()
51
- {
52
- }
55
+ connManager::~connManager(){}
53
56
 
54
57
  const module* getMod(unsigned __int64 conid)
55
58
  {
@@ -223,6 +226,54 @@ const connection::records& connManager::systemVariables() const
223
226
  return m_records;
224
227
  }
225
228
 
229
+ const connection::records& connManager::extendedVariables(blobBuffer* bb) const
230
+ {
231
+ m_records.clear();
232
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
233
+ if (thd == NULL)
234
+ m_stat = 20001;
235
+ else if (!checkGlobalACL(thd.get(), SUPER_ACL | REPL_CLIENT_ACL))
236
+ m_stat = STATUS_ACCESS_DENIED;
237
+ if (m_stat) return m_records;
238
+ binlogPos bpos;
239
+ short ret = getBinlogPos(thd.get(), &bpos, thd.get(), bb);
240
+ if (ret) return m_records;
241
+ for (int i = 0; i < TD_EXTENDED_VAR_SIZE; ++i)
242
+ {
243
+ m_records.push_back(connection::record());
244
+ connection::record& rec = m_records[m_records.size() - 1];
245
+ rec.id = i;
246
+ rec.type = 1;
247
+ switch (i)
248
+ {
249
+ case TD_EXTENDED_VAR_MYSQL_GTID_MODE:
250
+ {
251
+ rec.type = 0;
252
+ #if (defined(MYSQL_5_7))
253
+ rec.longValue = (long long)get_gtid_mode(GTID_MODE_LOCK_NONE);
254
+ #else
255
+ rec.longValue = 0;
256
+ #endif
257
+ break;
258
+ }
259
+ case TD_EXTENDED_VAR_BINLOG_FILE:
260
+ strncpy(rec.name, bpos.filename, CON_REC_VALUE_SIZE);
261
+ break;
262
+ case TD_EXTENDED_VAR_BINLOG_POS:
263
+ rec.longValue = bpos.pos;
264
+ rec.type = 0;
265
+ break;
266
+ case TD_EXTENDED_VAR_BINLOG_GTID:
267
+ if (bpos.type == REPL_POSTYPE_GTID)
268
+ rec.type = 2;
269
+ else
270
+ strncpy(rec.name, bpos.gtid, CON_REC_VALUE_SIZE);
271
+ break;
272
+ }
273
+ }
274
+ return m_records;
275
+ }
276
+
226
277
  const connection::records& connManager::statusVariables() const
227
278
  {
228
279
  m_records.clear();
@@ -241,77 +292,38 @@ const connection::records& connManager::statusVariables() const
241
292
  return m_records;
242
293
  }
243
294
 
244
-
245
295
  const connection::records& connManager::definedDatabases() const
246
296
  {
247
297
  m_records.clear();
248
- try
298
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
299
+ if (thd != NULL)
249
300
  {
250
- boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
251
- if (thd != NULL)
252
- {
253
- cp_security_ctx(thd.get())->skip_grants();
254
- readDbList(thd.get(), m_records);
255
- }
256
- }
257
- catch (bzs::rtl::exception& e)
258
- {
259
- const int* code = getCode(e);
260
- if (code)
261
- m_stat = *code;
262
- else
263
- {
264
- m_stat = 20000;
265
- sql_print_error("%s", boost::diagnostic_information(e).c_str());
266
- }
267
- printWarningMessage(code, getMsg(e));
268
- }
269
- catch (...)
270
- {
271
- m_stat = 20001;
301
+ cp_security_ctx(thd.get())->skip_grants();
302
+ readDbList(thd.get(), m_records);
272
303
  }
273
304
  return m_records;
274
305
  }
275
306
 
276
307
  const connection::records& connManager::getTableList(const char* dbname, int type) const
277
308
  {
278
- try
279
- {
280
- m_records.clear();
281
- if (dbname && dbname[0])
309
+ m_records.clear();
310
+ if (dbname && dbname[0])
311
+ {
312
+ boost::shared_ptr<database> db(new database(dbname, 1));
313
+ if (db)
282
314
  {
283
- boost::shared_ptr<database> db(new database(dbname, 1));
284
- if (db)
315
+ std::vector<std::string> tablelist;
316
+ schemaBuilder::listTable(db.get(), tablelist, type);
317
+ for (int i = 0; i < (int)tablelist.size(); ++i)
285
318
  {
286
- std::vector<std::string> tablelist;
287
- schemaBuilder::listTable(db.get(), tablelist, type);
288
- for (int i = 0; i < (int)tablelist.size(); ++i)
289
- {
290
- m_records.push_back(connection::record());
291
- connection::record& rec = m_records[m_records.size() - 1];
292
- strncpy(rec.name, tablelist[i].c_str(), 64);
293
- rec.name[64] = 0x00;
294
- rec.type = (short)type;
295
- }
319
+ m_records.push_back(connection::record());
320
+ connection::record& rec = m_records[m_records.size() - 1];
321
+ strncpy(rec.name, tablelist[i].c_str(), 64);
322
+ rec.name[64] = 0x00;
323
+ rec.type = 1;
296
324
  }
297
325
  }
298
326
  }
299
- catch (bzs::rtl::exception& e)
300
- {
301
- const int* code = getCode(e);
302
- if (code)
303
- m_stat = *code;
304
- else
305
- {
306
- m_stat = 20000;
307
- sql_print_error("%s", boost::diagnostic_information(e).c_str());
308
- }
309
- printWarningMessage(code, getMsg(e));
310
- }
311
- catch (...)
312
- {
313
- m_stat = 20001;
314
- }
315
327
  return m_records;
316
328
  }
317
329
 
@@ -332,44 +344,53 @@ bool connManager::checkGlobalACL(THD* thd, ulong wantAccess) const
332
344
  cp_security_ctx(thd)->skip_grants();
333
345
  else
334
346
  ::setGrant(thd, mod->host(), mod->user(), NULL);
335
- bool ret = (cp_masterAccess(thd) & wantAccess) != 0;
347
+ bool ret = (cp_masterAccess(thd) & wantAccess) != 0;
336
348
  if (!ret)
337
349
  m_stat = STATUS_ACCESS_DENIED;
338
350
  return ret;
339
351
  }
340
352
 
341
- const connection::records& connManager::readSlaveStatus(blobBuffer* bb) const
353
+ const connection::records& connManager::readByProtocol(int type, blobBuffer* bb,
354
+ const char* channel) const
342
355
  {
343
356
  m_records.clear();
344
- try
345
- {
346
- boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
347
- if (thd == NULL)
348
- {
349
- m_stat = 20001;
350
- return m_records;
351
- }
352
- if (!checkGlobalACL(thd.get(), SUPER_ACL | REPL_CLIENT_ACL))
353
- return m_records;
354
-
355
- m_stat = errorCode(getSlaveStatus(thd.get(), m_records, bb));
356
- }
357
- catch (bzs::rtl::exception& e)
357
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
358
+ if (thd == NULL)
359
+ m_stat = 20001;
360
+ else if (!checkGlobalACL(thd.get(), SUPER_ACL | REPL_CLIENT_ACL))
361
+ m_stat = STATUS_ACCESS_DENIED;
362
+ else
358
363
  {
359
- const int* code = getCode(e);
360
- if (code)
361
- m_stat = *code;
364
+ int ret;
365
+ if (type == TD_STSTCS_SLAVE_STATUS)
366
+ ret = getSlaveStatus(thd.get(), channel, m_records, bb);
362
367
  else
363
- {
364
- m_stat = 20000;
365
- sql_print_error("%s", boost::diagnostic_information(e).c_str());
366
- }
367
- printWarningMessage(code, getMsg(e));
368
+ ret = getSlaveHosts(thd.get(), m_records, bb);
369
+ m_stat = errorCode(ret);
368
370
  }
369
- catch (...)
370
- {
371
+ return m_records;
372
+ }
373
+
374
+ const connection::records& connManager::readSlaveStatus(const char* channel, blobBuffer* bb) const
375
+ {
376
+ return readByProtocol(TD_STSTCS_SLAVE_STATUS, bb, channel);
377
+ }
378
+
379
+ const connection::records& connManager::slaveHosts(blobBuffer* bb) const
380
+ {
381
+ return readByProtocol(TD_STSTCS_SLAVE_HOSTS, bb);
382
+ }
383
+
384
+ const connection::records& connManager::channels() const
385
+ {
386
+ m_records.clear();
387
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
388
+ if (thd == NULL)
371
389
  m_stat = 20001;
372
- }
390
+ else if (!checkGlobalACL(thd.get(), REPL_CLIENT_ACL))
391
+ m_stat = STATUS_ACCESS_DENIED;
392
+ else
393
+ m_stat = errorCode(getChannels(thd.get(), m_records));
373
394
  return m_records;
374
395
  }
375
396
 
@@ -381,13 +402,17 @@ void connManager::doDisconnect(unsigned __int64 conid)
381
402
  igetDatabases* dbm =
382
403
  dynamic_cast<igetDatabases*>(mod->m_commandExecuter.get());
383
404
  const databases& dbs = dbm->dbs();
384
- if (dbs.size())
405
+ for (size_t i = 0; i < dbs.size(); ++i)
385
406
  {
386
- if (dbs[0]->checkAcl(SHUTDOWN_ACL))
387
- mod->disconnect();
388
- else
389
- m_stat = STATUS_ACCESS_DENIED;
407
+ if (dbs[i])
408
+ {
409
+ if (!dbs[i]->checkAcl(SHUTDOWN_ACL))
410
+ m_stat = STATUS_ACCESS_DENIED;
411
+ break;
412
+ }
390
413
  }
414
+ if (m_stat == 0)
415
+ mod->disconnect();
391
416
  }
392
417
  }
393
418