Skip to content

Commit cfdf265

Browse files
committed
Cleaning wsrep-API dependencies from library code
Replace all wsrep_api.h dependencies with similar code in library implementation. Also add gcc/g++ 4.4 to travis automation to get better compiler coverage.
1 parent edcfcaf commit cfdf265

16 files changed

+449
-49
lines changed

.travis.yml

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,41 @@ language: cpp
22

33
matrix:
44
include:
5+
- os: linux
6+
dist: trusty
7+
name: "GCC 4.4 Debug"
8+
addons:
9+
apt:
10+
packages:
11+
- cmake
12+
- gcc-4.4
13+
- g++-4.4
14+
env: MATRIX_EVAL="CC=gcc-4.4 CXX=g++-4.4 TYPE=Debug STRICT=OFF UNIT_TESTS=OFF ASAN=OFF DBSIM=OFF"
15+
- os: linux
16+
name: "GCC 4.4 RelWithDebInfo"
17+
addons:
18+
apt:
19+
packages:
20+
- cmake
21+
- gcc-4.4
22+
- g++-4.4
23+
env: MATRIX_EVAL="CC=gcc-4.4 CXX=g++-4.4 TYPE=RelWithDebInfo STRICT=OFF UNIT_TESTS=OFF ASAN=OFF DBSIM=OFF"
524
- os: linux
625
name: "GCC 4.8 Debug"
726
addons:
827
apt:
928
packages:
1029
- cmake
1130
- libboost-test-dev
12-
env: MATRIX_EVAL="TYPE=Debug STRICT=OFF ASAN=ON DBSIM=OFF"
31+
env: MATRIX_EVAL="TYPE=Debug STRICT=OFF UNIT_TESTS=ON ASAN=ON DBSIM=OFF"
1332
- os: linux
1433
name: "GCC 4.8 RelWithDebInfo"
1534
addons:
1635
apt:
1736
packages:
1837
- cmake
1938
- libboost-test-dev
20-
env: MATRIX_EVAL="TYPE=RelWithDebInfo STRICT=OFF ASAN=ON DBSIM=OFF"
39+
env: MATRIX_EVAL="TYPE=RelWithDebInfo STRICT=OFF UNIT_TESTS=ON ASAN=ON DBSIM=OFF"
2140
- os: linux
2241
name: "GCC 5 Debug"
2342
addons:
@@ -31,7 +50,7 @@ matrix:
3150
- libboost-program-options-dev
3251
- libboost-filesystem-dev
3352
- libboost-thread-dev
34-
env: MATRIX_EVAL="CC=gcc-5 CXX=g++-5 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=ON"
53+
env: MATRIX_EVAL="CC=gcc-5 CXX=g++-5 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
3554
- os: linux
3655
name: "GCC 5 RelWithDebInfo"
3756
addons:
@@ -45,7 +64,7 @@ matrix:
4564
- libboost-program-options-dev
4665
- libboost-filesystem-dev
4766
- libboost-thread-dev
48-
env: MATRIX_EVAL="CC=gcc-5 CXX=g++-5 TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=ON"
67+
env: MATRIX_EVAL="CC=gcc-5 CXX=g++-5 TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
4968
- os: linux
5069
name: "GCC 6 Debug"
5170
addons:
@@ -59,7 +78,7 @@ matrix:
5978
- libboost-program-options-dev
6079
- libboost-filesystem-dev
6180
- libboost-thread-dev
62-
env: MATRIX_EVAL="CC=gcc-6 CXX=g++-6 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=ON"
81+
env: MATRIX_EVAL="CC=gcc-6 CXX=g++-6 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
6382
- os: linux
6483
name: "GCC 6 RelWithDebInfo"
6584
addons:
@@ -73,7 +92,7 @@ matrix:
7392
- libboost-program-options-dev
7493
- libboost-filesystem-dev
7594
- libboost-thread-dev
76-
env: MATRIX_EVAL="CC=gcc-6 CXX=g++-6 TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=ON"
95+
env: MATRIX_EVAL="CC=gcc-6 CXX=g++-6 TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
7796
- os: linux
7897
name: "GCC 7 Debug"
7998
addons:
@@ -87,7 +106,7 @@ matrix:
87106
- libboost-program-options-dev
88107
- libboost-filesystem-dev
89108
- libboost-thread-dev
90-
env: MATRIX_EVAL="CC=gcc-7 CXX=g++-7 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=ON"
109+
env: MATRIX_EVAL="CC=gcc-7 CXX=g++-7 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
91110
- os: linux
92111
name: "GCC 7 RelWithDebInfo"
93112
addons:
@@ -101,7 +120,7 @@ matrix:
101120
- libboost-program-options-dev
102121
- libboost-filesystem-dev
103122
- libboost-thread-dev
104-
env: MATRIX_EVAL="CC=gcc-7 CXX=g++-7 TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=ON"
123+
env: MATRIX_EVAL="CC=gcc-7 CXX=g++-7 TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
105124
- os: linux
106125
name: "Clang 3.6 Debug"
107126
addons:
@@ -116,7 +135,7 @@ matrix:
116135
- libboost-program-options-dev
117136
- libboost-filesystem-dev
118137
- libboost-thread-dev
119-
env: MATRIX_EVAL="CC=clang-3.6 CXX=clang++-3.6 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=ON"
138+
env: MATRIX_EVAL="CC=clang-3.6 CXX=clang++-3.6 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
120139
- os: linux
121140
name: "Clang 3.6 RelWithDebInfo"
122141
addons:
@@ -131,7 +150,7 @@ matrix:
131150
- libboost-program-options-dev
132151
- libboost-filesystem-dev
133152
- libboost-thread-dev
134-
env: MATRIX_EVAL="CC=clang-3.6 CXX=clang++-3.6 TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=ON"
153+
env: MATRIX_EVAL="CC=clang-3.6 CXX=clang++-3.6 TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=ON"
135154
- os: linux
136155
name: "Clang 4.0 Debug"
137156
addons:
@@ -146,7 +165,7 @@ matrix:
146165
- libboost-program-options-dev
147166
- libboost-filesystem-dev
148167
- libboost-thread-dev
149-
env: MATRIX_EVAL="CC=clang-4.0 CXX=clang++-4.0 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=OFF"
168+
env: MATRIX_EVAL="CC=clang-4.0 CXX=clang++-4.0 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
150169
- os: linux
151170
name: "Clang 4.0 RelWithDebInfo"
152171
addons:
@@ -161,7 +180,7 @@ matrix:
161180
- libboost-program-options-dev
162181
- libboost-filesystem-dev
163182
- libboost-thread-dev
164-
env: MATRIX_EVAL="CC=clang-4.0 CXX=clang++-4.0 TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=OFF"
183+
env: MATRIX_EVAL="CC=clang-4.0 CXX=clang++-4.0 TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
165184
- os: linux
166185
name: "Clang 5.0 Debug"
167186
addons:
@@ -176,7 +195,7 @@ matrix:
176195
- libboost-program-options-dev
177196
- libboost-filesystem-dev
178197
- libboost-thread-dev
179-
env: MATRIX_EVAL="CC=clang-5.0 CXX=clang++-5.0 TYPE=Debug STRICT=ON ASAN=OFF DBSIM=OFF"
198+
env: MATRIX_EVAL="CC=clang-5.0 CXX=clang++-5.0 TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
180199
- os: linux
181200
name: "Clang 5.0 RelWithDebInfo"
182201
addons:
@@ -207,7 +226,7 @@ matrix:
207226
- libboost-program-options-dev
208227
- libboost-filesystem-dev
209228
- libboost-thread-dev
210-
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=Debug STRICT=ON ASAN=OFF DBSIM=OFF"
229+
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
211230
- os: linux
212231
dist: xenial
213232
name: "Clang 7.0 RelWithDebInfo"
@@ -223,25 +242,25 @@ matrix:
223242
- libboost-program-options-dev
224243
- libboost-filesystem-dev
225244
- libboost-thread-dev
226-
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=OFF"
245+
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
227246
- os: osx
228247
osx_image: xcode10.1
229248
name: "Xcode 10.1 Debug"
230-
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=Debug STRICT=ON ASAN=OFF DBSIM=OFF"
249+
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=Debug STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
231250
- os: osx
232251
osx_image: xcode10.1
233252
name: "Xcode 10.1 RelWithDebInfo"
234-
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=RelWithDebInfo STRICT=ON ASAN=OFF DBSIM=OFF"
253+
env: MATRIX_EVAL="CC=clang CXX=clang++ TYPE=RelWithDebInfo STRICT=ON UNIT_TESTS=ON ASAN=OFF DBSIM=OFF"
235254

