1
0
Fork 0

run clang-format on replication-dump

This commit is contained in:
Jan Christoph Uhde 2016-09-06 15:24:16 +02:00
parent af8649479f
commit cea8110c2e
2 changed files with 89 additions and 71 deletions

View File

@ -37,8 +37,8 @@
#include "Wal/Marker.h" #include "Wal/Marker.h"
#include <velocypack/Dumper.h> #include <velocypack/Dumper.h>
#include <velocypack/Slice.h>
#include <velocypack/Options.h> #include <velocypack/Options.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h> #include <velocypack/velocypack-aliases.h>
using namespace arangodb; using namespace arangodb;
@ -167,8 +167,8 @@ static TRI_replication_operation_e TranslateType(
static int StringifyMarker(TRI_replication_dump_t* dump, static int StringifyMarker(TRI_replication_dump_t* dump,
TRI_voc_tick_t databaseId, TRI_voc_tick_t databaseId,
TRI_voc_cid_t collectionId, TRI_voc_cid_t collectionId,
TRI_df_marker_t const* marker, TRI_df_marker_t const* marker, bool isDump,
bool isDump, bool withTicks, bool isEdgeCollection) { bool withTicks, bool isEdgeCollection) {
TRI_ASSERT(MustReplicateWalMarkerType(marker)); TRI_ASSERT(MustReplicateWalMarkerType(marker));
TRI_df_marker_type_t const type = marker->getType(); TRI_df_marker_type_t const type = marker->getType();
@ -179,13 +179,16 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
// for debugging use the following // for debugging use the following
// Append(dump, "\",\"typeName\":\""); // Append(dump, "\",\"typeName\":\"");
// Append(dump, TRI_NameMarkerDatafile(marker)); // Append(dump, TRI_NameMarkerDatafile(marker));
if (dump->_compat28 && if (dump->_compat28 && (type == TRI_DF_MARKER_VPACK_DOCUMENT ||
(type == TRI_DF_MARKER_VPACK_DOCUMENT || type == TRI_DF_MARKER_VPACK_REMOVE)) { type == TRI_DF_MARKER_VPACK_REMOVE)) {
// 2.8-compatible format // 2.8-compatible format
VPackSlice slice(reinterpret_cast<char const*>(marker) + DatafileHelper::VPackOffset(type)); VPackSlice slice(reinterpret_cast<char const*>(marker) +
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer); DatafileHelper::VPackOffset(type));
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
VPackDumper dumper(
&adapter,
&dump->_vpackOptions); // note: we need the CustomTypeHandler here
// additionally dump "key" and "rev" attributes on the top-level // additionally dump "key" and "rev" attributes on the top-level
Append(dump, "\",\"key\":"); Append(dump, "\",\"key\":");
@ -206,7 +209,7 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
Append(dump, "\",\"type\":"); Append(dump, "\",\"type\":");
Append(dump, static_cast<uint64_t>(TranslateType(marker))); Append(dump, static_cast<uint64_t>(TranslateType(marker)));
} }
if (type == TRI_DF_MARKER_VPACK_DOCUMENT || if (type == TRI_DF_MARKER_VPACK_DOCUMENT ||
type == TRI_DF_MARKER_VPACK_REMOVE || type == TRI_DF_MARKER_VPACK_REMOVE ||
type == TRI_DF_MARKER_VPACK_BEGIN_TRANSACTION || type == TRI_DF_MARKER_VPACK_BEGIN_TRANSACTION ||
@ -237,8 +240,7 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
} }
} }
} }
} } else {
else {
// collection dump // collection dump
if (withTicks) { if (withTicks) {
Append(dump, "{\"tick\":\""); Append(dump, "{\"tick\":\"");
@ -248,12 +250,15 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
Append(dump, "{"); Append(dump, "{");
} }
if (dump->_compat28 && if (dump->_compat28 && (type == TRI_DF_MARKER_VPACK_DOCUMENT ||
(type == TRI_DF_MARKER_VPACK_DOCUMENT || type == TRI_DF_MARKER_VPACK_REMOVE)) { type == TRI_DF_MARKER_VPACK_REMOVE)) {
// 2.8-compatible format // 2.8-compatible format
VPackSlice slice(reinterpret_cast<char const*>(marker) + DatafileHelper::VPackOffset(type)); VPackSlice slice(reinterpret_cast<char const*>(marker) +
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer); DatafileHelper::VPackOffset(type));
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
VPackDumper dumper(
&adapter,
&dump->_vpackOptions); // note: we need the CustomTypeHandler here
// additionally dump "key" and "rev" attributes on the top-level // additionally dump "key" and "rev" attributes on the top-level
Append(dump, "\"key\":"); Append(dump, "\"key\":");
@ -269,29 +274,31 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
} else { } else {
Append(dump, static_cast<uint64_t>(TranslateType(marker))); Append(dump, static_cast<uint64_t>(TranslateType(marker)));
} }
} } else {
else {
Append(dump, "\"type\":"); Append(dump, "\"type\":");
Append(dump, static_cast<uint64_t>(TranslateType(marker))); Append(dump, static_cast<uint64_t>(TranslateType(marker)));
} }
} }
switch (type) { switch (type) {
case TRI_DF_MARKER_VPACK_DOCUMENT: case TRI_DF_MARKER_VPACK_DOCUMENT:
case TRI_DF_MARKER_VPACK_REMOVE: case TRI_DF_MARKER_VPACK_REMOVE:
case TRI_DF_MARKER_VPACK_CREATE_DATABASE: case TRI_DF_MARKER_VPACK_CREATE_DATABASE:
case TRI_DF_MARKER_VPACK_CREATE_COLLECTION: case TRI_DF_MARKER_VPACK_CREATE_COLLECTION:
case TRI_DF_MARKER_VPACK_CREATE_INDEX: case TRI_DF_MARKER_VPACK_CREATE_INDEX:
case TRI_DF_MARKER_VPACK_RENAME_COLLECTION: case TRI_DF_MARKER_VPACK_RENAME_COLLECTION:
case TRI_DF_MARKER_VPACK_CHANGE_COLLECTION: case TRI_DF_MARKER_VPACK_CHANGE_COLLECTION:
case TRI_DF_MARKER_VPACK_DROP_DATABASE: case TRI_DF_MARKER_VPACK_DROP_DATABASE:
case TRI_DF_MARKER_VPACK_DROP_COLLECTION: case TRI_DF_MARKER_VPACK_DROP_COLLECTION:
case TRI_DF_MARKER_VPACK_DROP_INDEX: { case TRI_DF_MARKER_VPACK_DROP_INDEX: {
Append(dump, ",\"data\":"); Append(dump, ",\"data\":");
VPackSlice slice(reinterpret_cast<char const*>(marker) + DatafileHelper::VPackOffset(type)); VPackSlice slice(reinterpret_cast<char const*>(marker) +
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer); DatafileHelper::VPackOffset(type));
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
VPackDumper dumper(
&adapter,
&dump->_vpackOptions); // note: we need the CustomTypeHandler here
dumper.dump(slice); dumper.dump(slice);
break; break;
} }
@ -350,7 +357,7 @@ static bool MustReplicateWalMarker(
if (dump->_vocbase->id() != databaseId) { if (dump->_vocbase->id() != databaseId) {
return false; return false;
} }
// finally check if the marker is for a collection that we want to ignore // finally check if the marker is for a collection that we want to ignore
TRI_voc_cid_t cid = collectionId; TRI_voc_cid_t cid = collectionId;
@ -362,14 +369,14 @@ static bool MustReplicateWalMarker(
return false; return false;
} }
} }
if (dump->_restrictCollection > 0 && if (dump->_restrictCollection > 0 &&
(cid != dump->_restrictCollection && ! IsTransactionWalMarker(dump, marker))) { (cid != dump->_restrictCollection &&
!IsTransactionWalMarker(dump, marker))) {
// restrict output to a single collection, but a different one // restrict output to a single collection, but a different one
return false; return false;
} }
if (marker->getTick() >= firstRegularTick) { if (marker->getTick() >= firstRegularTick) {
return true; return true;
} }
@ -393,7 +400,8 @@ static int DumpCollection(TRI_replication_dump_t* dump,
TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId, TRI_voc_tick_t databaseId, TRI_voc_cid_t collectionId,
TRI_voc_tick_t dataMin, TRI_voc_tick_t dataMax, TRI_voc_tick_t dataMin, TRI_voc_tick_t dataMax,
bool withTicks) { bool withTicks) {
LOG(TRACE) << "dumping collection " << collection->cid() << ", tick range " << dataMin << " - " << dataMax; LOG(TRACE) << "dumping collection " << collection->cid() << ", tick range "
<< dataMin << " - " << dataMax;
bool const isEdgeCollection = (collection->type() == TRI_COL_TYPE_EDGE); bool const isEdgeCollection = (collection->type() == TRI_COL_TYPE_EDGE);
@ -401,28 +409,32 @@ static int DumpCollection(TRI_replication_dump_t* dump,
TRI_voc_tick_t lastFoundTick = 0; TRI_voc_tick_t lastFoundTick = 0;
bool bufferFull = false; bool bufferFull = false;
auto callback = [&dump, &lastFoundTick, &databaseId, &collectionId, &withTicks, &isEdgeCollection, &bufferFull](TRI_voc_tick_t foundTick, TRI_df_marker_t const* marker) { auto callback = [&dump, &lastFoundTick, &databaseId, &collectionId,
&withTicks, &isEdgeCollection, &bufferFull](
TRI_voc_tick_t foundTick, TRI_df_marker_t const* marker) {
// note the last tick we processed // note the last tick we processed
lastFoundTick = foundTick; lastFoundTick = foundTick;
int res = StringifyMarker(dump, databaseId, collectionId, marker, true, withTicks, isEdgeCollection); int res = StringifyMarker(dump, databaseId, collectionId, marker, true,
withTicks, isEdgeCollection);
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res); THROW_ARANGO_EXCEPTION(res);
} }
if (static_cast<uint64_t>(TRI_LengthStringBuffer(dump->_buffer)) > dump->_chunkSize) { if (static_cast<uint64_t>(TRI_LengthStringBuffer(dump->_buffer)) >
dump->_chunkSize) {
// abort the iteration // abort the iteration
bufferFull = true; bufferFull = true;
return false; // stop iterating return false; // stop iterating
} }
return true; // continue iterating return true; // continue iterating
}; };
try { try {
bool hasMore = collection->applyForTickRange(dataMin, dataMax, callback); bool hasMore = collection->applyForTickRange(dataMin, dataMax, callback);
if (lastFoundTick > 0) { if (lastFoundTick > 0) {
// data available for requested range // data available for requested range
dump->_lastFoundTick = lastFoundTick; dump->_lastFoundTick = lastFoundTick;
@ -452,7 +464,7 @@ int TRI_DumpCollectionReplication(TRI_replication_dump_t* dump,
TRI_voc_tick_t dataMin, TRI_voc_tick_t dataMin,
TRI_voc_tick_t dataMax, bool withTicks) { TRI_voc_tick_t dataMax, bool withTicks) {
TRI_ASSERT(collection != nullptr); TRI_ASSERT(collection != nullptr);
// get a custom type handler // get a custom type handler
auto customTypeHandler = dump->_transactionContext->orderCustomTypeHandler(); auto customTypeHandler = dump->_transactionContext->orderCustomTypeHandler();
dump->_vpackOptions.customTypeHandler = customTypeHandler.get(); dump->_vpackOptions.customTypeHandler = customTypeHandler.get();
@ -470,7 +482,8 @@ int TRI_DumpCollectionReplication(TRI_replication_dump_t* dump,
CompactionPreventer compactionPreventer(collection); CompactionPreventer compactionPreventer(collection);
try { try {
res = DumpCollection(dump, collection, collection->vocbase()->id(), collection->cid(), dataMin, dataMax, withTicks); res = DumpCollection(dump, collection, collection->vocbase()->id(),
collection->cid(), dataMin, dataMax, withTicks);
} catch (...) { } catch (...) {
res = TRI_ERROR_INTERNAL; res = TRI_ERROR_INTERNAL;
} }
@ -535,31 +548,31 @@ int TRI_DumpLogReplication(
// end of datafile // end of datafile
break; break;
} }
TRI_df_marker_type_t type = marker->getType(); TRI_df_marker_type_t type = marker->getType();
if (type <= TRI_DF_MARKER_MIN || type >= TRI_DF_MARKER_MAX) { if (type <= TRI_DF_MARKER_MIN || type >= TRI_DF_MARKER_MAX) {
break; break;
} }
// handle special markers // handle special markers
if (type == TRI_DF_MARKER_PROLOGUE) { if (type == TRI_DF_MARKER_PROLOGUE) {
lastDatabaseId = DatafileHelper::DatabaseId(marker); lastDatabaseId = DatafileHelper::DatabaseId(marker);
lastCollectionId = DatafileHelper::CollectionId(marker); lastCollectionId = DatafileHelper::CollectionId(marker);
} } else if (type == TRI_DF_MARKER_HEADER ||
else if (type == TRI_DF_MARKER_HEADER || type == TRI_DF_MARKER_FOOTER) { type == TRI_DF_MARKER_FOOTER) {
lastDatabaseId = 0; lastDatabaseId = 0;
lastCollectionId = 0; lastCollectionId = 0;
} } else if (type == TRI_DF_MARKER_VPACK_CREATE_COLLECTION) {
else if (type == TRI_DF_MARKER_VPACK_CREATE_COLLECTION) {
// fill collection name cache // fill collection name cache
TRI_voc_tick_t databaseId = DatafileHelper::DatabaseId(marker); TRI_voc_tick_t databaseId = DatafileHelper::DatabaseId(marker);
TRI_ASSERT(databaseId != 0); TRI_ASSERT(databaseId != 0);
TRI_voc_cid_t collectionId = DatafileHelper::CollectionId(marker); TRI_voc_cid_t collectionId = DatafileHelper::CollectionId(marker);
TRI_ASSERT(collectionId != 0); TRI_ASSERT(collectionId != 0);
if (dump->_vocbase->id() == databaseId) { if (dump->_vocbase->id() == databaseId) {
VPackSlice slice(reinterpret_cast<char const*>(marker) + DatafileHelper::VPackOffset(type)); VPackSlice slice(reinterpret_cast<char const*>(marker) +
DatafileHelper::VPackOffset(type));
VPackSlice name = slice.get("name"); VPackSlice name = slice.get("name");
if (name.isString()) { if (name.isString()) {
dump->_collectionNames[collectionId] = name.copyString(); dump->_collectionNames[collectionId] = name.copyString();
@ -585,21 +598,21 @@ int TRI_DumpLogReplication(
break; break;
} }
} }
TRI_voc_tick_t databaseId; TRI_voc_tick_t databaseId;
TRI_voc_cid_t collectionId; TRI_voc_cid_t collectionId;
if (type == TRI_DF_MARKER_VPACK_DOCUMENT || type == TRI_DF_MARKER_VPACK_REMOVE) { if (type == TRI_DF_MARKER_VPACK_DOCUMENT ||
type == TRI_DF_MARKER_VPACK_REMOVE) {
databaseId = lastDatabaseId; databaseId = lastDatabaseId;
collectionId = lastCollectionId; collectionId = lastCollectionId;
} } else {
else {
databaseId = DatafileHelper::DatabaseId(marker); databaseId = DatafileHelper::DatabaseId(marker);
collectionId = DatafileHelper::CollectionId(marker); collectionId = DatafileHelper::CollectionId(marker);
} }
if (!MustReplicateWalMarker(dump, marker, databaseId, collectionId, firstRegularTick, if (!MustReplicateWalMarker(dump, marker, databaseId, collectionId,
transactionIds)) { firstRegularTick, transactionIds)) {
continue; continue;
} }
@ -614,7 +627,8 @@ int TRI_DumpLogReplication(
} }
} }
res = StringifyMarker(dump, databaseId, collectionId, marker, false, true, false); res = StringifyMarker(dump, databaseId, collectionId, marker, false,
true, false);
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res); THROW_ARANGO_EXCEPTION(res);
@ -632,7 +646,7 @@ int TRI_DumpLogReplication(
break; break;
} }
} }
if (outputAsArray) { if (outputAsArray) {
Append(dump, "]"); Append(dump, "]");
} }
@ -671,7 +685,8 @@ int TRI_DumpLogReplication(
int TRI_DetermineOpenTransactionsReplication(TRI_replication_dump_t* dump, int TRI_DetermineOpenTransactionsReplication(TRI_replication_dump_t* dump,
TRI_voc_tick_t tickMin, TRI_voc_tick_t tickMin,
TRI_voc_tick_t tickMax) { TRI_voc_tick_t tickMax) {
LOG(TRACE) << "determining transactions, tick range " << tickMin << " - " << tickMax; LOG(TRACE) << "determining transactions, tick range " << tickMin << " - "
<< tickMax;
std::unordered_map<TRI_voc_tid_t, TRI_voc_tick_t> transactions; std::unordered_map<TRI_voc_tid_t, TRI_voc_tick_t> transactions;
@ -706,7 +721,7 @@ int TRI_DetermineOpenTransactionsReplication(TRI_replication_dump_t* dump,
// end of datafile // end of datafile
break; break;
} }
TRI_df_marker_type_t const type = marker->getType(); TRI_df_marker_type_t const type = marker->getType();
if (type <= TRI_DF_MARKER_MIN || type >= TRI_DF_MARKER_MAX) { if (type <= TRI_DF_MARKER_MIN || type >= TRI_DF_MARKER_MAX) {
@ -747,7 +762,8 @@ int TRI_DetermineOpenTransactionsReplication(TRI_replication_dump_t* dump,
type == TRI_DF_MARKER_VPACK_ABORT_TRANSACTION) { type == TRI_DF_MARKER_VPACK_ABORT_TRANSACTION) {
transactions.erase(tid); transactions.erase(tid);
} else { } else {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "found invalid marker type"); THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"found invalid marker type");
} }
} }
} }

