transactd 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/{BUILD_UNIX-JA → BUILD_UNIX-JA.md} +6 -6
  3. data/CMakeLists.txt +20 -15
  4. data/{README-JA → README-JA.md} +23 -23
  5. data/{README → README.md} +22 -24
  6. data/RELEASE_NOTE +120 -0
  7. data/RELEASE_NOTE-JA +110 -0
  8. data/bin/common/tdclc_32_2_4.dll +0 -0
  9. data/bin/common/tdclc_64_2_4.dll +0 -0
  10. data/build/common/get_ruby_path.cmake +1 -1
  11. data/build/swig/ruby/tdclrb_wrap.cpp +1319 -830
  12. data/build/swig/tdcl.i +22 -2
  13. data/build/tdclc/tdclc.cbproj +1 -1
  14. data/build/tdclc/tdclc.rc +4 -4
  15. data/build/tdclcpp/tdclcpp.rc +4 -4
  16. data/build/tdclcpp/tdclcpp_bc.cbproj +2 -1
  17. data/build/tdclrb/CMakeLists.txt +6 -1
  18. data/build/tdclrb/bldgem/extconf.rb +5 -1
  19. data/build/tdclrb/tdclrb.rc +4 -4
  20. data/source/bzs/db/engine/mysql/database.cpp +44 -40
  21. data/source/bzs/db/engine/mysql/database.h +28 -8
  22. data/source/bzs/db/engine/mysql/dbManager.cpp +2 -0
  23. data/source/bzs/db/engine/mysql/dbManager.h +2 -7
  24. data/source/bzs/db/engine/mysql/mysqlInternal.h +79 -7
  25. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +5 -1
  26. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +32 -8
  27. data/source/bzs/db/protocol/tdap/client/activeTable.h +17 -4
  28. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +10 -4
  29. data/source/bzs/db/protocol/tdap/client/client.cpp +51 -6
  30. data/source/bzs/db/protocol/tdap/client/client.h +41 -11
  31. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +51 -15
  32. data/source/bzs/db/protocol/tdap/client/connMgr.h +6 -1
  33. data/source/bzs/db/protocol/tdap/client/database.cpp +26 -5
  34. data/source/bzs/db/protocol/tdap/client/database.h +3 -2
  35. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +38 -28
  36. data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -1
  37. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +2 -32
  38. data/source/bzs/db/protocol/tdap/client/field.cpp +0 -1
  39. data/source/bzs/db/protocol/tdap/client/filter.h +60 -33
  40. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +2 -5
  41. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +9 -0
  42. data/source/bzs/db/protocol/tdap/client/memRecord.h +1 -0
  43. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +99 -48
  44. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +5 -2
  45. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +76 -26
  46. data/source/bzs/db/protocol/tdap/client/nsTable.h +6 -4
  47. data/source/bzs/db/protocol/tdap/client/request.h +28 -11
  48. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +19 -11
  49. data/source/bzs/db/protocol/tdap/client/table.cpp +157 -70
  50. data/source/bzs/db/protocol/tdap/client/table.h +20 -5
  51. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +57 -4
  52. data/source/bzs/db/protocol/tdap/client/trdormapi.h +55 -20
  53. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +65 -31
  54. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +2 -0
  55. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +24 -36
  56. data/source/bzs/db/protocol/tdap/mysql/request.h +1 -1
  57. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +98 -18
  58. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +12 -7
  59. data/source/bzs/db/protocol/tdap/tdapRequest.h +3 -8
  60. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +1 -9
  61. data/source/bzs/db/protocol/tdap/tdapSchema.h +31 -1
  62. data/source/bzs/db/protocol/tdap/tdapcapi.h +49 -6
  63. data/source/bzs/db/protocol/tdap/uri.h +41 -6
  64. data/source/bzs/db/transactd/appModule.cpp +0 -1
  65. data/source/bzs/db/transactd/appModule.h +0 -2
  66. data/source/bzs/db/transactd/connManager.cpp +202 -33
  67. data/source/bzs/db/transactd/connManager.h +11 -4
  68. data/source/bzs/db/transactd/connectionRecord.h +19 -5
  69. data/source/bzs/db/transactd/transactd.cpp +39 -8
  70. data/source/bzs/env/crosscompile.cpp +1 -1
  71. data/source/bzs/example/queryData.cpp +1 -1
  72. data/source/bzs/netsvc/client/iconnection.h +2 -0
  73. data/source/bzs/netsvc/client/tcpClient.cpp +48 -26
  74. data/source/bzs/netsvc/client/tcpClient.h +171 -106
  75. data/source/bzs/netsvc/server/IAppModule.h +0 -1
  76. data/source/bzs/netsvc/server/serverPipe.cpp +5 -1
  77. data/source/bzs/netsvc/server/serverPipe.h +2 -1
  78. data/source/bzs/test/tdclatl/test_query_atl.js +105 -0
  79. data/source/bzs/test/tdclphp/transactd_Test.php +129 -11
  80. data/source/bzs/test/tdclrb/transactd_spec.rb +74 -2
  81. data/source/bzs/test/transactdBench/scaling_bench.cpp +1 -1
  82. data/source/bzs/test/trdclengn/test_trdclengn.cpp +45 -20
  83. data/source/global/tdclatl/Bookmark.cpp +28 -0
  84. data/source/global/tdclatl/Bookmark.h +65 -0
  85. data/source/global/tdclatl/Database.cpp +2 -2
  86. data/source/global/tdclatl/Database.h +1 -3
  87. data/source/global/tdclatl/DbDef.cpp +6 -0
  88. data/source/global/tdclatl/DbDef.h +1 -0
  89. data/source/global/tdclatl/QueryBase.cpp +29 -0
  90. data/source/global/tdclatl/QueryBase.h +4 -0
  91. data/source/global/tdclatl/Record.cpp +14 -2
  92. data/source/global/tdclatl/Record.h +1 -1
  93. data/source/global/tdclatl/Table.cpp +80 -16
  94. data/source/global/tdclatl/Table.h +23 -8
  95. data/source/global/tdclatl/_IDatabaseEvents_CP.h +39 -0
  96. data/source/global/tdclatl/activeTable.cpp +2 -2
  97. data/source/global/tdclatl/activeTable.h +1 -1
  98. data/source/global/tdclatl/tdclatl.idl +64 -14
  99. metadata +12 -12
  100. data/bin/common/tdclc_32_2_3.dll +0 -0
  101. data/bin/common/tdclc_64_2_3.dll +0 -0
  102. data/build/tdclcpp/BUILDNUMBER.txt +0 -1
  103. data/build/tdclrb/BUILDNUMBER.txt +0 -1
  104. /data/{BUILD_WIN-JA → BUILD_WIN-JA.md} +0 -0
  105. /data/{README_ORMSRCGEN-JA → README_ORMSRCGEN-JA.md} +0 -0
  106. /data/{README_ORMSRCGEN → README_ORMSRCGEN.md} +0 -0
