17 .reserve(prefix.size() + key.size())
24 std::shared_ptr<storage::BufferStorage> storage)
25 : storage_(
std::move(storage)),
26 log_(log::
createLogger(
"OffchainPersistentStorage",
"offchain")) {
32 auto iKey = internalKey(key);
33 std::lock_guard lg(
mutex_);
34 return storage_->put(iKey, std::move(value));
39 auto iKey = internalKey(key);
40 std::lock_guard lg(
mutex_);
46 const std::optional<common::BufferView> &expected,
48 auto iKey = internalKey(key);
49 std::lock_guard lg(
mutex_);
50 OUTCOME_TRY(get_opt,
storage_->tryLoad(iKey));
52 std::optional<common::BufferView> existing;
53 if (get_opt.has_value()) {
54 existing = get_opt.value();
57 if ((not existing.has_value() and not expected.has_value())
58 or (existing.has_value() and expected.has_value()
59 and existing == expected)) {
60 OUTCOME_TRY(
storage_->put(iKey, std::move(value)));
68 auto iKey = internalKey(key);
Class represents arbitrary (including empty) byte buffer.
OffchainPersistentStorageImpl(std::shared_ptr< storage::BufferStorage > storage)
common::BufferView BufferView
outcome::result< void > clear(const common::BufferView &key) override
Remove a value from the local storage.
const common::Buffer kOffchainWorkerStoragePrefix
outcome::result< void > set(const common::BufferView &key, common::Buffer value) override
Sets a value in the storage.
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
outcome::result< bool > compare_and_set(const common::BufferView &key, const std::optional< common::BufferView > &expected, common::Buffer value) override
Sets a new value in the local storage if the condition matches the current value. ...
std::shared_ptr< storage::BufferStorage > storage_
outcome::result< common::Buffer > get(const common::BufferView &key) override
Gets a value from the local storage.
Logger createLogger(const std::string &tag)