!146 fix dms crash bug when db crashed

Merge pull request !146 from zhangmingxiang/0222
This commit is contained in:
openharmony_ci 2022-02-23 06:48:42 +00:00 committed by Gitee
commit 6e3f6ce848
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 45 additions and 10 deletions

View File

@ -31,7 +31,7 @@ namespace OHOS {
namespace DistributedSchedule {
class DistributedDataStorage {
public:
DistributedDataStorage() = default;
DistributedDataStorage();
~DistributedDataStorage() = default;
/**
@ -86,6 +86,8 @@ public:
*/
bool Query(const std::string& networkId, int32_t missionId, DistributedKv::Value& value) const;
void NotifyRemoteDied(const wptr<IRemoteObject>& remote);
private:
bool InitKvDataService();
bool WaitKvDataService();
@ -98,7 +100,7 @@ private:
bool DeleteInnerLocked(const std::string& uuid, int32_t missionId);
bool FuzzyDeleteInnerLocked(const std::string& networkId);
bool QueryInnerLocked(const std::string& uuid, int32_t missionId, DistributedKv::Value& value) const;
void InitHandler();
bool InitHandler();
static void GenerateKey(const std::string& uuid, int32_t missionId, DistributedKv::Key& key);
static void GenerateValue(const uint8_t* byteStream, size_t len, DistributedKv::Value& value);

View File

@ -117,6 +117,7 @@ public:
void NotifyMissionSnapshotCreated(int32_t missionId);
void NotifyMissionSnapshotChanged(int32_t missionId);
void NotifyMissionSnapshotDestroyed(int32_t missionId);
void NotifyRemoteDied(const wptr<IRemoteObject>& remote);
private:
std::map<std::string, std::shared_ptr<AppExecFwk::EventHandler>> deviceHandle_;
mutable std::mutex remoteMissionInfosLock_;

View File

@ -39,17 +39,24 @@ constexpr int32_t RETRY_TIMES_WAIT_KV_DATA = 30;
constexpr int32_t RETRY_TIMES_GET_KVSTORE = 5;
}
DistributedDataStorage::DistributedDataStorage()
{
appId_.appId = APP_ID;
storeId_.storeId = STORE_ID;
}
bool DistributedDataStorage::Init()
{
HILOGD("begin.");
kvStoreDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new KvStoreDeathRecipient());
appId_.appId = APP_ID;
storeId_.storeId = STORE_ID;
InitHandler();
if (dmsDataStorageHandler_ == nullptr) {
if (kvStoreDeathRecipient_ == nullptr) {
kvStoreDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new KvStoreDeathRecipient());
}
bool ret = InitHandler();
if (!ret) {
HILOGE("InitHandler failed!");
return false;
}
bool ret = InitKvDataService();
ret = InitKvDataService();
if (!ret) {
HILOGE("InitKvDataService failed!");
return false;
@ -165,12 +172,25 @@ void DistributedDataStorage::SubscribeDistributedDataStorage()
}
}
void DistributedDataStorage::InitHandler()
bool DistributedDataStorage::InitHandler()
{
if (dmsDataStorageHandler_ == nullptr) {
shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("dmsDataStorageHandler");
dmsDataStorageHandler_ = make_shared<AppExecFwk::EventHandler>(runner);
}
if (dmsDataStorageHandler_ == nullptr) {
HILOGW("dmsDataStorageHandler_ is null!");
return false;
}
return true;
}
void DistributedDataStorage::NotifyRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGD("begin.");
if (kvStoreDeathRecipient_ != nullptr) {
remote->RemoveDeathRecipient(kvStoreDeathRecipient_);
}
}
bool DistributedDataStorage::Stop()

View File

@ -156,9 +156,20 @@ bool DistributedSchedMissionManager::IsDeviceIdValidated(const std::string& devi
return true;
}
void DistributedSchedMissionManager::NotifyRemoteDied(const wptr<IRemoteObject>& remote)
{
if (distributedDataStorage_ == nullptr) {
HILOGE("DistributedDataStorage null!");
return;
}
distributedDataStorage_->NotifyRemoteDied(remote);
}
int32_t DistributedSchedMissionManager::InitDataStorage()
{
distributedDataStorage_ = std::make_shared<DistributedDataStorage>();
if (distributedDataStorage_ == nullptr) {
distributedDataStorage_ = std::make_shared<DistributedDataStorage>();
}
if (!distributedDataStorage_->Init()) {
HILOGE("InitDataStorage DistributedDataStorage init failed!");
return ERR_NULL_OBJECT;

View File

@ -27,6 +27,7 @@ const std::string TAG = "KvStoreDeathRecipient";
void KvStoreDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGD("called.");
DistributedSchedMissionManager::GetInstance().NotifyRemoteDied(remote);
DistributedSchedMissionManager::GetInstance().InitDataStorage();
}
} // namespace DistributedSchedule