@@ -20,6 +20,12 @@
20
20
  #include "appModule.h"
21
21
  #include <bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h>
22
22
  #include "connManager.h"
23
+ #include <bzs/db/engine/mysql/mysqlThd.h>
24
+ #include <bzs/db/protocol/tdap/mysql/databaseSchema.h>
25
+ #include <bzs/db/engine/mysql/errorMessage.h>
26
+
27
+ /* implemnts in transactd.cpp */
28
+ extern const char* get_trd_sys_var(int index);
23
29
 
24
30
  namespace bzs
25
31
  {
@@ -47,11 +53,8 @@ const module* getMod(unsigned __int64 conid)
47
53
  return NULL;
48
54
  }
49
55
 
50
- const database* connManager::getDatabase(const module* mod, int dbid) const
56
+ const database* connManager::getDatabase(igetDatabases* dbm, int dbid) const
51
57
  {
52
-
53
- igetDatabases* dbm =
54
- dynamic_cast<igetDatabases*>(mod->m_commandExecuter.get());
55
58
  const databases& dbs = dbm->dbs();
56
59
  if (dbid < (int)dbs.size())
57
60
  return dbs[dbid].get();
@@ -75,21 +78,43 @@ void connManager::getConnectionList() const
75
78
  }
76
79
  }
77
80
 
