!2338 添加search触发事件

Merge pull request !2338 from wangjiaqiang/master
This commit is contained in:
openharmony_ci 2024-10-13 11:27:30 +00:00 committed by Gitee
commit f69a2df6d6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 43 additions and 22 deletions

View File

@ -38,6 +38,7 @@ public:
DATA_SYNC,
LOCK_CLOUD_CONTAINER,
UNLOCK_CLOUD_CONTAINER,
SET_SEARCH_TRIGGER,
CLOUD_BUTT
};

View File

@ -23,10 +23,11 @@ class API_EXPORT SetSearchableEvent : public CloudEvent {
public:
struct EventInfo {
bool isSearchable;
bool isRebuild;
};
SetSearchableEvent(StoreInfo storeInfo, EventInfo evtInfo)
: CloudEvent(SET_SEARCHABLE, std::move(storeInfo)), info_(std::move(evtInfo))
SetSearchableEvent(StoreInfo storeInfo, EventInfo evtInfo, int32_t evtId = SET_SEARCHABLE)
: CloudEvent(evtId, std::move(storeInfo)), info_(std::move(evtInfo))
{
}
@ -36,6 +37,11 @@ public:
{
return info_.isSearchable;
}
bool GetIsRebuild() const
{
return info_.isRebuild;
}
private:
EventInfo info_;
};

View File

@ -132,7 +132,7 @@ public:
const std::vector<std::string> &tables, int type, const std::vector<Reference> &references) = 0;
virtual int32_t SetTrackerTable(const std::string &tableName, const std::set<std::string> &trackerColNames,
const std::string &extendColName) = 0;
const std::string &extendColName, bool isForceUpgrade) = 0;
virtual int32_t Insert(const std::string &table, VBuckets &&values) = 0;

View File

@ -556,8 +556,8 @@ int32_t KVDBGeneralStore::SetDistributedTables(
return GeneralError::E_OK;
}
int32_t KVDBGeneralStore::SetTrackerTable(
const std::string &tableName, const std::set<std::string> &trackerColNames, const std::string &extendColName)
int32_t KVDBGeneralStore::SetTrackerTable(const std::string &tableName, const std::set<std::string> &trackerColNames,
const std::string &extendColName, bool isForceUpgrade)
{
return GeneralError::E_OK;
}

View File

@ -50,7 +50,7 @@ public:
int32_t SetDistributedTables(
const std::vector<std::string> &tables, int32_t type, const std::vector<Reference> &references) override;
int32_t SetTrackerTable(const std::string &tableName, const std::set<std::string> &trackerColNames,
const std::string &extendColName) override;
const std::string &extendColName, bool isForceUpgrade = false) override;
int32_t Insert(const std::string &table, VBuckets &&values) override;
int32_t Update(const std::string &table, const std::string &setSql, Values &&values, const std::string &whereSql,
Values &&conditions) override;

View File

