Skip to content

Commit

Permalink
filter key if cache is used for the key
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
Signed-off-by: Alexander Lednev <[email protected]>
  • Loading branch information
iceseer committed Sep 12, 2022
1 parent 6f50064 commit 691de9e
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions irohad/ametsuchi/impl/rocksdb_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,19 +1021,18 @@ namespace iroha::ametsuchi {
keyBuffer().clear();
fmt::format_to(keyBuffer(), fmtstring, std::forward<Args>(args)...);

if (!DatabaseCache<std::string>::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<std::string>::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;
Expand All @@ -1055,11 +1054,11 @@ namespace iroha::ametsuchi {
keyBuffer().clear();
fmt::format_to(keyBuffer(), fmtstring, std::forward<Args>(args)...);

if (!DatabaseCache<std::string>::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<std::string>::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());

Expand All @@ -1077,13 +1076,12 @@ namespace iroha::ametsuchi {
keyBuffer().clear();
fmt::format_to(keyBuffer(), fmtstring, std::forward<Args>(args)...);

if (!DatabaseCache<std::string>::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<std::string>::allowed(slice.ToStringView()))
return rocksdb::Status::InvalidArgument("Contains invalid symbols.");
c->erase(slice.ToStringView());
}

return transaction()->Delete(getHandle(cf_type), slice);
}
Expand Down

0 comments on commit 691de9e

Please sign in to comment.