transactd 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/common/tdclc_32_3_2.dll +0 -0
  3. data/bin/common/{tdclc_64_3_1.dll → tdclc_64_3_2.dll} +0 -0
  4. data/build/swig/ruby/ruby.swg +3 -0
  5. data/build/swig/ruby/tdclrb_wrap.cpp +2413 -126
  6. data/build/swig/tdcl.i +120 -9
  7. data/build/tdclc/tdclc.cbproj +4 -1
  8. data/build/tdclc/tdclc.rc +4 -4
  9. data/build/tdclcpp/tdclcpp.rc +4 -4
  10. data/build/tdclcpp/tdclcpp_bc.cbproj +8 -1
  11. data/build/tdclrb/tdclrb.rc +4 -4
  12. data/source/bzs/db/engine/mysql/database.cpp +138 -130
  13. data/source/bzs/db/engine/mysql/database.h +43 -48
  14. data/source/bzs/db/engine/mysql/dbManager.cpp +81 -96
  15. data/source/bzs/db/engine/mysql/dbManager.h +13 -22
  16. data/source/bzs/db/engine/mysql/mysqlInternal.h +157 -291
  17. data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +425 -0
  18. data/source/bzs/db/engine/mysql/mysqlProtocol.h +72 -0
  19. data/source/bzs/db/engine/mysql/mysqlThd.cpp +8 -6
  20. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +7 -3
  21. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +1 -0
  22. data/source/bzs/db/protocol/tdap/client/client.h +22 -8
  23. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +225 -21
  24. data/source/bzs/db/protocol/tdap/client/connMgr.h +42 -16
  25. data/source/bzs/db/protocol/tdap/client/database.cpp +58 -15
  26. data/source/bzs/db/protocol/tdap/client/database.h +3 -3
  27. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +93 -85
  28. data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -2
  29. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +9 -5
  30. data/source/bzs/db/protocol/tdap/client/filter.h +2 -2
  31. data/source/bzs/db/protocol/tdap/client/groupComp.h +2 -2
  32. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +1 -1
  33. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +71 -12
  34. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +7 -1
  35. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +35 -2
  36. data/source/bzs/db/protocol/tdap/client/nsTable.h +1 -0
  37. data/source/bzs/db/protocol/tdap/client/recordset.cpp +5 -1
  38. data/source/bzs/db/protocol/tdap/client/recordset.h +15 -0
  39. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +21 -16
  40. data/source/bzs/db/protocol/tdap/client/serializer.cpp +32 -11
  41. data/source/bzs/db/protocol/tdap/client/serializer.h +4 -1
  42. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +3 -2
  43. data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +3 -0
  44. data/source/bzs/db/protocol/tdap/client/table.cpp +18 -14
  45. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +8 -3
  46. data/source/bzs/db/protocol/tdap/mysql/characterset.cpp +1 -0
  47. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +83 -43
  48. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +3 -1
  49. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +7 -7
  50. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +247 -137
  51. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +9 -9
  52. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +1 -4
  53. data/source/bzs/db/protocol/tdap/tdapSchema.h +3 -7
  54. data/source/bzs/db/protocol/tdap/tdapcapi.h +23 -3
  55. data/source/bzs/db/protocol/tdap/uri.h +40 -0
  56. data/source/bzs/db/transactd/appModule.cpp +14 -5
  57. data/source/bzs/db/transactd/appModule.h +10 -1
  58. data/source/bzs/db/transactd/connManager.cpp +93 -48
  59. data/source/bzs/db/transactd/connManager.h +10 -7
  60. data/source/bzs/db/transactd/connectionRecord.h +114 -19
  61. data/source/bzs/env/tstring.h +2 -0
  62. data/source/bzs/example/changeSchema.cpp +1 -1
  63. data/source/bzs/example/changeSchema_c.cpp +1 -1
  64. data/source/bzs/example/insertRecords.cpp +2 -1
  65. data/source/bzs/example/insertRecords_c.cpp +2 -1
  66. data/source/bzs/example/queryData.cpp +5 -2
  67. data/source/bzs/netsvc/server/IAppModule.h +6 -0
  68. data/source/bzs/test/tdclatl/test_v3.js +75 -0
  69. data/source/bzs/test/tdclphp/transactd_v3_Test.php +104 -7
  70. data/source/bzs/test/tdclrb/transactd_v3_spec.rb +84 -0
  71. data/source/bzs/test/trdclengn/testField.h +66 -6
  72. data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +10 -1
  73. data/source/bzs/test/trdclengn/test_trdclengn.cpp +85 -0
  74. data/source/bzs/test/trdclengn/testbase.h +1 -1
  75. data/source/global/tdclatl/BinlogPos.cpp +64 -0
  76. data/source/global/tdclatl/BinlogPos.h +84 -0
  77. data/source/global/tdclatl/ConnMgr.cpp +285 -0
  78. data/source/global/tdclatl/ConnMgr.h +83 -0
  79. data/source/global/tdclatl/ConnRecord.cpp +123 -0
  80. data/source/global/tdclatl/ConnRecord.h +69 -0
  81. data/source/global/tdclatl/ConnRecords.cpp +57 -0
  82. data/source/global/tdclatl/ConnRecords.h +55 -0
  83. data/source/global/tdclatl/Database.cpp +36 -0
  84. data/source/global/tdclatl/Database.h +4 -0
  85. data/source/global/tdclatl/Table.cpp +14 -1
  86. data/source/global/tdclatl/Table.h +1 -0
  87. data/source/global/tdclatl/resource.h +0 -0
  88. data/source/global/tdclatl/tdclatl.idl +148 -4
  89. metadata +14 -4
  90. data/bin/common/tdclc_32_3_1.dll +0 -0
