8000 Bug fix/refactor rocks db transaction state and rocks db methods by mpoeter · Pull Request #14543 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content
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
Introduce RocksDBSingleOperationReadOnlyMethods.
  • Loading branch information
mpoeter committed Jul 22, 2021
commit 63c5291d621ad2dcfd884e24fa26c49db9acbdcc
4 changes: 3 additions & 1 deletion arangod/RocksDBEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ set(ROCKSDB_SOURCES
RocksDBEngine/Listeners/RocksDBThrottle.cpp
RocksDBEngine/Methods/RocksDBBatchedMethods.cpp
RocksDBEngine/Methods/RocksDBBatchedWithIndexMethods.cpp
RocksDBEngine/Methods/RocksDBReadonlyMethods.cpp
RocksDBEngine/Methods/RocksDBReadOnlyBaseMethods.cpp
RocksDBEngine/Methods/RocksDBReadOnlyMethods.cpp
RocksDBEngine/Methods/RocksDBSingleOperationReadOnlyMethods.cpp
RocksDBEngine/Methods/RocksDBTrxMethods.cpp
RocksDBEngine/RocksDBBackgroundThread.cpp
RocksDBEngine/RocksDBBuilderIndex.cpp
Expand Down
81 changes: 81 additions & 0 deletions arangod/RocksDBEngine/Methods/RocksDBReadOnlyBaseMethods.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Manuel Pöter
////////////////////////////////////////////////////////////////////////////////

#include "RocksDBReadOnlyBaseMethods.h"

#include "RocksDBEngine/RocksDBTransactionState.h"

#include <rocksdb/db.h>
#include <rocksdb/status.h>

using namespace arangodb;

RocksDBReadOnlyBaseMethods::RocksDBReadOnlyBaseMethods(RocksDBTransactionState* state)
: RocksDBTransactionMethods(state) {}

void RocksDBReadOnlyBaseMethods::prepareOperation(DataSourceId cid, RevisionId rid,
TRI_voc_document_operation_e operationType) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

void RocksDBReadOnlyBaseMethods::rollbackOperation(TRI_voc_document_operation_e operationType) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

Result RocksDBReadOnlyBaseMethods::addOperation(DataSourceId collectionId, RevisionId revisionId,
TRI_voc_document_operation_e opType,
bool& hasPerformedIntermediateCommit) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyBaseMethods::GetForUpdate(rocksdb::ColumnFamilyHandle* cf,
rocksdb::Slice const& key,
rocksdb::PinnableSlice* val) {
return this->Get(cf, key, val);
}

rocksdb::Status RocksDBReadOnlyBaseMethods::Put(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const&,
rocksdb::Slice const&, bool) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyBaseMethods::PutUntracked(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const&,
rocksdb::Slice const&) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyBaseMethods::Delete(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const& key) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyBaseMethods::SingleDelete(rocksdb::ColumnFamilyHandle*,
RocksDBKey const&) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

void RocksDBReadOnlyBaseMethods::PutLogData(rocksdb::Slice const& blob) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}
75 changes: 75 additions & 0 deletions arangod/RocksDBEngine/Methods/RocksDBReadOnlyBaseMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2021 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Manuel Pöter
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "RocksDBEngine/RocksDBTransactionMethods.h"

namespace rocksdb {
class TransactionDB;
} // namespace rocksdb

namespace arangodb {

class RocksDBReadOnlyBaseMethods : public RocksDBTransactionMethods {
public:
explicit RocksDBReadOnlyBaseMethods(RocksDBTransactionState* state);

uint64_t numCommits() const override { return 0; }

bool hasOperations() const noexcept override { return false; }

uint64_t numOperations() const noexcept override { return 0; }

void prepareOperation(DataSourceId cid, RevisionId rid, TRI_voc_document_operation_e operationType) override;

void rollbackOperation(TRI_voc_document_operation_e operationType) override;

Result addOperation(DataSourceId collectionId, RevisionId revisionId,
TRI_voc_document_operation_e opType,
bool& hasPerformedIntermediateCommit) override;

rocksdb::Status GetForUpdate(rocksdb::ColumnFamilyHandle*,
rocksdb::Slice const&,
rocksdb::PinnableSlice*) override;
rocksdb::Status Put(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
rocksdb::Slice const& val, bool assume_tracked) override;
rocksdb::Status PutUntracked(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
rocksdb::Slice const& val) override;
rocksdb::Status Delete(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key) override;
rocksdb::Status SingleDelete(rocksdb::ColumnFamilyHandle*, RocksDBKey const&) override;
void PutLogData(rocksdb::Slice const&) override;

void SetSavePoint() override {}
rocksdb::Status RollbackToSavePoint() override {
return rocksdb::Status::OK();
}
rocksdb::Status RollbackToWriteBatchSavePoint() override {
// simply relay to the general method (which in this derived class does nothing)
return RollbackToSavePoint();
}
void PopSavePoint() override {}
};

} // namespace arangodb

