mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 00:20:44 +00:00
!146 fix dms crash bug when db crashed
Merge pull request !146 from zhangmingxiang/0222
This commit is contained in:
commit
6e3f6ce848
@ -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);
|
||||
|
||||
|
@ -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_;
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user