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.
- checksums.yaml +4 -4
- data/CMakeLists.txt +2 -2
- data/bin/common/tdclc_32_3_5.dll +0 -0
- data/bin/common/tdclc_64_3_5.dll +0 -0
- data/build/common/options.cmake +12 -0
- data/build/common/transactd_cl_common.cmake +1 -0
- data/build/common/transactd_required.cmake +5 -0
- data/build/swig/ruby/tdclrb_wrap.cpp +1029 -130
- data/build/swig/tdcl.i +60 -5
- data/build/tdclc/CMakeLists.txt +30 -32
- data/build/tdclc/libtdclcm.map +1 -1
- data/build/tdclc/tdclc.cbproj +1 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/CMakeLists.txt +39 -48
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +4 -1
- data/build/tdclrb/CMakeLists.txt +5 -4
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/engine/mysql/database.cpp +45 -35
- data/source/bzs/db/engine/mysql/database.h +6 -8
- data/source/bzs/db/engine/mysql/dbManager.cpp +11 -0
- data/source/bzs/db/engine/mysql/dbManager.h +1 -0
- data/source/bzs/db/engine/mysql/ha.cpp +174 -0
- data/source/bzs/db/engine/mysql/ha.h +50 -0
- data/source/bzs/db/engine/mysql/mysqlInternal.h +18 -1
- data/source/bzs/db/engine/mysql/mysqlProtocol.cpp +222 -9
- data/source/bzs/db/engine/mysql/mysqlProtocol.h +5 -0
- data/source/bzs/db/protocol/tdap/client/client.cpp +23 -9
- data/source/bzs/db/protocol/tdap/client/client.h +125 -94
- data/source/bzs/db/protocol/tdap/client/connMgr.cpp +139 -30
- data/source/bzs/db/protocol/tdap/client/connMgr.h +40 -8
- data/source/bzs/db/protocol/tdap/client/database.cpp +17 -17
- data/source/bzs/db/protocol/tdap/client/database.h +15 -0
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +10 -4
- data/source/bzs/db/protocol/tdap/client/haNameResolver.cpp +486 -0
- data/source/bzs/db/protocol/tdap/client/haNameResolver.h +74 -0
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +102 -71
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +15 -3
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +2 -5
- data/source/bzs/db/protocol/tdap/client/nsTable.h +2 -1
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +2 -2
- data/source/bzs/db/protocol/tdap/client/table.cpp +1 -2
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +13 -0
- data/source/bzs/db/protocol/tdap/client/trnsctcl.def +1 -0
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +9 -7
- data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +2 -2
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +328 -117
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +7 -8
- data/source/bzs/db/protocol/tdap/tdapcapi.h +81 -41
- data/source/bzs/db/transactd/connManager.cpp +118 -93
- data/source/bzs/db/transactd/connManager.h +6 -1
- data/source/bzs/db/transactd/connectionRecord.h +27 -7
- data/source/bzs/db/transactd/transactd.cpp +24 -13
- data/source/bzs/env/crosscompile.h +2 -0
- data/source/bzs/netsvc/client/iconnection.h +2 -0
- data/source/bzs/netsvc/client/tcpClient.cpp +45 -14
- data/source/bzs/netsvc/client/tcpClient.h +21 -4
- data/source/bzs/netsvc/server/IAppModule.h +1 -0
- data/source/bzs/netsvc/server/serverCpt.cpp +1 -1
- data/source/bzs/netsvc/server/serverPipe.cpp +2 -0
- data/source/bzs/netsvc/server/serverTpool.cpp +3 -5
- data/source/bzs/test/tdclatl/test_v3.js +91 -3
- data/source/bzs/test/tdclphp/transactd_v3_Test.php +89 -3
- data/source/bzs/test/tdclrb/transactd_v3_spec.rb +69 -2
- data/source/bzs/test/trdclengn/testField.h +19 -1
- data/source/bzs/test/trdclengn/test_tdclcpp_ha.cpp +388 -0
- data/source/bzs/test/trdclengn/test_tdclcpp_v3.cpp +6 -1
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +1 -0
- data/source/bzs/test/trdclengn/testbase.h +7 -1
- data/source/global/replication/haCommand.cpp +843 -0
- data/source/global/replication/haCommand.h +78 -0
- data/source/global/replication/haMgr.cpp +321 -0
- data/source/global/replication/replCommand.cpp +696 -0
- data/source/global/replication/replCommand.h +161 -0
- data/source/global/tdclatl/BinlogPos.cpp +10 -0
- data/source/global/tdclatl/BinlogPos.h +1 -0
- data/source/global/tdclatl/ConnMgr.cpp +89 -2
- data/source/global/tdclatl/ConnMgr.h +13 -1
- data/source/global/tdclatl/ConnRecord.cpp +8 -2
- data/source/global/tdclatl/ConnRecord.h +4 -3
- data/source/global/tdclatl/Database.cpp +13 -0
- data/source/global/tdclatl/Database.h +2 -0
- data/source/global/tdclatl/HaNameREsolver.cpp +54 -0
- data/source/global/tdclatl/HaNameREsolver.h +68 -0
- data/source/global/tdclatl/resource.h +0 -0
- data/source/global/tdclatl/tdclatl.idl +76 -5
- metadata +16 -6
- data/bin/common/tdclc_32_3_4.dll +0 -0
- data/bin/common/tdclc_64_3_4.dll +0 -0
- data/source/bzs/db/protocol/tdap/mysql/debuglog.cpp +0 -423
- data/source/bzs/db/protocol/tdap/mysql/debuglog.h +0 -116
data/build/tdclrb/CMakeLists.txt
CHANGED
|
@@ -72,7 +72,8 @@ endif()
|
|
|
72
72
|
if(WIN32)
|
|
73
73
|
link_directories("${TRANSACTD_RUBY_GEM_ROOT_PATH}/bin/common")
|
|
74
74
|
else()
|
|
75
|
-
|
|
75
|
+
cmake_policy(SET CMP0015 OLD)
|
|
76
|
+
link_directories(../tdclcpp)
|
|
76
77
|
endif()
|
|
77
78
|
|
|
78
79
|
|
|
@@ -145,11 +146,11 @@ if(TRANSACTD_HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
|
|
145
146
|
endif()
|
|
146
147
|
if(MSVC)
|
|
147
148
|
set_property(TARGET ${this_target} APPEND PROPERTY COMPILE_DEFINITIONS
|
|
148
|
-
WIN32 _WIN32 _WINDOWS _USRDLL
|
|
149
|
-
|
|
149
|
+
WIN32 _WIN32 _WINDOWS _USRDLL
|
|
150
|
+
TRDCL_AUTOLINK TRDCLENGN_EXPORTS _CRT_SECURE_NO_WARNINGS)
|
|
150
151
|
else()
|
|
151
152
|
set_property(TARGET ${this_target} APPEND PROPERTY COMPILE_DEFINITIONS
|
|
152
|
-
PIC _REENTRANT
|
|
153
|
+
PIC _REENTRANT)
|
|
153
154
|
if(NOT MINGW)
|
|
154
155
|
set_property(TARGET ${this_target} APPEND PROPERTY COMPILE_DEFINITIONS
|
|
155
156
|
LINUX)
|
data/build/tdclrb/tdclrb.rc
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
//
|
|
30
30
|
|
|
31
31
|
VS_VERSION_INFO VERSIONINFO
|
|
32
|
-
FILEVERSION 3,
|
|
33
|
-
PRODUCTVERSION 3,
|
|
32
|
+
FILEVERSION 3,5,0,220
|
|
33
|
+
PRODUCTVERSION 3,5,0,220
|
|
34
34
|
FILEFLAGSMASK 0x3fL
|
|
35
35
|
#ifdef _DEBUG
|
|
36
36
|
FILEFLAGS 0x1L
|
|
@@ -47,9 +47,9 @@ BEGIN
|
|
|
47
47
|
BEGIN
|
|
48
48
|
VALUE "CompanyName", "BizStation Corp."
|
|
49
49
|
VALUE "FileDescription", "Transactd Ruby client"
|
|
50
|
-
VALUE "FileVersion", "3.
|
|
50
|
+
VALUE "FileVersion", "3.5.0.220"
|
|
51
51
|
VALUE "LegalCopyright", "Copyright(C) 2016 BizStation Corp"
|
|
52
|
-
VALUE "ProductVersion", "3.
|
|
52
|
+
VALUE "ProductVersion", "3.5.0.220"
|
|
53
53
|
VALUE "ProductName", "Transactd Client (GPL V2)"
|
|
54
54
|
END
|
|
55
55
|
END
|
|
@@ -2094,7 +2094,7 @@ void table::readRecords(IReadRecordsHandler* hdr, bool includeCurrent, int type,
|
|
|
2094
2094
|
bool noBookmark)
|
|
2095
2095
|
{
|
|
2096
2096
|
|
|
2097
|
-
if ((m_table->file->inited == handler::NONE) || !m_cursor)
|
|
2097
|
+
if ((m_table->file->inited == handler::NONE) || (m_table->file->inited == handler::INDEX && !m_cursor))
|
|
2098
2098
|
{
|
|
2099
2099
|
m_stat = STATUS_NO_CURRENT;
|
|
2100
2100
|
return;
|
|
@@ -2108,50 +2108,58 @@ void table::readRecords(IReadRecordsHandler* hdr, bool includeCurrent, int type,
|
|
|
2108
2108
|
// dummy bookmark , use if bobbokmark=true
|
|
2109
2109
|
unsigned int tmp = 0;
|
|
2110
2110
|
const uchar* bm = (unsigned char*)&tmp;
|
|
2111
|
-
|
|
2111
|
+
uint poslen = posPtrLen();
|
|
2112
|
+
short tmp_stat = 0;
|
|
2113
|
+
bool inTrn = m_db.inSnapshot() || m_db.inTransaction();
|
|
2112
2114
|
// Is a current position read or not?
|
|
2113
2115
|
bool read = !includeCurrent;
|
|
2114
2116
|
bool forword =
|
|
2115
2117
|
(type == READ_RECORD_GETNEXT) || (type == READ_RECORD_STEPNEXT);
|
|
2118
|
+
|
|
2116
2119
|
while ((reject != 0) && (rows != 0))
|
|
2117
2120
|
{
|
|
2118
2121
|
if (read)
|
|
2119
2122
|
{
|
|
2120
2123
|
unlockRow(false);
|
|
2121
|
-
|
|
2122
|
-
if (type == READ_RECORD_GETNEXT)
|
|
2123
|
-
m_stat = m_table->file->ha_index_next(m_table->record[0]);
|
|
2124
|
-
else if (type == READ_RECORD_GETPREV)
|
|
2125
|
-
m_stat = m_table->file->ha_index_prev(m_table->record[0]);
|
|
2126
|
-
else if (type == READ_RECORD_STEPNEXT)
|
|
2127
|
-
m_stat = m_table->file->ha_rnd_next(m_table->record[0]);
|
|
2128
|
-
else if (type == READ_RECORD_STEPPREV)
|
|
2124
|
+
switch(type)
|
|
2129
2125
|
{
|
|
2126
|
+
case READ_RECORD_GETNEXT:
|
|
2127
|
+
m_stat = m_table->file->ha_index_next(m_table->record[0]);break;
|
|
2128
|
+
case READ_RECORD_GETPREV:
|
|
2129
|
+
m_stat = m_table->file->ha_index_prev(m_table->record[0]);break;
|
|
2130
|
+
case READ_RECORD_STEPNEXT:
|
|
2131
|
+
m_stat = m_table->file->ha_rnd_next(m_table->record[0]);break;
|
|
2132
|
+
default: //READ_RECORD_STEPPREV
|
|
2133
|
+
setCursorStaus();
|
|
2130
2134
|
m_stat = STATUS_NOSUPPORT_OP;
|
|
2131
2135
|
return;
|
|
2132
2136
|
}
|
|
2133
|
-
setCursorStaus();
|
|
2137
|
+
//setCursorStaus();
|
|
2134
2138
|
}
|
|
2135
2139
|
else
|
|
2136
2140
|
read = true;
|
|
2137
2141
|
|
|
2138
2142
|
if (m_stat)
|
|
2143
|
+
{
|
|
2144
|
+
tmp_stat = m_stat;
|
|
2139
2145
|
break;
|
|
2146
|
+
}
|
|
2140
2147
|
int ret = hdr->match(forword);
|
|
2141
2148
|
if (ret == REC_MACTH)
|
|
2142
2149
|
{
|
|
2143
|
-
|
|
2144
2150
|
if (!noBookmark)
|
|
2145
2151
|
bm = position();
|
|
2146
|
-
|
|
2147
|
-
if (
|
|
2152
|
+
tmp_stat = hdr->write(bm, poslen);
|
|
2153
|
+
if (tmp_stat)
|
|
2148
2154
|
break;
|
|
2149
2155
|
--rows;
|
|
2150
2156
|
}else
|
|
2151
2157
|
{
|
|
2152
|
-
unlock();
|
|
2158
|
+
if (inTrn) unlock();
|
|
2159
|
+
|
|
2153
2160
|
if (ret == REC_NOMACTH_NOMORE)
|
|
2154
2161
|
{
|
|
2162
|
+
setCursorStaus();
|
|
2155
2163
|
m_stat = STATUS_REACHED_FILTER_COND;
|
|
2156
2164
|
return;
|
|
2157
2165
|
}
|
|
@@ -2159,6 +2167,8 @@ void table::readRecords(IReadRecordsHandler* hdr, bool includeCurrent, int type,
|
|
|
2159
2167
|
--reject;
|
|
2160
2168
|
}
|
|
2161
2169
|
}
|
|
2170
|
+
setCursorStaus();
|
|
2171
|
+
m_stat = tmp_stat;
|
|
2162
2172
|
if (reject == 0)
|
|
2163
2173
|
m_stat = STATUS_LIMMIT_OF_REJECT;
|
|
2164
2174
|
}
|
|
@@ -2722,6 +2732,26 @@ void table::getCreateSql(String* s)
|
|
|
2722
2732
|
cp_store_create_info(m_db.thd(), &tables, s, NULL, (int)FALSE);
|
|
2723
2733
|
}
|
|
2724
2734
|
|
|
2735
|
+
void table::setValue(int index, const std::string& v, int type)
|
|
2736
|
+
{
|
|
2737
|
+
Field* field = *(m_table->field + index);
|
|
2738
|
+
if ((v.size() == 1) && (v[0] == 0x00))
|
|
2739
|
+
field->set_null();
|
|
2740
|
+
else
|
|
2741
|
+
field->set_notnull();
|
|
2742
|
+
if ((type == UPDATE_INC) || (type == UPDATE_DEC))
|
|
2743
|
+
{
|
|
2744
|
+
__int64 old = field->val_int();
|
|
2745
|
+
__int64 intv = _atoi64(v.c_str());
|
|
2746
|
+
if (type == UPDATE_INC)
|
|
2747
|
+
field->store(old + intv, false);
|
|
2748
|
+
else
|
|
2749
|
+
field->store(old - intv, false);
|
|
2750
|
+
}
|
|
2751
|
+
else
|
|
2752
|
+
field->store(v.c_str(), (uint)v.size(), &my_charset_bin);
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2725
2755
|
#ifdef USE_HANDLERSOCKET
|
|
2726
2756
|
|
|
2727
2757
|
int table::fieldIndexByName(const char* name) const
|
|
@@ -2744,26 +2774,6 @@ void table::setUseFieldList(const std::string& csv)
|
|
|
2744
2774
|
addUseField(fieldIndexByName(values[i].c_str()));
|
|
2745
2775
|
}
|
|
2746
2776
|
|
|
2747
|
-
void table::setValue(int index, const std::string& v, int type)
|
|
2748
|
-
{
|
|
2749
|
-
Field* field = *(m_table->field + index);
|
|
2750
|
-
if ((v.size() == 1) && (v[0] == 0x00))
|
|
2751
|
-
field->set_null();
|
|
2752
|
-
else
|
|
2753
|
-
field->set_notnull();
|
|
2754
|
-
if ((type == UPDATE_INC) || (type == UPDATE_DEC))
|
|
2755
|
-
{
|
|
2756
|
-
__int64 old = field->val_int();
|
|
2757
|
-
__int64 intv = _atoi64(v.c_str());
|
|
2758
|
-
if (type == UPDATE_INC)
|
|
2759
|
-
field->store(old + intv, false);
|
|
2760
|
-
else
|
|
2761
|
-
field->store(old - intv, false);
|
|
2762
|
-
}
|
|
2763
|
-
else
|
|
2764
|
-
field->store(v.c_str(), (uint)v.size(), &my_charset_bin);
|
|
2765
|
-
}
|
|
2766
|
-
|
|
2767
2777
|
void table::setUseValues(const std::vector<std::string>& values, int type)
|
|
2768
2778
|
{
|
|
2769
2779
|
for (int i = 0; i < (int)values.size(); i++)
|
|
@@ -78,6 +78,9 @@ class table;
|
|
|
78
78
|
*/
|
|
79
79
|
#define REF_SIZE_MAX 112
|
|
80
80
|
|
|
81
|
+
#define UPDATE_REPLACE 0
|
|
82
|
+
#define UPDATE_INC 1
|
|
83
|
+
#define UPDATE_DEC 2
|
|
81
84
|
|
|
82
85
|
|
|
83
86
|
/** Control mysql table cahche
|
|
@@ -346,7 +349,6 @@ class table : private boost::noncopyable
|
|
|
346
349
|
bookmarks* bms();
|
|
347
350
|
int percentage(uchar* first, uchar* last, uchar* cur);
|
|
348
351
|
|
|
349
|
-
bool setNonKey(bool scan = false);
|
|
350
352
|
void fillNull(uchar* ptr, int size);
|
|
351
353
|
|
|
352
354
|
inline void* keybuf() const { return &m_keybuf[0]; }
|
|
@@ -382,19 +384,12 @@ class table : private boost::noncopyable
|
|
|
382
384
|
std::vector<int> m_useFields;
|
|
383
385
|
void checkFiledIndex(int index);
|
|
384
386
|
int fieldIndexByName(const char* name) const;
|
|
385
|
-
|
|
386
387
|
void addUseField(int index) { m_useFields.push_back(index); };
|
|
387
|
-
|
|
388
388
|
public:
|
|
389
389
|
std::vector<int>& useFields() { return m_useFields; };
|
|
390
390
|
void setUseFieldList(const std::string& csv);
|
|
391
|
-
void setValue(int index, const std::string& v, int type);
|
|
392
391
|
void setUseValues(const std::vector<std::string>& values, int type);
|
|
393
392
|
|
|
394
|
-
#define UPDATE_REPLACE 0
|
|
395
|
-
#define UPDATE_INC 1
|
|
396
|
-
#define UPDATE_DEC 2
|
|
397
|
-
|
|
398
393
|
#endif
|
|
399
394
|
|
|
400
395
|
public:
|
|
@@ -524,6 +519,7 @@ public:
|
|
|
524
519
|
{
|
|
525
520
|
return (1U << m_table->key_info[(int)m_keyNum].user_defined_key_parts) - 1;
|
|
526
521
|
}
|
|
522
|
+
bool setNonKey(bool scan = false);
|
|
527
523
|
unsigned long long tableFlags() const { return m_table->file->ha_table_flags();}
|
|
528
524
|
void seekKey(enum ha_rkey_function find_flag, key_part_map keyMap);
|
|
529
525
|
void getNextSame(key_part_map keyMap);
|
|
@@ -779,6 +775,8 @@ public:
|
|
|
779
775
|
inline void setTimestampAlways(bool v) { m_timestampAlways = v;}
|
|
780
776
|
|
|
781
777
|
void getCreateSql(String* s);
|
|
778
|
+
|
|
779
|
+
void setValue(int index, const std::string& v, int type);
|
|
782
780
|
};
|
|
783
781
|
|
|
784
782
|
class fieldBitmap
|
|
@@ -157,6 +157,17 @@ void dbManager::releaseDatabase(short cid)
|
|
|
157
157
|
m_handles.erase(m_handles.begin() + i);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
int dbManager::trxProcessing()
|
|
161
|
+
{
|
|
162
|
+
int transactins = 0;
|
|
163
|
+
for (size_t i = 0; i < m_dbs.size(); i++)
|
|
164
|
+
{
|
|
165
|
+
if (m_dbs[i]->inTransaction() || m_dbs[i]->inSnapshot())
|
|
166
|
+
++transactins;
|
|
167
|
+
}
|
|
168
|
+
return transactins;
|
|
169
|
+
}
|
|
170
|
+
|
|
160
171
|
database* dbManager::useDataBase(int id) const
|
|
161
172
|
{
|
|
162
173
|
if (id >= (int)m_dbs.size())
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*=================================================================
|
|
2
|
+
Copyright (C) 2016 BizStation Corp All rights reserved.
|
|
3
|
+
|
|
4
|
+
This program is free software; you can redistribute it and/or
|
|
5
|
+
modify it under the terms of the GNU General Public License
|
|
6
|
+
as published by the Free Software Foundation; either version 2
|
|
7
|
+
of the License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program; if not, write to the Free Software
|
|
16
|
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
17
|
+
02111-1307, USA.
|
|
18
|
+
=================================================================*/
|
|
19
|
+
#include <my_config.h>
|
|
20
|
+
# include <string>
|
|
21
|
+
#include <boost/thread.hpp>
|
|
22
|
+
#include "ha.h"
|
|
23
|
+
#include "mysqlInternal.h"
|
|
24
|
+
#include <bzs/env/fileopen.h>
|
|
25
|
+
#include <bzs/db/protocol/tdap/tdapcapi.h>
|
|
26
|
+
|
|
27
|
+
/* implemnts in transactd.cpp */
|
|
28
|
+
extern unsigned int g_startup_ha;
|
|
29
|
+
|
|
30
|
+
unsigned int g_ha;
|
|
31
|
+
bool trx_blocking = trx_noblock;
|
|
32
|
+
|
|
33
|
+
namespace bzs
|
|
34
|
+
{
|
|
35
|
+
namespace db
|
|
36
|
+
{
|
|
37
|
+
namespace engine
|
|
38
|
+
{
|
|
39
|
+
namespace mysql
|
|
40
|
+
{
|
|
41
|
+
|
|
42
|
+
#define roleInfoName "transactd_srv_master"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
boost::recursive_try_mutex g_tmtx_ha;
|
|
46
|
+
boost::try_mutex g_tmtx_trx;
|
|
47
|
+
|
|
48
|
+
int getRoleFromFile()
|
|
49
|
+
{
|
|
50
|
+
int ret = -1;
|
|
51
|
+
char filename[FN_REFLEN];
|
|
52
|
+
fn_format(filename, roleInfoName, "", ".info", MY_REPLACE_EXT | MY_UNPACK_FILENAME);
|
|
53
|
+
FILE* fp = fileOpen(filename, "r");
|
|
54
|
+
if (fp)
|
|
55
|
+
{
|
|
56
|
+
char buf[20];
|
|
57
|
+
char* p = fgets(buf, 20, fp);
|
|
58
|
+
if (p && *p)
|
|
59
|
+
ret = atol(p);
|
|
60
|
+
fclose(fp);
|
|
61
|
+
}else
|
|
62
|
+
sql_print_error("Transactd: File : %s was not opened for read", filename);
|
|
63
|
+
return ret;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bool saveRoleToFile(int role)
|
|
67
|
+
{
|
|
68
|
+
char filename[FN_REFLEN];
|
|
69
|
+
fn_format(filename, roleInfoName, "", ".info", MY_REPLACE_EXT | MY_UNPACK_FILENAME);
|
|
70
|
+
FILE* fp = fileOpen(filename, "w");
|
|
71
|
+
if (fp)
|
|
72
|
+
{
|
|
73
|
+
const char* p = (role == HA_ROLE_MASTER) ? "1" :
|
|
74
|
+
((role == HA_ROLE_NONE) ? "2" : "0");
|
|
75
|
+
fputs(p, fp);
|
|
76
|
+
fclose(fp);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
sql_print_error("Transactd: File : %s was not opened for write", filename);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int initHa()
|
|
84
|
+
{
|
|
85
|
+
boost::recursive_try_mutex::scoped_lock lck(g_tmtx_ha);
|
|
86
|
+
g_ha = g_startup_ha & ~HA_RESTORE_ROLE;
|
|
87
|
+
if (g_startup_ha & HA_RESTORE_ROLE)
|
|
88
|
+
{
|
|
89
|
+
int ret = getRoleFromFile();
|
|
90
|
+
if (ret != -1)
|
|
91
|
+
g_ha |= (unsigned int)ret;
|
|
92
|
+
}
|
|
93
|
+
return g_ha;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
bool haLock()
|
|
97
|
+
{
|
|
98
|
+
return g_tmtx_ha.try_lock();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
bool haUnlock()
|
|
102
|
+
{
|
|
103
|
+
#ifdef _WIN32
|
|
104
|
+
if (g_tmtx_ha.locking_thread_id)
|
|
105
|
+
{
|
|
106
|
+
g_tmtx_ha.unlock();
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
#else
|
|
111
|
+
g_tmtx_ha.unlock();
|
|
112
|
+
return true;
|
|
113
|
+
#endif
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
bool setRole(int role)
|
|
117
|
+
{
|
|
118
|
+
int ret = getRole();
|
|
119
|
+
if (ret != role)
|
|
120
|
+
{
|
|
121
|
+
if (g_tmtx_ha.try_lock())
|
|
122
|
+
{
|
|
123
|
+
g_ha &= ~(HA_ROLE_MASTER | HA_ROLE_NONE);
|
|
124
|
+
g_ha |= role;
|
|
125
|
+
saveRoleToFile(role);
|
|
126
|
+
g_tmtx_ha.unlock();
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
int getRole()
|
|
135
|
+
{
|
|
136
|
+
return (g_ha & (HA_ROLE_MASTER | HA_ROLE_NONE));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
bool setEnableFailover(bool enable)
|
|
140
|
+
{
|
|
141
|
+
if (g_tmtx_ha.try_lock())
|
|
142
|
+
{
|
|
143
|
+
if (enable)
|
|
144
|
+
g_ha |= HA_ENABLE_FAILOVER;
|
|
145
|
+
else
|
|
146
|
+
g_ha &= ~HA_ENABLE_FAILOVER;
|
|
147
|
+
g_tmtx_ha.unlock();
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
bool getEnableFailover()
|
|
154
|
+
{
|
|
155
|
+
return (g_ha & HA_ENABLE_FAILOVER) != 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
bool setTrxBlock(bool v)
|
|
159
|
+
{
|
|
160
|
+
if (g_tmtx_trx.try_lock())
|
|
161
|
+
{
|
|
162
|
+
trx_blocking = v ? trx_block : trx_noblock;
|
|
163
|
+
g_tmtx_trx.unlock();
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
} // namespace mysql
|
|
171
|
+
} // namespace engine
|
|
172
|
+
} // namespace db
|
|
173
|
+
} // namespace bzs
|
|
174
|
+
|