78
- void connManager::getDatabaseList(const module* mod) const
81
+ void connManager::getDatabaseList(igetDatabases* dbm, const module* mod) const
79
82
  {
80
- igetDatabases* dbm =
81
- dynamic_cast<igetDatabases*>(mod->m_commandExecuter.get());
82
83
  const databases& dbs = dbm->dbs();
83
84
  for (size_t j = 0; j < dbs.size(); j++)
84
85
  {
85
-
86
86
  if (dbs[j])
87
87
  {
88
+ const database* db = dbs[j].get();
88
89
  m_records.push_back(connection::record());
89
90
  connection::record& rec = m_records[m_records.size() - 1];
90
91
  rec.conId = (unsigned __int64)mod;
91
- rec.cid = dbs[j]->clientID();
92
+ rec.cid = db->clientID();
92
93
  rec.dbid = (unsigned short)j;
94
+ rec.status = 0;
95
+ rec.inTransaction = db->inTransaction();
96
+ rec.inSnapshot = db->inSnapshot();
97
+ if (rec.inTransaction)
98
+ {
99
+ if (db->transactionIsolation() == ISO_REPEATABLE_READ)
100
+ rec.trnType = MULTILOCK_GAP;
101
+ else if (db->transactionIsolation() == ISO_READ_COMMITTED)
102
+ {
103
+ if (db->transactionType() == TRN_RECORD_LOCK_SINGLE)
104
+ rec.trnType = SINGLELOCK_NOGAP;
105
+ else
106
+ rec.trnType = MULTILOCK_NOGAP;
107
+ }
108
+ }
109
+ if (rec.inSnapshot)
110
+ {
111
+ if (db->transactionIsolation() == 0)
112
+ rec.trnType = CONSISTENT_READ;
113
+ else if (db->transactionIsolation() == ISO_REPEATABLE_READ)
114
+ rec.trnType = MULTILOCK_GAP_SHARE;
115
+ else if (db->transactionIsolation() == ISO_READ_COMMITTED)
116
+ rec.trnType = MULTILOCK_NOGAP_SHARE;
117
+ }
93
118
  strncpy_s(rec.name, 64, dbs[j]->name().c_str(), 64);
94
119
  }
95
120
  }
@@ -108,33 +133,44 @@ const connManager::records& connManager::getRecords(unsigned __int64 conid,
108
133
  const module* mod = getMod(conid);
109
134
  if (mod)
110
135
  {
111
- //Lock module execute
112
- boost::try_mutex::scoped_try_lock m(mod->mutex(),
113
- boost::try_to_lock_t());
114
- if (m.owns_lock())
136
+ igetDatabases* dbm =
137
+ dynamic_cast<igetDatabases*>(mod->m_commandExecuter.get());
138
+
139
+ //Lock database add remove
140
+ boost::mutex::scoped_lock lck(dbm->mutex());
141
+
142
+ if (dbid < 0)
143
+ getDatabaseList(dbm, mod);
144
+ else
115
145
  {
116
- if (dbid < 0)
117
- getDatabaseList(mod);
118
- else
146
+ const database* db = getDatabase(dbm, dbid);
147
+ if (db)
119
148
  {
120
- const database* db = getDatabase(mod, dbid);
121
- if (db)
149
+ const std::vector<boost::shared_ptr<table> >& tables =
150
+ db->tables();
151
+
152
+ //Lock table add release in the db
153
+ boost::mutex::scoped_lock lckt(database::tableRef.mutex());
154
+ for (size_t k = 0; k < tables.size(); k++)
122
155
  {
123
- const std::vector<boost::shared_ptr<table> >& tables =
124
- db->tables();
125
- for (size_t k = 0; k < tables.size(); k++)
156
+ const table* tb = tables[k].get();
157
+ if (tb)
126
158
  {
127
- const table* tb = tables[k].get();
128
- if (tb)
129
- {
130
- m_records.push_back(connection::record());
131
- connection::record& rec =
132
- m_records[m_records.size() - 1];
133
- rec.conId = (unsigned __int64)mod;
134
- rec.cid = db->clientID();
135
-
136
- strncpy_s(rec.name, 64, tb->name().c_str(), 64);
137
- }
159
+ m_records.push_back(connection::record());
160
+ connection::record& rec =
161
+ m_records[m_records.size() - 1];
162
+ rec.conId = (unsigned __int64)mod;
163
+ rec.cid = tb->id();
164
+ rec.readCount = tb->readCount();
165
+ rec.updCount = tb->updCount();
166
+ rec.delCount = tb->delCount();
167
+ rec.insCount = tb->insCount();
168
+ rec.status = 0;
169
+ rec.openNormal = (tb->mode() == TD_OPEN_NORMAL);
170
+ rec.openReadOnly = (tb->mode() == TD_OPEN_READONLY);
171
+ rec.openEx = (tb->mode() == TD_OPEN_EXCLUSIVE);
172
+ rec.openReadOnlyEx = (tb->mode() == TD_OPEN_READONLY_EXCLUSIVE);
173
+ strncpy_s(rec.name, 64, tb->name().c_str(), 64);
138
174
  }
139
175
  }
140
176
  }
@@ -144,6 +180,138 @@ const connManager::records& connManager::getRecords(unsigned __int64 conid,
144
180
  return m_records;
145
181
  }
146
182
 
183
+ const connManager::records& connManager::systemVariables() const
184
+ {
185
+ m_records.clear();
186
+ for (int i = 0 ; i < TD_VAR_SIZE; ++i)
187
+ {
188
+ const char* p = ::get_trd_sys_var(i);
189
+ if (p)
190
+ {
191
+ m_records.push_back(connection::record());
192
+ connection::record& rec = m_records[m_records.size() - 1];
193
+ rec.value_id = i;
194
+ switch(i)
195
+ {
196
+ case TD_VER_DB:
197
+ case TD_VAR_LISTENADDRESS:
198
+ case TD_VAR_LISTENPORT:
199
+ case TD_VAR_HOSTCHECKNAME:
200
+ case TD_VAR_ISOLATION:
201
+ case TD_VAR_AUTHTYPE:
202
+ case TD_VAR_HSLISTENPORT:
203
+ strncpy(rec.value, p , 65);
204
+ break;
205
+ case TD_VER_SERVER:
206
+ sprintf_s(rec.value, 65, "%d.%d.%d", TRANSACTD_VER_MAJOR, TRANSACTD_VER_MINOR, TRANSACTD_VER_RELEASE);
207
+ break;
208
+ default:
209
+ _ltoa_s(*((unsigned int*)p), rec.value, 65, 10);
210
+ break;
211
+ }
212
+ }
213
+ }
214
+ return m_records;
215
+ }
216
+
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
226
+ {
227
+ m_records.clear();
228
+ THD* thd = createThdForThread();
229
+ try
230
+ {
231
+ if (thd)
232
+ {
233
+ cp_security_ctx(thd)->skip_grants();
234
+ SQL_Strings files;
235
+ db_list(thd, &files);
236
+ #ifdef MARIADDB_10_0
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);
246
+ }
247
+ }
248
+ catch (bzs::rtl::exception& e)
249
+ {
250
+ if (thd)
251
+ deleteThdForThread(thd);
252
+ const int* code = getCode(e);
253
+ if (code)
254
+ m_stat = *code;
255
+ else
256
+ {
257
+ m_stat = 20000;
258
+ sql_print_error("%s", boost::diagnostic_information(e).c_str());
259
+ }
260
+ printWarningMessage(code, getMsg(e));
261
+ }
262
+ catch (...)
263
+ {
264
+ try
265
+ {
266
+ m_stat = 20001;
267
+ deleteThdForThread(thd);
268
+ }
269
+ catch(...){}
270
+ }
271
+ return m_records;
272
+ }
273
+
274
+ const connManager::records& connManager::schemaTableList(const char* dbname)
275
+ {
276
+ try
277
+ {
278
+ m_records.clear();
279
+ if (dbname && dbname[0])
280
+ {
281
+ boost::shared_ptr<database> db(new database(dbname, 1));
282
+ if (db)
283
+ {
284
+ std::vector<std::string> tablelist;
285
+ schemaBuilder::listSchemaTable(db.get(), tablelist);
286
+ for (int i = 0; i < (int)tablelist.size(); ++i)
287
+ {
288
+ m_records.push_back(connection::record());
289
+ connection::record& rec = m_records[m_records.size() - 1];
290
+ strncpy(rec.name, tablelist[i].c_str(), 64);
291
+ rec.name[64] = 0x00;
292
+ }
293
+ }
294
+ }
295
+ }
296
+ catch (bzs::rtl::exception& e)
297
+ {
298
+ const int* code = getCode(e);
299
+ if (code)
300
+ m_stat = *code;
301
+ else
302
+ {
303
+ m_stat = 20000;
304
+ sql_print_error("%s", boost::diagnostic_information(e).c_str());
305
+ }
306
+ printWarningMessage(code, getMsg(e));
307
+ }
308
+ catch (...)
309
+ {
310
+ m_stat = 20001;
311
+ }
312
+ return m_records;
313
+ }
314
+
147
315
  void connManager::doDisconnect(unsigned __int64 conid)
148
316
  {
149
317
  module* mod = const_cast<module*>(getMod(conid));
@@ -179,7 +347,8 @@ void connManager::doDisconnectAll()
179
347
  for (size_t i = 0; i < modules.size(); i++)
180
348
  {
181
349
  const module* mod = dynamic_cast<module*>(modules[i]);
182
- doDisconnect((unsigned __int64)mod);
350
+ if (mod && ((unsigned __int64)mod != m_me))
351
+ doDisconnect((unsigned __int64)mod);
183
352
  }
184
353
  }
185
354
 
@@ -30,6 +30,7 @@ namespace engine
30
30
  namespace mysql
31
31
  {
32
32
  class database;
33
+ class igetDatabases;
33
34
  }
34
35
  }
35
36
  namespace transactd
@@ -45,19 +46,25 @@ public:
45
46
  private:
46
47
  mutable records m_records;
47
48
  unsigned __int64 m_me;
49
+ mutable short m_stat;
48
50
  void getConnectionList() const;
49
- void getDatabaseList(const module* mod) const;
50
- const bzs::db::engine::mysql::database* getDatabase(const module* mod,
51
- int dbid) const;
51
+ void getDatabaseList(bzs::db::engine::mysql::igetDatabases* dbm,
52
+ const module* mod) const;
53
+ const bzs::db::engine::mysql::database* getDatabase(
54
+ bzs::db::engine::mysql::igetDatabases* dbm, int dbid) const;
52
55
  void doDisconnect(unsigned __int64 conid);
53
56
  void doDisconnectAll();
54
57
 
55
58
  public:
56
- connManager(unsigned __int64 me) : m_me(me){};
59
+ connManager(unsigned __int64 me) : m_me(me), m_stat(0){};
57
60
  virtual ~connManager();
61
+ const connManager::records& systemVariables() const;
58
62
  const records& getRecords(unsigned __int64 conid, int dbid) const;
63
+ const records& getDefinedDatabaseList() const;
64
+ const records& schemaTableList(const char* dbname);
59
65
  void disconnect(unsigned __int64 conid);
60
66
  void disconnectAll();
67
+ short stat() const {return m_stat;}
61
68
  };
62
69
 
63
70
  } // namespace transactd
