diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 32edf1eed..f654f9036 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -114,6 +114,9 @@ class BinlogKeyValue : public KeyValueSyncInterface { void close() { *this = BinlogKeyValue(); } + void close(td::Promise<> promise) override { + binlog_->close(std::move(promise)); + } SeqNo set(string key, string value) override { auto lock = rw_mutex_.lock_write().move_as_ok(); diff --git a/tddb/td/db/KeyValueSyncInterface.h b/tddb/td/db/KeyValueSyncInterface.h index 272adbcf5..f9f92f465 100644 --- a/tddb/td/db/KeyValueSyncInterface.h +++ b/tddb/td/db/KeyValueSyncInterface.h @@ -43,6 +43,8 @@ class KeyValueSyncInterface { virtual void erase_by_prefix(Slice prefix) = 0; virtual void force_sync(Promise<> &&promise) = 0; + + virtual void close(Promise<> promise) = 0; }; } // namespace td diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp index 364e51d0a..a6b9bbc8e 100644 --- a/tddb/td/db/TQueue.cpp +++ b/tddb/td/db/TQueue.cpp @@ -234,6 +234,11 @@ class TQueueImpl : public TQueue { return do_get(queue_id, q, q.events.front().event_id, true, Time::now(), span); } + void close(td::Promise<> promise) override { + callback_->close(std::move(promise)); + callback_ = nullptr; + } + private: struct Queue { EventId tail_id; @@ -436,6 +441,11 @@ Status TQueueBinlog::replay(const BinlogEvent &binlog_event, TQueue &q) return Status::OK(); } +template +void TQueueBinlog::close(td::Promise<> promise) { + binlog_->close(std::move(promise)); +} + template class TQueueBinlog; template class TQueueBinlog; @@ -457,5 +467,8 @@ void TQueueMemoryStorage::replay(TQueue &q) const { CHECK(is_added); } } +void TQueueMemoryStorage::close(td::Promise<> promise) { + promise.set_value({}); +} } // namespace td diff --git a/tddb/td/db/TQueue.h b/tddb/td/db/TQueue.h index 1d9e901af..f7e90adc2 100644 --- a/tddb/td/db/TQueue.h +++ b/tddb/td/db/TQueue.h @@ -12,6 +12,8 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" +#include "td/actor/PromiseFuture.h" + #include #include #include @@ -81,6 +83,7 @@ class TQueue { virtual uint64 push(QueueId queue_id, const RawEvent &event) = 0; virtual void pop(uint64 logevent_id) = 0; + virtual void close(td::Promise<> promise) = 0; }; static unique_ptr create(); @@ -111,6 +114,7 @@ class TQueue { virtual size_t get_size(QueueId queue_id) = 0; virtual void run_gc(double now) = 0; + virtual void close(td::Promise<> promise) = 0; }; StringBuilder &operator<<(StringBuilder &string_builder, const TQueue::EventId id); @@ -129,6 +133,7 @@ class TQueueBinlog : public TQueue::StorageCallback { void set_binlog(std::shared_ptr binlog) { binlog_ = std::move(binlog); } + virtual void close(td::Promise<> promise) override; private: std::shared_ptr binlog_; @@ -141,6 +146,7 @@ class TQueueMemoryStorage : public TQueue::StorageCallback { uint64 push(QueueId queue_id, const RawEvent &event) override; void pop(uint64 logevent_id) override; void replay(TQueue &q) const; + virtual void close(td::Promise<> promise) override; private: uint64 next_logevent_id_{1}; diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index dc4229f13..5f8784eda 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -293,6 +293,11 @@ Status Binlog::close(bool need_sync) { return Status::OK(); } +void Binlog::close(td::Promise<> promise) { + TRY_STATUS_PROMISE(promise, close()); + promise.set_value({}); +} + void Binlog::change_key(DbKey new_db_key) { db_key_ = std::move(new_db_key); aes_ctr_key_salt_ = BufferSlice(); diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index f5197b7ec..f3af3dfb4 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -21,6 +21,8 @@ #include "td/utils/StorerBase.h" #include "td/utils/UInt.h" +#include "td/actor/PromiseFuture.h" + #include namespace td { @@ -103,6 +105,7 @@ class Binlog { void change_key(DbKey new_db_key); Status close(bool need_sync = true) TD_WARN_UNUSED_RESULT; + void close(td::Promise<>); Status close_and_destroy() TD_WARN_UNUSED_RESULT; static Status destroy(Slice path) TD_WARN_UNUSED_RESULT;