@@ -185,6 +185,11 @@ typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
185
185
  */
186
186
  #define TD_ASBLOB_ENDROW -125
187
187
 
188
+ /** TD_GET_SCHEMA sub operations
189
+ */
190
+ #define SC_SUBOP_BY_SQL -1
191
+ #define SC_SUBOP_VIEW_BY_SQL -2
192
+
188
193
  /** TD_GET_STASTISTICS sub operations
189
194
  */
190
195
  #define TD_STSTCS_READ 0
@@ -193,6 +198,10 @@ typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
193
198
  #define TD_STSTCS_DATABASE_LIST 3
194
199
  #define TD_STSTCS_SYSTEM_VARIABLES 4
195
200
  #define TD_STSTCS_SCHEMA_TABLE_LIST 5
201
+ #define TD_STSTCS_TABLE_LIST 6
202
+ #define TD_STSTCS_VIEW_LIST 7
203
+ #define TD_STSTCS_SLAVE_STATUS 8
204
+
196
205
  /** connect sub operation
197
206
  */
198
207
 
@@ -201,6 +210,14 @@ typedef void(__STDCALL* WIN_TPOOL_SHUTDOWN_PTR)();
201
210
  #define LG_SUBOP_NEWCONNECT 3
202
211
  #define LG_SUBOP_RECONNECT 4
203
212
  #define LG_SUBOP_DISCONNECT_EX 5 //for reconnect test
213
+ #define LG_SUBOP_ASSOCIATE 6
214
+
215
+ /** TD_STSTCS_TABLE_LIST type list
216
+ */
217
+ #define TABLE_TYPE_NORMAL_TABLE 1
218
+ #define TABLE_TYPE_VIEW 2
219
+ #define TABLE_TYPE_TD_SCHEMA 4
220
+
204
221
 
205
222
  /** TIMESTAMP_MODE
206
223
  */
@@ -455,6 +472,7 @@ enum combineType
455
472
  #define STATUS_LMIT_OF_PREPAREED 203
456
473
  #define STATUS_ALREADY_INSNAPSHOT 204
457
474
  #define STATUS_ALREADY_INTRANSACTION 205
475
+ #define STATUS_ALREADY_INEXCLUSIVE 206
458
476
  #define SERVER_CLIENT_NOT_COMPATIBLE 3003
459
477
  #define NET_BAD_SRB_FORMAT 3021
460
478
  #define ERROR_TD_HOSTNAME_NOT_FOUND 3103
@@ -478,6 +496,8 @@ inline bool canRecoverNetError(short code)
478
496
  #define TRANSACTD_SCHEMANAME _T("transactd_schema")
479
497
  #define TYPE_SCHEMA_BDF 0
480
498
  #define TYPE_SCHEMA_DDF 1
499
+ #define TYPE_SCHEMA_BDF_NOPRELOAD 2
500
+
481
501
 
