8000 fix invalid handling of `_lastValue` in case of multiple coordinators by jsteemann · Pull Request #7734 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

fix invalid handling of _lastValue in case of multiple coordinators #7734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
attempt to fix tests
  • Loading branch information
jsteemann committed Dec 11, 2018
commit a802c634e017e267a8f08bf760ff995e07cf39a8
28 changes: 24 additions & 4 deletions arangod/VocBase/KeyGenerator.cpp
8000
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ class TraditionalKeyGeneratorSingle final : public TraditionalKeyGenerator {
public:
/// @brief create the generator
explicit TraditionalKeyGeneratorSingle(bool allowUserKeys)
: TraditionalKeyGenerator(allowUserKeys), _lastValue(0) {}
: TraditionalKeyGenerator(allowUserKeys), _lastValue(0) {
TRI_ASSERT(!ServerState::instance()->isCoordinator());
}

/// @brief build a VelocyPack representation of the generator in the builder
void toVelocyPack(arangodb::velocypack::Builder& builder) const override {
Expand Down Expand Up @@ -252,11 +254,19 @@ class TraditionalKeyGeneratorSingle final : public TraditionalKeyGenerator {
};

/// @brief traditional key generator for a coordinator
/// please note that coordinator-based key generators are frequently
/// created and discarded, so ctor & dtor need to be very efficient.
/// additionally, do not put any state into this object, as for the
/// same logical collection the ClusterInfo may create many different
/// temporary LogicalCollection objects one after the other, which
/// will also discard the collection's particular KeyGenerator object!
class TraditionalKeyGeneratorCluster final : public TraditionalKeyGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we not share the key generator objects between LogicalCollection instances ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rather use LogicalCollection objects instead of just KeyGenerator objects.

public:
/// @brief create the generator
explicit TraditionalKeyGeneratorCluster(bool allowUserKeys)
: TraditionalKeyGenerator(allowUserKeys) {}
: TraditionalKeyGenerator(allowUserKeys) {
TRI_ASSERT(ServerState::instance()->isCoordinator());
}

private:
/// @brief generate a key value (internal)
Expand Down Expand Up @@ -385,7 +395,9 @@ class PaddedKeyGeneratorSingle final : public PaddedKeyGenerator {
public:
/// @brief create the generator
explicit PaddedKeyGeneratorSingle(bool allowUserKeys)
: PaddedKeyGenerator(allowUserKeys), _lastValue(0) {}
: PaddedKeyGenerator(allowUserKeys), _lastValue(0) {
TRI_ASSERT(!ServerState::instance()->isCoordinator());
}

/// @brief build a VelocyPack representation of the generator in the builder
void toVelocyPack(arangodb::velocypack::Builder& builder) const override {
Expand Down Expand Up @@ -441,11 +453,19 @@ class PaddedKeyGeneratorSingle final : public PaddedKeyGenerator {
};

/// @brief padded key generator for a coordinator
/// please note that coordinator-based key generators are frequently
/// created and discarded, so ctor & dtor need to be very efficient.
/// additionally, do not put any state into this object, as for the
/// same logical collection the ClusterInfo may create many different
/// temporary LogicalCollection objects one after the other, which
/// will also discard the collection's particular KeyGenerator object!
class PaddedKeyGeneratorCluster final : public PaddedKeyGenerator {
public:
/// @brief create the generator
explicit PaddedKeyGeneratorCluster(bool allowUserKeys)
: PaddedKeyGenerator(allowUserKeys) {}
: PaddedKeyGenerator(allowUserKeys) {
TRI_ASSERT(ServerState::instance()->isCoordinator());
}

private:
/// @brief generate a key value (internal)
Expand Down
8 changes: 8 additions & 0 deletions arangod/VocBase/KeyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Builder;
class Slice;
}

/// generic key generator interface
///
/// please note that coordinator-based key generators are frequently
/// created and discarded, so ctor & dtor need to be very efficient.
/// additionally, do not put any state into this object, as for the
/// same logical collection the ClusterInfo may create many different
/// temporary LogicalCollection objects one after the other, which
/// will also discard the collection's particular KeyGenerator object!
class KeyGenerator {
KeyGenerator(KeyGenerator const&) = delete;
KeyGenerator& operator=(KeyGenerator const&) = delete;
Expand Down
10 changes: 9 additions & 1 deletion arangod/VocBase/LogicalCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class ChecksumResult : public Result {
velocypack::Builder _builder;
};

/// please note that coordinator-based logical collections are frequently
/// created and discarded, so ctor & dtor need to be as efficient as possible.
/// additionally, do not put any volatile state into this object in the coordinator,
/// as the ClusterInfo may create many different temporary physical LogicalCollection
/// objects (one after the other) even for the same "logical" LogicalCollection.
/// this which will also discard the collection's volatile state each time!
/// all state of a LogicalCollection in the coordinator case needs to be derived
/// from the JSON info in the agency's plan entry for the collection...
class LogicalCollection : public LogicalDataSource {
friend struct ::TRI_vocbase_t;

Expand Down Expand Up @@ -424,4 +432,4 @@ class LogicalCollection : public LogicalDataSource {

} // namespace arangodb

#endif
#endif
10 changes: 7 additions & 3 deletions tests/js/common/shell/shell-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ function TraditionalSuite () {
lastKey = key;
}

assertEqual(lastKey, c.properties().keyOptions.lastValue);
if (!cluster || !cluster.isCluster || !cluster.isCluster()) {
assertEqual(lastKey, c.properties().keyOptions.lastValue);
}
},

testPaddedTracking : function () {
Expand All @@ -293,8 +295,10 @@ function TraditionalSuite () {
lastKey = key;
}

let hex = c.properties().keyOptions.lastValue.toString(16);
assertEqual(lastKey, Array(16 + 1 - hex.length).join("0") + hex);
if (!cluster || !cluster.isCluster || !cluster.isCluster()) {
let hex = c.properties().keyOptions.lastValue.toString(16);
assertEqual(lastKey, Array(16 + 1 - hex.length).join("0") + hex);
}
}

};
Expand Down
0