1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-31 18:24:25 +03:00

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.
This commit is contained in:
Teemu Ollakka
2019-02-16 17:09:18 +02:00
parent 58aa3e821f
commit 29835fbec0
14 changed files with 354 additions and 30 deletions

View File

@ -307,6 +307,10 @@ namespace wsrep
/**
* Append a key into transaction write set.
*
* @param key Key to be appended
*
* @return Zero on success, non-zero on failure.
*/
int append_key(const wsrep::key& key)
{
@ -315,6 +319,27 @@ namespace wsrep
return transaction_.append_key(key);
}
/**
* Append keys in key_array into transaction write set.
*
* @param keys Array of keys to be appended
*
* @return Zero in case of success, non-zero on failure.
*/
int append_keys(const wsrep::key_array& keys)
{
assert(mode_ == m_local || mode_ == m_toi);
assert(state_ == s_exec);
for (auto i(keys.begin()); i != keys.end(); ++i)
{
if (transaction_.append_key(*i))
{
return 1;
}
}
return 0;
}
/**
* Append data into transaction write set.
*/

View File

@ -20,12 +20,19 @@
/** @file compiler.hpp
*
* Compiler specific options.
* Compiler specific macro definitions.
*
* WSREP_OVERRIDE - Set to "override" if the compiler supports it, otherwise
* left empty.
* WSREP_CONSTEXPR_OR_INLINE - Set to "constexpr" if the compiler supports it,
* otherwise "inline".
*/
#define WSREP_UNUSED __attribute__((unused))
#if __cplusplus >= 201103L
#define WSREP_OVERRIDE override
#define WSREP_CONSTEXPR_OR_INLINE constexpr
#else
#define WSREP_OVERRIDE
#define WSREP_CONSTEXPR_OR_INLINE inline
#endif // __cplusplus >= 201103L

View File

@ -22,9 +22,16 @@
#include "id.hpp"
#include "seqno.hpp"
#include "compiler.hpp"
#include <iosfwd>
/**
* Minimum number of bytes guaratneed to store GTID string representation,
* terminating '\0' not included (36 + 1 + 20).
*/
#define WSREP_LIB_GTID_C_STR_LEN 57
namespace wsrep
{
class gtid
@ -61,6 +68,18 @@ namespace wsrep
wsrep::seqno seqno_;
};
/**
* Scan a GTID from C string.
*
* @param buf Buffer containing the string
* @param len Length of buffer
* @param[out] gtid Gtid to be printed to
*
* @return Number of bytes scanned, negative value on error.
*/
ssize_t scan_from_c_str(const char* buf, size_t buf_len,
wsrep::gtid& gtid);
/**
* Print a GTID into character buffer.
* @param buf Pointer to the beginning of the buffer
@ -68,16 +87,16 @@ namespace wsrep
*
* @return Number of characters printed or negative value for error
*/
ssize_t gtid_print_to_c_str(const wsrep::gtid&, char* buf, size_t buf_len);
ssize_t print_to_c_str(const wsrep::gtid&, char* buf, size_t buf_len);
/**
* Return minimum number of bytes guaranteed to store GTID string
* representation, terminating '\0' not included (36 + 1 + 20)
* Overload for ostream operator<<.
*/
static inline size_t gtid_c_str_len()
{
return 57;
}
std::ostream& operator<<(std::ostream&, const wsrep::gtid&);
/**
* Overload for istream operator>>.
*/
std::istream& operator>>(std::istream&, wsrep::gtid&);
}

View File

@ -42,10 +42,11 @@ namespace wsrep
class id
{
public:
typedef struct native_type { unsigned char buf[16]; } native_type;
/**
* Default constructor. Constructs an empty identifier.
*/
id() : data_() { std::memset(data_, 0, sizeof(data_)); }
id() : data_() { std::memset(data_.buf, 0, sizeof(data_.buf)); }
/**
* Construct from string. The input string may contain either
@ -62,24 +63,24 @@ namespace wsrep
{
throw wsrep::runtime_error("Too long identifier");
}
std::memset(data_, 0, sizeof(data_));
std::memcpy(data_, data, size);
std::memset(data_.buf, 0, sizeof(data_.buf));
std::memcpy(data_.buf, data, size);
}
bool operator<(const id& other) const
{
return (std::memcmp(data_, other.data_, sizeof(data_)) < 0);
return (std::memcmp(data_.buf, other.data_.buf, sizeof(data_.buf)) < 0);
}
bool operator==(const id& other) const
{
return (std::memcmp(data_, other.data_, sizeof(data_)) == 0);
return (std::memcmp(data_.buf, other.data_.buf, sizeof(data_.buf)) == 0);
}
bool operator!=(const id& other) const
{
return !(*this == other);
}
const void* data() const { return data_; }
const void* data() const { return data_.buf; }
size_t size() const { return sizeof(data_); }
@ -94,7 +95,7 @@ namespace wsrep
}
private:
static const wsrep::id undefined_;
unsigned char data_[16];
native_type data_;
};
std::ostream& operator<<(std::ostream&, const wsrep::id& id);

View File

@ -25,6 +25,7 @@
#include "buffer.hpp"
#include "client_id.hpp"
#include "transaction_id.hpp"
#include "compiler.hpp"
#include <cassert>
#include <cstring>
@ -404,6 +405,14 @@ namespace wsrep
*/
virtual void* native() const = 0;
/**
* Empty provider magic. If none provider is passed to make_provider(),
* a dummy provider is loaded.
*/
static WSREP_CONSTEXPR_OR_INLINE
const char* none() { return "none"; }
/**
* Create a new provider.
*

View File

@ -20,8 +20,6 @@
#ifndef WSREP_SEQNO_HPP
#define WSREP_SEQNO_HPP
#include "exception.hpp"
#include <iosfwd>
namespace wsrep
@ -33,6 +31,8 @@ namespace wsrep
class seqno
{
public:
typedef long long native_type;
seqno()
: seqno_(-1)
{ }
@ -77,8 +77,9 @@ namespace wsrep
return (*this + seqno(other));
}
static seqno undefined() { return seqno(-1); }
private:
long long seqno_;
native_type seqno_;
};
std::ostream& operator<<(std::ostream& os, wsrep::seqno seqno);

View File

@ -179,6 +179,13 @@ namespace wsrep
rm_sync
};
/**
* Magic string to tell provider to engage into trivial (empty)
* state transfer. No data will be passed, but the node shall be
* considered joined.
*/
static WSREP_CONSTEXPR_OR_INLINE
const char* sst_trivial() { return "trivial"; };
virtual ~server_state();