From 691de9e25841c98958de818d4bf152568400a0e6 Mon Sep 17 00:00:00 2001 From: iceseer Date: Mon, 12 Sep 2022 22:00:22 +0300 Subject: [PATCH] filter key if cache is used for the key Signed-off-by: iceseer Signed-off-by: Alexander Lednev <57529355+iceseer@users.noreply.github.com> --- irohad/ametsuchi/impl/rocksdb_common.hpp | 34 +++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/irohad/ametsuchi/impl/rocksdb_common.hpp b/irohad/ametsuchi/impl/rocksdb_common.hpp index 861c5cf9b1c..f8ea25e1372 100644 --- a/irohad/ametsuchi/impl/rocksdb_common.hpp +++ b/irohad/ametsuchi/impl/rocksdb_common.hpp @@ -1021,19 +1021,18 @@ namespace iroha::ametsuchi { keyBuffer().clear(); fmt::format_to(keyBuffer(), fmtstring, std::forward(args)...); - if (!DatabaseCache::allowed( - std::string_view{keyBuffer().data(), keyBuffer().size()})) - return rocksdb::Status::InvalidArgument("Contains invalid symbols."); - valueBuffer().clear(); rocksdb::Slice const slice(keyBuffer().data(), keyBuffer().size()); - if (auto c = cache(); c && c->isCacheable(slice.ToStringView()) - && c->get(slice.ToStringView(), [&](auto const &str) { - valueBuffer() = str; - return true; - })) { - return rocksdb::Status(); + if (auto c = cache(); c && c->isCacheable(slice.ToStringView())) { + if (!DatabaseCache::allowed(slice.ToStringView())) + return rocksdb::Status::InvalidArgument("Contains invalid symbols."); + + if (c->get(slice.ToStringView(), [&](auto const &str) { + valueBuffer() = str; + return true; + })) + return rocksdb::Status(); } rocksdb::ReadOptions ro; @@ -1055,11 +1054,11 @@ namespace iroha::ametsuchi { keyBuffer().clear(); fmt::format_to(keyBuffer(), fmtstring, std::forward(args)...); - if (!DatabaseCache::allowed( - std::string_view{keyBuffer().data(), keyBuffer().size()})) + rocksdb::Slice const slice(keyBuffer().data(), keyBuffer().size()); + if (auto c = cache(); c && c->isCacheable(slice.ToStringView()) + && !DatabaseCache::allowed(slice.ToStringView())) return rocksdb::Status::InvalidArgument("Contains invalid symbols."); - rocksdb::Slice const slice(keyBuffer().data(), keyBuffer().size()); auto status = transaction()->Put(getHandle(cf_type), slice, valueBuffer()); @@ -1077,13 +1076,12 @@ namespace iroha::ametsuchi { keyBuffer().clear(); fmt::format_to(keyBuffer(), fmtstring, std::forward(args)...); - if (!DatabaseCache::allowed( - std::string_view{keyBuffer().data(), keyBuffer().size()})) - return rocksdb::Status::InvalidArgument("Contains invalid symbols."); - rocksdb::Slice const slice(keyBuffer().data(), keyBuffer().size()); - if (auto c = cache(); c && c->isCacheable(slice.ToStringView())) + if (auto c = cache(); c && c->isCacheable(slice.ToStringView())) { + if (!DatabaseCache::allowed(slice.ToStringView())) + return rocksdb::Status::InvalidArgument("Contains invalid symbols."); c->erase(slice.ToStringView()); + } return transaction()->Delete(getHandle(cf_type), slice); }