482
502
  #define FILTER_CURRENT_TYPE_NOTINC 0
483
503
  #define FILTER_CURRENT_TYPE_INC 1
@@ -593,7 +613,7 @@ struct handshale_t
593
613
  If you change this version then you need change The ($TargetName) project options too.
594
614
  */
595
615
  #define C_INTERFACE_VER_MAJOR "3"//##1 Build marker! Don't remove
596
- #define C_INTERFACE_VER_MINOR "1"//##2 Build marker! Don't remove
616
+ #define C_INTERFACE_VER_MINOR "2"//##2 Build marker! Don't remove
597
617
  #define C_INTERFACE_VER_RELEASE "0"//##3 Build marker! Don't remove
598
618
 
599
619
  /* dnamic load library name.
@@ -657,7 +677,7 @@ struct handshale_t
657
677
  */
658
678
 
659
679
  #define CPP_INTERFACE_VER_MAJOR "3"//##4 Build marker! Don't remove
660
- #define CPP_INTERFACE_VER_MINOR "1"//##5 Build marker! Don't remove
680
+ #define CPP_INTERFACE_VER_MINOR "2"//##5 Build marker! Don't remove
661
681
  #define CPP_INTERFACE_VER_RELEASE "0"//##6 Build marker! Don't remove
662
682
 
663
683
  /* use autolink tdclcpp */
@@ -694,7 +714,7 @@ struct handshale_t
694
714
 
695
715
 
696
716
  #define TRANSACTD_VER_MAJOR 3//##7 Build marker! Don't remove
697
- #define TRANSACTD_VER_MINOR 1//##8 Build marker! Don't remove
717
+ #define TRANSACTD_VER_MINOR 2//##8 Build marker! Don't remove
698
718
  #define TRANSACTD_VER_RELEASE 0//##9 Build marker! Don't remove
699
719
 
700
720
  #endif // BZS_DB_PROTOCOL_TDAP_TDAPCAPI_H
@@ -130,6 +130,8 @@ inline const _TCHAR* dbname(const _TCHAR* uri, _TCHAR* buf, size_t size)
130
130
  {
131
131
  _tcsncpy_s(buf, size, st, en - st);
132
132
  buf[en - st] = 0x00;
133
+ int n = (int)(en - st -1);
134
+ if (n >= 0 && buf[n] == '/') buf[n] = 0x00;
133
135
  }
134
136
  }
135
137
  }
@@ -185,6 +187,27 @@ inline const _TCHAR* passwd(const _TCHAR* uri, _TCHAR* buf, size_t size)
185
187
  return buf;
186
188
  }
187
189
 
190
+
191
+ {
192
+ _TCHAR pwd[MAX_PATH];
193
+ passwd(uri, pwd, MAX_PATH);
194
+
195
+ buf[0] = 0x00;
196
+ const _TCHAR* st = _tcsstr(uri, _T("://"));
197
+ if (st)
198
+ {
199
+ st = _tcsstr(st + 3, _T("/"));
200
+ _tcsncpy_s(buf, size, uri, ++st - uri);
201
+ buf[st - uri] = 0x00;
202
+ if (pwd[0])
203
+ {
204
+ _tcscat_s(buf, MAX_PATH, _T("?pwd="));
205
+ _tcscat_s(buf, MAX_PATH, pwd);
206
+ }
207
+
208
+ }
209
+ return buf;
210
+ }
188
211
 
189
212
  inline _TCHAR* stripParam(const _TCHAR* uri, _TCHAR* buf, size_t size)
190
213
  {
@@ -239,6 +262,23 @@ inline const _TCHAR* stripAuth(const _TCHAR* uri, _TCHAR* buf, size_t size)
239
262
  return buf;
240
263
  }
241
264
 
265
+ inline const _TCHAR* appendAuth(const _TCHAR* uri, const _TCHAR* user, const _TCHAR* passwd,
266
+ _TCHAR* buf, size_t size)
267
+ {
268
+ memset(buf, 0, size);
269
+ if (_tcslen(uri) + _tcslen(user) + _tcslen(passwd) + _tcslen(_T("@&pwd=")) > size -1)
270
+ return buf;
271
+
272
+ const _TCHAR* st = _tcsstr(uri, _T("://"));
273
+ _tcsncpy_s(buf, size, uri, st + 3 - uri);
274
+ _tcscat_s(buf, size, user);
275
+ _tcscat_s(buf, size, _T("@"));
276
+ _tcscat_s(buf, size, st+3);
277
+ _tcscat_s(buf, size, _T("&pwd="));
278
+ _tcscat_s(buf, size, passwd);
279
+ return buf;
280
+ }
281
+
242
282
  inline void reorder_digest(boost::uuids::detail::sha1::digest_type val)
