Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
70 changes: 70 additions & 0 deletions chain/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,53 @@ cc_library(
"//common/lru:lru_cache",
"//platform/statistic:stats",
"//third_party:leveldb",
"@com_google_absl//absl/base",
"@com_google_absl//absl/synchronization",
],
)

cc_library(
name = "ipfs_client",
srcs = ["ipfs_client.cpp"],
hdrs = ["ipfs_client.h"],
deps = [
":storage",
"//chain/storage/proto:ipfs_config_cc_proto",
"//common:comm",
"@boost//:asio",
"@boost//:beast",
],
)

cc_library(
name = "secondary_index",
hdrs = ["interface/secondary_index.h"],
deps = [],
)

cc_library(
name = "in_memory_index",
srcs = ["in_memory_index.cpp"],
hdrs = ["in_memory_index.h"],
deps = [
":secondary_index",
],
)

cc_library(
name = "tiered_storage",
srcs = ["tiered_storage.cpp"],
hdrs = ["tiered_storage.h"],
deps = [
":in_memory_index",
":leveldb",
":storage",
":ipfs_client",
"//chain/storage/proto:ipfs_config_cc_proto",
"//chain/storage/proto:tiered_index_cc_proto",
"//common:comm",
"@com_google_absl//absl/base",
"@com_google_absl//absl/synchronization",
],
)

Expand All @@ -81,3 +128,26 @@ cc_test(
"//platform/statistic:stats",
],
)

cc_test(
name = "tiered_storage_test",
size = "small",
timeout = "short",
srcs = ["tiered_storage_test.cpp"],
deps = [
":leveldb",
":memory_db",
":tiered_storage",
":ipfs_client",
"//common/test:test_main",
],
)

cc_binary(
name = "ipfs_integration_test",
srcs = ["ipfs_integration_test.cpp"],
deps = [
":ipfs_client",
"//chain/storage/proto:ipfs_config_cc_proto",
],
)
46 changes: 46 additions & 0 deletions chain/storage/in_memory_index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#include "chain/storage/in_memory_index.h"

namespace resdb {
namespace storage {

void InMemoryHashIndex::Add(const std::string& key, const std::string& cid) {
index_[key] = cid;
}

std::string InMemoryHashIndex::Get(const std::string& key) const {
auto it = index_.find(key);
if (it != index_.end()) {
return it->second;
}
return "";
}

void InMemoryHashIndex::Clear() {
index_.clear();
}

size_t InMemoryHashIndex::Size() const {
return index_.size();
}

} // namespace storage
} // namespace resdb
42 changes: 42 additions & 0 deletions chain/storage/in_memory_index.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#pragma once

#include <string>
#include <unordered_map>

#include "chain/storage/interface/secondary_index.h"

namespace resdb {
namespace storage {

class InMemoryHashIndex : public SecondaryIndex {
public:
void Add(const std::string& key, const std::string& cid) override;
std::string Get(const std::string& key) const override;
void Clear() override;
size_t Size() const override;

private:
std::unordered_map<std::string, std::string> index_;
};

} // namespace storage
} // namespace resdb
37 changes: 37 additions & 0 deletions chain/storage/interface/secondary_index.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#pragma once

#include <string>

namespace resdb {
namespace storage {

class SecondaryIndex {
public:
virtual ~SecondaryIndex() = default;
virtual void Add(const std::string& key, const std::string& cid) = 0;
virtual std::string Get(const std::string& key) const = 0;
virtual void Clear() = 0;
virtual size_t Size() const = 0;
};

} // namespace storage
} // namespace resdb
Loading