From c1077d54d1a37f9f5716c402846b3dc80b17e170 Mon Sep 17 00:00:00 2001 From: yc1111 Date: Wed, 24 Jan 2024 03:48:17 +0000 Subject: [PATCH] Fix document parsing error for QLDB --- exps/check_stat.sh | 2 +- exps/clean.sh | 2 +- ledger/common/db.h | 22 ++++++++++------------ ledger/qldb/qlnode.cc | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/exps/check_stat.sh b/exps/check_stat.sh index 304183d..7518f4f 100755 --- a/exps/check_stat.sh +++ b/exps/check_stat.sh @@ -13,5 +13,5 @@ done for host in `cat clients` do echo client $host - ssh $host "pgrep rangeClient" + ssh $host "pgrep verifyClient" done diff --git a/exps/clean.sh b/exps/clean.sh index 06c864e..0270348 100755 --- a/exps/clean.sh +++ b/exps/clean.sh @@ -4,7 +4,7 @@ for server in `cat replicas` do echo ${server} rsync -a ${expdir} ${server}:${rootdir}/ - ssh ${server} "killall -9 strongstore; rm -rf ${logdir}; mkdir -p /tmp/testdb; mkdir -p /tmp/testledger; rm -rf /tmp/testdb/*; rm -rf /tmp/testledger/*; rm -rf /tmp/qldb.store/" + ssh ${server} "killall -9 strongstore; rm -rf ${logdir}; mkdir -p /tmp/testdb; mkdir -p /tmp/testledger; rm -rf /tmp/testdb/*; rm -rf /tmp/testledger/*; rm -rf /tmp/qldb.store/; rm -rf /tmp/replica*.store;" done for client in `cat clients` diff --git a/ledger/common/db.h b/ledger/common/db.h index 8b440a7..898634d 100644 --- a/ledger/common/db.h +++ b/ledger/common/db.h @@ -40,7 +40,8 @@ class DB { } inline void CreateCache(const std::string& id, Chunk&& chunk) { - m_cache_.emplace(id, std::move(chunk)); + tbb::concurrent_hash_map::accessor a; + m_cache_.insert(a, std::make_pair(id, std::move(chunk))); } inline bool Get(const std::string& key, std::string* value) const { @@ -48,18 +49,15 @@ class DB { } inline Chunk* Get(const std::string& key) { - auto it = m_cache_.find(key); - if (it != m_cache_.end()) { - return &it->second; - } - rocksdb::PinnableSlice value; - if (db_->Get(rocksdb::ReadOptions(), db_->DefaultColumnFamily(), - rocksdb::Slice(key), &value).ok()) { - m_cache_.emplace(key, ToChunk(value)); + tbb::concurrent_hash_map::accessor a; + if (m_cache_.find(a, key)) return &(a->second); + std::string value; + if (db_->Get(rocksdb::ReadOptions(), key, &value).ok()) { + m_cache_.insert(a, std::make_pair(key, ToChunk(value))); } else { - m_cache_.emplace(key, Chunk()); + m_cache_.insert(a, std::make_pair(key, Chunk())); } - return &m_cache_[key]; + return &(a->second); } inline Chunk* Get(const Hash& key) { @@ -154,7 +152,7 @@ class DB { rocksdb::DB* db_; long total_; tbb::concurrent_hash_map cache_; - std::unordered_map m_cache_; + tbb::concurrent_hash_map m_cache_; }; } // namespace ledgebase diff --git a/ledger/qldb/qlnode.cc b/ledger/qldb/qlnode.cc index a6e2868..fdd9aa7 100644 --- a/ledger/qldb/qlnode.cc +++ b/ledger/qldb/qlnode.cc @@ -8,7 +8,7 @@ Chunk Document::Encode(const Slice& key, const Slice& val, const BlockAddress& addr, const MetaData& meta) { - auto ledger_nm_bytes = addr.ledger_name.len(); + auto ledger_nm_bytes = uint32_t(addr.ledger_name.len()); auto key_bytes = key.len(); auto entry_bytes = key.len() + val.len() + sizeof(uint32_t) * 2; size_t bytes = Document::fixed_length + key.len() + val.len()