已合并
getfilehandles async #2214
rainlost创建于 7月21日
getfilehandles async #2214
已合并
共 2 个文件变更+61-33
| @@ -382,6 +382,9 @@ public: | |||
| 382 | ErrCode SendFileHandle(const std::string &bundleName, const std::string &fileName); | 382 | ErrCode SendFileHandle(const std::string &bundleName, const std::string &fileName); |
| 383 | ErrCode SendIncrementalFileHandle(const std::string &bundleName, const std::string &fileName); | 383 | ErrCode SendIncrementalFileHandle(const std::string &bundleName, const std::string &fileName); |
| 384 | ErrCode SendIncrementalFileHandles(const std::string &bundleName, const vector<std::string> &fileNames); | 384 | ErrCode SendIncrementalFileHandles(const std::string &bundleName, const vector<std::string> &fileNames); |
| 385 | + std::function<void()> CreateIncrementalFileHandlesTask(const std::string &bundleName, | ||
| 386 | + const std::vector<std::string> &fileNames, | ||
| 387 | + sptr<IExtension> proxy); | ||
| 385 | void SetExtOnRelease(const BundleName &bundleName, bool isOnRelease); | 388 | void SetExtOnRelease(const BundleName &bundleName, bool isOnRelease); |
| 386 | void RemoveExtOnRelease(const BundleName &bundleName); | 389 | void RemoveExtOnRelease(const BundleName &bundleName); |
| 387 | void ClearAndNoticeClient(const std::string &bundleName, ErrCode errCode, bool checkRestoreEnd = true); | 390 | void ClearAndNoticeClient(const std::string &bundleName, ErrCode errCode, bool checkRestoreEnd = true); |
| @@ -484,6 +487,8 @@ public: | |||
| 484 | logElapsed("getDataSizeThreadPool_.Start"); | 487 | logElapsed("getDataSizeThreadPool_.Start"); |
| 485 | callbackScannedInfoThreadPool_.Start(BConstants::SA_THREAD_POOL_COUNT); | 488 | callbackScannedInfoThreadPool_.Start(BConstants::SA_THREAD_POOL_COUNT); |
| 486 | logElapsed("callbackScannedInfoThreadPool_.Start"); | 489 | logElapsed("callbackScannedInfoThreadPool_.Start"); |
| 490 | + getFileHandlesThreadPool_.Start(BConstants::SA_THREAD_POOL_COUNT); | ||
| 491 | + logElapsed("getFileHandlesThreadPool_.Start"); | ||
| 487 | session_ = sptr<SvcSessionManager>(new SvcSessionManager(wptr(this))); | 492 | session_ = sptr<SvcSessionManager>(new SvcSessionManager(wptr(this))); |
| 488 | logElapsed("SvcSessionManager construct"); | 493 | logElapsed("SvcSessionManager construct"); |
| 489 | disposal_ = make_shared<BJsonDisposalConfig>(); | 494 | disposal_ = make_shared<BJsonDisposalConfig>(); |
| @@ -505,6 +510,7 @@ public: | |||
| 505 | sendScannendResultThreadPool_.Stop(); | 510 | sendScannendResultThreadPool_.Stop(); |
| 506 | getDataSizeThreadPool_.Stop(); | 511 | getDataSizeThreadPool_.Stop(); |
| 507 | callbackScannedInfoThreadPool_.Stop(); | 512 | callbackScannedInfoThreadPool_.Stop(); |
| 513 | + getFileHandlesThreadPool_.Stop(); | ||
| 508 | }; | 514 | }; |
| 509 | 515 | ||
| 510 | private: | 516 | private: |
| @@ -938,6 +944,7 @@ public: | |||
| 938 | std::unique_ptr<DefaultAppManager> defaultAppManager_; | 944 | std::unique_ptr<DefaultAppManager> defaultAppManager_; |
| 939 | RestoreTypeEnum restoreType_ = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; | 945 | RestoreTypeEnum restoreType_ = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND; |
| 940 | std::string oldBackupVersion_ = ""; | 946 | std::string oldBackupVersion_ = ""; |
| 947 | + OHOS::ThreadPool getFileHandlesThreadPool_; | ||
| 941 | }; | 948 | }; |
| 942 | } // namespace OHOS::FileManagement::Backup | 949 | } // namespace OHOS::FileManagement::Backup |
| 943 | 950 | ||
| @@ -954,43 +954,64 @@ ErrCode Service::SendIncrementalFileHandles(const std::string &bundleName, const | |||
| 954 | HILOGE("SendIncrementalFileHandles failed, bundleName:%{public}s", bundleName.c_str()); | 954 | HILOGE("SendIncrementalFileHandles failed, bundleName:%{public}s", bundleName.c_str()); |
| 955 | return BError(BError::Codes::SA_INVAL_ARG); | 955 | return BError(BError::Codes::SA_INVAL_ARG); |
| 956 | } | 956 | } |
| 957 | - | 957 | + auto task = CreateIncrementalFileHandlesTask(bundleName, fileNames, proxy); |
| 958 | - std::vector<std::string> saFileNames; | 958 | + getFileHandlesThreadPool_.AddTask([task]() { |
| 959 | - std::vector<std::string> extFileNames; | 959 | + try { |
| 960 | - for (const auto &fileName : fileNames) { | 960 | + task(); |
| 961 | - if (StringUtils::IsAncoFile(fileName)) { | 961 | + } catch (...) { |
| 962 | - saFileNames.push_back(fileName); | 962 | + HILOGE("Failed to add task to thread pool"); |
| 963 | - } else { | ||
| 964 | - extFileNames.push_back(fileName); | ||
| 965 | } | 963 | } |
| 966 | - } | 964 | + }); |
| 967 | - | ||
| 968 | - std::vector<std::string> finalFileNames; | ||
| 969 | - std::vector<FileOpenResult> openResults; | ||
| 970 | - ErrCode finalErr = ERR_OK; | ||
| 971 | - if (!saFileNames.empty()) { | ||
| 972 | - auto err = SendIncrementalFileHandlesByEnhance(bundleName, saFileNames, openResults); | ||
| 973 | - finalFileNames = std::move(saFileNames); | ||
| 974 | - finalErr = err == ERR_OK ? finalErr : err; | ||
| 975 | - } | ||
| 976 | - if (!extFileNames.empty()) { | ||
| 977 | - std::vector<FileOpenResult> extOpenResults; | ||
| 978 | - proxy->GetIncrementalFileHandles(extFileNames, extOpenResults); | ||
| 979 | - finalFileNames.insert(finalFileNames.end(), extFileNames.begin(), extFileNames.end()); | ||
| 980 | - openResults.insert(openResults.end(), extOpenResults.begin(), extOpenResults.end()); | ||
| 981 | - } | ||
| 982 | - | ||
| 983 | - auto err = AppIncrementalFileReadys(bundleName, finalFileNames, openResults); | ||
| 984 | - finalErr = err == ERR_OK ? finalErr : err; | ||
| 985 | - | ||
| 986 | - if (finalErr != ERR_OK) { | ||
| 987 | - AppRadar::Info info(bundleName, "", ""); | ||
| 988 | - AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandles", GetUserIdDefault(), | ||
| 989 | - BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, finalErr); | ||
| 990 | - } | ||
| 991 | return BError(BError::Codes::OK); | 965 | return BError(BError::Codes::OK); |
| 992 | } | 966 | } |
| 993 | 967 | ||
| 968 | +std::function<void()> Service::CreateIncrementalFileHandlesTask(const std::string &bundleName, | ||
| 969 | + const std::vector<std::string> &fileNames, | ||
| 970 | + sptr<IExtension> proxy) | ||
| 971 | +{ | ||
| 972 | + return [obj {wptr<Service>(this)}, bundleName, fileNames, proxyObj {wptr<IExtension>(proxy)}]() { | ||
| 973 | + HILOGI("Start GetIncrementalFileHandles Task, bundleName:%{public}s, size:%{public}zu", bundleName.c_str(), | ||
| 974 | + fileNames.size()); | ||
| 975 | + auto ptr = obj.promote(); | ||
| 976 | + auto proxyPtr = proxyObj.promote(); | ||
| 977 | + if (ptr == nullptr || proxyPtr == nullptr) { | ||
| 978 | + HILOGE("ptr is nullptr"); | ||
| 979 | + return; | ||
| 980 | + } | ||
| 981 | + std::vector<std::string> saFileNames; | ||
| 982 | + std::vector<std::string> extFileNames; | ||
| 983 | + for (const auto &fileName : fileNames) { | ||
| 984 | + if (StringUtils::IsAncoFile(fileName)) { | ||
| 985 | + saFileNames.push_back(fileName); | ||
| 986 | + } else { | ||
| 987 | + extFileNames.push_back(fileName); | ||
| 988 | + } | ||
| 989 | + } | ||
| 990 | + std::vector<std::string> finalFileNames; | ||
| 991 | + std::vector<FileOpenResult> openResults; | ||
| 992 | + ErrCode finalErr = ERR_OK; | ||
| 993 | + if (!saFileNames.empty()) { | ||
| 994 | + auto err = ptr->SendIncrementalFileHandlesByEnhance(bundleName, saFileNames, openResults); | ||
| 995 | + finalFileNames = std::move(saFileNames); | ||
| 996 | + finalErr = err == ERR_OK ? finalErr : err; | ||
| 997 | + } | ||
| 998 | + if (!extFileNames.empty()) { | ||
| 999 | + std::vector<FileOpenResult> extOpenResults; | ||
| 1000 | + proxyPtr->GetIncrementalFileHandles(extFileNames, extOpenResults); | ||
| 1001 | + finalFileNames.insert(finalFileNames.end(), extFileNames.begin(), extFileNames.end()); | ||
| 1002 | + openResults.insert(openResults.end(), extOpenResults.begin(), extOpenResults.end()); | ||
| 1003 | + } | ||
| 1004 | + auto err = ptr->AppIncrementalFileReadys(bundleName, finalFileNames, openResults); | ||
| 1005 | + finalErr = err == ERR_OK ? finalErr : err; | ||
| 1006 | + if (finalErr != ERR_OK) { | ||
| 1007 | + AppRadar::Info info(bundleName, "", ""); | ||
| 1008 | + AppRadar::GetInstance().RecordRestoreFuncRes(info, "Service::GetIncrementalFileHandles", | ||
| 1009 | + ptr->GetUserIdDefault(), | ||
| 1010 | + BizStageRestore::BIZ_STAGE_GET_FILE_HANDLE_FAIL, finalErr); | ||
| 1011 | + } | ||
| 1012 | + }; | ||
| 1013 | +} | ||
| 1014 | + | ||
| 994 | ErrCode Service::SendIncrementalFileHandlesByEnhance(const std::string &bundleName, | 1015 | ErrCode Service::SendIncrementalFileHandlesByEnhance(const std::string &bundleName, |
| 995 | const vector<std::string> &fileNames, | 1016 | const vector<std::string> &fileNames, |
| 996 | std::vector<FileOpenResult> &openResults) | 1017 | std::vector<FileOpenResult> &openResults) |