8000 Bug fix/refactor rocks db transaction state and rocks db methods (#14… · arangodb/arangodb@1c85cdf · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c85cdf

Browse files
authored
Bug fix/refactor rocks db transaction state and rocks db methods (#14543)
1 parent eb68014 commit 1c85cdf

40 files changed

+2097
-1278
lines changed

arangod/RestHandler/RestDocumentHandler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "Basics/Common.h"
2727
#include "RestHandler/RestVocbaseBaseHandler.h"
28-
#include "Utils/SingleCollectionTransaction.h"
2928

3029
namespace arangodb {
3130
namespace transaction {

arangod/RestHandler/RestGraphHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "Graph/GraphOperations.h"
3131
#include "Transaction/StandaloneContext.h"
3232
#include "Utils/OperationOptions.h"
33-
#include "Utils/SingleCollectionTransaction.h"
3433

3534
#include <velocypack/Collection.h>
3635
#include <utility>

arangod/RocksDBEngine/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ set(ROCKSDB_SOURCES
4343
RocksDBEngine/Listeners/RocksDBMetricsListener.cpp
4444
RocksDBEngine/Listeners/RocksDBShaCalculator.cpp
4545
RocksDBEngine/Listeners/RocksDBThrottle.cpp
46+
RocksDBEngine/Methods/RocksDBBatchedMethods.cpp
47+
RocksDBEngine/Methods/RocksDBBatchedWithIndexMethods.cpp
48+
RocksDBEngine/Methods/RocksDBReadOnlyBaseMethods.cpp
49+
RocksDBEngine/Methods/RocksDBReadOnlyMethods.cpp
50+
RocksDBEngine/Methods/RocksDBSingleOperationReadOnlyMethods.cpp
51+
RocksDBEngine/Methods/RocksDBSingleOperationTrxMethods.cpp
52+
RocksDBEngine/Methods/RocksDBTrxBaseMethods.cpp
53+
RocksDBEngine/Methods/RocksDBTrxMethods.cpp
4654
RocksDBEngine/RocksDBBackgroundThread.cpp
4755
RocksDBEngine/RocksDBBuilderIndex.cpp
4856
RocksDBEngine/RocksDBCollection.cpp
@@ -64,7 +72,7 @@ set(ROCKSDB_SOURCES
6472
RocksDBEngine/RocksDBLogValue.cpp
6573
RocksDBEngine/RocksDBMetaCollection.cpp
6674
RocksDBEngine/RocksDBMetadata.cpp
67-
RocksDBEngine/RocksDBMethods.cpp
75+
RocksDBEngine/RocksDBTransactionMethods.cpp
6876
RocksDBEngine/RocksDBOptimizerRules.cpp
6977
RocksDBEngine/RocksDBOptionFeature.cpp
7078
RocksDBEngine/RocksDBPrimaryIndex.cpp
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Simon Grätzer
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#include "RocksDBBatchedMethods.h"
25+
26+
using namespace arangodb;
27+
28+
RocksDBBatchedMethods::RocksDBBatchedMethods(rocksdb::WriteBatch* wb)
29+
: RocksDBMethods(), _wb(wb) {}
30+
31+
rocksdb::Status RocksDBBatchedMethods::Get(rocksdb::ColumnFamilyHandle* cf,
32+
rocksdb::Slice const& key,
33+
rocksdb::PinnableSlice* val) {
34+
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
35+
"BatchedMethods does not provide Get");
36+
}
37+
38+
rocksdb::Status RocksDBBatchedMethods::GetForUpdate(rocksdb::ColumnFamilyHandle* cf,
39+
rocksdb::Slice const& key,
40+
rocksdb::PinnableSlice* val) {
41+
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
42+
"BatchedMethods does not provide GetForUpdate");
43+
}
44+
45+
rocksdb::Status RocksDBBatchedMethods::Put(rocksdb::ColumnFamilyHandle* cf,
46+
RocksDBKey const& key,
47+
rocksdb::Slice const& val,
48+
bool assume_tracked) {
49+
TRI_ASSERT(cf != nullptr);
50+
return _wb->Put(cf, key.string(), val);
51+
}
52+
53+
rocksdb::Status RocksDBBatchedMethods::PutUntracked(rocksdb::ColumnFamilyHandle* cf,
54+
RocksDBKey const& key,
55+
rocksdb::Slice const& val) {
56+
return RocksDBBatchedMethods::Put(cf, key, val, /*assume_tracked*/false);
57+
}
58+
59+
rocksdb::Status RocksDBBatchedMethods::Delete(rocksdb::ColumnFamilyHandle* cf,
60+
RocksDBKey const& key) {
61+
TRI_ASSERT(cf != nullptr);
62+
return _wb->Delete(cf, key.string());
63+
}
64+
65+
rocksdb::Status RocksDBBatchedMethods::SingleDelete(rocksdb::ColumnFamilyHandle* cf,
66+
RocksDBKey const& key) {
67+
TRI_ASSERT(cf != nullptr);
68+
return _wb->SingleDelete(cf, key.string());
69+
}
70+
71+
void RocksDBBatchedMethods::PutLogData(rocksdb::Slice const& blob) {
72+
_wb->PutLogData(blob);
73+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Simon Grätzer
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#pragma once
25+
26+
#include "RocksDBEngine/RocksDBMethods.h"
27+
28+
namespace arangodb {
29+
30+
/// wraps a writebatch - non transactional
31+
class RocksDBBatchedMethods final : public RocksDBMethods {
32+
public:
33+
explicit RocksDBBatchedMethods(rocksdb::WriteBatch*);
34+
35+
rocksdb::Status Get(rocksdb::ColumnFamilyHandle*, rocksdb::Slice const& key,
36+
rocksdb::PinnableSlice* val) override;
37+
rocksdb::Status GetForUpdate(rocksdb::ColumnFamilyHandle*,
38+
rocksdb::Slice const&,
39+
rocksdb::PinnableSlice*) override;
40+
rocksdb::Status Put(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
41+
rocksdb::Slice const& val, bool assume_tracked) override;
42+
rocksdb::Status PutUntracked(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
43+
rocksdb::Slice const& val) override;
44+
rocksdb::Status Delete(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key) override;
45+
rocksdb::Status SingleDelete(rocksdb::ColumnFamilyHandle*, RocksDBKey const&) override;
46+
void PutLogData(rocksdb::Slice const&) override;
47+
48+
private:
49+
rocksdb::WriteBatch* _wb;
50+
};
51+
52+
} // namespace arangodb
53+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Simon Grätzer
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#include "RocksDBBatchedWithIndexMethods.h"
25+
26+
using namespace arangodb;
27+
28+
RocksDBBatchedWithIndexMethods::RocksDBBatchedWithIndexMethods(rocksdb::TransactionDB* db,
29+
rocksdb::WriteBatchWithIndex* wb)
30+
: RocksDBMethods(), _db(db), _wb(wb) {
31+
TRI_ASSERT(_db != nullptr);
32+
TRI_ASSERT(_wb != nullptr);
33+
}
34+
35+
rocksdb::Status RocksDBBatchedWithIndexMethods::Get(rocksdb::ColumnFamilyHandle* cf,
36+
rocksdb::Slice const& key,
37+
rocksdb::PinnableSlice* val) {
38+
TRI_ASSERT(cf != nullptr);
39+
rocksdb::ReadOptions ro;
40+
return _wb->GetFromBatchAndDB(_db, ro, cf, key, val);
41+
}
42+
43+
rocksdb::Status RocksDBBatchedWithIndexMethods::GetForUpdate(rocksdb::ColumnFamilyHandle* cf,
44+
rocksdb::Slice const& key,
45+
rocksdb::PinnableSlice* val) {
46+
return this->Get(cf, key, val);
47+
}
48+
49+
rocksdb::Status RocksDBBatchedWithIndexMethods::Put(rocksdb::ColumnFamilyHandle* cf,
50+
RocksDBKey const& key,
51+
rocksdb::Slice const& val,
52+
bool assume_tracked) {
53+
TRI_ASSERT(cf != nullptr);
54+
return _wb->Put(cf, key.string(), val);
55+
}
56+
57+
rocksdb::Status RocksDBBatchedWithIndexMethods::PutUntracked(rocksdb::ColumnFamilyHandle* cf,
58+
RocksDBKey const& key,
59+
rocksdb::Slice const& val) {
60+
return RocksDBBatchedWithIndexMethods::Put(cf, key, val, /*assume_tracked*/false);
61+
}
62+
63+
rocksdb::Status RocksDBBatchedWithIndexMethods::Delete(rocksdb::ColumnFamilyHandle* cf,
64+
RocksDBKey const& key) {
65+
TRI_ASSERT(cf != nullptr);
66+
return _wb->Delete(cf, key.string());
67+
}
68+
69+
rocksdb::Status RocksDBBatchedWithIndexMethods::SingleDelete(rocksdb::ColumnFamilyHandle* cf,
70+
RocksDBKey const& key) {
71+
TRI_ASSERT(cf != nullptr);
72+
return _wb->SingleDelete(cf, key.string());
73+
}
74+
75+
void RocksDBBatchedWithIndexMethods::PutLogData(rocksdb::Slice const& blob) {
76+
_wb->PutLogData(blob);
77+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Simon Grätzer
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#pragma once
25+
26+
#include "RocksDBEngine/RocksDBMethods.h"
27+
28+
#include <rocksdb/utilities/write_batch_with_index.h>
29+
30+
namespace rocksdb {
31+
class WriteBatchWithIndex;
32+
} // namespace rocksdb
33+
34+
namespace arangodb {
35+
36+
/// wraps a writebatch with index - non transactional
37+
class RocksDBBatchedWithIndexMethods final : public RocksDBMethods {
38+
public:
39+
RocksDBBatchedWithIndexMethods(rocksdb::TransactionDB* db,
40+
rocksdb::WriteBatchWithIndex*);
41+
42+
rocksdb::Status Get(rocksdb::ColumnFamilyHandle*, rocksdb::Slice const& key,
43+
rocksdb::PinnableSlice* val) override;
44+
rocksdb::Status GetForUpdate(rocksdb::ColumnFamilyHandle*,
45+
rocksdb::Slice const&,
46+
rocksdb::PinnableSlice*) override;
47+
rocksdb::Status Put(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
48+
rocksdb::Slice const& val, bool assume_tracked) override;
49+
rocksdb::Status PutUntracked(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
50+
rocksdb::Slice const& val) override;
51+
rocksdb::Status Delete(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key) override;
52+
rocksdb::Status SingleDelete(rocksdb::ColumnFamilyHandle*, RocksDBKey const&) override;
53+
void PutLogData(rocksdb::Slice const&) override;
54+
55+
private:
56+
rocksdb::TransactionDB* _db;
57+
rocksdb::WriteBatchWithIndex* _wb;
58+
};
59+
60+
} // namespace arangodb
61+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
/// DISCLAIMER
3+
///
4+
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
5+
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6+
///
7+
/// Licensed under the Apache License, Version 2.0 (the "License");
8+
/// you may not use this file except in compliance with the License.
9+
/// You may obtain a copy of the License at
10+
///
11+
/// http://www.apache.org/licenses/LICENSE-2.0
12+
///
13+
/// Unless required by applicable law or agreed to in writing, software
14+
/// distributed under the License is distributed on an "AS IS" BASIS,
15+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
/// See the License for the specific language governing permissions and
17+
/// limitations under the License.
18+
///
19+
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20+
///
21+
/// @author Manuel Pöter
22+
////////////////////////////////////////////////////////////////////////////////
23+
24+
#include "RocksDBReadOnlyBaseMethods.h"
25+
26+
#include "RocksDBEngine/RocksDBTransactionState.h"
27+
28+
#include <rocksdb/db.h>
29+
#include <rocksdb/status.h>
30+
31+
using namespace arangodb;
32+
33+
RocksDBReadOnlyBaseMethods::RocksDBReadOnlyBaseMethods(RocksDBTransactionState* state)
34+
: RocksDBTransactionMethods(state) {}
35+
36+
void RocksDBReadOnlyBaseMethods::prepareOperation(DataSourceId cid, RevisionId rid,
37+
TRI_voc_document_operation_e operationType) {
38+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
39+
}
40+
41+
void RocksDBReadOnlyBaseMethods::rollbackOperation(TRI_voc_document_operation_e operationType) {
42+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
43+
}
44+
45+
Result RocksDBReadOnlyBaseMethods::addOperation(DataSourceId collectionId, RevisionId revisionId,
46+
TRI_voc_document_operation_e opType) {
47+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
48+
}
49+
50+
rocksdb::Status RocksDBReadOnlyBaseMethods::GetForUpdate(rocksdb::ColumnFamilyHandle* cf,
51+
rocksdb::Slice const& key,
52+
rocksdb::PinnableSlice* val) {
53+
return this->Get(cf, key, val);
54+
}
55+
56+
rocksdb::Status RocksDBReadOnlyBaseMethods::Put(rocksdb::ColumnFamilyHandle* cf,
57+
RocksDBKey const&,
58+
rocksdb::Slice const&, bool) {
59+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
60+
}
61+
62+
rocksdb::Status RocksDBReadOnlyBaseMethods::PutUntracked(rocksdb::ColumnFamilyHandle* cf,
63+
RocksDBKey const&,
64+
rocksdb::Slice const&) {
65+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
66+
}
67+
68+
rocksdb::Status RocksDBReadOnlyBaseMethods::Delete(rocksdb::ColumnFamilyHandle* cf,
69+
RocksDBKey const& key) {
70+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
71+
}
72+
73+
rocksdb::Status RocksDBReadOnlyBaseMethods::SingleDelete(rocksdb::ColumnFamilyHandle*,
74+
RocksDBKey const&) {
75+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
76+
}
77+
78+
void RocksDBReadOnlyBaseMethods::PutLogData(rocksdb::Slice const& blob) {
79+
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
80+
}

0 commit comments

Comments
 (0)
0