64 changes: 5 additions & 59 deletions arangod/RocksDBEngine/Methods/RocksDBReadonlyMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
/// @author Simon Grätzer
////////////////////////////////////////////////////////////////////////////////

#include "RocksDBReadonlyMethods.h"
#include "RocksDBReadOnlyMethods.h"

#include "RocksDBEngine/RocksDBTransactionState.h"

#include <rocksdb/db.h>
#include <rocksdb/status.h>

using namespace arangodb;

RocksDBReadOnlyMethods::RocksDBReadOnlyMethods(RocksDBTransactionState* state,
rocksdb::TransactionDB* db)
: RocksDBTransactionMethods(state), _db(db) {
: RocksDBReadOnlyBaseMethods(state), _ 67ED db(db) {
TRI_ASSERT(_db != nullptr);
_readOptions.prefix_same_as_start = true; // should always be true
_readOptions.fill_cache = _state->options().fillBlockCache;
Expand All @@ -44,9 +43,7 @@ RocksDBReadOnlyMethods::~RocksDBReadOnlyMethods() {

Result RocksDBReadOnlyMethods::beginTransaction() {
TRI_ASSERT(_readOptions.snapshot == nullptr);
if (!_state->isSingleOperation()) {
_readOptions.snapshot = _db->GetSnapshot(); // must call ReleaseSnapshot later
}
_readOptions.snapshot = _db->GetSnapshot(); // must call ReleaseSnapshot later
return {};
}

Expand All @@ -68,7 +65,6 @@ rocksdb::ReadOptions RocksDBReadOnlyMethods::iteratorReadOptions() const {
/// Returns true if a snapshot was acquired, otherwise false (i.e., if we already had a snapshot)
bool RocksDBReadOnlyMethods::ensureSnapshot() {
if (_readOptions.snapshot == nullptr) {
TRI_ASSERT(_state->isSingleOperation());
_readOptions.snapshot = _db->GetSnapshot();
return true;
}
Expand All @@ -81,64 +77,16 @@ rocksdb::SequenceNumber RocksDBReadOnlyMethods::GetSequenceNumber() const {
}
return _db->GetLatestSequenceNumber();
}

void RocksDBReadOnlyMethods::prepareOperation(DataSourceId cid, RevisionId rid,
TRI_voc_document_operation_e operationType) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

void RocksDBReadOnlyMethods::rollbackOperation(TRI_voc_document_operation_e operationType) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

Result RocksDBReadOnlyMethods::addOperation(DataSourceId collectionId, RevisionId revisionId,
TRI_voc_document_operation_e opType,
bool& hasPerformedIntermediateCommit) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}


rocksdb::Status RocksDBReadOnlyMethods::Get(rocksdb::ColumnFamilyHandle* cf,
rocksdb::Slice const& key,
rocksdb::PinnableSlice* val) {
TRI_ASSERT(cf != nullptr);
rocksdb::ReadOptions const& ro = _readOptions;
TRI_ASSERT(ro.snapshot != nullptr ||
(_state->isReadOnlyTransaction() && _state->isSingleOperation()));
TRI_ASSERT(ro.snapshot != nullptr);
return _db->Get(ro, cf, key, val);
}

rocksdb::Status RocksDBReadOnlyMethods::GetForUpdate(rocksdb::ColumnFamilyHandle* cf,
rocksdb::Slice const& key,
rocksdb::PinnableSlice* val) {
return this->Get(cf, key, val);
}

rocksdb::Status RocksDBReadOnlyMethods::Put(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const&,
rocksdb::Slice const&, bool) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyMethods::PutUntracked(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const&,
rocksdb::Slice const&) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyMethods::Delete(rocksdb::ColumnFamilyHandle* cf,
RocksDBKey const& key) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

rocksdb::Status RocksDBReadOnlyMethods::SingleDelete(rocksdb::ColumnFamilyHandle*,
RocksDBKey const&) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

void RocksDBReadOnlyMethods::PutLogData(rocksdb::Slice const& blob) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_READ_ONLY);
}

std::unique_ptr<rocksdb::Iterator> RocksDBReadOnlyMethods::NewIterator(
rocksdb::ReadOptions const& opts, rocksdb::ColumnFamilyHandle* cf) {
TRI_ASSERT(cf != nullptr);
Expand All @@ -153,8 +101,6 @@ std::unique_ptr<rocksdb::Iterator> RocksDBReadOnlyMethods::NewIterator(

void RocksDBReadOnlyMethods::releaseSnapshot() {
if (_readOptions.snapshot != nullptr) {
TRI_ASSERT(_state->isReadOnlyTransaction() ||
_state->hasHint(transaction::Hints::Hint::INTERMEDIATE_COMMITS));
_db->ReleaseSnapshot(_readOptions.snapshot);
_readOptions.snapshot = nullptr;
}
Expand Down
43 changes: 2 additions & 41 deletions arangod/RocksDBEngine/Methods/RocksDBReadonlyMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@

#pragma once

#include "RocksDBEngine/RocksDBTransactionMethods.h"
#include "RocksDBEngine/Methods/RocksDBReadOnlyBaseMethods.h"

namespace rocksdb {
class TransactionDB;
// class Iterator;
// class WriteBatch;
// class WriteBatchWithIndex;
// struct ReadOptions;
} // namespace rocksdb

namespace arangodb {

// only implements GET and NewIterator
class RocksDBReadOnlyMethods final : public RocksDBTransactionMethods {
class RocksDBReadOnlyMethods final : public RocksDBReadOnlyBaseMethods {
public:
explicit RocksDBReadOnlyMethods(RocksDBTransactionState* state, rocksdb::TransactionDB* db);

Expand All @@ -48,52 +44,17 @@ class RocksDBReadOnlyMethods final : public RocksDBTransactionMethods {

Result abortTransaction() override;

uint64_t numCommits() const override { return 0; }

rocksdb::ReadOptions iteratorReadOptions() const override;

bool ensureSnapshot() override;

rocksdb::SequenceNumber GetSequenceNumber() const override;

bool hasOperations() const noexcept override { return false; }

uint64_t numOperations() const noexcept override { return 0; }

void prepareOperation(DataSourceId cid, RevisionId rid, TRI_voc_document_operation_e operationType) override;

void rollbackOperation(TRI_voc_document_operation_e operationType) override;

Result addOperation(DataSourceId collectionId, RevisionId revisionId,
TRI_voc_document_operation_e opType,
bool& hasPerformedIntermediateCommit) override;

rocksdb::Status Get(rocksdb::ColumnFamilyHandle*, rocksdb::Slice const& key,
rocksdb::PinnableSlice* val) override;
rocksdb::Status GetForUpdate(rocksdb::ColumnFamilyHandle*,
rocksdb::Slice const&,
rocksdb::PinnableSlice*) override;
rocksdb::Status Put(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
rocksdb::Slice const& val, bool assume_tracked) override;
rocksdb::Status PutUntracked(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key,
rocksdb::Slice const& val) override;
rocksdb::Status Delete(rocksdb::ColumnFamilyHandle*, RocksDBKey const& key) override;
rocksdb::Status SingleDelete(rocksdb::ColumnFamilyHandle*, RocksDBKey const&) override;
void PutLogData(rocksdb::Slice const&) override;

std::unique_ptr<rocksdb::Iterator> NewIterator(rocksdb::ReadOptions const&,
rocksdb::ColumnFamilyHandle*) override;

void SetSavePoint() override {}
rocksdb::Status RollbackToSavePoint() override {
return rocksdb::Status::OK();
}
rocksdb::Status RollbackToWriteBatchSavePoint() override {
// simply relay to the general method (which in this derived class does nothing)
return RollbackToSavePoint();
}
void PopSavePoint() override {}

private:
void releaseSnapshot();

Expand Down
Loading
0