@@ -34,15 +34,24 @@ namespace connection
34
34
  {
35
35
  struct record
36
36
  {
37
- record() : conId(0), cid(0), dbid(0)
37
+ record() : conId(0), cid(0), dbid(0), trnType(0), status(0), readCount(0),
38
+ updCount(0), delCount(0), insCount(0)
38
39
  {
39
40
  name[0] = 0x00;
40
- status = 0;
41
41
  }
42
42
  __int64 conId;
43
- unsigned int cid;
43
+ union
44
+ {
45
+ unsigned int cid;
46
+ unsigned int value_id;
47
+ };
44
48
  unsigned short dbid;
45
- char name[64];
49
+ short trnType;
50
+ union
51
+ {
52
+ char name[67];
53
+ char value[67];
54
+ };
46
55
  union
47
56
  {
48
57
  char status;
@@ -53,9 +62,14 @@ struct record
53
62
  char openNormal : 1;
54
63
  char openReadOnly : 1;
55
64
  char openEx : 1;
56
- char dummy : 3;
65
+ char openReadOnlyEx : 1;
66
+ char dummy : 2;
57
67
  };
58
68
  };
69
+ unsigned int readCount;
70
+ unsigned int updCount;
71
+ unsigned int delCount;
72
+ unsigned int insCount;
59
73
  };