236255
before_install:
237256
- eval ${MATRIX_EVAL}
238257

239258
script:
240-
- echo CC=${CC} CXX=${CXX} TYPE=${TYPE} STRICT=${STRICT} ASAN=${ASAN} DBSIM=${DBSIM}
259+
- echo CC=${CC} CXX=${CXX} TYPE=${TYPE} STRICT=${STRICT} ${UNIT_TESTS} ASAN=${ASAN} DBSIM=${DBSIM}
241260
- cmake . -DCMAKE_BUILD_TYPE=${TYPE}
242261
-DWSREP_LIB_MAINTAINER_MODE:BOOL=ON
243262
-DWSREP_LIB_STRICT_BUILD_FLAGS:BOOL=${STRICT}
244-
-DWSREP_LIB_WITH_UNIT_TESTS:BOOL=ON
263+
-DWSREP_LIB_WITH_UNIT_TESTS:BOOL=${UNIT_TESTS}
245264
-DWSREP_LIB_WITH_DBSIM:BOOL=${DBSIM}
246265
-DWSREP_LIB_WITH_ASAN:BOOL=${ASAN}
247266
- make VERBOSE=1 -j 4

include/wsrep/client_state.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ namespace wsrep
291291

292292
/**
293293
* Append a key into transaction write set.
294+
*
295+
* @param key Key to be appended
296+
*
297+
* @return Zero on success, non-zero on failure.
294298
*/
295299
int append_key(const wsrep::key& key)
296300
{
@@ -299,6 +303,27 @@ namespace wsrep
299303
return transaction_.append_key(key);
300304
}
301305

