transactd 3.1.0 → 3.2.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 (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
@@ -18,10 +18,12 @@
18
18
  ================================================================= */
19
19
 
20
20
  #include "dbManager.h"
21
+ #include "errorMessage.h"
21
22
  #include <bzs/netsvc/server/IAppModule.h> //for result value macro.
22
23
  #include <bzs/rtl/exception.h>
23
24
  #include <time.h>
24
25
  #include "mysqlThd.h"
26
+ #include <bzs/db/engine/mysql/mysqlProtocol.h>
25
27
 
26
28
  namespace bzs
27
29
  {
@@ -34,6 +36,7 @@ namespace mysql
34
36
 
35
37
  #define STATUS_ALREADY_INSNAPSHOT 204
36
38
  #define STATUS_ALREADY_INTRANSACTION 205
39
+ #define STATUS_ALREADY_INEXCLUSIVE 206
37
40
 
38
41
  class smartDbsReopen
39
42
  {
@@ -49,15 +52,21 @@ public:
49
52
  if (m_dbs[i] && m_dbs[i]->thd() == m_thd)
50
53
  {
51
54
  if (m_dbs[i]->inSnapshot())
52
- THROW_BZS_ERROR_WITH_CODEMSG(STATUS_ALREADY_INSNAPSHOT, "Allready in snapshot.");
55
+ THROW_BZS_ERROR_WITH_CODEMSG(STATUS_ALREADY_INSNAPSHOT, "Already in snapshot.");
53
56
  else if (m_dbs[i]->inTransaction())
54
- THROW_BZS_ERROR_WITH_CODEMSG(STATUS_ALREADY_INTRANSACTION, "Allready in transaction.");
57
+ THROW_BZS_ERROR_WITH_CODEMSG(STATUS_ALREADY_INTRANSACTION, "Already in transaction.");
58
+ else if(m_dbs[i]->usingExclusveMode())
59
+ {
60
+ int code = STATUS_ALREADY_INEXCLUSIVE;
61
+ std::string s = "Already in exclusive mode when DDL command execute.";
62
+ printWarningMessage(&code, &s);
63
+ }
55
64
  m_dbs[i]->use();
56
65
  m_dbs[i]->unUseTables(false);
57
66
  m_dbs[i]->closeForReopen();
58
67
  }
59
68
  }
60
- attachThd(m_thd);
69
+ //attachThd(m_thd);
61
70
  }
62
71
 
63
72
  ~smartDbsReopen()
@@ -80,12 +89,27 @@ public:
80
89
  std::string smartDbsReopen::removeName = "";
81
90
 
82
91
 
83
- dbManager::dbManager() : m_autoHandle(0), m_authChecked(false)
92
+ dbManager::dbManager(netsvc::server::IAppModule* mod) : m_autoHandle(0), m_thd(NULL),
93
+ m_mod(mod), m_authChecked(false)
84
94
  {
85
95
  }
86
96
 
87
97
  dbManager::~dbManager()
88
98
  {
99
+ if (m_thd)
100
+ deleteThdForThread(m_thd);
101
+ }
102
+
103
+ THD* dbManager::getThd()
104
+ {
105
+ if (!m_thd)
106
+ {
107
+ m_thd = createThdForThread();
108
+
109
+ }
110
+ else
111
+ attachThd(m_thd);
112
+ return m_thd;
89
113
  }
90
114
 
91
115
  bool dbManager::isShutDown() const
@@ -146,11 +170,6 @@ database* dbManager::useDataBase(int id) const
146
170
  database* dbManager::createDatabase(const char* dbname, short cid) const
147
171
  {
148
172
  database* db = new database(dbname, cid);
149
- if (m_authChecked)
150
- {
151
- if (m_host != "")
152
- db->setGrant(m_host.c_str(), m_user.c_str());
153
- }
154
173
  return db;
155
174
  }
156
175
 
@@ -225,91 +244,77 @@ int dbManager::addHandle(int dbid, int tableid, int assignid)
225
244
  return assignid;
226
245
  }
227
246
 
