8000 Properly compare velocypack objects in Agency operations (#6921) · mnemosdev/arangodb@8b7a409 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b7a409

Browse files
graetzerjsteemann
authored andcommitted
Properly compare velocypack objects in Agency operations (arangodb#6921)
* Properly compare velocypack objects in Agency operations * Add changelog * added option for VPackDumper
1 parent 9b36a94 commit 8b7a409

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

3rdParty/velocypack/include/velocypack/Options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ struct Options {
111111
// with a Dumper (creates \uxxxx sequences)
112112
bool escapeUnicode = false;
113113

114+
// dump Object attributes in index order (true) or in "undefined"
115+
// order (false). undefined order may be faster but not deterministic
116+
bool dumpAttributesInIndexOrder = true;
117+
114118
// disallow using type External (to prevent injection of arbitrary pointer
115119
// values as a security precaution)
116120
bool disallowExternals = false;

3rdParty/velocypack/src/Dumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void Dumper::dumpValue(Slice const* slice, Slice const* base) {
376376
}
377377

378378
case ValueType::Object: {
379-
ObjectIterator it(*slice);
379+
ObjectIterator it(*slice, !options->dumpAttributesInIndexOrder);
380380
_sink->push_back('{');
381381
if (options->prettyPrint) {
382382
_sink->push_back('\n');

arangod/Agency/Node.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,9 @@ template <> bool Node::handle<ERASE>(VPackSlice const& slice) {
539539

540540
if (this->slice().isArray()) {
541541
if (haveVal) {
542+
VPackSlice valToErase = slice.get("val");
542543
for (auto const& old : VPackArrayIterator(this->slice())) {
543-
if (old != slice.get("val")) {
544+
if (VelocyPackHelper::compare(old, valToErase, /*useUTF8*/true) != 0) {
544545
tmp.add(old);
545546
}
546547
}
@@ -581,8 +582,13 @@ bool Node::handle<REPLACE>(VPackSlice const& slice) {
581582
Builder tmp;
582583
{ VPackArrayBuilder t(&tmp);
583584
if (this->slice().isArray()) {
585+
VPackSlice valToRepl = slice.get("val");
584586
for (auto const& old : VPackArrayIterator(this->slice())) {
585-
tmp.add(old == slice.get("val") ? slice.get("new") : old);
587+
if (VelocyPackHelper::compare(old, valToRepl, /*useUTF8*/true) == 0) {
588+
tmp.add(slice.get("new"));
589+
} else {
590+
tmp.add(old);
591+
}
586592
}
587593
}
588594
}

arangod/Cluster/ClusterInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,7 @@ int ClusterInfo::ensureIndexCoordinatorWithoutRollback(
26322632
return setErrormsg(TRI_ERROR_OUT_OF_MEMORY, errorMsg);
26332633
}
26342634

2635+
// will contain the error number and message
26352636
std::shared_ptr<int> dbServerResult = std::make_shared<int>(-1);
26362637
std::shared_ptr<std::string> errMsg = std::make_shared<std::string>();
26372638

@@ -2668,8 +2669,7 @@ int ClusterInfo::ensureIndexCoordinatorWithoutRollback(
26682669
errorMsg = "Error during index creation: " + errorMsg;
26692670

26702671
// Returns the specific error number if set, or the general
2671-
// error
2672-
// otherwise
2672+
// error otherwise
26732673
*dbServerResult =
26742674
arangodb::basics::VelocyPackHelper::getNumericValue<int>(
26752675
v, "errorNum", TRI_ERROR_ARANGO_INDEX_CREATION_FAILED);

arangod/ClusterEngine/ClusterEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void ClusterEngine::addRestHandlers(rest::RestHandlerFactory& handlerFactory) {
409409
void ClusterEngine::waitForEstimatorSync(std::chrono::milliseconds maxWaitTime) {
410410
// fixes tests by allowing us to reload the cluster selectivity estimates
411411
// If test `shell-cluster-collection-selectivity.js` fails consider increasing timeout
412-
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
412+
std::this_thread::sleep_for(std::chrono::seconds(5));
413413
}
414414

415415
/// @brief open an existing database. internal function

arangod/GeneralServer/GeneralCommTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void GeneralCommTask::handleRequestDirectly(
460460
TRI_ASSERT(doLock || _peer->runningInThisThread());
461461

462462
auto self = shared_from_this();
463-
handler->runHandler([self, this, doLock](rest::RestHandler* handler) {
463+
handler->runHandler([self, this](rest::RestHandler* handler) {
464464

465465
RequestStatistics* stat = handler->stealStatistics();
466466
auto h = handler->shared_from_this();

lib/Basics/VelocyPackHelper.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ void VelocyPackHelper::initialize() {
165165
CustomTypeHandler.reset(new DefaultCustomTypeHandler);
166166

167167
VPackOptions::Defaults.customTypeHandler = CustomTypeHandler.get();
168-
VPackOptions::Defaults.escapeUnicode = false; // false here, but will be set
169-
// when converting to JSON for
170-
// HTTP xfer
168+
169+
// false here, but will be set when converting to JSON for HTTP xfer
170+
VPackOptions::Defaults.escapeUnicode = false;
171+
172+
// allow dumping of Object attributes in "arbitrary" order (i.e. non-sorted order)
173+
VPackOptions::Defaults.dumpAttributesInIndexOrder = false;
171174

172175
// run quick selfs test with the attribute translator
173176
TRI_ASSERT(

0 commit comments

Comments
 (0)
0