306+
/**
307+
* Append keys in key_array into transaction write set.
308+
*
309+
* @param keys Array of keys to be appended
310+
*
311+
* @return Zero in case of success, non-zero on failure.
312+
*/
313+
int append_keys(const wsrep::key_array& keys)
314+
{
315+
assert(mode_ == m_local || mode_ == m_toi);
316+
assert(state_ == s_exec);
317+
for (auto i(keys.begin()); i != keys.end(); ++i)
318+
{
319+
if (transaction_.append_key(*i))
320+
{
321+
return 1;
322+
}
323+
}
324+
return 0;
325+
}
326+
302327
/**
303328
* Append data into transaction write set.
304329
*/

include/wsrep/compiler.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@
2020

2121
/** @file compiler.hpp
2222
*
23-
* Compiler specific options.
23+
* Compiler specific macro definitions.
24+
*
25+
* WSREP_OVERRIDE - Set to "override" if the compiler supports it, otherwise
26+
* left empty.
27+
* WSREP_CONSTEXPR_OR_INLINE - Set to "constexpr" if the compiler supports it,
28+
* otherwise "inline".
2429
*/
2530

2631
#define WSREP_UNUSED __attribute__((unused))
2732
#if __cplusplus >= 201103L
2833
#define WSREP_OVERRIDE override
34+
#define WSREP_CONSTEXPR_OR_INLINE constexpr
2935
#else
3036
#define WSREP_OVERRIDE
37+
#define WSREP_CONSTEXPR_OR_INLINE inline
3138
#endif // __cplusplus >= 201103L

include/wsrep/gtid.hpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222

2323
#include "id.hpp"
2424
#include "seqno.hpp"
25+
#include "compiler.hpp"
2526

2627
#include <iosfwd>
2728

29+
/**
30+
* Minimum number of bytes guaratneed to store GTID string representation,
31+
* terminating '\0' not included (36 + 1 + 20).
32+
*/
33+
#define WSREP_LIB_GTID_C_STR_LEN 57
34+
2835
namespace wsrep
2936
{
3037
class gtid
@@ -54,23 +61,35 @@ namespace wsrep
5461
wsrep::seqno seqno_;
5562
};
5663

64+
/**
65+
* Scan a GTID from C string.
66+
*
67+
* @param buf Buffer containing the string
68+
* @param len Length of buffer
69+
* @param[out] gtid Gtid to be printed to
70+
*
71+
* @return Number of bytes scanned, negative value on error.
72+
*/
73+
ssize_t scan_from_c_str(const char* buf, size_t buf_len,
74+
wsrep::gtid& gtid);
75+
5776
/**
5877
* Print a GTID into character buffer.
5978
* @param buf Pointer to the beginning of the buffer
6079
* @param buf_len Buffer length
6180
*
6281
* @return Number of characters printed or negative value for error
6382
*/
64-
ssize_t gtid_print_to_c_str(const wsrep::gtid&, char* buf, size_t buf_len);
83+
ssize_t print_to_c_str(const wsrep::gtid&, char* buf, size_t buf_len);
84+
6585
/**
66-
* Return minimum number of bytes guaranteed to store GTID string
67-
* representation, terminating '\0' not included (36 + 1 + 20)
86+
* Overload for ostream operator<<.
6887
*/
69-
static inline size_t gtid_c_str_len()
70-
{
71-
return 57;
72-
}
7388
std::ostream& operator<<(std::ostream&, const wsrep::gtid&);
89+
90+
/**
91+
* Overload for istream operator>>.
92+
*/
7493
std::istream& operator>>(std::istream&, wsrep::gtid&);
7594
}
7695

include/wsrep/id.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ namespace wsrep
4242
class id
4343
{
4444
public:
45+
typedef struct native_type { unsigned char buf[16]; } native_type;
4546
/**
4647
* Default constructor. Constructs an empty identifier.
4748
*/
48-
id() : data_() { std::memset(data_, 0, sizeof(data_)); }
49+
id() : data_() { std::memset(data_.buf, 0, sizeof(data_.buf)); }
4950

5051
/**
5152
* Construct from string. The input string may contain either
@@ -62,24 +63,24 @@ namespace wsrep
6263
{
6364
throw wsrep::runtime_error("Too long identifier");
6465
}
65-
std::memset(data_, 0, sizeof(data_));
66-
std::memcpy(data_, data, size);
66+
std::memset(data_.buf, 0, sizeof(data_.buf));
67+
std::memcpy(data_.buf, data, size);
6768
}
6869

6970
bool operator<(const id& other) const
7071
{
71-
return (std::memcmp(data_, other.data_, sizeof(data_)) < 0);
72+
return (std::memcmp(data_.buf, other.data_.buf, sizeof(data_.buf)) < 0);
7273
}
7374

7475
bool operator==(const id& other) const
7576
{
76-
return (std::memcmp(data_, other.data_, sizeof(data_)) == 0);
77+
return (std::memcmp(data_.buf, other.data_.buf, sizeof(data_.buf)) == 0);
7778
}
7879
bool operator!=(const id& other) const
7980
{
8081
return !(*this == other);
8182
}
82-
const void* data() const { return data_; }
83+
const void* data() const { return data_.buf; }
8384

8485
size_t size() const { return sizeof(data_); }
8586

@@ -94,7 +95,7 @@ namespace wsrep
9495
}
9596
private:
9697
static const wsrep::id undefined_;
97-
unsigned char data_[16];
98+
native_type data_;
9899
};
99100

100101
std::ostream& operator<<(std::ostream&, const wsrep::id& id);

include/wsrep/provider.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "buffer.hpp"
2626
#include "client_id.hpp"
2727
#include "transaction_id.hpp"
28+
#include "compiler.hpp"
2829

2930
#include <cassert>
3031
#include <cstring>
@@ -375,6 +376,14 @@ namespace wsrep
375376
*/
376377
virtual void* native() const = 0;
377378

379+
380+
/**
381+
* Empty provider magic. If none provider is passed to make_provider(),
382+
* a dummy provider is loaded.
383+
*/
384+
static WSREP_CONSTEXPR_OR_INLINE
385+
const char* none() { return "none"; }
386+
378387
/**
379388
* Create a new provider.
380389
*

0 commit comments

Comments
 (0)