View File

@ -39,9 +39,10 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct TRI_replication_dump_t { struct TRI_replication_dump_t {
TRI_replication_dump_t(std::shared_ptr<arangodb::StandaloneTransactionContext> transactionContext, TRI_replication_dump_t(std::shared_ptr<arangodb::StandaloneTransactionContext>
size_t chunkSize, transactionContext,
bool includeSystem, TRI_voc_cid_t restrictCollection) size_t chunkSize, bool includeSystem,
TRI_voc_cid_t restrictCollection, bool useVpp = false)
: _transactionContext(transactionContext), : _transactionContext(transactionContext),
_vocbase(transactionContext->vocbase()), _vocbase(transactionContext->vocbase()),
_buffer(nullptr), _buffer(nullptr),
@ -95,8 +96,9 @@ struct TRI_replication_dump_t {
/// @brief dump data from a single collection /// @brief dump data from a single collection
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int TRI_DumpCollectionReplication(TRI_replication_dump_t*, arangodb::LogicalCollection*, int TRI_DumpCollectionReplication(TRI_replication_dump_t*,
TRI_voc_tick_t, TRI_voc_tick_t, bool); arangodb::LogicalCollection*, TRI_voc_tick_t,
TRI_voc_tick_t, bool);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief dump data from the replication log /// @brief dump data from the replication log