243
283
  {
244
284
  for (int i=0;i<5;++i)
@@ -305,7 +305,7 @@ public:
305
305
  */
306
306
  module::module(const boost::asio::ip::tcp::endpoint& endpoint,
307
307
  iconnection* connection, bool tpool, int type)
308
- : m_endpoint(endpoint), m_connection(connection), m_useThreadPool(tpool)
308
+ : m_endpoint(endpoint), m_connection(connection), m_useThreadPool(tpool), m_skipGrants(false)
309
309
  {
310
310
  if (type & PROTOCOL_TYPE_BTRV)
311
311
  m_commandExecuter.reset(new protocol::tdap::mysql::commandExecuter(this));
@@ -325,10 +325,12 @@ module::module(const boost::asio::ip::tcp::endpoint& endpoint,
325
325
 
326
326
  module::~module(void)
327
327
  {
328
- boost::mutex::scoped_lock lck(modulesMutex);
329
- modules.erase(find(modules.begin(), modules.end(), this));
330
- delete m_nw;
331
- m_commandExecuter.reset();
328
+ {
329
+ boost::mutex::scoped_lock lck(modulesMutex);
330
+ modules.erase(find(modules.begin(), modules.end(), this));
331
+ delete m_nw;
332
+ m_commandExecuter.reset();
333
+ }
332
334
  if (m_useThreadPool == false)
333
335
  {
334
336
  my_thread_end();
@@ -434,6 +436,13 @@ bool module::checkHost(const char* hostCheckname, /*out*/char* hostName, int siz
434
436
  p = "localhost";
435
437
  strcpy(hostName, p);
436
438
  }
439
+ if (ret)
440
+ {
441
+ if (hostCheckname && hostCheckname[0])
442
+ setUser(hostCheckname);
443
+ if (hostName && hostName[0])
444
+ setHost(hostName);
445
+ }
437
446
  return ret;
438
447
  }
439
448
 
@@ -41,13 +41,17 @@ namespace transactd
41
41
  class module : public netsvc::server::IAppModule, private boost::noncopyable
42
42
  {
43
43
  friend class connManager;
44
+ friend class dbExecuter;
44
45
  boost::shared_ptr<protocol::ICommandExecuter> m_commandExecuter;
45
46
  const boost::asio::ip::tcp::endpoint m_endpoint;
46
47
  bzs::netsvc::server::iconnection* m_connection;
47
48
  const char* m_readBuf;
48
49
  size_t m_readSize;
49
50
  netsvc::server::netWriter* m_nw;
51
+ std::string m_user;
52
+ std::string m_host;
50
53
  bool m_useThreadPool;
54
+ bool m_skipGrants;
51
55
  bool perseLineEnd(const char* p, size_t size) const;
52
56
  size_t onRead(const char* data, size_t size, bool& complete);
53
57
  size_t onAccept(char* message, size_t bufsize);
@@ -62,8 +66,13 @@ public:
62
66
  bool isShutDown() { return m_commandExecuter->isShutDown(); }
63
67
  bool checkHost(const char* hostCheckname, /*out*/char* hostName, int size);
64
68
  void disconnect();
69
+ const char* user() const {return m_user.c_str();}
70
+ const char* host() const {return m_host.c_str();}
71
+ void setUser(const char* v) { m_user = v;}
72
+ void setHost(const char* v) { m_host = v;}
73
+ void skipGrants(bool v) {m_skipGrants = v;}
74
+ bool isSkipGrants() const {return m_skipGrants;}
65
75
  };
66
-
67
76
  } // namespace transactd
68
77
  } // namespace db
69
78
  } // namespace bzs
@@ -21,12 +21,17 @@
21
21
  #include <bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h>
22
22
  #include "connManager.h"
23
23
  #include <bzs/db/engine/mysql/mysqlThd.h>
24
+ #include <bzs/db/engine/mysql/mysqlProtocol.h>
24
25
  #include <bzs/db/protocol/tdap/mysql/databaseSchema.h>
25
26
  #include <bzs/db/engine/mysql/errorMessage.h>
26
27
 
28
+
27
29
  /* implemnts in transactd.cpp */
28
30
  extern const char* get_trd_sys_var(int index);
29
31
 
32
+
33
+ extern int getSlaveStatus(THD* thd, bzs::db::transactd::connection::records& recs);
34
+
30
35
  namespace bzs
31
36
  {
32
37
  using namespace netsvc::server;
@@ -89,38 +94,38 @@ void connManager::getDatabaseList(igetDatabases* dbm, const module* mod) const
89
94
  m_records.push_back(connection::record());
90
95
  connection::record& rec = m_records[m_records.size() - 1];
91
96
  rec.conId = (unsigned __int64)mod;
92
- rec.cid = db->clientID();
93
- rec.dbid = (unsigned short)j;
97
+ rec.id = db->clientID();
98
+ rec.db = (unsigned short)j;
94
99
  rec.status = 0;
95
100
  rec.inTransaction = db->inTransaction();
96
101
  rec.inSnapshot = db->inSnapshot();
97
102
  if (rec.inTransaction)
98
103
  {
99
104
  if (db->transactionIsolation() == ISO_REPEATABLE_READ)
100
- rec.trnType = MULTILOCK_GAP;
105
+ rec.type = MULTILOCK_GAP;
101
106
  else if (db->transactionIsolation() == ISO_READ_COMMITTED)
102
107
  {
103
108
  if (db->transactionType() == TRN_RECORD_LOCK_SINGLE)
104
- rec.trnType = SINGLELOCK_NOGAP;
109
+ rec.type = SINGLELOCK_NOGAP;
105
110
  else
106
- rec.trnType = MULTILOCK_NOGAP;
111
+ rec.type = MULTILOCK_NOGAP;
107
112
  }
108
113
  }
109
114
  if (rec.inSnapshot)
110
115
  {
111
116
  if (db->transactionIsolation() == 0)
112
- rec.trnType = CONSISTENT_READ;
117
+ rec.type = CONSISTENT_READ;
113
118
  else if (db->transactionIsolation() == ISO_REPEATABLE_READ)
114
- rec.trnType = MULTILOCK_GAP_SHARE;
119
+ rec.type = MULTILOCK_GAP_SHARE;
115
120
  else if (db->transactionIsolation() == ISO_READ_COMMITTED)
116
- rec.trnType = MULTILOCK_NOGAP_SHARE;
121
+ rec.type = MULTILOCK_NOGAP_SHARE;
117
122
  }
118
123
  strncpy_s(rec.name, 64, dbs[j]->name().c_str(), 64);
119
124
  }
120
125
  }
