8000 acquire an index snapshot for document write ops (#17834) · hicder/arangodb@9744ef1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9744ef1

Browse files
authored
acquire an index snapshot for document write ops (arangodb#17834)
1 parent aff3f9c commit 9744ef1

18 files changed

+521
-189
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
devel
22
-----
33

4+
* Acquire a snapshot of the (list of) indexes when starting document insert,
5+
update/replace and remove operations, and use that snapshot throughout the
6+
operation. Previously, the list of indexes was acquired multiple times during
7+
a write operation, and it was (at least in theory) possible that the list of
8+
indexes changed between the individual acquistions.
9+
The PR also contains an optimization to not fetch the full document from the
10+
storage engine for remove and replace operations in case the full document is
11+
not needed to process the operation. This is the case when the collection
12+
does not contain any secondary indexes and `returnOld` is not used.
13+
414
* Added experimental startup option `--rocksdb.block-cache-jemalloc-allocator`.
515
This option defaults to `false`. When set to `true`, a jemalloc-based memory
616
allocator will be used to allocate memory for the RocksDB block cache.

arangod/ClusterEngine/ClusterCollection.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,18 @@
3838
#include "Indexes/Index.h"
3939
#include "Indexes/IndexIterator.h"
4040
#include "Logger/LogMacros.h"
41-
#include "RestServer/DatabaseFeature.h"
4241
#include "StorageEngine/EngineSelectorFeature.h"
4342
#include "StorageEngine/StorageEngine.h"
44-
#include "StorageEngine/TransactionState.h"
4543
#include "Transaction/Helpers.h"
44+
#include "Transaction/IndexesSnapshot.h"
4645
#include "Transaction/StandaloneContext.h"
47-
#include "Utils/CollectionNameResolver.h"
4846
#include "Utils/Events.h"
4947
#include "Utils/OperationOptions.h"
5048
#include "VocBase/Identifiers/LocalDocumentId.h"
5149
#include "VocBase/LogicalCollection.h"
52-
#include "VocBase/ticks.h"
5350
#include "VocBase/voc-types.h"
5451

5552
#include <velocypack/Collection.h>
56-
#include <velocypack/Iterator.h>
5753

5854
namespace arangodb {
5955

@@ -141,14 +137,16 @@ Result ClusterCollection::updateProperties(velocypack::Slice slice) {
141137
TRI_ASSERT(_info.isClosed());
142138

143139
// notify all indexes about the properties change for the collection
144-
RECURSIVE_READ_LOCKER(_indexesLock, _indexesLockWriteOwner);
145-
for (auto& idx : _indexes) {
140+
auto indexesSnapshot = getIndexesSnapshot();
141+
auto const& indexes = indexesSnapshot.getIndexes();
142+
for (auto& idx : indexes) {
146143
// note: we have to exclude inverted indexes here,
147144
// as they are a different class type (no relationship to
148145
// ClusterIndex).
149146
if (idx->type() != Index::TRI_IDX_TYPE_INVERTED_INDEX) {
150147
TRI_ASSERT(dynamic_cast<ClusterIndex*>(idx.get()) != nullptr);
151-
static_cast<ClusterIndex*>(idx.get())->updateProperties(_info.slice());
148+
std::static_pointer_cast<ClusterIndex>(idx)->updateProperties(
149+
_info.slice());
152150
}
153151
}
154152

@@ -286,25 +284,28 @@ Result ClusterCollection::lookupDocument(
286284
return {TRI_ERROR_NOT_IMPLEMENTED};
287285
}
288286

289-
Result ClusterCollection::insert(transaction::Methods&, RevisionId,
290-
velocypack::Slice, OperationOptions const&) {
287+
Result ClusterCollection::insert(transaction::Methods&, IndexesSnapshot const&,
288+
RevisionId, velocypack::Slice,
289+
OperationOptions const&) {
291290
return {TRI_ERROR_NOT_IMPLEMENTED};
292291
}
293292

294-
Result ClusterCollection::update(transaction::Methods&, LocalDocumentId,
295-
RevisionId, velocypack::Slice, RevisionId,
296-
velocypack::Slice, OperationOptions const&) {
293+
Result ClusterCollection::update(transaction::Methods&, IndexesSnapshot const&,
294+
LocalDocumentId, RevisionId, velocypack::Slice,
295+
RevisionId, velocypack::Slice,
296+
OperationOptions const&) {
297297
return {TRI_ERROR_NOT_IMPLEMENTED};
298298
}
299299

300-
Result ClusterCollection::replace(transaction::Methods&, LocalDocumentId,
301-
RevisionId, velocypack::Slice, RevisionId,
300+
Result ClusterCollection::replace(transaction::Methods&, IndexesSnapshot const&,
301+
LocalDocumentId, RevisionId,
302+
velocypack::Slice, RevisionId,
302303
velocypack::Slice, OperationOptions const&) {
303304
return {TRI_ERROR_NOT_IMPLEMENTED};
304305
}
305306

306-
Result ClusterCollection::remove(transaction::Methods&, LocalDocumentId,
307-
RevisionId, velocypack::Slice,
307+
Result ClusterCollection::remove(transaction::Methods&, IndexesSnapshot const&,
308+
LocalDocumentId, RevisionId, velocypack::Slice,
308309
OperationOptions const&) {
309310
return {TRI_ERROR_NOT_IMPLEMENTED};
310311
}

arangod/ClusterEngine/ClusterCollection.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,30 @@ class ClusterCollection final : public PhysicalCollection {
119119
bool fillCache,
120120
ReadOwnWrites readOwnWrites) const override;
121121

122-
Result insert(transaction::Methods& trx, RevisionId newRevisionId,
123-
velocypack::Slice newDocument,
122+
Result insert(transaction::Methods& trx,
123+
IndexesSnapshot const& indexesSnapshot,
124+
RevisionId newRevisionId, velocypack::Slice newDocument,
124125
OperationOptions const& options) override;
125126

126-
Result update(transaction::Methods& trx, LocalDocumentId previousDocumentId,
127+
Result update(transaction::Methods& trx,
128+
IndexesSnapshot const& indexesSnapshot,
129+
LocalDocumentId previousDocumentId,
127130
RevisionId previousRevisionId,
128131
velocypack::Slice previousDocument, RevisionId newRevisionId,
129132
velocypack::Slice newDocument,
130133
OperationOptions const& options) override;
131134

132-
Result replace(transaction::Methods& trx, LocalDocumentId previousDocumentId,
135+
Result replace(transaction::Methods& trx,
136+
IndexesSnapshot const& indexesSnapshot,
137+
LocalDocumentId previousDocumentId,
133138
RevisionId previousRevisionId,
134139
velocypack::Slice previousDocument, RevisionId newRevisionId,
135140
velocypack::Slice newDocument,
136141
OperationOptions const& options) override;
137142

138-
Result remove(transaction::Methods& trx, LocalDocumentId previousDocumentId,
143+
Result remove(transaction::Methods& trx,
144+
IndexesSnapshot const& indexesSnapshot,
145+
LocalDocumentId previousDocumentId,
139146
RevisionId previousRevisionId,
140147
velocypack::Slice previousDocument,
141148
OperationOptions const& options) override;

arangod/Replication/DatabaseInitialSyncer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "StorageEngine/StorageEngine.h"
5454
#include "StorageEngine/TransactionState.h"
5555
#include "Transaction/Helpers.h"
56+
#include "Transaction/IndexesSnapshot.h"
5657
#include "Transaction/Methods.h"
5758
#include "Transaction/StandaloneContext.h"
5859
#include "Utils/CollectionGuard.h"
@@ -113,6 +114,8 @@ arangodb::Result removeRevisions(
113114
if (!toRemove.empty()) {
114115
PhysicalCollection* physical = collection.getPhysical();
115116

117+
auto indexesSnapshot = physical->getIndexesSnapshot();
118+
116119
arangodb::OperationOptions options;
117120
options.silent = true;
118121
options.ignoreRevs = true;
@@ -131,8 +134,8 @@ arangodb::Result removeRevisions(
131134
arangodb::ReadOwnWrites::yes);
132135

133136
if (r.ok()) {
134-
r = physical->remove(trx, documentId, rid, tempBuilder->slice(),
135-
options);
137+
r = physical->remove(trx, indexesSnapshot, documentId, rid,
138+
tempBuilder->slice(), options);
136139
}
137140

138141
if (r.ok()) {
@@ -179,6 +182,7 @@ arangodb::Result fetchRevisions(
179182
}
180183

181184
PhysicalCollection* physical = collection.getPhysical();
185+
auto indexesSnapshot = physical->getIndexesSnapshot();
182186

183187
std::string path = arangodb::replutils::ReplicationUrl + "/" +
184188
RestReplicationHandler::Revisions + "/" +
@@ -207,8 +211,8 @@ arangodb::Result fetchRevisions(
207211

208212
if (r.ok()) {
209213
TRI_ASSERT(tempBuilder->slice().isObject());
210-
r = physical->remove(trx, documentId, revisionId, tempBuilder->slice(),
211-
options);
214+
r = physical->remove(trx, indexesSnapshot, documentId, revisionId,
215+
tempBuilder->slice(), options);
212216
}
213217
}
214218

0 commit comments

Comments
 (0)
0