60
74
 
61
75
  } // connection
@@ -21,6 +21,7 @@
21
21
  #include <bzs/netsvc/server/serverTpool.h>
22
22
  #include <bzs/rtl/exception.h>
23
23
  #include <bzs/rtl/debuglog.h>
24
+ #include <bzs/db/protocol/tdap/tdapcapi.h>
24
25
  #include <stdio.h>
25
26
  #include <iostream>
26
27
  #include <string>
@@ -46,16 +47,14 @@ using namespace bzs::netsvc::server;
46
47
  static char* g_listenAddress = NULL;
47
48
  static char* g_listenPort = NULL;
48
49
  static char* g_hostCheckUserName = NULL;
49
-
50
50
  static unsigned int g_tcpServerType = TCP_CPT_SERVER;
51
-
52
51
  static unsigned int g_maxTcpConnections = 200;
53
52
  static unsigned int g_pool_threads = 20;
54
- unsigned int g_pipeCommSharememSize = PIPE_SHARE_MEM_SIZE;
55
53
  int g_tableNmaeLower = 1; // defined in btrvProtocol.h
56
54
  unsigned int g_lock_wait_timeout = 1;
57
55
  char* g_transaction_isolation = NULL;
58
56
  char* g_auth_type = NULL;
57
+ unsigned int g_pipeCommSharememSize = PIPE_SHARE_MEM_SIZE;
59
58
  //int g_grant_apply = 0;//skip