121
126
  }
122
127
 
123
- const connManager::records& connManager::getRecords(unsigned __int64 conid,
128
+ const connection::records& connManager::getRecords(unsigned __int64 conid,
124
129
  int dbid) const
125
130
  {
126
131
  //Lock module count
@@ -159,8 +164,7 @@ const connManager::records& connManager::getRecords(unsigned __int64 conid,
159
164
  m_records.push_back(connection::record());
160
165
  connection::record& rec =
161
166
  m_records[m_records.size() - 1];
162
- rec.conId = (unsigned __int64)mod;
163
- rec.cid = tb->id();
167
+ rec.id = tb->id();
164
168
  rec.readCount = tb->readCount();
165
169
  rec.updCount = tb->updCount();
166
170
  rec.delCount = tb->delCount();
@@ -180,7 +184,7 @@ const connManager::records& connManager::getRecords(unsigned __int64 conid,
180
184
  return m_records;
181
185
  }
182
186
 
183
- const connManager::records& connManager::systemVariables() const
187
+ const connection::records& connManager::systemVariables() const
184
188
  {
185
189
  m_records.clear();
186
190
  for (int i = 0 ; i < TD_VAR_SIZE; ++i)
@@ -190,7 +194,7 @@ const connManager::records& connManager::systemVariables() const
190
194
  {
191
195
  m_records.push_back(connection::record());
192
196
  connection::record& rec = m_records[m_records.size() - 1];
193
- rec.value_id = i;
197
+ rec.id = i;
194
198
  switch(i)
195
199
  {
196
200
  case TD_VER_DB:
@@ -214,41 +218,20 @@ const connManager::records& connManager::systemVariables() const
214
218
  return m_records;
215
219
  }
216
220
 
217
- inline void appenDbList(connManager::records& recs, LEX_STRING* db_name)
218
- {
219
- recs.push_back(connection::record());
220
- connection::record& rec = recs[recs.size() - 1];
221
- strncpy(rec.name, db_name->str, 64);
222
- rec.name[64] = 0x00;
223
- }
224
-
225
- const connManager::records& connManager::getDefinedDatabaseList() const
221
+ const connection::records& connManager::definedDatabases() const
226
222
  {
227
223
  m_records.clear();
228
- THD* thd = createThdForThread();
229
224
  try
230
225
  {
231
- if (thd)
226
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
227
+ if (thd != NULL)
232
228
  {
233
- cp_security_ctx(thd)->skip_grants();
234
- SQL_Strings files;
235
- db_list(thd, &files);
236
- #if (defined(MARIADDB_10_0) || defined(MARIADDB_10_1))
237
- for (int i = 0; i < (int)files.elements(); ++i)
238
- appenDbList(m_records, files.at(i));
239
- #else
240
- List_iterator_fast<LEX_STRING> it(files);
241
- LEX_STRING* db_name;
242
- while ((db_name = it++))
243
- appenDbList(m_records, db_name);
244
- #endif
245
- deleteThdForThread(thd);
229
+ cp_security_ctx(thd.get())->skip_grants();
230
+ readDbList(thd.get(), m_records);
246
231
  }
247
232
  }
248
233
  catch (bzs::rtl::exception& e)
249
234
  {
250
- if (thd)
251
- deleteThdForThread(thd);
252
235
  const int* code = getCode(e);
253
236
  if (code)
254
237
  m_stat = *code;
@@ -261,17 +244,12 @@ const connManager::records& connManager::getDefinedDatabaseList() const
261
244
  }
262
245
  catch (...)
263
246
  {
264
- try
265
- {
266
- m_stat = 20001;
267
- deleteThdForThread(thd);
268
- }
269
- catch(...){}
247
+ m_stat = 20001;
270
248
  }
271
249
  return m_records;
272
250
  }
273
251
 
274
- const connManager::records& connManager::schemaTableList(const char* dbname)
252
+ const connection::records& connManager::getTableList(const char* dbname, int type) const
275
253
  {
276
254
  try
277
255
  {
@@ -282,13 +260,14 @@ const connManager::records& connManager::schemaTableList(const char* dbname)
282
260
  if (db)
283
261
  {
284
262
  std::vector<std::string> tablelist;
285
- schemaBuilder::listSchemaTable(db.get(), tablelist);
263
+ schemaBuilder::listTable(db.get(), tablelist, type);
286
264
  for (int i = 0; i < (int)tablelist.size(); ++i)
287
265
  {
288
266
  m_records.push_back(connection::record());
289
267
  connection::record& rec = m_records[m_records.size() - 1];
290
268
  strncpy(rec.name, tablelist[i].c_str(), 64);
291
269
  rec.name[64] = 0x00;
270
+ rec.type = (short)type;
292
271
  }
293
272
  }
294
273
  }
@@ -312,6 +291,64 @@ const connManager::records& connManager::schemaTableList(const char* dbname)
312
291
  return m_records;
313
292
  }
314
293
 
294
+ const connection::records& connManager::definedTables(const char* dbname, int type) const
295
+ {
296
+ return getTableList(dbname, type);
297
+ }
298
+
299
+ const connection::records& connManager::schemaTables(const char* dbname) const
300
+ {
301
+ return getTableList(dbname, TABLE_TYPE_TD_SCHEMA);
302
+ }
303
+
304
+ bool connManager::checkGlobalACL(THD* thd, ulong wantAccess) const
305
+ {
306
+ const module* mod = reinterpret_cast<const module*>(m_me);
307
+ if (mod->isSkipGrants())
308
+ cp_security_ctx(thd)->skip_grants();
309
+ else
310
+ ::setGrant(thd, mod->host(), mod->user(), NULL);
311
+ bool ret = (cp_masterAccess(thd) & wantAccess) != 0;
312
+ if (!ret)
313
+ m_stat = STATUS_ACCESS_DENIED;
314
+ return ret;
315
+ }
316
+
317
+ const connection::records& connManager::readSlaveStatus() const
318
+ {
319
+ m_records.clear();
320
+ try
321
+ {
322
+ boost::shared_ptr<THD> thd(createThdForThread(), deleteThdForThread);
323
+ if (thd == NULL)
324
+ {
325
+ m_stat = 20001;
326
+ return m_records;
327
+ }
328
+ if (!checkGlobalACL(thd.get(), SUPER_ACL | REPL_CLIENT_ACL))
329
+ return m_records;
330
+
331
+ m_stat = errorCode(getSlaveStatus(thd.get(), m_records));
332
+ }
333
+ catch (bzs::rtl::exception& e)
334
+ {
335
+ const int* code = getCode(e);
336
+ if (code)
337
+ m_stat = *code;
338
+ else
339
+ {
340
+ m_stat = 20000;
341
+ sql_print_error("%s", boost::diagnostic_information(e).c_str());
342
+ }
343
+ printWarningMessage(code, getMsg(e));
344
+ }
345
+ catch (...)
346
+ {
347
+ m_stat = 20001;
348
+ }
349
+ return m_records;
350
+ }
351
+
315
352
  void connManager::doDisconnect(unsigned __int64 conid)
316
353
  {
317
354
  module* mod = const_cast<module*>(getMod(conid));
@@ -321,7 +358,12 @@ void connManager::doDisconnect(unsigned __int64 conid)
321
358
  dynamic_cast<igetDatabases*>(mod->m_commandExecuter.get());
322
359
  const databases& dbs = dbm->dbs();
323
360
  if (dbs.size())
324
- mod->disconnect();
361
+ {
362
+ if (dbs[0]->checkAcl(SHUTDOWN_ACL))
363
+ mod->disconnect();
364
+ else
365
+ m_stat = STATUS_ACCESS_DENIED;
366
+ }
325
367
  }
326
368
  }
327
369
 
@@ -344,12 +386,15 @@ void connManager::disconnect(unsigned __int64 conid)
344
386
 
345
387
  void connManager::doDisconnectAll()
346
388
  {
389
+ short stat = 0;
347
390
  for (size_t i = 0; i < modules.size(); i++)
348
391
  {
349
392
  const module* mod = dynamic_cast<module*>(modules[i]);
350
393
  if (mod && ((unsigned __int64)mod != m_me))
351
394
  doDisconnect((unsigned __int64)mod);
395
+ if (stat == 0) stat = m_stat;
352
396
  }
397
+ m_stat = stat;
353
398
  }
354
399
 
355
400
  void connManager::disconnectAll()
@@ -41,10 +41,10 @@ class module;
41
41
  class connManager
42
42
  {
43
43
  public:
44
- typedef std::vector<connection::record> records;
44
+
45
45
 
46
46
  private:
47
- mutable records m_records;
47
+ mutable connection::records m_records;
48
48
  unsigned __int64 m_me;
49
49
  mutable short m_stat;
50
50
  void getConnectionList() const;
@@ -54,14 +54,17 @@ private:
54
54
  bzs::db::engine::mysql::igetDatabases* dbm, int dbid) const;
55
55
  void doDisconnect(unsigned __int64 conid);
56
56
  void doDisconnectAll();
57
-
57
+ const connection::records& getTableList(const char* dbname, int type) const;
58
+ bool checkGlobalACL(THD* thd, ulong wantAccess) const;
58
59
  public:
59
60
  connManager(unsigned __int64 me) : m_me(me), m_stat(0){};
60
61
  virtual ~connManager();
61
- const connManager::records& systemVariables() const;
62
- const records& getRecords(unsigned __int64 conid, int dbid) const;
63
- const records& getDefinedDatabaseList() const;
64
- const records& schemaTableList(const char* dbname);
62
+ const connection::records& systemVariables() const;
63
+ const connection::records& getRecords(unsigned __int64 conid, int dbid) const;
64
+ const connection::records& definedDatabases() const;
65
+ const connection::records& schemaTables(const char* dbname) const;
66
+ const connection::records& definedTables(const char* dbname, int type) const;
67
+ const connection::records& readSlaveStatus() const;
65
68
  void disconnect(unsigned __int64 conid);
66
69
  void disconnectAll();
67
70
  short stat() const {return m_stat;}