mirror of https://gitee.com/bigwinds/arangodb
run clang-format on replication-dump
This commit is contained in:
parent
af8649479f
commit
cea8110c2e
|
@ -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();
|
||||||
|
|
||||||
|
@ -180,12 +180,15 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
|
||||||
// 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) +
|
||||||
|
DatafileHelper::VPackOffset(type));
|
||||||
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
||||||
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here
|
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\":");
|
||||||
|
@ -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) +
|
||||||
|
DatafileHelper::VPackOffset(type));
|
||||||
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
||||||
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here
|
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,8 +274,7 @@ 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)));
|
||||||
}
|
}
|
||||||
|
@ -289,9 +293,12 @@ static int StringifyMarker(TRI_replication_dump_t* dump,
|
||||||
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) +
|
||||||
|
DatafileHelper::VPackOffset(type));
|
||||||
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
arangodb::basics::VPackStringBufferAdapter adapter(dump->_buffer);
|
||||||
VPackDumper dumper(&adapter, &dump->_vpackOptions); // note: we need the CustomTypeHandler here
|
VPackDumper dumper(
|
||||||
|
&adapter,
|
||||||
|
&dump->_vpackOptions); // note: we need the CustomTypeHandler here
|
||||||
dumper.dump(slice);
|
dumper.dump(slice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -364,12 +371,12 @@ static bool MustReplicateWalMarker(
|
||||||
}
|
}
|
||||||
|
|
||||||
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,23 +409,27 @@ 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 {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -546,12 +559,11 @@ int TRI_DumpLogReplication(
|
||||||
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);
|
||||||
|
@ -559,7 +571,8 @@ int TRI_DumpLogReplication(
|
||||||
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();
|
||||||
|
@ -589,17 +602,17 @@ int TRI_DumpLogReplication(
|
||||||
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);
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue