Not so ugly interface

This commit is contained in:
alesapin 2022-01-21 16:35:28 +03:00
parent 5ec76cd827
commit 9248a1ae03
4 changed files with 15 additions and 16 deletions

2
contrib/NuRaft vendored

@ -1 +1 @@
Subproject commit c2043aa250e53ad5cf75e596e319d587af4dcb3c Subproject commit 1707a7572aa66ec5d0a2dbe2bf5effa3352e6b2d

View File

@ -8,7 +8,6 @@
#include <Poco/SHA1Engine.h> #include <Poco/SHA1Engine.h>
#include <Poco/Base64Encoder.h> #include <Poco/Base64Encoder.h>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <Common/hex.h>
#include <Coordination/pathUtils.h> #include <Coordination/pathUtils.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
@ -318,7 +317,7 @@ struct KeeperStorageCreateRequestProcessor final : public KeeperStorageRequestPr
created_node.is_sequental = request.is_sequential; created_node.is_sequental = request.is_sequential;
auto [map_key, _] = container.insert(path_created, std::move(created_node)); auto [map_key, _] = container.insert(path_created, std::move(created_node));
auto child_path = getBaseName(map_key); auto child_path = getBaseName(map_key->getKey());
int32_t parent_cversion = request.parent_cversion; int32_t parent_cversion = request.parent_cversion;
int64_t prev_parent_zxid; int64_t prev_parent_zxid;
@ -514,7 +513,7 @@ struct KeeperStorageRemoveRequestProcessor final : public KeeperStorageRequestPr
storage.acl_map.addUsage(prev_node.acl_id); storage.acl_map.addUsage(prev_node.acl_id);
auto [map_key, _] = storage.container.insert(path, prev_node); auto [map_key, _] = storage.container.insert(path, prev_node);
storage.container.updateValue(parentPath(path), [child_name = getBaseName(map_key)] (KeeperStorage::Node & parent) storage.container.updateValue(parentPath(path), [child_name = getBaseName(map_key->getKey())] (KeeperStorage::Node & parent)
{ {
++parent.stat.numChildren; ++parent.stat.numChildren;
--parent.stat.cversion; --parent.stat.cversion;

View File

@ -129,7 +129,7 @@ public:
using const_iterator = typename List::const_iterator; using const_iterator = typename List::const_iterator;
using ValueUpdater = std::function<void(V & value)>; using ValueUpdater = std::function<void(V & value)>;
std::pair<StringRef, bool> insert(const std::string & key, const V & value) std::pair<typename IndexMap::LookupResult, bool> insert(const std::string & key, const V & value)
{ {
size_t hash_value = map.hash(key); size_t hash_value = map.hash(key);
auto it = map.find(key, hash_value); auto it = map.find(key, hash_value);
@ -144,10 +144,10 @@ public:
it->getMapped() = itr; it->getMapped() = itr;
updateDataSize(INSERT, key.size(), value.sizeInBytes(), 0); updateDataSize(INSERT, key.size(), value.sizeInBytes(), 0);
return std::make_pair(it->getKey(), true); return std::make_pair(it, true);
} }
return std::make_pair(it->getKey(), false); return std::make_pair(it, false);
} }
void insertOrReplace(const std::string & key, const V & value) void insertOrReplace(const std::string & key, const V & value)

View File

@ -844,10 +844,10 @@ struct IntNode
TEST_P(CoordinationTest, SnapshotableHashMapSimple) TEST_P(CoordinationTest, SnapshotableHashMapSimple)
{ {
DB::SnapshotableHashTable<IntNode> hello; DB::SnapshotableHashTable<IntNode> hello;
EXPECT_TRUE(hello.insert("hello", 5)); EXPECT_TRUE(hello.insert("hello", 5).second);
EXPECT_TRUE(hello.contains("hello")); EXPECT_TRUE(hello.contains("hello"));
EXPECT_EQ(hello.getValue("hello"), 5); EXPECT_EQ(hello.getValue("hello"), 5);
EXPECT_FALSE(hello.insert("hello", 145)); EXPECT_FALSE(hello.insert("hello", 145).second);
EXPECT_EQ(hello.getValue("hello"), 5); EXPECT_EQ(hello.getValue("hello"), 5);
hello.updateValue("hello", [](IntNode & value) { value = 7; }); hello.updateValue("hello", [](IntNode & value) { value = 7; });
EXPECT_EQ(hello.getValue("hello"), 7); EXPECT_EQ(hello.getValue("hello"), 7);
@ -859,10 +859,10 @@ TEST_P(CoordinationTest, SnapshotableHashMapSimple)
TEST_P(CoordinationTest, SnapshotableHashMapTrySnapshot) TEST_P(CoordinationTest, SnapshotableHashMapTrySnapshot)
{ {
DB::SnapshotableHashTable<IntNode> map_snp; DB::SnapshotableHashTable<IntNode> map_snp;
EXPECT_TRUE(map_snp.insert("/hello", 7)); EXPECT_TRUE(map_snp.insert("/hello", 7).second);
EXPECT_FALSE(map_snp.insert("/hello", 145)); EXPECT_FALSE(map_snp.insert("/hello", 145).second);
map_snp.enableSnapshotMode(); map_snp.enableSnapshotMode(100000);
EXPECT_FALSE(map_snp.insert("/hello", 145)); EXPECT_FALSE(map_snp.insert("/hello", 145).second);
map_snp.updateValue("/hello", [](IntNode & value) { value = 554; }); map_snp.updateValue("/hello", [](IntNode & value) { value = 554; });
EXPECT_EQ(map_snp.getValue("/hello"), 554); EXPECT_EQ(map_snp.getValue("/hello"), 554);
EXPECT_EQ(map_snp.snapshotSize(), 2); EXPECT_EQ(map_snp.snapshotSize(), 2);
@ -880,7 +880,7 @@ TEST_P(CoordinationTest, SnapshotableHashMapTrySnapshot)
EXPECT_EQ(itr, map_snp.end()); EXPECT_EQ(itr, map_snp.end());
for (size_t i = 0; i < 5; ++i) for (size_t i = 0; i < 5; ++i)
{ {
EXPECT_TRUE(map_snp.insert("/hello" + std::to_string(i), i)); EXPECT_TRUE(map_snp.insert("/hello" + std::to_string(i), i).second);
} }
EXPECT_EQ(map_snp.getValue("/hello3"), 3); EXPECT_EQ(map_snp.getValue("/hello3"), 3);
@ -951,7 +951,7 @@ TEST_P(CoordinationTest, SnapshotableHashMapDataSize)
hello.clear(); hello.clear();
EXPECT_EQ(hello.getApproximateDataSize(), 0); EXPECT_EQ(hello.getApproximateDataSize(), 0);
hello.enableSnapshotMode(); hello.enableSnapshotMode(10000);
hello.insert("hello", 1); hello.insert("hello", 1);
EXPECT_EQ(hello.getApproximateDataSize(), 9); EXPECT_EQ(hello.getApproximateDataSize(), 9);
hello.updateValue("hello", [](IntNode & value) { value = 2; }); hello.updateValue("hello", [](IntNode & value) { value = 2; });
@ -984,7 +984,7 @@ TEST_P(CoordinationTest, SnapshotableHashMapDataSize)
world.erase("world"); world.erase("world");
EXPECT_EQ(world.getApproximateDataSize(), 0); EXPECT_EQ(world.getApproximateDataSize(), 0);
world.enableSnapshotMode(); world.enableSnapshotMode(100000);
world.insert("world", n1); world.insert("world", n1);
EXPECT_EQ(world.getApproximateDataSize(), 98); EXPECT_EQ(world.getApproximateDataSize(), 98);
world.updateValue("world", [&](Node & value) { value = n2; }); world.updateValue("world", [&](Node & value) { value = n2; });