8000 Merge branch '3.4' of github.com:arangodb/arangodb into 3.4.5 · arangodb/arangodb@648fbb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 648fbb8

Browse files
committed
Merge branch '3.4' of github.com:arangodb/arangodb into 3.4.5
2 parents c1841af + 6ceb86a commit 648fbb8

18 files changed

+206
-113
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ v3.4.5 (2019-03-27)
175175
* wait for statistics collections to be created before running resilience
176176
tests
177177

178+
* fix ttl values in agency when key overwritten with no ttl
179+
178180
v3.4.4 (2019-03-12)
179181
-------------------
180182

arangod/Agency/Node.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,17 @@ Store& Node::store() { return *(root()._store); }
375375

376376
Store const& Node::store() const { return *(root()._store); }
377377

378+
Store* Node::getStore() {
379+
Node* par = _parent;
380+
Node* tmp = this;
381+
while (par != nullptr) {
382+
tmp = par;
383+
par = par->_parent;
384+
}
385+
return tmp->_store; // Can be nullptr if we are not in a Node that belongs
386+
// to a store.
387+
}
388+
378389
// velocypack value type of this node
379390
ValueType Node::valueType() const { return slice().type(); }
380391

@@ -396,11 +407,13 @@ TimePoint const& Node::timeToLive() const {
396407

397408
// remove time to live entry for this node
398409
bool Node::removeTimeToLive() {
399-
if (_store != nullptr) {
400-
_store->removeTTL(uri());
401-
if (_ttl != std::chrono::system_clock::time_point()) {
402-
_ttl = std::chrono::system_clock::time_point();
403-
}
410+
Store* s = getStore(); // We could be in a Node that belongs to a store,
411+
// or in one that doesn't.
412+
if (s != nullptr) {
413+
s->removeTTL(uri());
414+
}
415+
if (_ttl != std::chrono::system_clock::time_point()) {
416+
_ttl = std::chrono::system_clock::time_point();
404417
}
405418
return true;
406419
}

arangod/Agency/Node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ class Node {
195195
/// @brief Get our container
196196
Store const& store() const;
197197

198+
private: // FIXME: More should be private here, but this is a late
199+
// addition, so we might as well get it right for this one.
200+
/// @brief Get store if it exists:
201+
Store* getStore();
202+
203+
public:
198204
/// @brief Create JSON representation of this node and below
199205
std::string toJson() const;
200206

arangod/Aql/Collection.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,25 @@ std::shared_ptr<std::vector<std::string>> Collection::shardIds(
150150
}
151151

152152
/// @brief returns the shard keys of a collection
153-
std::vector<std::string> Collection::shardKeys() const {
153+
std::vector<std::string> Collection::shardKeys(bool normalize) const {
154154
auto coll = getCollection();
155+
auto const& originalKeys = coll->shardKeys();
156+
157+
if (normalize &&
158+
coll->isSmart() && coll->type() == TRI_COL_TYPE_DOCUMENT) {
159+
// smart vertex collection always has ["_key:"] as shard keys
160+
TRI_ASSERT(originalKeys.size() == 1);
161+
TRI_ASSERT(originalKeys[0] == "_key:");
162+
// now normalize it this to _key
163+
return std::vector<std::string>{ StaticStrings::KeyString };
164+
}
165+
155166
std::vector<std::string> keys;
156-
for (auto const& x : coll->shardKeys()) {
157-
keys.emplace_back(x);
167+
keys.reserve(originalKeys.size());
168+
for (auto const& key : originalKeys) {
169+
keys.emplace_back(key);
158170
}
171+
159172
return keys;
160173
}
161174

arangod/Aql/Collection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ struct Collection {
103103
std::shared_ptr<std::vector<std::string>> shardIds(std::unordered_set<std::string> const& includedShards) const;
104104

105105
/// @brief returns the shard keys of a collection
106-
std::vector<std::string> shardKeys() const;
106+
/// if "normalize" is true, then the shard keys for a smart vertex collection
107+
/// will be reported as "_key" instead of "_key:"
108+
std::vector<std::string> shardKeys(bool normalize) const;
107109

108110
size_t numberOfShards() const;
109111

arangod/Aql/OptimizerRules.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ std::string getSingleShardId(arangodb::aql::ExecutionPlan const* plan,
585585
}
586586

587587
// note for which shard keys we need to look for
588-
auto shardKeys = collection->shardKeys();
588+
auto shardKeys = collection->shardKeys(true);
589589
std::unordered_set<std::string> toFind;
590590
for (auto const& it : shardKeys) {
591591
if (it.find('.') != std::string::npos) {
@@ -1439,7 +1439,7 @@ class PropagateConstantAttributesHelper {
14391439
// don't remove a smart join attribute access!
14401440
return;
14411441
} else {
1442-
std::vector<std::string> const& shardKeys = logical->shardKeys();
1442+
std::vector<std::string> shardKeys = collection->shardKeys(true);
14431443
if (std::find(shardKeys.begin(), shardKeys.end(), nameAttribute->getString()) != shardKeys.end()) {
14441444
// don't remove equality lookups on shard keys, as this may prevent
14451445
// the restrict-to-single-shard rule from being applied later!
@@ -4711,7 +4711,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
47114711
break; // abort . . .
47124712
}
47134713
// check the remove node's collection is sharded over _key
4714-
std::vector<std::string> shardKeys = rn->collection()->shardKeys();
4714+
std::vector<std::string> shardKeys = rn->collection()->shardKeys(false);
47154715
if (shardKeys.size() != 1 || shardKeys[0] != StaticStrings::KeyString) {
47164716
break; // abort . . .
47174717
}
@@ -4730,7 +4730,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
47304730
}
47314731

47324732
// note for which shard keys we need to look for
4733-
auto shardKeys = rn->collection()->shardKeys();
4733+
auto shardKeys = rn->collection()->shardKeys(false);
47344734
std::unordered_set<std::string> toFind;
47354735
for (auto const& it : shardKeys) {
47364736
toFind.emplace(it);

arangod/Aql/QueryList.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ void QueryList::clearSlow() {
293293
_slow.clear();
294294
_slowCount = 0;
295295
}
296+
297+
size_t QueryList::count() {
298+
READ_LOCKER(writeLocker, _lock);
299+
return _current.size();
300+
}
296301

297302
std::string QueryList::extractQueryString(Query const* query, size_t maxLength) const {
298303
return query->queryString().extract(maxLength);

arangod/Aql/QueryList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ class QueryList {
198198
/// @brief clear the list of slow queries
199199
void clearSlow();
200200

201+
size_t count();
202+
201203
private:
202204
std::string extractQueryString(Query const* query, size_t maxLength) const;
203205

arangod/MMFiles/MMFilesCollectionExport.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -91,54 +91,54 @@ void MMFilesCollectionExport::run(uint64_t maxWaitTime, size_t limit) {
9191
std::this_thread::sleep_for(std::chrono::microseconds(SleepTime));
9292
}
9393
}
94+
95+
auto guard = scopeGuard([this]() {
96+
// delete guard right now as we're about to return
97+
// if we would continue holding the guard's collection lock and return,
98+
// and the export object gets later freed in a different thread, then all
99+
// would be lost. so we'll release the lock here and rely on the cleanup
100+
// thread not unloading the collection (as we've acquired a document ditch
101+
// for the collection already - this will prevent unloading of the
102+
// collection's datafiles etc.)
103+
_guard.reset();
104+
});
94105

95-
{
96-
auto ctx = transaction::StandaloneContext::Create(_collection->vocbase());
97-
SingleCollectionTransaction trx(ctx, _name, AccessMode::Type::READ);
98-
99-
// already locked by guard above
100 93C6 -
trx.addHint(transaction::Hints::Hint::NO_USAGE_LOCK);
106+
auto ctx = transaction::StandaloneContext::Create(_collection->vocbase());
107+
SingleCollectionTransaction trx(ctx, _name, AccessMode::Type::READ);
101108

102-
Result res = trx.begin();
109+
// already locked by guard above
110+
trx.addHint(transaction::Hints::Hint::NO_USAGE_LOCK);
103111

104-
if (!res.ok()) {
105-
THROW_ARANGO_EXCEPTION(res);
106-
}
112+
Result res = trx.begin();
107113

108-
size_t maxDocuments =
109-
_collection->numberDocuments(&trx, transaction::CountType::Normal);
114+
if (!res.ok()) {
115+
THROW_ARANGO_EXCEPTION(res);
116+
}
110117

111-
if (limit > 0 && limit < maxDocuments) {
112-
maxDocuments = limit;
113-
} else {
114-
limit = maxDocuments;
115-
}
118+
size_t maxDocuments =
119+
_collection->numberDocuments(&trx, transaction::CountType::Normal);
116120

117-
_vpack.reserve(maxDocuments);
121+
if (limit > 0 && limit < maxDocuments) {
122+
maxDocuments = limit;
123+
} else {
124+
limit = maxDocuments;
125+
}
118126

119-
MMFilesCollection* mmColl = MMFilesCollection::toMMFilesCollection(_collection);
120-
ManagedDocumentResult mmdr;
121-
trx.invokeOnAllElements(_collection->name(), [this, &limit, &trx, &mmdr,
122-
mmColl](LocalDocumentId const& token) {
123-
if (limit == 0) {
124-
return false;
125-
}
126-
if (mmColl->readDocumentConditional(&trx, token, 0, mmdr)) {
127-
_vpack.emplace_back(mmdr.vpack());
128-
--limit;
129-
}
130-
return true;
131-
});
127+
_vpack.reserve(maxDocuments);
132128

133-
trx.finish(res.errorNumber());
134-
}
129+
MMFilesCollection* mmColl = MMFilesCollection::toMMFilesCollection(_collection);
130+
ManagedDocumentResult mmdr;
131+
trx.invokeOnAllElements(_collection->name(), [this, &limit, &trx, &mmdr,
132+
mmColl](LocalDocumentId const& token) {
133+
if (limit == 0) {
134+
return false;
135+
}
136+
if (mmColl->readDocumentConditional(&trx, token, 0, mmdr)) {
137+
_vpack.emplace_back(mmdr.vpack());
138+
--limit;
139+
}
140+
return true;
141+
});
135142

136-
// delete guard right now as we're about to return
137-
// if we would continue holding the guard's collection lock and return,
138-
// and the export object gets later freed in a different thread, then all
139-
// would be lost. so we'll release the lock here and rely on the cleanup
140-
// thread not unloading the collection (as we've acquired a document ditch
141-
// for the collection already - this will prevent unloading of the
142-
// collection's datafiles etc.)
143-
_guard.reset();
143+
trx.finish(res.errorNumber());
144144
}

arangod/MMFiles/MMFilesRestReplicationHandler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,7 @@ void MMFilesRestReplicationHandler::handleCommandCreateKeys() {
668668
size_t const count = keys->count();
669669
auto keysRepository = _vocbase.collectionKeys();
670670

671-
keysRepository->store(keys.get());
672-
keys.release();
671+
keysRepository->store(std::move(keys));
673672

674673
VPackBuilder result;
675674
result.add(VPackValue(VPackValueType::Object));

arangod/RestServer/DatabaseFeature.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "ApplicationFeatures/ApplicationServer.h"
2828
#include "Aql/PlanCache.h"
2929
#include "Aql/QueryCache.h"
30+
#include "Aql/QueryList.h"
3031
#include "Aql/QueryRegistry.h"
3132
#include "Basics/ArangoGlobalContext.h"
3233
#include "Basics/FileUtils.h"
@@ -49,6 +50,7 @@
4950
#include "RestServer/TraverserEngineRegistryFeature.h"
5051
#include "StorageEngine/EngineSelectorFeature.h"
5152
#include "StorageEngine/StorageEngine.h"
53+
#include "Utils/CollectionKeysRepository.h"
5254
#include "Utils/CollectionNameResolver.h"
5355
#include "Utils/CursorRepository.h"
5456
#include "Utils/Events.h"
@@ -408,13 +410,27 @@ void DatabaseFeature::stop() {
408410
continue;
409411
}
410412

413+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
414+ // i am here for debugging only.
415+
LOG_TOPIC(DEBUG, Logger::FIXME)
416+
<< "shutting down database " << vocbase->name() << ": " << (void*) vocbase
417+
<< ", cursors: " << vocbase->cursorRepository()->count()
418+
<< ", keys: " << vocbase->collectionKeys()->count()
419+
<< ", queries: " << vocbase->queryList()->count();
420+
#endif
411421
vocbase->processCollections(
412422
[](LogicalCollection* collection) {
413423
// no one else must modify the collection's status while we are in here
414424
collection->executeWhileStatusWriteLocked(
415425
[collection]() { collection->close(); });
416426
},
417427
true);
428+
429+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
430+
// i am here for debugging only.
431+
LOG_TOPIC(DEBUG, Logger::FIXME)
432+
<< "shutting down database " << vocbase->name() << ": " << (void*) vocbase << " successful";
433+
#endif
418434
}
419435
}
420436

0 commit comments

Comments
 (0)
0