@ -812,8 +812,8 @@ int32_t RdbGeneralStore::SetDistributedTables(const std::vector<std::string> &ta
return GeneralError::E_OK;
}
int32_t RdbGeneralStore::SetTrackerTable(
const std::string &tableName, const std::set<std::string> &trackerColNames, const std::string &extendColName)
int32_t RdbGeneralStore::SetTrackerTable(const std::string &tableName, const std::set<std::string> &trackerColNames,
const std::string &extendColName, bool isForceUpgrade)
{
std::shared_lock<decltype(rwMutex_)> lock(rwMutex_);
if (delegate_ == nullptr) {
@ -821,7 +821,7 @@ int32_t RdbGeneralStore::SetTrackerTable(
Anonymous::Change(storeInfo_.storeName).c_str(), Anonymous::Change(tableName).c_str());
return GeneralError::E_ALREADY_CLOSED;
}
auto status = delegate_->SetTrackerTable({ tableName, extendColName, trackerColNames });
auto status = delegate_->SetTrackerTable({ tableName, extendColName, trackerColNames, isForceUpgrade });
if (status == DBStatus::WITH_INVENTORY_DATA) {
ZLOGI("Set tracker table with inventory data, database:%{public}s, tables name:%{public}s",
Anonymous::Change(storeInfo_.storeName).c_str(), Anonymous::Change(tableName).c_str());

View File

@ -62,7 +62,7 @@ public:
int32_t SetDistributedTables(const std::vector<std::string> &tables, int32_t type,
const std::vector<Reference> &references) override;
int32_t SetTrackerTable(const std::string& tableName, const std::set<std::string>& trackerColNames,
const std::string& extendColName) override;
const std::string& extendColName, bool isForceUpgrade = false) override;
int32_t Insert(const std::string &table, VBuckets &&values) override;
int32_t Update(const std::string &table, const std::string &setSql, Values &&values, const std::string &whereSql,
Values &&conditions) override;

View File

@ -26,7 +26,6 @@
#include "cloud/make_query_event.h"
#include "cloud/schema_meta.h"
#include "commonevent/data_change_event.h"
#include "commonevent/set_searchable_event.h"
#include "communicator/device_manager_adapter.h"
#include "crypto_manager.h"
#include "device_matrix.h"
@ -279,13 +278,18 @@ std::shared_ptr<DistributedData::GeneralStore> RdbServiceImpl::GetStore(const Rd
}
int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam &param, const std::vector<std::string> &tables,
const std::vector<Reference> &references, int32_t type)
const std::vector<Reference> &references, bool isRebuild, int32_t type)
{
if (!CheckAccess(param.bundleName_, param.storeName_)) {
ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(),
Anonymous::Change(param.storeName_).c_str());
return RDB_ERROR;
}
if (type == DistributedRdb::DistributedTableType::DISTRIBUTED_SEARCH) {
DistributedData::SetSearchableEvent::EventInfo eventInfo;
eventInfo.isRebuild = isRebuild;
return PostSearchEvent(CloudEvent::SET_SEARCH_TRIGGER, param, eventInfo);
}
auto meta = GetStoreMetaData(param);
if (type == DistributedRdb::DistributedTableType::DISTRIBUTED_DEVICE) {
@ -1124,6 +1128,14 @@ int32_t RdbServiceImpl::SetSearchable(const RdbSyncerParam& param, bool isSearch
Anonymous::Change(param.storeName_).c_str());
return RDB_ERROR;
}
SetSearchableEvent::EventInfo eventInfo;
eventInfo.isSearchable = isSearchable;
return PostSearchEvent(CloudEvent::SET_SEARCHABLE, param, eventInfo);
}
int32_t RdbServiceImpl::PostSearchEvent(int32_t evtId, const RdbSyncerParam& param,
SetSearchableEvent::EventInfo &eventInfo)
{
StoreInfo storeInfo;
storeInfo.tokenId = IPCSkeleton::GetCallingTokenID();
storeInfo.bundleName = param.bundleName_;
@ -1133,11 +1145,8 @@ int32_t RdbServiceImpl::SetSearchable(const RdbSyncerParam& param, bool isSearch
storeInfo.user = user;
storeInfo.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid;
SetSearchableEvent::EventInfo eventInfo;
eventInfo.isSearchable = isSearchable;
auto evt = std::make_unique<SetSearchableEvent>(std::move(storeInfo), std::move(eventInfo));
auto evt = std::make_unique<SetSearchableEvent>(std::move(storeInfo), std::move(eventInfo), evtId);
EventCenter::GetInstance().PostEvent(std::move(evt));
return RDB_OK;
}

View File

@ -21,6 +21,7 @@
#include <string>
#include "cloud/cloud_event.h"
#include "commonevent/set_searchable_event.h"
#include "concurrent_map.h"
#include "feature/static_acts.h"
#include "metadata/secret_key_meta_data.h"
@ -53,7 +54,7 @@ public:
int32_t InitNotifier(const RdbSyncerParam &param, sptr<IRemoteObject> notifier) override;
int32_t SetDistributedTables(const RdbSyncerParam &param, const std::vector<std::string> &tables,
const std::vector<Reference> &references, int32_t type = DISTRIBUTED_DEVICE) override;
const std::vector<Reference> &references, bool isRebuild, int32_t type = DISTRIBUTED_DEVICE) override;
std::pair<int32_t, std::shared_ptr<ResultSet>> RemoteQuery(const RdbSyncerParam& param, const std::string& device,
const std::string& sql, const std::vector<std::string>& selectionArgs) override;
@ -200,6 +201,9 @@ private:
int32_t SaveDebugInfo(const StoreMetaData &metaData, const RdbSyncerParam &param);
int32_t PostSearchEvent(int32_t evtId, const RdbSyncerParam& param,
DistributedData::SetSearchableEvent::EventInfo &eventInfo);
static Factory factory_;
ConcurrentMap<uint32_t, SyncAgents> syncAgents_;
std::shared_ptr<ExecutorPool> executors_;

View File

@ -113,13 +113,14 @@ int32_t RdbServiceStub::OnRemoteSetDistributedTables(MessageParcel &data, Messag
std::vector<std::string> tables;
std::vector<Reference> references;
int32_t type;
if (!ITypesUtil::Unmarshal(data, param, tables, references, type)) {
bool isRebuild;
if (!ITypesUtil::Unmarshal(data, param, tables, references, type, isRebuild)) {
ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables size:%{public}zu type:%{public}d",
param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), tables.size(), type);
return IPC_STUB_INVALID_DATA_ERR;
}
auto status = SetDistributedTables(param, tables, references, type);
auto status = SetDistributedTables(param, tables, references, isRebuild, type);
if (!ITypesUtil::Marshal(reply, status)) {
ZLOGE("Marshal status:0x%{public}x", status);
return IPC_STUB_WRITE_PARCEL_ERR;

View File

@ -37,8 +37,8 @@ int32_t GeneralStoreMock::SetDistributedTables(
return 0;
}
int32_t GeneralStoreMock::SetTrackerTable(
const std::string &tableName, const std::set<std::string> &trackerColNames, const std::string &extendColName)
int32_t GeneralStoreMock::SetTrackerTable(const std::string &tableName,
const std::set<std::string> &trackerColNames, const std::string &extendColName, bool isForceUpgrade)
{
return 0;
}

View File

@ -28,7 +28,7 @@ public:
int32_t SetDistributedTables(
const std::vector<std::string> &tables, int32_t type, const std::vector<Reference> &references) override;
int32_t SetTrackerTable(const std::string &tableName, const std::set<std::string> &trackerColNames,
const std::string &extendColName) override;
const std::string &extendColName, bool isForceUpgrade = false) override;
int32_t Insert(const std::string &table, VBuckets &&values) override;
int32_t Update(const std::string &table, const std::string &setSql, Values &&values, const std::string &whereSql,
Values &&conditions) override;