8000 fix potential issue during cluster index creation (#14690) · arangodb/arangodb@5f0e28c · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f0e28c

Browse files
jsteemannKVS85
andauthored
fix potential issue during cluster index creation (#14690)
* fix potential issue during cluster index creation * Fix a potential multi-threading issue in index creation on coordinators, when an agency callback was triggered at the same time the method `ensureIndexCoordinatorInner` was left. * Update CHANGELOG Co-authored-by: Vadim <vadim@arangodb.com>
1 parent 4a4d017 commit 5f0e28c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
v3.7.15 (XXXX-XX-XX)
22
--------------------
33

4+
* Fix a potential multi-threading issue in index creation on coordinators, when
5+
an agency callback was triggered at the same time the method
6+
`ensureIndexCoordinatorInner` was left.
7+
48
* When creating Pregel memory-mapped files, create them with O_TMPFILE attribute
59
on Linux so that files are guaranteed to vanish even if a process dies.
610

arangod/Cluster/ClusterInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,7 +4008,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
40084008
// This object watches whether the collection is still present in Plan
40094009
// It assumes that the collection *is* present and only changes state
40104010
// if the collection disappears
4011-
CollectionWatcher collectionWatcher(_agencyCallbackRegistry, collection);
4011+
auto collectionWatcher = std::make_shared<CollectionWatcher>(_agencyCallbackRegistry, collection);
40124012

40134013
if (!result.successful()) {
40144014
if (result.httpCode() == (int)arangodb::rest::ResponseCode::PRECONDITION_FAILED) {
@@ -4111,7 +4111,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
41114111
}
41124112
}
41134113

4114-
if (!collectionWatcher.isPresent()) {
4114+
if (!collectionWatcher->isPresent()) {
41154115
return Result(TRI_ERROR_ARANGO_INDEX_CREATION_FAILED,
41164116
"Collection " + collectionID +
41174117
" has gone from database " + databaseName +
@@ -4198,7 +4198,7 @@ Result ClusterInfo::ensureIndexCoordinatorInner(LogicalCollection const& collect
41984198
// when we wanted to roll back the index creation.
41994199
}
42004200

4201-
if (!collectionWatcher.isPresent()) {
4201+
if (!collectionWatcher->isPresent()) {
42024202
return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
42034203
"collection " + collectionID +
42044204
"appears to have been dropped from database " +

arangod/Cluster/ClusterInfo.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct ClusterCollectionCreationInfo;
6464
// make sure a collection is still in Plan
6565
// we are only going from *assuming* that it is present
6666
// to it being changed to not present.
67-
class CollectionWatcher {
67+
class CollectionWatcher : public std::enable_shared_from_this<CollectionWatcher> {
6868
public:
6969
CollectionWatcher(CollectionWatcher const&) = delete;
7070
CollectionWatcher(AgencyCallbackRegistry* agencyCallbackRegistry, LogicalCollection const& collection)
@@ -76,24 +76,27 @@ class CollectionWatcher {
7676

7777
_agencyCallback = std::make_shared<AgencyCallback>(
7878
collection.vocbase().server(), where,
79-
[this](VPackSlice const& result) {
80-
if (result.isNone()) {
81-
_present.store(false);
79+
[self = weak_from_this()](VPackSlice const& result) {
80+
auto watcher = self.lock();
81+
if (result.isNone() && watcher) {
82+
watcher->_present.store(false);
8283
}
8384
return true;
8485
},
8586
true, false);
87+
8688
_agencyCallbackRegistry->registerCallback(_agencyCallback);
8789
}
90+
8891
~CollectionWatcher();
8992

9093
bool isPresent() {
9194
// Make sure we did not miss a callback
9295
_agencyCallback->refetchAndUpdate(true, false);
9396
return _present.load();
94-
};
97+
}
9598

96-
private:
99+
private:
97100
AgencyCallbackRegistry *_agencyCallbackRegistry;
98101
std::shared_ptr<AgencyCallback> _agencyCallback;
99102

0 commit comments

Comments
 (0)
0