60
59
 
61
60
 
@@ -145,7 +144,9 @@ static int transactd_plugin_init(void* p)
145
144
  {
146
145
  boost::shared_ptr<IAppModuleBuilder> app(new transctionalIF(
147
146
  PROTOCOL_TYPE_BTRV | PROTOCOL_TYPE_MEMBUFFER));
148
- srv_p.reset(new pipe::server(app, PIPE_NAME, g_maxPipeConnections,
147
+ srv_p.reset(new pipe::server(app, PIPE_NAME,
148
+ ((strcmp(g_listenPort, "8610") == 0) ? "": g_listenPort),
149
+ g_maxPipeConnections,
149
150
  g_pipeCommSharememSize,
150
151
  g_hostCheckUserName));
151
152
  srv_p->registerErrorHandler(&srvErh);
@@ -226,7 +227,7 @@ static struct st_mysql_daemon transactd_info = {
226
227
  MYSQL_DAEMON_INTERFACE_VERSION
227
228
  };
228
229
 
229
- /** system valiable define
230
+ /** system variables define
230
231
  */
231
232
  static MYSQL_SYSVAR_STR(address, g_listenAddress,
232
233
  PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC,
@@ -300,9 +301,39 @@ static struct st_mysql_sys_var* g_systemVariables[] =
300
301
  0
301
302
  };
302
303
 
303
- /** show valiables struct.
304
+ const char* get_trd_sys_var(int index)
305
+ {
306
+ switch(index)
307
+ {
308
+ case TD_VAR_LISTENADDRESS:return g_listenAddress;
309
+ case TD_VAR_LISTENPORT:return g_listenPort;
310
+ case TD_VAR_HOSTCHECKNAME:return g_hostCheckUserName;
311
+ case TD_VAR_MAXTCPCONNECTIONS:return (const char*)&g_maxTcpConnections;
312
+ case TD_VAR_TABLENAMELOWER:return (const char*)&g_tableNmaeLower;
313
+ case TD_VAR_POOLTHREADS:return (const char*)&g_pool_threads;
314
+ case TD_VAR_TCPSERVERTYPE:return (const char*)&g_tcpServerType;
315
+ case TD_VAR_LOCKWAITTIMEOUT:return (const char*)&g_lock_wait_timeout;
316
+ case TD_VAR_ISOLATION:return g_transaction_isolation;
317
+ case TD_VAR_AUTHTYPE:return g_auth_type;
318
+ #ifdef PIPE_SERVER
319
+ case TD_VAR_PIPESHAREMEMSIZE:return (const char*)&g_pipeCommSharememSize;
320
+ case TD_VAR_MAXPIPECONNECTIONS:return (const char*)&g_maxPipeConnections;
321
+ case TD_VAR_USEPIPE:return (const char*)&g_usePipedLocal;
322
+ #endif
323
+ #ifdef USE_HANDLERSOCKET
324
+ case TD_VAR_HSLISTENPORT:return g_hs_listenPort;
325
+ case TD_VAR_USEHS:return (const char*)&g_use_hs;
326
+ #endif
327
+ case TD_VER_DB: return MYSQL_SERVER_VERSION;
328
+ case TD_VER_SERVER:return "";
329
+
330
+ };
331
+ return NULL;
332
+ }
333
+
334
+ /** show status struct.
304
335
  */
305
- static st_mysql_show_var g_showVariables[] = {
336
+ static st_mysql_show_var g_statusVariables[] = {
306
337
  { "trnsctd_tcp_connections", (char*)&cpt::g_connections, SHOW_INT },
307
338
  { "trnsctd_tcp_wait_threads", (char*)&cpt::g_waitThread, SHOW_INT },
308
339
  { "trnsctd_tpool_connections", (char*)&tpool::g_connections, SHOW_INT },
@@ -329,7 +360,7 @@ mysql_declare_plugin(transactd)
329
360
  transactd_plugin_init,
330
361
  transactd_plugin_deinit,
331
362
  0x0100,
332
- g_showVariables,
363
+ g_statusVariables,
333
364
  g_systemVariables,
334
365
  NULL
335
366
  }
@@ -127,7 +127,7 @@ int wmemcmp16(const char16_t* sl, const char16_t* sr, size_t n)
127
127
  ++sl;
128
128
  ++sr;
129
129
  }
130
- return 0 - *sr;
130
+ //return 0 - *sr;
131
131
  }
132
132
 
133
133
 
@@ -241,7 +241,7 @@ bool createUserExtTable(dbdef* def)
241
241
 
242
242
  bool createCacheTable(dbdef* def)
243
243
  {
244
- short tableid = 4;
244
+ short tableid = 5;
245
245
  tabledef t;
246
246
  tabledef* td = &t;
247
247
  td->charsetIndex = mysql::charsetIndex(GetACP());
@@ -29,6 +29,7 @@
29
29
  #include <boost/asio/ip/tcp.hpp>
30
30
  #include <boost/asio/buffer.hpp>
31
31
  #endif
32
+ #include <boost/system/system_error.hpp>
32
33
  #include <vector>
33
34
 
34
35
 
@@ -105,6 +106,7 @@ public:
105
106
  virtual void write(unsigned int writeSize) = 0;
106
107
  virtual char* read() = 0;
107
108
  virtual bool isHandShakable() const = 0;
109
+ virtual const boost::system::error_code& error() const = 0;
108
110
  };
109
111
 
110
112
  #define CONNECTION_FUNCTION_DIRECT_READ 1
@@ -39,7 +39,7 @@ namespace netsvc
39
39
  namespace client
40
40
  {
41
41
 
42
- char connections::port[PORTNUMBUF_SIZE] = { "8610" };
42
+ char connections::m_port[PORTNUMBUF_SIZE] = { "8610" };
43
43
  bool connections::m_usePipedLocal = true;
44
44
  #ifdef _WIN32
45
45
  int connections::connectTimeout = 20000;
@@ -68,7 +68,7 @@ connections::connections(const char* pipeName) : m_pipeName(pipeName),m_resolver
68
68
  m_usePipedLocal = (atol(tmp) != 0);
69
69
  GetPrivateProfileString("transctd_client", "port", "8610", tmp, 30,
70
70
  buf);
71
- strcpy_s(port, PORTNUMBUF_SIZE, tmp);
71
+ strcpy_s(m_port, PORTNUMBUF_SIZE, tmp);
72
72
  GetPrivateProfileString("transctd_client", "connectTimeout",
73
73
  DEFAULT_CONNECT_TIMEOUT, tmp, 30, buf);
74
74
  connectTimeout = atoi(tmp)*1000;
@@ -93,7 +93,7 @@ connections::connections(const char* pipeName) : m_pipeName(pipeName),m_resolver
93
93
  std::string p = pt.get<std::string>("transctd_client.port");
94
94
  if (p == "")
95
95
  p = "8610";
96
- strcpy_s(port, PORTNUMBUF_SIZE, p.c_str());
96
+ strcpy_s(m_port, PORTNUMBUF_SIZE, p.c_str());
97
97
 
98
98
  p = pt.get<std::string>("transctd_client.connectTimeout");
99
99
  connectTimeout = atol(p.c_str());
@@ -137,8 +137,11 @@ connection* connections::getConnection(asio::ip::tcp::endpoint& ep)
137
137
  }
138
138
 
139
139
  asio::ip::tcp::endpoint connections::endpoint(const std::string& host,
140
+ const char* port,
140
141
  boost::system::error_code& ec)
141
142
  {
143
+
144
+ if (!port || port[0] == 0x00) port = m_port;
142
145
  tcp::resolver::query query(host, port);
143
146
 
144
147
  tcp::resolver::iterator dest = m_resolver.resolve(query, ec);
@@ -156,11 +159,11 @@ asio::ip::tcp::endpoint connections::endpoint(const std::string& host,
156
159
  return endpoint;
157
160
  }
158
161
 
159
- connection* connections::getConnection(const std::string& host)
162
+ connection* connections::getConnection(const std::string& host, const char* port)
160
163
  {
161
164
  mutex::scoped_lock lck(m_mutex);
162
165
  boost::system::error_code ec;
163
- tcp::endpoint ep = endpoint(host, ec);
166
+ tcp::endpoint ep = endpoint(host, port, ec);
164
167
  if (!ec)
165
168
  return getConnection(ep);
166
169
  return NULL;
@@ -204,14 +207,14 @@ bool connections::disconnect(connection* c)
204
207
  */
205
208
  bool connections::isUseNamedPipe(asio::ip::tcp::endpoint& ep)
206
209
  {
207
- boost::system::error_code ec;
208
- asio::ip::tcp::endpoint local = endpoint("127.0.0.1", ec);
209
- if (!ec && (local == ep))
210
+ asio::ip::tcp::endpoint local(ip::address::from_string("127.0.0.1"), ep.port());
211
+ if (local == ep)
210
212
  return true;
211
213
  char buf[MAX_PATH];
212
214
  if (::gethostname(buf, MAX_PATH) == 0)
213
215
  {
214
- local = endpoint(buf, ec);
216
+ boost::system::error_code ec;
217
+ local = endpoint(buf, m_port, ec);
215
218
  if (local == ep)
216
219
  return true;
217
220
  }
@@ -238,27 +241,35 @@ inline connection* connections::doConnect(connection* c)
238
241
  try
239
242
  {
240
243
  c->connect();
241
- return c;
244
+ if (c->isConnected())
245
+ return c;
246
+ m_e = c->error();
247
+ delete c;
248
+ return NULL;
242
249
  }
243
250
  catch (bzs::netsvc::client::exception& e)
244
251
  {
252
+ m_e = boost::system::error_code(e.error(), get_system_category());
245
253
  delete c;
246
- throw e;
254
+ return NULL;
247
255
  }
248
256
  catch (boost::system::system_error& e)
249
257
  {
258
+ m_e = e.code();
250
259
  delete c;
251
- throw e;
260
+ return NULL;
252
261
  }
253
- catch (std::exception& e)
262
+ catch (std::exception& /*e*/)
254
263
  {
264
+ m_e = boost::system::error_code(1, get_system_category());
255
265
  delete c;
256
- throw e;
266
+ return NULL;
257
267
  }
258
268
  catch (...)
259
269
  {
270
+ m_e = boost::system::error_code(1, get_system_category());
260
271
  delete c;
261
- throw;
272
+ return NULL;
262
273
  }
263
274
  }
264
275
 
@@ -272,34 +283,42 @@ inline bool connections::doHandShake(connection* c, handshake f, void* data)
272
283
  {
273
284
  if (!f)
274
285
  c->read();
275
- else
286
+ else
276
287
  ret = f(c, data);
288
+ if (c->error())
289
+ m_e = asio::error::connection_refused;
290
+ else if (!ret)
291
+ m_e = asio::error::no_permission;
277
292
  if (!ret)
278
293
  delete c;
279
294
  }
280
295
  return ret;
281
296
  }
282
- catch (bzs::netsvc::client::exception& /*e*/)
297
+ catch (bzs::netsvc::client::exception& e)
283
298
  {
284
299
  delete c;
285
- throw;
300
+ m_e = boost::system::error_code(e.error(), get_system_category());
301
+ return false;
286
302
  }
287
- catch (boost::system::system_error& /*e*/)
303
+ catch (boost::system::system_error& e)
288
304
  {
305
+ m_e = e.code();
289
306
  delete c;
290
- throw;
307
+ return false;
291
308
  }
292
309
  }
293
310
 
311
+ #if defined(__BCPLUSPLUS__)
312
+ #pragma warn -8004
313
+ #endif
294
314
  // The connection of found from connection list of same address is returned.
295
- connection* connections::connect(const std::string& host, handshake f, void* data, bool newConnection)
315
+ connection* connections::connect(const std::string& host, const char* port, handshake f, void* data, bool newConnection)
296
316
  {
297
317
  bool namedPipe = false;
298
- boost::system::error_code ec;
299
318
  connection* c;
300
319
  mutex::scoped_lock lck(m_mutex);
301
- asio::ip::tcp::endpoint ep = endpoint(host, ec);
302
- if (ec)
320
+ asio::ip::tcp::endpoint ep = endpoint(host, port, m_e);
321
+ if (m_e)
303
322
  return NULL;
304
323
  #ifdef USE_PIPE_CLIENT
305
324
  namedPipe = (m_usePipedLocal && isUseNamedPipe(ep));
@@ -319,13 +338,16 @@ connection* connections::connect(const std::string& host, handshake f, void* dat
319
338
  c->addref();
320
339
  return c;
321
340
  }
341
+ #if defined(__BCPLUSPLUS__)
342
+ #pragma warn .8004
343
+ #endif
322
344
 
323
- bool connections::reconnect(connection* c, const std::string& host,
345
+ bool connections::reconnect(connection* c, const std::string& host, const char* port,
324
346
  handshake f, void* data)
325
347
  {
326
348
  boost::system::error_code ec;
327
349
  mutex::scoped_lock lck(m_mutex);
328
- asio::ip::tcp::endpoint ep = endpoint(host, ec);
350
+ asio::ip::tcp::endpoint ep = endpoint(host, port, ec);
329
351
  if (ec)
330
352
  return false;
331
353
  c->reconnect(ep);