Skip to content

Commit

Permalink
Merge pull request #68 from resilientdb/res_local
Browse files Browse the repository at this point in the history
Res local
  • Loading branch information
DakaiKang authored Aug 5, 2023
2 parents 10741e8 + 1be0a28 commit 02fca86
Show file tree
Hide file tree
Showing 33 changed files with 1,150 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### NexRes v1.7.0 ([2023-08-04](https://github.com/resilientdb/resilientdb/releases/tag/nexres-v1.7.0))

**Implemented Enhancements:** Support recovery locally when restarting Nexres.([Junchao Chen](https://github.com/cjcchen))


### NexRes v1.6.0 ([2023-05-30](https://github.com/resilientdb/resilientdb/releases/tag/nexres-v1.6.0))

**Implemented Enhancements:** Refactoring and enhancement of the codebase to highlight the entire software stack of ResilientDB consisting of the following layers ([Junchao Chen](https://github.com/cjcchen))
Expand Down
3 changes: 1 addition & 2 deletions chain/state/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cc_library(
srcs = ["chain_state.cpp"],
hdrs = ["chain_state.h"],
deps = [
"//chain/storage:storage",
"//chain/storage",
"//common:comm",
],
)
Expand All @@ -18,4 +18,3 @@ cc_test(
"//common/test:test_main",
],
)

22 changes: 13 additions & 9 deletions chain/state/chain_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@

namespace resdb {

ChainState::ChainState(std::unique_ptr<Storage> storage) : storage_(std::move(storage)){
ChainState::ChainState(std::unique_ptr<Storage> storage)
: storage_(std::move(storage)) {}

Storage* ChainState::GetStorage() {
return storage_ ? storage_.get() : nullptr;
}

int ChainState::SetValue(const std::string& key, const std::string& value) {
kv_map_[key] = value;
if(storage_) {
if (storage_) {
return storage_->SetValue(key, value);
}
kv_map_[key] = value;
return 0;
}

Expand All @@ -45,7 +49,7 @@ std::string ChainState::GetValue(const std::string& key) {
if (search != kv_map_.end())
return search->second;
else {
if(storage_){
if (storage_) {
std::string value = storage_->GetValue(key);
kv_map_[key] = value;
}
Expand All @@ -54,8 +58,8 @@ std::string ChainState::GetValue(const std::string& key) {
}

std::string ChainState::GetAllValues(void) {
if(storage_){
return storage_->GetAllValues();
if (storage_) {
return storage_->GetAllValues();
}
std::string values = "[";
bool first_iteration = true;
Expand All @@ -69,9 +73,9 @@ std::string ChainState::GetAllValues(void) {
}

std::string ChainState::GetRange(const std::string& min_key,
const std::string& max_key) {
if(storage_){
return storage_->GetRange(min_key, max_key);
const std::string& max_key) {
if (storage_) {
return storage_->GetRange(min_key, max_key);
}
std::string values = "[";
bool first_iteration = true;
Expand Down
2 changes: 2 additions & 0 deletions chain/state/chain_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ChainState {
std::string GetAllValues(void);
std::string GetRange(const std::string& min_key, const std::string& max_key);

Storage* GetStorage();

private:
std::unique_ptr<Storage> storage_ = nullptr;
std::unordered_map<std::string, std::string> kv_map_;
Expand Down
3 changes: 2 additions & 1 deletion chain/storage/mock_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

#pragma once

#include "gmock/gmock.h"
#include "chain/storage/storage.h"
#include "gmock/gmock.h"

namespace resdb {

Expand All @@ -38,6 +38,7 @@ class MockStorage : public Storage {
MOCK_METHOD(std::string, GetAllValues, (), (override));
MOCK_METHOD(std::string, GetRange, (const std::string&, const std::string&),
(override));
MOCK_METHOD(bool, Flush, (), (override));
};

} // namespace resdb
10 changes: 9 additions & 1 deletion chain/storage/res_leveldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ std::string ResLevelDB::GetRange(const std::string& min_key,
return values;
}

//}
bool ResLevelDB::Flush() {
leveldb::Status status = db_->Write(leveldb::WriteOptions(), &batch_);
if (status.ok()) {
batch_.Clear();
return true;
}
LOG(ERROR) << "flush buffer fail:" << status.ToString();
return false;
}

} // namespace resdb
4 changes: 3 additions & 1 deletion chain/storage/res_leveldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#include <optional>
#include <string>

#include "chain/storage/storage.h"
#include "leveldb/db.h"
#include "leveldb/write_batch.h"
#include "platform/proto/replica_info.pb.h"
#include "chain/storage/storage.h"

namespace resdb {

Expand All @@ -50,6 +50,8 @@ class ResLevelDB : public Storage {
std::string GetRange(const std::string& min_key,
const std::string& max_key) override;

bool Flush() override;

private:
void CreateDB(const std::string& path);

Expand Down
12 changes: 11 additions & 1 deletion chain/storage/res_rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
*/

#include "storage/res_rocksdb.h"
#include "chain/storage/res_rocksdb.h"

#include <assert.h>
#include <glog/logging.h>
Expand Down Expand Up @@ -158,4 +158,14 @@ std::string ResRocksDB::GetRange(const std::string& min_key,
return values;
}

bool ResRocksDB::Flush() {
rocksdb::Status status = db_->Write(rocksdb::WriteOptions(), &batch_);
if (status.ok()) {
batch_.Clear();
return true;
}
LOG(ERROR) << "write value fail:" << status.ToString();
return false;
}

} // namespace resdb
4 changes: 3 additions & 1 deletion chain/storage/res_rocksdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include <optional>
#include <string>

#include "chain/storage/storage.h"
#include "platform/proto/replica_info.pb.h"
#include "rocksdb/db.h"
#include "rocksdb/write_batch.h"
#include "storage/storage.h"

namespace resdb {

Expand All @@ -48,6 +48,8 @@ class ResRocksDB : public Storage {
std::string GetRange(const std::string& min_key,
const std::string& max_key) override;

bool Flush() override;

private:
std::unique_ptr<rocksdb::DB> db_ = nullptr;
rocksdb::WriteBatch batch_;
Expand Down
3 changes: 3 additions & 0 deletions chain/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Storage {
// Get values on a range of keys
virtual std::string GetRange(const std::string& min_key,
const std::string& max_key) = 0;

// Flush data to disk
virtual bool Flush() = 0;
};

} // namespace resdb
1 change: 1 addition & 0 deletions executor/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cc_library(
srcs = ["transaction_manager.cpp"],
hdrs = ["transaction_manager.h"],
deps = [
"//chain/storage",
"//common:comm",
"//platform/proto:resdb_cc_proto",
],
Expand Down
3 changes: 3 additions & 0 deletions executor/common/transaction_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <memory>

#include "chain/storage/storage.h"
#include "platform/proto/resdb.pb.h"

namespace resdb {
Expand All @@ -51,6 +52,8 @@ class TransactionManager {

bool NeedResponse();

virtual Storage* GetStorage() { return nullptr; };

private:
bool is_out_of_order_ = false;
bool need_response_ = true;
Expand Down
5 changes: 2 additions & 3 deletions executor/contract/manager/address_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@

#include "executor/contract/manager/address_manager.h"

#include <glog/logging.h>
#include <gtest/gtest.h>

#include "eEVM/util.h"
#include "glog/logging.h"
#include "gtest/gtest.h"

namespace resdb {
namespace contract {
Expand Down
18 changes: 18 additions & 0 deletions platform/consensus/checkpoint/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package(default_visibility = ["//platform/consensus:__subpackages__"])

cc_library(
name = "checkpoint",
hdrs = ["checkpoint.h"],
deps = [
],
)

cc_library(
name = "mock_checkpoint",
testonly = True,
hdrs = ["mock_checkpoint.h"],
deps = [
":checkpoint",
"//common/test",
],
)
38 changes: 38 additions & 0 deletions platform/consensus/checkpoint/checkpoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2019-2022 ExpoLab, UC Davis
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

#pragma once

namespace resdb {

class CheckPoint {
public:
CheckPoint() = default;
virtual ~CheckPoint() = default;

virtual uint64_t GetStableCheckpoint() = 0;
};

} // namespace resdb
39 changes: 39 additions & 0 deletions platform/consensus/checkpoint/mock_checkpoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2022 ExpoLab, UC Davis
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

#pragma once

#include <gmock/gmock.h>

#include "platform/consensus/checkpoint/checkpoint.h"

namespace resdb {

class MockCheckPoint : public CheckPoint {
public:
MOCK_METHOD(uint64_t, GetStableCheckpoint, (), (override));
};

} // namespace resdb
4 changes: 4 additions & 0 deletions platform/consensus/execution/transaction_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void TransactionExecutor::Stop() {
}
}

Storage* TransactionExecutor::GetStorage() {
return transaction_manager_ ? transaction_manager_->GetStorage() : nullptr;
}

void TransactionExecutor::SetPreExecuteFunc(PreExecuteFunc pre_exec_func) {
pre_exec_func_ = pre_exec_func;
}
Expand Down
2 changes: 2 additions & 0 deletions platform/consensus/execution/transaction_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class TransactionExecutor {

void SetSeqUpdateNotifyFunc(SeqUpdateNotifyFunc func);

Storage* GetStorage();

private:
void Execute(std::unique_ptr<Request> request, bool need_execute = true);
void OnlyExecute(std::unique_ptr<Request> request);
Expand Down
6 changes: 4 additions & 2 deletions platform/consensus/ordering/pbft/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ cc_library(
":lock_free_collector_pool",
":transaction_collector",
":transaction_utils",
"//chain/storage:txn_memory_db",
"//executor/common:transaction_manager",
"//platform/config:resdb_config",
"//platform/networkstrate:server_comm",
"//platform/proto:resdb_cc_proto",
"//chain/storage:txn_memory_db",
],
)

Expand Down Expand Up @@ -113,12 +113,13 @@ cc_library(
hdrs = ["checkpoint_manager.h"],
deps = [
":transaction_utils",
"//chain/storage:txn_memory_db",
"//common/crypto:signature_verifier",
"//platform/config:resdb_config",
"//platform/consensus/checkpoint",
"//platform/networkstrate:replica_communicator",
"//platform/networkstrate:server_comm",
"//platform/proto:checkpoint_info_cc_proto",
"//chain/storage:txn_memory_db",
],
)

Expand Down Expand Up @@ -225,6 +226,7 @@ cc_library(
":query",
":viewchange_manager",
"//common/crypto:signature_verifier",
"//platform/consensus/recovery",
"//platform/networkstrate:consensus_manager",
],
)
Expand Down
Loading

0 comments on commit 02fca86

Please sign in to comment.