228
- int dbManager::ddl_execSql(THD* thd, const std::string& sql_stmt)
247
+ int dbManager::ddl_execSql(database* db, const std::string& sql_stmt)
229
248
  {
230
- smartDbsReopen reopen(thd, m_dbs);
231
- thd->variables.lock_wait_timeout = OPEN_TABLE_TIMEOUT_SEC;
232
- thd->clear_error();
233
- int result = cp_query_command(thd, (char*)sql_stmt.c_str());
234
- if (thd->is_error())
235
- result = errorCode(thd->cp_get_sql_error());
236
- cp_lex_clear(thd); // reset values for insert
249
+ THD* thd = getThd();
250
+ int result = 0;
251
+ if (db)
252
+ {
253
+ copyGrant(thd, db->thd(), db->name().c_str());
254
+ setDbName(thd, db->name().c_str());
255
+ }
256
+ else
257
+ {
258
+ if (m_mod->isSkipGrants())
259
+ cp_security_ctx(thd)->skip_grants();
260
+ else
261
+ setGrant(thd, m_mod->host(), m_mod->user(), "");
262
+ setDbName(thd, "");
263
+ }
264
+ result = errorCode(execSql(thd, sql_stmt.c_str()));
265
+ if (thd->mdl_context.has_locks())
266
+ close_thread_tables(thd);
267
+ thd->mdl_context.release_transactional_locks();
268
+ if (db)
269
+ db->use();
237
270
  return result;
238
271
  }
239
272
 
240
- int dbManager::ddl_createDataBase(THD* thd, const std::string& dbname)
273
+ int dbManager::ddl_createDataBase(/*THD* thd,*/ const std::string& dbname)
241
274
  {
242
275
  std::string cmd = "create database `" + dbname + "`";
243
- return ddl_execSql(thd, cmd);
276
+ return ddl_execSql(NULL, cmd);
244
277
  }
245
278
 
