fix:force close before unwatch

Signed-off-by: htt1997 <hutao105@huawei.com>
This commit is contained in:
htt1997 2024-08-01 18:18:34 +08:00
parent 54b97ea30f
commit 58a2c6130a
9 changed files with 12 additions and 14 deletions

View File

@ -147,7 +147,7 @@ public:
virtual int32_t UnregisterDetailProgressObserver() = 0;
virtual int32_t Close() = 0;
virtual int32_t Close(bool isForce = false) = 0;
virtual int32_t AddRef() = 0;

View File

@ -42,7 +42,7 @@ void AutoCache::Bind(std::shared_ptr<Executor> executor)
if (executor == nullptr || taskId_ != Executor::INVALID_TASK_ID) {
return;
}
executor_ = executor;
executor_ = std::move(executor);
}
AutoCache::AutoCache()
@ -226,8 +226,8 @@ AutoCache::Delegate::Delegate(GeneralStore *delegate, const Watchers &watchers,
AutoCache::Delegate::~Delegate()
{
if (store_ != nullptr) {
store_->Close(true);
store_->Unwatch(Origin::ORIGIN_ALL, *this);
store_->Close();
store_->Release();
store_ = nullptr;
}

View File

@ -241,14 +241,13 @@ bool KVDBGeneralStore::IsBound()
return isBound_;
}
int32_t KVDBGeneralStore::Close()
int32_t KVDBGeneralStore::Close(bool isForce)
{
std::unique_lock<decltype(rwMutex_)> lock(rwMutex_);
if (delegate_ == nullptr) {
return GeneralError::E_OK;
}
int32_t count = delegate_->GetTaskCount();
if (count > 0) {
if (!isForce && delegate_->GetTaskCount() > 0) {
return GeneralError::E_BUSY;
}
if (delegate_ != nullptr) {

View File

@ -66,7 +66,7 @@ public:
int32_t Unwatch(int32_t origin, Watcher &watcher) override;
int32_t RegisterDetailProgressObserver(DetailAsync async) override;
int32_t UnregisterDetailProgressObserver() override;
int32_t Close() override;
int32_t Close(bool isForce = false) override;
int32_t AddRef() override;
int32_t Release() override;
int32_t BindSnapshots(std::shared_ptr<std::map<std::string, std::shared_ptr<Snapshot>>> bindAssets) override;

View File

@ -204,14 +204,13 @@ bool RdbGeneralStore::IsBound()
return isBound_;
}
int32_t RdbGeneralStore::Close()
int32_t RdbGeneralStore::Close(bool isForce)
{
std::unique_lock<decltype(rwMutex_)> lock(rwMutex_);
if (delegate_ == nullptr) {
return 0;
}
int32_t count = delegate_->GetCloudSyncTaskCount();
if (count > 0) {
if (!isForce && delegate_->GetCloudSyncTaskCount() > 0) {
return GeneralError::E_BUSY;
}
auto status = manager_.CloseStore(delegate_);

View File

@ -76,7 +76,7 @@ public:
int32_t Unwatch(int32_t origin, Watcher &watcher) override;
int32_t RegisterDetailProgressObserver(DetailAsync async) override;
int32_t UnregisterDetailProgressObserver() override;
int32_t Close() override;
int32_t Close(bool isForce = false) override;
int32_t AddRef() override;
int32_t Release() override;
int32_t BindSnapshots(std::shared_ptr<std::map<std::string, std::shared_ptr<Snapshot>>> bindAssets) override;

View File

@ -62,7 +62,7 @@ int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &pr
}
MessageParcel reply;
MessageOption option;
MessageOption option(MessageOption::TF_ASYNC);
if (Remote()->SendRequest(
static_cast<uint32_t>(NotifierIFCode::RDB_NOTIFIER_CMD_DATA_CHANGE), data, reply, option) != 0) {
ZLOGE("storeName:%{public}s, send request failed", DistributedData::Anonymous::Change(origin.store).c_str());

View File

@ -104,7 +104,7 @@ int32_t GeneralStoreMock::UnregisterDetailProgressObserver()
return 0;
}
int32_t GeneralStoreMock::Close()
int32_t GeneralStoreMock::Close(bool isForce)
{
return 0;
}

View File

@ -43,7 +43,7 @@ public:
int32_t Unwatch(int32_t origin, Watcher &watcher) override;
int32_t RegisterDetailProgressObserver(DetailAsync async) override;
int32_t UnregisterDetailProgressObserver() override;
int32_t Close() override;
int32_t Close(bool isForce) override;
int32_t AddRef() override;
int32_t Release() override;
int32_t BindSnapshots(std::shared_ptr<std::map<std::string, std::shared_ptr<Snapshot>>> bindAssets) override;