1
0
Fork 0

constexpr

This commit is contained in:
Jan Steemann 2016-03-04 12:33:59 +01:00
parent 0c580f1076
commit eb82d96836
16 changed files with 135 additions and 209 deletions

View File

@ -205,7 +205,7 @@ bool Index::validateHandle(char const* key, size_t* split) {
return false;
}
if (p - key > TRI_COL_NAME_LENGTH) {
if (static_cast<size_t>(p - key) > TRI_COL_NAME_LENGTH) {
return false;
}

View File

@ -199,59 +199,6 @@ bool RestVocbaseBaseHandler::checkCreateCollection(std::string const& name,
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generates a HTTP 201 or 202 response
/// DEPRECATED
////////////////////////////////////////////////////////////////////////////////
void RestVocbaseBaseHandler::generate20x(
HttpResponse::HttpResponseCode responseCode,
std::string const& collectionName, TRI_voc_key_t key, TRI_voc_rid_t rid,
TRI_col_type_e type) {
std::string handle(
DocumentHelper::assembleDocumentId(collectionName, key));
std::string rev(StringUtils::itoa(rid));
createResponse(responseCode);
_response->setContentType("application/json; charset=utf-8");
if (responseCode != HttpResponse::OK) {
// 200 OK is sent is case of delete or update.
// in these cases we do not return etag nor location
_response->setHeader("etag", 4, "\"" + rev + "\"");
std::string escapedHandle(
DocumentHelper::assembleDocumentId(collectionName, key, true));
if (_request->compatibility() < 10400L) {
// pre-1.4 location header (e.g. /_api/document/xyz)
_response->setHeader("location", 8,
std::string(DOCUMENT_PATH + "/" + escapedHandle));
} else {
// 1.4+ location header (e.g. /_db/_system/_api/document/xyz)
if (type == TRI_COL_TYPE_EDGE) {
_response->setHeader("location", 8,
std::string("/_db/" + _request->databaseName() +
EDGE_PATH + "/" + escapedHandle));
} else {
_response->setHeader("location", 8,
std::string("/_db/" + _request->databaseName() +
DOCUMENT_PATH + "/" + escapedHandle));
}
}
}
// _id and _key are safe and do not need to be JSON-encoded
_response->body()
.appendText("{\"error\":false,\"" TRI_VOC_ATTRIBUTE_ID "\":\"")
.appendText(handle)
.appendText("\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"")
.appendText(rev)
.appendText("\",\"" TRI_VOC_ATTRIBUTE_KEY "\":\"")
.appendText(key)
.appendText("\"}");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generates a HTTP 20x response
////////////////////////////////////////////////////////////////////////////////
@ -353,27 +300,16 @@ void RestVocbaseBaseHandler::generatePreconditionFailed(
////////////////////////////////////////////////////////////////////////////////
void RestVocbaseBaseHandler::generatePreconditionFailed(
std::string const& collectionName, std::string const& key, TRI_voc_rid_t rid) {
std::string rev(StringUtils::itoa(rid));
std::string const& collectionName, std::string const& key, TRI_voc_rid_t rev) {
createResponse(HttpResponse::PRECONDITION_FAILED);
_response->setContentType("application/json; charset=utf-8");
_response->setHeader("etag", 4, "\"" + rev + "\"");
VPackBuilder builder;
builder.openObject();
builder.add(TRI_VOC_ATTRIBUTE_ID, VPackValue(DocumentHelper::assembleDocumentId(collectionName, key)));
builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(std::to_string(rev)));
builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(key));
builder.close();
// _id and _key are safe and do not need to be JSON-encoded
_response->body()
.appendText("{\"error\":true,\"code\":")
.appendInteger((int32_t)HttpResponse::PRECONDITION_FAILED)
.appendText(",\"errorNum\":")
.appendInteger((int32_t)TRI_ERROR_ARANGO_CONFLICT)
.appendText(",\"errorMessage\":\"precondition failed\"")
.appendText(",\"" TRI_VOC_ATTRIBUTE_ID "\":\"")
.appendText(DocumentHelper::assembleDocumentId(collectionName, key))
.appendText("\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"")
.appendText(StringUtils::itoa(rid))
.appendText("\",\"" TRI_VOC_ATTRIBUTE_KEY "\":\"")
.appendText(key)
.appendText("\"}");
generatePreconditionFailed(builder.slice());
}
////////////////////////////////////////////////////////////////////////////////
@ -440,7 +376,7 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& document,
void RestVocbaseBaseHandler::generateTransactionError(
std::string const& collectionName, int res, std::string const& key,
TRI_voc_rid_t rid) {
TRI_voc_rid_t rev) {
switch (res) {
case TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND:
if (collectionName.empty()) {
@ -485,7 +421,7 @@ void RestVocbaseBaseHandler::generateTransactionError(
case TRI_ERROR_ARANGO_CONFLICT:
generatePreconditionFailed(collectionName,
key.empty() ? "unknown" : key, rid);
key.empty() ? "unknown" : key, rev);
return;
case TRI_ERROR_CLUSTER_SHARD_GONE:

View File

@ -139,14 +139,6 @@ class RestVocbaseBaseHandler : public RestBaseHandler {
bool checkCreateCollection(std::string const&, TRI_col_type_e);
//////////////////////////////////////////////////////////////////////////////
/// @brief generates a HTTP 201 or 202 response
/// DEPRECATED
//////////////////////////////////////////////////////////////////////////////
void generate20x(rest::HttpResponse::HttpResponseCode, std::string const&,
TRI_voc_key_t, TRI_voc_rid_t, TRI_col_type_e);
//////////////////////////////////////////////////////////////////////////////
/// @brief generates a HTTP 201 or 202 response
//////////////////////////////////////////////////////////////////////////////
@ -209,7 +201,7 @@ class RestVocbaseBaseHandler : public RestBaseHandler {
//////////////////////////////////////////////////////////////////////////////
void generatePreconditionFailed(std::string const&, std::string const& key,
TRI_voc_rid_t rid);
TRI_voc_rid_t rev);
//////////////////////////////////////////////////////////////////////////////
/// @brief generates precondition failed, without transaction info

View File

@ -30,6 +30,24 @@
namespace arangodb {
namespace DatafileHelper {
////////////////////////////////////////////////////////////////////////////////
/// @brief maximal size of a marker
////////////////////////////////////////////////////////////////////////////////
constexpr TRI_voc_size_t MaximalMarkerSize() {
static_assert(sizeof(TRI_voc_size_t) >= 4, "TRI_voc_size_t is too small");
return 2UL * 1024UL * 1024UL * 1024UL; // 2 GB
}
////////////////////////////////////////////////////////////////////////////////
/// @brief journal overhead
////////////////////////////////////////////////////////////////////////////////
constexpr TRI_voc_size_t JournalOverhead() {
return sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the 8-byte aligned size for the value
////////////////////////////////////////////////////////////////////////////////
@ -92,7 +110,7 @@ static inline size_t VPackOffset(TRI_df_marker_type_t type) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initializes a marker
/// @brief initializes a marker, using user-defined tick
////////////////////////////////////////////////////////////////////////////////
static inline void InitMarker(TRI_df_marker_t* marker,
@ -108,12 +126,62 @@ static inline void InitMarker(TRI_df_marker_t* marker,
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initializes a marker
/// @brief initializes a marker, using tick 0
////////////////////////////////////////////////////////////////////////////////
static inline void InitMarker(TRI_df_marker_t* marker,
TRI_df_marker_type_t type, uint32_t size) {
InitMarker(marker, type, size, 0);
InitMarker(marker, type, size, 0); // always use tick 0
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a header marker
////////////////////////////////////////////////////////////////////////////////
static inline TRI_df_header_marker_t CreateHeaderMarker(TRI_voc_size_t maximalSize, TRI_voc_tick_t fid) {
static_assert(sizeof(TRI_voc_tick_t) == sizeof(TRI_voc_fid_t), "invalid tick/fid sizes");
TRI_df_header_marker_t header;
InitMarker(reinterpret_cast<TRI_df_marker_t*>(&header), TRI_DF_MARKER_HEADER, sizeof(TRI_df_header_marker_t), fid);
header._version = TRI_DF_VERSION;
header._maximalSize = maximalSize;
header._fid = fid;
return header;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a prologue marker
////////////////////////////////////////////////////////////////////////////////
static inline TRI_df_prologue_marker_t CreatePrologueMarker(TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId) {
TRI_df_prologue_marker_t header;
InitMarker(reinterpret_cast<TRI_df_marker_t*>(&header), TRI_DF_MARKER_PROLOGUE, sizeof(TRI_df_prologue_marker_t));
header._databaseId = databaseId;
header._collectionId = collectionId;
return header;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a footer marker, using a user-defined tick
////////////////////////////////////////////////////////////////////////////////
static inline TRI_df_footer_marker_t CreateFooterMarker(TRI_voc_tick_t tick) {
TRI_df_footer_marker_t footer;
InitMarker(reinterpret_cast<TRI_df_marker_t*>(&footer), TRI_DF_MARKER_FOOTER, sizeof(TRI_df_footer_marker_t), tick);
return footer;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a footer marker, using tick 0
////////////////////////////////////////////////////////////////////////////////
static inline TRI_df_footer_marker_t CreateFooterMarker() {
return CreateFooterMarker(0); // always use tick 0
}
}

View File

@ -456,7 +456,7 @@ bool TRI_ValidateDocumentIdKeyGenerator(char const* key, size_t* split) {
return false;
}
if (p - key > TRI_COL_NAME_LENGTH) {
if (static_cast<size_t>(p - key) > TRI_COL_NAME_LENGTH) {
return false;
}

View File

@ -826,12 +826,8 @@ static uint64_t GetNumericFilenamePart(char const* filename) {
static int WriteInitialHeaderMarker(TRI_datafile_t* datafile, TRI_voc_fid_t fid,
TRI_voc_size_t maximalSize) {
// create the header
TRI_df_header_marker_t header;
DatafileHelper::InitMarker(reinterpret_cast<TRI_df_marker_t*>(&header), TRI_DF_MARKER_HEADER, sizeof(TRI_df_header_marker_t), static_cast<TRI_voc_tick_t>(fid));
header._version = TRI_DF_VERSION;
header._maximalSize = maximalSize;
header._fid = fid;
TRI_df_header_marker_t header = DatafileHelper::CreateHeaderMarker(
maximalSize, static_cast<TRI_voc_tick_t>(fid));
// reserve space and write header to file
TRI_df_marker_t* position;
@ -1267,7 +1263,7 @@ bool TRI_IsValidMarkerDatafile(TRI_df_marker_t const* marker) {
return false;
}
if (marker->getSize() >= static_cast<TRI_voc_size_t>(TRI_MARKER_MAXIMAL_SIZE)) {
if (marker->getSize() >= DatafileHelper::MaximalMarkerSize()) {
// a single marker bigger than 256 MB seems unreasonable
// note: this is an arbitrary limit
return false;
@ -1301,7 +1297,7 @@ int TRI_ReserveElementDatafile(TRI_datafile_t* datafile, TRI_voc_size_t size,
}
// check the maximal size
if (size + TRI_JOURNAL_OVERHEAD > datafile->_maximalSize) {
if (size + DatafileHelper::JournalOverhead() > datafile->_maximalSize) {
// marker is bigger than journal size.
// adding the marker to this datafile will not work
@ -1315,7 +1311,7 @@ int TRI_ReserveElementDatafile(TRI_datafile_t* datafile, TRI_voc_size_t size,
// if we get here, the collection's 'maximalJournalSize' property is
// higher than the size of this datafile.
// maybe the marker will fit into a new datafile with the bigger size?
if (size + TRI_JOURNAL_OVERHEAD > maximalJournalSize) {
if (size + DatafileHelper::JournalOverhead() > maximalJournalSize) {
// marker still won't fit
return TRI_set_errno(TRI_ERROR_ARANGO_DOCUMENT_TOO_LARGE);
}
@ -1628,9 +1624,7 @@ int TRI_SealDatafile(TRI_datafile_t* datafile) {
}
// create the footer
TRI_df_footer_marker_t footer;
DatafileHelper::InitMarker(reinterpret_cast<TRI_df_marker_t*>(&footer), TRI_DF_MARKER_FOOTER,
sizeof(TRI_df_footer_marker_t), datafile->_tickMax);
TRI_df_footer_marker_t footer = DatafileHelper::CreateFooterMarker(datafile->_tickMax);
// reserve space and write footer to file
datafile->_footerSize = 0;
@ -1771,12 +1765,12 @@ static std::string DiagnoseMarker(TRI_df_marker_t const* marker,
TRI_voc_size_t size = marker->getSize();
if (size >= static_cast<TRI_voc_size_t>(TRI_MARKER_MAXIMAL_SIZE)) {
// a single marker bigger than 256 MB seems unreasonable
if (size >= DatafileHelper::MaximalMarkerSize()) {
// a single marker bigger than this size seems unreasonable
// note: this is an arbitrary limit
result << "marker size value (" << size
<< ") is wrong. expecting value less than "
<< TRI_MARKER_MAXIMAL_SIZE;
<< DatafileHelper::MaximalMarkerSize();
return result.str();
}

View File

@ -94,8 +94,6 @@ struct TRI_datafile_t;
/// @brief maximum size of a single marker (in bytes)
////////////////////////////////////////////////////////////////////////////////
#define TRI_MARKER_MAXIMAL_SIZE (256 * 1024 * 1024)
////////////////////////////////////////////////////////////////////////////////
/// @brief state of the datafile
////////////////////////////////////////////////////////////////////////////////

View File

@ -344,11 +344,13 @@ static int StringifyMarkerDump(TRI_replication_dump_t* dump,
APPEND_STRING(buffer, "\",\"data\":{");
// common document meta-data
#if 0
APPEND_STRING(buffer, "\"" TRI_VOC_ATTRIBUTE_KEY "\":\"");
TRI_AppendString2StringBuffer(buffer, key, keyLength);
APPEND_STRING(buffer, "\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"");
APPEND_UINT64(buffer, (uint64_t)rid);
APPEND_CHAR(buffer, '"');
#endif
#if 0
// Is it an edge marker?

View File

@ -2069,11 +2069,7 @@ void TRI_GetDatabaseDefaultsServer(TRI_server_t* server,
////////////////////////////////////////////////////////////////////////////////
TRI_voc_tick_t TRI_NewTickServer() {
uint64_t tick = ServerIdentifier;
tick |= (++CurrentTick) << 16;
return tick;
return ++CurrentTick;
}
////////////////////////////////////////////////////////////////////////////////
@ -2081,7 +2077,7 @@ TRI_voc_tick_t TRI_NewTickServer() {
////////////////////////////////////////////////////////////////////////////////
void TRI_UpdateTickServer(TRI_voc_tick_t tick) {
TRI_voc_tick_t t = tick >> 16;
TRI_voc_tick_t t = tick;
auto expected = CurrentTick.load(std::memory_order_relaxed);
@ -2099,7 +2095,7 @@ void TRI_UpdateTickServer(TRI_voc_tick_t tick) {
////////////////////////////////////////////////////////////////////////////////
TRI_voc_tick_t TRI_CurrentTickServer() {
return (ServerIdentifier | (CurrentTick << 16));
return CurrentTick;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -97,55 +97,55 @@ extern bool IGNORE_DATAFILE_ERRORS;
/// @brief name of the _from attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_FROM "_from"
constexpr auto TRI_VOC_ATTRIBUTE_FROM = "_from";
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _to attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_TO "_to"
constexpr auto TRI_VOC_ATTRIBUTE_TO = "_to";
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _key attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_KEY "_key"
constexpr auto TRI_VOC_ATTRIBUTE_KEY = "_key";
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _rev attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_REV "_rev"
constexpr auto TRI_VOC_ATTRIBUTE_REV = "_rev";
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _id attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_ID "_id"
constexpr auto TRI_VOC_ATTRIBUTE_ID = "_id";
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the system database
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_SYSTEM_DATABASE "_system"
constexpr auto TRI_VOC_SYSTEM_DATABASE = "_system";
////////////////////////////////////////////////////////////////////////////////
/// @brief maximal path length
////////////////////////////////////////////////////////////////////////////////
#define TRI_COL_PATH_LENGTH (512)
constexpr size_t TRI_COL_PATH_LENGTH = 512;
////////////////////////////////////////////////////////////////////////////////
/// @brief maximal name length
////////////////////////////////////////////////////////////////////////////////
#define TRI_COL_NAME_LENGTH (64)
constexpr size_t TRI_COL_NAME_LENGTH = 64;
////////////////////////////////////////////////////////////////////////////////
/// @brief default maximal collection journal size
////////////////////////////////////////////////////////////////////////////////
#define TRI_JOURNAL_DEFAULT_MAXIMAL_SIZE (1024 * 1024 * 32)
constexpr size_t TRI_JOURNAL_DEFAULT_MAXIMAL_SIZE = 1024 * 1024 * 32; // 32 MB
////////////////////////////////////////////////////////////////////////////////
/// @brief minimal collection journal size (for testing, we allow very small
@ -154,44 +154,37 @@ extern bool IGNORE_DATAFILE_ERRORS;
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
#define TRI_JOURNAL_MINIMAL_SIZE (16 * 1024)
constexpr size_t TRI_JOURNAL_MINIMAL_SIZE = 16 * 1024; // 16 KB
#else
#define TRI_JOURNAL_MINIMAL_SIZE (1024 * 1024)
constexpr size_t TRI_JOURNAL_MINIMAL_SIZE = 1024 * 1024; // 1 MB
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief journal overhead
////////////////////////////////////////////////////////////////////////////////
#define TRI_JOURNAL_OVERHEAD \
(sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t))
////////////////////////////////////////////////////////////////////////////////
/// @brief document handle separator as character
////////////////////////////////////////////////////////////////////////////////
#define TRI_DOCUMENT_HANDLE_SEPARATOR_CHR '/'
constexpr char TRI_DOCUMENT_HANDLE_SEPARATOR_CHR = '/';
////////////////////////////////////////////////////////////////////////////////
/// @brief document handle separator as string
////////////////////////////////////////////////////////////////////////////////
#define TRI_DOCUMENT_HANDLE_SEPARATOR_STR "/"
constexpr auto TRI_DOCUMENT_HANDLE_SEPARATOR_STR = "/";
////////////////////////////////////////////////////////////////////////////////
/// @brief index handle separator as character
////////////////////////////////////////////////////////////////////////////////
#define TRI_INDEX_HANDLE_SEPARATOR_CHR '/'
constexpr char TRI_INDEX_HANDLE_SEPARATOR_CHR = '/';
////////////////////////////////////////////////////////////////////////////////
/// @brief index handle separator as string
////////////////////////////////////////////////////////////////////////////////
#define TRI_INDEX_HANDLE_SEPARATOR_STR "/"
constexpr auto TRI_INDEX_HANDLE_SEPARATOR_STR = "/";
////////////////////////////////////////////////////////////////////////////////
/// @brief collection enum

View File

@ -164,42 +164,3 @@ char* Logfile::reserve(size_t size) {
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a header marker
////////////////////////////////////////////////////////////////////////////////
TRI_df_header_marker_t Logfile::getHeaderMarker() const {
TRI_df_header_marker_t header;
DatafileHelper::InitMarker(reinterpret_cast<TRI_df_marker_t*>(&header), TRI_DF_MARKER_HEADER, sizeof(TRI_df_header_marker_t));
header._version = TRI_DF_VERSION;
header._maximalSize = static_cast<TRI_voc_size_t>(allocatedSize());
header._fid = static_cast<TRI_voc_fid_t>(_id);
return header;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a prologue marker
////////////////////////////////////////////////////////////////////////////////
TRI_df_prologue_marker_t Logfile::getPrologueMarker(TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId) const {
TRI_df_prologue_marker_t header;
DatafileHelper::InitMarker(reinterpret_cast<TRI_df_marker_t*>(&header), TRI_DF_MARKER_PROLOGUE, sizeof(TRI_df_prologue_marker_t));
header._databaseId = databaseId;
header._collectionId = collectionId;
return header;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief create a footer marker
////////////////////////////////////////////////////////////////////////////////
TRI_df_footer_marker_t Logfile::getFooterMarker() const {
TRI_df_footer_marker_t footer;
DatafileHelper::InitMarker(reinterpret_cast<TRI_df_marker_t*>(&footer), TRI_DF_MARKER_FOOTER, sizeof(TRI_df_footer_marker_t));
return footer;
}

View File

@ -27,6 +27,7 @@
#include "Basics/Common.h"
#include "Basics/Logger.h"
#include "VocBase/datafile.h"
#include "VocBase/DatafileHelper.h"
#include "VocBase/voc-types.h"
#include "Wal/Marker.h"
@ -155,7 +156,7 @@ class Logfile {
}
return static_cast<uint64_t>(allocatedSize() - _df->_currentSize -
overhead());
DatafileHelper::JournalOverhead());
}
//////////////////////////////////////////////////////////////////////////////
@ -208,12 +209,6 @@ class Logfile {
_users == 0);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief return the logfile overhead
//////////////////////////////////////////////////////////////////////////////
static inline uint32_t overhead() { return TRI_JOURNAL_OVERHEAD; }
//////////////////////////////////////////////////////////////////////////////
/// @brief return the logfile status as a string
//////////////////////////////////////////////////////////////////////////////
@ -292,24 +287,6 @@ class Logfile {
char* reserve(size_t);
//////////////////////////////////////////////////////////////////////////////
/// @brief create a header marker
//////////////////////////////////////////////////////////////////////////////
TRI_df_header_marker_t getHeaderMarker() const;
//////////////////////////////////////////////////////////////////////////////
/// @brief create a prologue marker
//////////////////////////////////////////////////////////////////////////////
TRI_df_prologue_marker_t getPrologueMarker(TRI_voc_tick_t, TRI_voc_cid_t) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief create a footer marker
//////////////////////////////////////////////////////////////////////////////
TRI_df_footer_marker_t getFooterMarker() const;
//////////////////////////////////////////////////////////////////////////////
/// @brief increase the number of collect operations waiting
//////////////////////////////////////////////////////////////////////////////

View File

@ -660,7 +660,7 @@ void LogfileManager::unregisterFailedTransactions(
////////////////////////////////////////////////////////////////////////////////
bool LogfileManager::logfileCreationAllowed(uint32_t size) {
if (size + Logfile::overhead() > filesize()) {
if (size + DatafileHelper::JournalOverhead() > filesize()) {
// oversize entry. this is always allowed because otherwise everything would
// lock
return true;
@ -2274,7 +2274,7 @@ int LogfileManager::createReserveLogfile(uint32_t size) {
uint32_t realsize;
if (size > 0 && size > filesize()) {
// create a logfile with the requested size
realsize = size + Logfile::overhead();
realsize = size + DatafileHelper::JournalOverhead();
} else {
// create a logfile with default size
realsize = filesize();

View File

@ -588,7 +588,12 @@ int Slots::closeLogfile(Slot::TickType& lastCommittedTick, bool& worked) {
////////////////////////////////////////////////////////////////////////////////
int Slots::writeHeader(Slot* slot) {
TRI_df_header_marker_t header = _logfile->getHeaderMarker();
TRI_ASSERT(_logfile != nullptr);
TRI_df_header_marker_t header = DatafileHelper::CreateHeaderMarker(
static_cast<TRI_voc_size_t>(_logfile->allocatedSize()),
static_cast<TRI_voc_fid_t>(_logfile->id())
);
size_t const size = header.base.getSize();
auto* mem = static_cast<void*>(_logfile->reserve(size));
@ -610,7 +615,7 @@ int Slots::writeHeader(Slot* slot) {
////////////////////////////////////////////////////////////////////////////////
int Slots::writePrologue(Slot* slot, void* mem, TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId) {
TRI_df_prologue_marker_t header = _logfile->getPrologueMarker(databaseId, collectionId);
TRI_df_prologue_marker_t header = DatafileHelper::CreatePrologueMarker(databaseId, collectionId);
size_t const size = header.base.getSize();
TRI_ASSERT(mem != nullptr);
@ -629,7 +634,7 @@ int Slots::writePrologue(Slot* slot, void* mem, TRI_voc_tick_t databaseId, TRI_v
int Slots::writeFooter(Slot* slot) {
TRI_ASSERT(_logfile != nullptr);
TRI_df_footer_marker_t footer = _logfile->getFooterMarker();
TRI_df_footer_marker_t footer = DatafileHelper::CreateFooterMarker();
size_t const size = footer.base.getSize();
auto* mem = static_cast<void*>(_logfile->reserve(size));

View File

@ -47,7 +47,7 @@ ConnectionOptions ConnectionManager::_globalConnectionOptions = {
static ConnectionManager* Instance = nullptr;
ConnectionManager::~ConnectionManager() {
for (size_t i = 0; i < CONNECTION_MANAGER_BUCKETS; ++i) {
for (size_t i = 0; i < ConnectionManagerBuckets(); ++i) {
WRITE_LOCKER(writeLocker, _connectionsBuckets[i]._lock);
for (auto& it : _connectionsBuckets[i]._connections) {
@ -334,7 +334,7 @@ void ConnectionManager::closeUnusedConnections(double limit) {
// copy the list of ServerConnections first
std::vector<ConnectionManager::ServerConnections*> copy;
{
for (size_t i = 0; i < CONNECTION_MANAGER_BUCKETS; ++i) {
for (size_t i = 0; i < ConnectionManagerBuckets(); ++i) {
READ_LOCKER(readLocker, _connectionsBuckets[i]._lock);
for (auto& it : _connectionsBuckets[i]._connections) {

View File

@ -30,12 +30,16 @@
#include <list>
// TODO: change to constexpr when feasible
#define CONNECTION_MANAGER_BUCKETS 8
namespace arangodb {
namespace httpclient {
////////////////////////////////////////////////////////////////////////////////
/// @brief number of buckets
////////////////////////////////////////////////////////////////////////////////
constexpr int ConnectionManagerBuckets() { return 8; }
////////////////////////////////////////////////////////////////////////////////
/// @brief options for connections
////////////////////////////////////////////////////////////////////////////////
@ -187,7 +191,7 @@ class ConnectionManager {
//////////////////////////////////////////////////////////////////////////////
size_t bucket(std::string const& endpoint) const {
return std::hash<std::string>()(endpoint) % CONNECTION_MANAGER_BUCKETS;
return std::hash<std::string>()(endpoint) % ConnectionManagerBuckets();
}
//////////////////////////////////////////////////////////////////////////////
@ -207,7 +211,7 @@ class ConnectionManager {
arangodb::basics::ReadWriteLock _lock;
};
ConnectionsBucket _connectionsBuckets[CONNECTION_MANAGER_BUCKETS];
ConnectionsBucket _connectionsBuckets[ConnectionManagerBuckets()];
};
}
}