246
- int dbManager::ddl_dropDataBase(THD* thd, const std::string& dbname,
279
+ int dbManager::ddl_dropDataBase(/*THD* thd,*/ const std::string& dbname,
247
280
  const std::string& dbSqlname, short cid)
248
281
  {
249
282
  std::string cmd = "drop database `" + dbSqlname + "`";
250
- smartDbsReopen::removeName = dbname;
251
- int ret = ddl_execSql(thd, cmd);
252
- smartDbsReopen::removeName = "";
253
- boost::mutex::scoped_lock lck(m_mutex);
254
- if (ret == 0)
255
- {
256
- int index = -1;
257
- for (int i = (int)m_dbs.size() - 1; i >= 0; i--)
258
- {
259
- if (m_dbs[i] != NULL && (m_dbs[i]->clientID() == cid))
260
- {
261
- index = i;
262
- break;
263
- }
264
- }
265
- if (index != -1)
266
- {
267
- m_dbs[index].reset();
268
- for (int i = (int)m_handles.size() - 1; i >= 0; i--)
269
- if (m_handles[i].db == index)
270
- m_handles.erase(m_handles.begin() + i);
271
- }
272
- }
283
+ int ret = ddl_execSql(NULL, cmd);
273
284
  return ret;
274
285
  }
275
286
 
276
- int dbManager::ddl_useDataBase(THD* thd, const std::string& dbSqlname)
287
+ int dbManager::ddl_createTable(database* db, const char* cmd)
277
288
  {
278
- std::string cmd = "use `" + dbSqlname + "`";
279
- return ddl_execSql(thd, cmd);
280
- }
281
-
282
- int dbManager::closeCacheTable(database* db, const std::string& tbname)
283
- {
284
- if (database::tableRef.count(db->name(), tbname))
285
- return DBM_ERROR_TABLE_USED;
286
-
287
- TABLE_LIST tables;
288
- tables.init_one_table(db->name().c_str(), db->name().size(), tbname.c_str(),
289
- tbname.size(), tbname.c_str(), TL_READ);
290
- if (close_cached_tables(db->thd(), &tables, true, 50000000L))
291
- return HA_ERR_LOCK_WAIT_TIMEOUT;
292
- return 0;
289
+ smartDbsReopen reopen(db->thd(), m_dbs);
290
+ return ddl_execSql(db, cmd);
293
291
  }
294
292
 
295
293
  int dbManager::ddl_dropTable(database* db, const std::string& tbname,
296
294
  const std::string& dbSqlname,
297
295
  const std::string& tbSqlname)
298
296
  {
299
- db->closeTable(tbname.c_str(), true);
300
- int ret = closeCacheTable(db, tbname);
301
- if (ret)
302
- return ret;
303
- db->thd()->variables.lock_wait_timeout = 0;
297
+ smartDbsReopen reopen(db->thd(), m_dbs);
304
298
  std::string cmd = "drop table `" + dbSqlname + "`.`" + tbSqlname + "`";
305
- return ddl_execSql(db->thd(), cmd);
299
+ return ddl_execSql(db, cmd);
306
300
  }
307
301
 
308
302
  int dbManager::ddl_addIndex(database* db, const std::string& tbname,
309
303
  const std::string& cmd)
310
304
  {
311
305
  std::string c = "ALTER TABLE `" + db->name() + "`." + cmd;
312
- return ddl_execSql(db->thd(), c);
306
+ smartDbsReopen reopen(db->thd(), m_dbs);
307
+ return ddl_execSql(db, c);
308
+ }
309
+
310
+ /** Key name of multi byte charctord is not supported. Use only ascii.
311
+ */
312
+ int dbManager::ddl_dropIndex(database* db, const std::string& tbname, const char* keyname)
313
+ {
314
+ std::string s = "drop index `" + std::string(keyname) + "` on `" + db->name() +
315
+ "`.`" + tbname + "`";
316
+ smartDbsReopen reopen(db->thd(), m_dbs);
317
+ return ddl_execSql(db, s.c_str());
313
318
  }
314
319
 
315
320
  int dbManager::ddl_renameTable(database* db, const std::string& oldName,
@@ -317,14 +322,10 @@ int dbManager::ddl_renameTable(database* db, const std::string& oldName,
317
322
  const std::string& oldSqlName,
318
323
  const std::string& newSqlName)
319
324
  {
320
- db->closeTable(oldName.c_str(), true);
321
- int ret = closeCacheTable(db, oldName);
322
- if (ret)
323
- return ret;
324
-
325
325
  std::string cmd = "rename table `" + dbSqlName + "`.`" + oldSqlName +
326
326
  "` to `" + dbSqlName + "`.`" + newSqlName + "`";
327
- return ddl_execSql(db->thd(), cmd);
327
+ smartDbsReopen reopen(db->thd(), m_dbs);
328
+ return ddl_execSql(db, cmd);
328
329
  }
329
330
 
330
331
  int dbManager::ddl_replaceTable(database* db, const std::string& name1,
@@ -333,8 +334,6 @@ int dbManager::ddl_replaceTable(database* db, const std::string& name1,
333
334
  const std::string& nameSql1,
334
335
  const std::string& nameSql2)
335
336
  { // rename name1 to name2.
336
- db->closeTable(name1.c_str(), true);
337
- db->closeTable(name2.c_str(), true);
338
337
  char nameSql3[255];
339
338
 
340
339
  time_t timer_ = time(NULL);
@@ -343,42 +342,28 @@ int dbManager::ddl_replaceTable(database* db, const std::string& name1,
343
342
  t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
344
343
  t->tm_sec);
345
344
 
346
- int ret = closeCacheTable(db, name2);
347
- if (ret)
348
- return ret;
349
345
 
350
346
  std::string cmd = "rename table `" + dbSqlName + "`.`" + nameSql2 +
351
347
  "` to `" + dbSqlName + "`.`" + nameSql3 + "`,`" +
352
348
  dbSqlName + "`.`" + nameSql1 + "` to `" + dbSqlName +
353
349
  "`.`" + nameSql2 + "`";
354
- ret = ddl_execSql(db->thd(), cmd);
350
+ smartDbsReopen reopen(db->thd(), m_dbs);
351
+ int ret = ddl_execSql(db, cmd);
355
352
  if (ret == 0)
356
353
  {
357
354
  std::string cmd = "drop table `" + dbSqlName + "`.`" + nameSql3 + "`";
358
- return ddl_execSql(db->thd(), cmd);
355
+ return ddl_execSql(db, cmd);
359
356
  }
360
357
  return ret;
361
358
  }
362
359
 
363
- std::string
364
- dbManager::makeSQLChangeTableComment(const std::string& dbSqlName,
365
- const std::string& tableSqlName,
366
- const char* comment)
360
+ int dbManager::ddl_tableComment(database* db, const std::string& tbname,
361
+ const char* comment)
367
362
  {
368
- std::string s = "alter table `" + dbSqlName + "`.`" + tableSqlName +
363
+ std::string s = "alter table `" + db->name() + "`.`" + tbname +
369
364
  "` comment \"" + comment + "\"";
370
- return s;
371
- }
372
-
373
- /** Key name of multi byte charctord is not supported. Use only ascii.
374
- */
375
- std::string dbManager::makeSQLDropIndex(const std::string& dbSqlName,
376
- const std::string& tbSqlName,
377
- const char* name)
378
- {
379
- std::string s = "drop index `" + std::string(name) + "` on `" + dbSqlName +
380
- "`.`" + tbSqlName + "`";
381
- return s;
365
+ smartDbsReopen reopen(db->thd(), m_dbs);
366
+ return ddl_execSql(db, s.c_str());
382
367
  }
383
368
 
384
369
  void dbManager::clenupNoException()
@@ -21,7 +21,7 @@
21
21
  #include <my_config.h>
22
22
  #include <boost/thread/mutex.hpp>
23
23
  #include <bzs/db/engine/mysql/database.h>
24
-
24
+ #include <bzs/netsvc/server/IAppModule.h>
25
25
  /* dbManager original error code */
26
26
  #define DBM_ERROR_TABLE_USED HA_ERR_LAST + 1
27
27
 
@@ -37,31 +37,27 @@ namespace mysql
37
37
  struct handle
38
38
  {
39
39
  handle(int i, short d, short t) : id(i), db(d), tb(t), cid(0){};
40
-
41
40
  int id;
42
41
  short db;
43
42
  short tb;
44
43
  short cid;
45
44
  };
46
45
 
47
-
48
46
  class dbManager
49
47
  {
50
48
  // Lock for isSutdown(), called by another thread
51
49
  mutable boost::mutex m_mutex;
52
-
53
50
  int m_autoHandle;
51
+ THD* m_thd;
54
52
 
55
53
  protected:
54
+ netsvc::server::IAppModule* m_mod;
56
55
  mutable databases m_dbs;
57
-
58
56
  mutable std::vector<handle> m_handles;
59
-
60
57
  table* m_tb;
61
- std::string m_user;
62
- std::string m_host;
63
58
  bool m_authChecked;
64
59
 
60
+ THD* getThd();
65
61
  database* createDatabase(const char* dbname, short cid) const;
66
62
  void releaseDatabase(short cid);
67
63
  handle* getHandle(int handle) const;
@@ -72,17 +68,18 @@ protected:
72
68
  void checkNewHandle(int newHandle) const;
73
69
  int addHandle(int dbid, int tableid, int assignid = -1);
74
70
  database* useDataBase(int id) const;
75
- int closeCacheTable(database* db, const std::string& tbname);
76
- int ddl_execSql(THD* thd, const std::string& sql_stmt);
77
- int ddl_createDataBase(THD* thd, const std::string& dbname);
78
- int ddl_dropDataBase(THD* thd, const std::string& dbname,
71
+ int ddl_execSql(database* db, const std::string& sql_stmt);
72
+ int ddl_createDataBase(const std::string& dbname);
73
+ int ddl_dropDataBase(const std::string& dbname,
79
74
  const std::string& dbSqlname, short cid);
80
- int ddl_useDataBase(THD* thd, const std::string& dbSqlname);
81
75
  int ddl_dropTable(database* db, const std::string& tbname,
82
76
  const std::string& sqldbname,
83
77
  const std::string& sqltbname);
78
+ int ddl_createTable(database* db, const char* cmd);
84
79
  int ddl_addIndex(database* db, const std::string& tbname,
85
80
  const std::string& cmd);
81
+ int ddl_dropIndex(database* db, const std::string& tbname,
82
+ const char* keyname);
86
83
  int ddl_renameTable(database* db, const std::string& oldName,
87
84
  const std::string& dbSqlName,
88
85
  const std::string& oldSqlName,
@@ -91,22 +88,16 @@ protected:
91
88
  const std::string& name2, const std::string& dbSqlName,
92
89
  const std::string& nameSql1,
93
90
  const std::string& nameSql2);
94
- std::string makeSQLChangeTableComment(const std::string& dbSqlName,
95
- const std::string& tableSqlName,
96
- const char* comment);
97
- std::string makeSQLDropIndex(const std::string& dbSqlName,
98
- const std::string& tbSqlName,
99
- const char* name);
91
+ int ddl_tableComment(database* db, const std::string& tbname,
92
+ const char* comment);
100
93
  void clenupNoException();
101
94
  virtual int errorCode(int ha_error) = 0;
102
95
 
103
96
  public:
104
- dbManager();
97
+ dbManager(netsvc::server::IAppModule* mod);
105
98
  virtual ~dbManager();
106
99
  bool isShutDown() const;
107
-
108
100
  const databases& dbs() const { return m_dbs; }
109
-
110
101
  boost::mutex& mutex() { return m_mutex; }
111
102
  };
112
103