1 Star 0 Fork 0

廖永煌/lyh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0506_3.diff 219.81 KB
一键复制 编辑 原始数据 按行查看 历史
廖永煌 提交于 2025-05-10 09:29 +08:00 . 1
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a70dc8a01..ff1d2789f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -321,7 +321,8 @@ endif()
set(DB_PATH ${PROJECT_SOURCE_DIR}/frameworks/libs/distributeddb)
-add_executable(distributed_ut ${DISTRIBUTEDDB_SRC} ${SECUREC_SRC} ${SQLITE_SRC})
+add_executable(distributed_ut ${DISTRIBUTEDDB_SRC} ${SECUREC_SRC} ${SQLITE_SRC}
+ frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_multi_user_sync_test.cpp)
target_link_libraries(
distributed_ut
diff --git a/frameworks/libs/distributeddb/communicator/include/icommunicator.h b/frameworks/libs/distributeddb/communicator/include/icommunicator.h
index 4b73ab326..e85fae308 100644
--- a/frameworks/libs/distributeddb/communicator/include/icommunicator.h
+++ b/frameworks/libs/distributeddb/communicator/include/icommunicator.h
@@ -26,7 +26,7 @@
namespace DistributedDB {
// inMsg is heap memory, its ownership transfers by calling OnMessageCallback
-using OnMessageCallback = std::function<void(const std::string &srcTarget, Message *inMsg)>;
+using OnMessageCallback = std::function<void(const std::string &srcTarget, const std::string userId, Message *inMsg)>;
constexpr uint32_t SEND_TIME_OUT = 3000; // 3s
struct SendConfig {
@@ -36,7 +36,7 @@ struct SendConfig {
ExtendInfo paramInfo;
};
-inline void SetSendConfigParam(const DBProperties &dbProperty, const std::string &dstTarget, bool nonBlock,
+inline void SetSendConfigParam(const DBProperties &dbProperty, const DeviceSyncTarget &dstTarget, bool nonBlock,
uint32_t timeout, SendConfig &sendConf)
{
sendConf.nonBlock = nonBlock;
@@ -46,7 +46,8 @@ inline void SetSendConfigParam(const DBProperties &dbProperty, const std::string
sendConf.paramInfo.appId = dbProperty.GetStringProp(DBProperties::APP_ID, "");
sendConf.paramInfo.userId = dbProperty.GetStringProp(DBProperties::USER_ID, "");
sendConf.paramInfo.storeId = dbProperty.GetStringProp(DBProperties::STORE_ID, "");
- sendConf.paramInfo.dstTarget = dstTarget;
+ sendConf.paramInfo.dstTarget = dstTarget.device;
+ sendConf.paramInfo.targetUserId = dstTarget.userId;
sendConf.paramInfo.subUserId = dbProperty.GetStringProp(DBProperties::SUB_USER, "");
}
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator.cpp b/frameworks/libs/distributeddb/communicator/src/communicator.cpp
index 608adaf91..027424553 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator.cpp
+++ b/frameworks/libs/distributeddb/communicator/src/communicator.cpp
@@ -144,7 +144,7 @@ int Communicator::SendMessage(const std::string &dstTarget, const Message *inMsg
return errCode;
}
-void Communicator::OnBufferReceive(const std::string &srcTarget, const SerialBuffer *inBuf)
+void Communicator::OnBufferReceive(const std::string &srcTarget, const std::string &userId, const SerialBuffer *inBuf)
{
std::lock_guard<std::mutex> messageHandleLockGuard(messageHandleMutex_);
if (srcTarget.size() != 0 && inBuf != nullptr && onMessageHandle_) {
@@ -166,7 +166,7 @@ void Communicator::OnBufferReceive(const std::string &srcTarget, const SerialBuf
return;
}
LOGI("[Comm][Receive] label=%.3s, srcTarget=%s{private}.", VEC_TO_STR(commLabel_), srcTarget.c_str());
- onMessageHandle_(srcTarget, message);
+ onMessageHandle_(srcTarget, userId, message);
} else {
LOGE("[Comm][Receive] label=%.3s, src.size=%zu or buf or handle invalid.", VEC_TO_STR(commLabel_),
srcTarget.size());
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator.h b/frameworks/libs/distributeddb/communicator/src/communicator.h
index 976ce0ae9..5bee40aaf 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator.h
+++ b/frameworks/libs/distributeddb/communicator/src/communicator.h
@@ -56,7 +56,7 @@ public:
const OnSendEnd &onEnd) override;
// Call by CommunicatorAggregator directly
- void OnBufferReceive(const std::string &srcTarget, const SerialBuffer *inBuf);
+ void OnBufferReceive(const std::string &srcTarget, const std::string &userId, const SerialBuffer *inBuf);
// Call by CommunicatorAggregator directly
void OnConnectChange(const std::string &target, bool isConnect);
diff --git a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
index ea724de99..ee3bbaf75 100644
--- a/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
+++ b/frameworks/libs/distributeddb/communicator/src/communicator_aggregator.cpp
@@ -276,7 +276,7 @@ void CommunicatorAggregator::ActivateCommunicator(const LabelType &commLabel, co
// Do Redeliver, the communicator is responsible to deal with the frame
std::list<FrameInfo> framesToRedeliver = retainer_.FetchFramesForSpecificCommunicator(commLabel);
for (auto &entry : framesToRedeliver) {
- commMap_[userId].at(commLabel).first->OnBufferReceive(entry.srcTarget, entry.buffer);
+ commMap_[userId].at(commLabel).first->OnBufferReceive(entry.srcTarget, userId, entry.buffer);
}
}
@@ -749,7 +749,7 @@ int CommunicatorAggregator::TryDeliverAppLayerFrameToCommunicatorNoMutex(const s
{
// Ignore nonactivated communicator, which is regarded as inexistent
if (commMap_[userId].count(toLabel) != 0 && commMap_[userId].at(toLabel).second) {
- commMap_[userId].at(toLabel).first->OnBufferReceive(srcTarget, inFrameBuffer);
+ commMap_[userId].at(toLabel).first->OnBufferReceive(srcTarget, userId, inFrameBuffer);
// Frame handed over to communicator who is responsible to delete it. The frame is deleted here after return.
inFrameBuffer = nullptr;
return E_OK;
@@ -771,7 +771,7 @@ int CommunicatorAggregator::TryDeliverAppLayerFrameToCommunicatorNoMutex(const s
}
}
if (communicator != nullptr && (userId.empty() || isEmpty)) {
- communicator->OnBufferReceive(srcTarget, inFrameBuffer);
+ communicator->OnBufferReceive(srcTarget, userId, inFrameBuffer);
inFrameBuffer = nullptr;
return E_OK;
}
diff --git a/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h b/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
index 0fdb757aa..6a0f50d1b 100644
--- a/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
+++ b/frameworks/libs/distributeddb/interfaces/include/iprocess_communicator.h
@@ -35,6 +35,7 @@ struct ExtendInfo {
std::string userId;
std::string dstTarget;
std::string subUserId;
+ std::string targetUserId;
};
struct UserInfo {
diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h
index 08870ff23..c39b5205b 100644
--- a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h
+++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h
@@ -204,6 +204,8 @@ public:
const std::function<void(const std::map<std::string, DBStatus> &devicesMap)> &onComplete,
const Query &query, bool wait) = 0;
+ DB_API virtual DBStatus Sync(const DeviceSyncParam &param, const KvDeviceSyncOnCompleteCallback &onComplete) = 0;
+
// Sync with device, provides sync count information
DB_API virtual DBStatus Sync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess) = 0;
diff --git a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h
index b58f83fe2..2370db55d 100644
--- a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h
+++ b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h
@@ -61,6 +61,8 @@ public:
DB_API virtual DBStatus Sync(const std::vector<std::string> &devices, SyncMode mode,
const Query &query, const SyncStatusCallback &onComplete, bool wait) = 0;
+ DB_API virtual DBStatus Sync(const DeviceSyncParam &param, const RdbDeviceSyncOnCompleteCallback &onComplete) = 0;
+
DB_API virtual int32_t GetCloudSyncTaskCount()
{
return 0;
diff --git a/frameworks/libs/distributeddb/interfaces/include/store_types.h b/frameworks/libs/distributeddb/interfaces/include/store_types.h
index a5dd8fd81..9aa88fe05 100644
--- a/frameworks/libs/distributeddb/interfaces/include/store_types.h
+++ b/frameworks/libs/distributeddb/interfaces/include/store_types.h
@@ -20,6 +20,7 @@
#include <map>
#include <set>
#include <string>
+#include <utility>
#include "query.h"
#include "types_export.h"
@@ -202,6 +203,28 @@ struct DeviceSyncOption {
bool isWait = true;
};
+struct DeviceSyncTarget {
+ std::string device;
+ std::string userId;
+
+ DeviceSyncTarget(std::string device, std::string userId) : device(std::move(device)), userId(std::move(userId)) {}
+
+ bool operator<(const DeviceSyncTarget& other) const {
+ if (device == other.device) {
+ return userId < other.userId;
+ }
+ return device < other.device;
+ }
+};
+
+struct DeviceSyncParam {
+ std::vector<DeviceSyncTarget> syncTargets;
+ SyncMode mode = SYNC_MODE_PULL_ONLY;
+ Query query; // isQuery must be set to true if the query is set
+ bool isQuery = false;
+ bool isWait = true;
+};
+
struct DeviceSyncInfo {
uint32_t total = 0;
uint32_t finishedCount = 0;
@@ -224,6 +247,11 @@ using SyncProcessCallback = std::function<void(const std::map<std::string, SyncP
using DeviceSyncProcessCallback = std::function<void(const std::map<std::string, DeviceSyncProcess> &processMap)>;
+using KvDeviceSyncOnCompleteCallback = std::function<void(const std::map<DeviceSyncTarget, DBStatus> &devicesMap)>;
+
+using RdbDeviceSyncOnCompleteCallback = std::function<void(const std::map<DeviceSyncTarget,
+ std::vector<TableStatus>> &devicesMap)>;
+
struct RemoteCondition {
std::string sql; // The sql statement;
std::vector<std::string> bindArgs; // The bind args.
diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp
index e38585b3d..f8bb55213 100644
--- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp
+++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp
@@ -573,8 +573,12 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector<std::string> &devices, Sy
return NOT_SUPPORT;
}
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
PragmaSync pragmaData(
- devices, mode, [this, onComplete](const std::map<std::string, int> &statuses) {
+ syncTargets, mode, [this, onComplete](const std::map<DeviceSyncTarget, int> &statuses) {
OnSyncComplete(statuses, onComplete);
}, wait);
int errCode = conn_->Pragma(PRAGMA_SYNC_DEVICES, &pragmaData);
@@ -612,8 +616,13 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector<std::string> &devices, Sy
LOGE("not support order by timestamp and query by range");
return NOT_SUPPORT;
}
+
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
PragmaSync pragmaData(
- devices, mode, querySyncObj, [this, onComplete](const std::map<std::string, int> &statuses) {
+ syncTargets, mode, querySyncObj, [this, onComplete](const std::map<DeviceSyncTarget, int> &statuses) {
OnSyncComplete(statuses, onComplete);
}, wait);
int errCode = conn_->Pragma(PRAGMA_SYNC_DEVICES, &pragmaData);
@@ -624,6 +633,42 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector<std::string> &devices, Sy
return OK;
}
+DBStatus KvStoreNbDelegateImpl::Sync(const DeviceSyncParam &param, const KvDeviceSyncOnCompleteCallback &onComplete)
+{
+ if (conn_ == nullptr) {
+ LOGE("%s", INVALID_CONNECTION);
+ return DB_ERROR;
+ }
+ if (param.mode > SYNC_MODE_PUSH_PULL) {
+ LOGE("not support other mode");
+ return NOT_SUPPORT;
+ }
+
+ QuerySyncObject querySyncObj(param.query);
+ if (!querySyncObj.GetRelationTableNames().empty()) {
+ LOGE("check query table names from tables failed!");
+ return NOT_SUPPORT;
+ }
+
+ if (!DBCommon::CheckQueryWithoutMultiTable(param.query)) {
+ LOGE("not support for invalid query");
+ return NOT_SUPPORT;
+ }
+ if (querySyncObj.GetSortType() != SortType::NONE || querySyncObj.IsQueryByRange()) {
+ LOGE("not support order by timestamp and query by range");
+ return NOT_SUPPORT;
+ }
+ PragmaSync pragmaData(param, [this, onComplete](const std::map<DeviceSyncTarget, int> &statuses) {
+ OnSyncComplete(statuses, onComplete);
+ });
+ int errCode = conn_->Pragma(PRAGMA_SYNC_DEVICES, &pragmaData);
+ if (errCode < E_OK) {
+ LOGE("[KvStoreNbDelegate] QuerySync data failed:%d", errCode);
+ return TransferDBErrno(errCode);
+ }
+ return OK;
+}
+
void KvStoreNbDelegateImpl::OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &processMap,
const DeviceSyncProcessCallback &onProcess) const
{
@@ -1015,13 +1060,26 @@ DBStatus KvStoreNbDelegateImpl::DeleteInner(const IOption &option, const Key &ke
return TransferDBErrno(errCode);
}
-void KvStoreNbDelegateImpl::OnSyncComplete(const std::map<std::string, int> &statuses,
+void KvStoreNbDelegateImpl::OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
const std::function<void(const std::map<std::string, DBStatus> &devicesMap)> &onComplete) const
{
std::map<std::string, DBStatus> result;
for (const auto &pair : statuses) {
DBStatus status = SyncOperation::DBStatusTrans(pair.second);
- result.insert(std::pair<std::string, DBStatus>(pair.first, status));
+ result.insert(std::pair<std::string, DBStatus>(pair.first.device, status));
+ }
+ if (onComplete) {
+ onComplete(result);
+ }
+}
+
+void KvStoreNbDelegateImpl::OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
+ const KvDeviceSyncOnCompleteCallback &onComplete) const
+{
+ std::map<DeviceSyncTarget, DBStatus> result;
+ for (const auto &pair : statuses) {
+ DBStatus status = SyncOperation::DBStatusTrans(pair.second);
+ result.insert(std::pair<DeviceSyncTarget, DBStatus>(pair.first, status));
}
if (onComplete) {
onComplete(result);
@@ -1074,8 +1132,15 @@ DBStatus KvStoreNbDelegateImpl::SubscribeRemoteQuery(const std::vector<std::stri
LOGE("not support order by timestamp and query by range");
return NOT_SUPPORT;
}
- PragmaSync pragmaData(devices, SyncModeType::SUBSCRIBE_QUERY, querySyncObj,
- [this, onComplete](const std::map<std::string, int> &statuses) { OnSyncComplete(statuses, onComplete); }, wait);
+
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ PragmaSync pragmaData(syncTargets, SyncModeType::SUBSCRIBE_QUERY, querySyncObj,
+ [this, onComplete](const std::map<DeviceSyncTarget, int> &statuses) {
+ OnSyncComplete(statuses, onComplete);
+ }, wait);
int errCode = conn_->Pragma(PRAGMA_SUBSCRIBE_QUERY, &pragmaData);
if (errCode < E_OK) {
LOGE("[KvStoreNbDelegate] Subscribe remote data with query failed:%d", errCode);
@@ -1098,8 +1163,15 @@ DBStatus KvStoreNbDelegateImpl::UnSubscribeRemoteQuery(const std::vector<std::st
LOGE("not support order by timestamp and query by range");
return NOT_SUPPORT;
}
- PragmaSync pragmaData(devices, SyncModeType::UNSUBSCRIBE_QUERY, querySyncObj,
- [this, onComplete](const std::map<std::string, int> &statuses) { OnSyncComplete(statuses, onComplete); }, wait);
+
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ PragmaSync pragmaData(syncTargets, SyncModeType::UNSUBSCRIBE_QUERY, querySyncObj,
+ [this, onComplete](const std::map<DeviceSyncTarget, int> &statuses) {
+ OnSyncComplete(statuses, onComplete);
+ }, wait);
int errCode = conn_->Pragma(PRAGMA_SUBSCRIBE_QUERY, &pragmaData);
if (errCode < E_OK) {
LOGE("[KvStoreNbDelegate] Unsubscribe remote data with query failed:%d", errCode);
diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h
index e03bc6f3c..2717de01d 100644
--- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h
+++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h
@@ -133,6 +133,8 @@ public:
const std::function<void(const std::map<std::string, DBStatus> &devicesMap)> &onComplete,
const Query &query, bool wait) override;
+ DBStatus Sync(const DeviceSyncParam &param, const KvDeviceSyncOnCompleteCallback &onComplete);
+
// Sync with devices, provides sync count information
DBStatus Sync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess) override;
@@ -203,8 +205,11 @@ private:
DBStatus DeleteInner(const IOption &option, const Key &key);
DBStatus GetEntriesInner(const IOption &option, const Key &keyPrefix, std::vector<Entry> &entries) const;
- void OnSyncComplete(const std::map<std::string, int> &statuses,
+ void OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
const std::function<void(const std::map<std::string, DBStatus> &devicesMap)> &onComplete) const;
+
+ void OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
+ const KvDeviceSyncOnCompleteCallback &onComplete) const;
void OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &processMap,
const DeviceSyncProcessCallback &onProcess) const;
diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp
index 5cf4ebdb9..a666aec23 100644
--- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp
+++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.cpp
@@ -109,9 +109,17 @@ DBStatus RelationalStoreDelegateImpl::Sync(const std::vector<std::string> &devic
LOGE("not support query with tables");
return NOT_SUPPORT;
}
- RelationalStoreConnection::SyncInfo syncInfo{devices, mode,
- [this, onComplete](const std::map<std::string, std::vector<TableStatus>> &devicesStatus) {
- OnSyncComplete(devicesStatus, onComplete);
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ RelationalStoreConnection::SyncInfo syncInfo{syncTargets, mode,
+ [this, onComplete](const std::map<DeviceSyncTarget, std::vector<TableStatus>> &devicesStatus) {
+ std::map<std::string, std::vector<TableStatus>> devicesSyncStatus;
+ for (const auto &status : devicesStatus) {
+ devicesSyncStatus[status.first.device] = status.second;
+ }
+ OnSyncComplete(devicesSyncStatus, onComplete);
}, query, wait};
int errCode = conn_->SyncToDevice(syncInfo);
if (errCode != E_OK) {
@@ -121,6 +129,35 @@ DBStatus RelationalStoreDelegateImpl::Sync(const std::vector<std::string> &devic
return OK;
}
+DBStatus RelationalStoreDelegateImpl::Sync(const DeviceSyncParam &param,
+ const RdbDeviceSyncOnCompleteCallback &onComplete)
+{
+ if (conn_ == nullptr) {
+ LOGE("Invalid connection for operation!");
+ return DB_ERROR;
+ }
+
+ if (param.mode > SYNC_MODE_PUSH_PULL) {
+ LOGE("not support other mode");
+ return NOT_SUPPORT;
+ }
+
+ if (!param.isQuery || !DBCommon::CheckQueryWithoutMultiTable(param.query)) {
+ LOGE("not set query or not support query with tables");
+ return NOT_SUPPORT;
+ }
+ RelationalStoreConnection::SyncInfo syncInfo{param.syncTargets, param.mode,
+ [this, onComplete](const std::map<DeviceSyncTarget, std::vector<TableStatus>> &devicesStatus) {
+ OnSyncComplete(devicesStatus, onComplete);
+ }, param.query, param.isWait};
+ int errCode = conn_->SyncToDevice(syncInfo);
+ if (errCode != E_OK) {
+ LOGW("[RelationalStore Delegate] sync data to device failed:%d", errCode);
+ return TransferDBErrno(errCode);
+ }
+ return OK;
+}
+
DBStatus RelationalStoreDelegateImpl::RemoveDeviceData(const std::string &device, const std::string &tableName)
{
if (conn_ == nullptr) {
@@ -172,12 +209,29 @@ void RelationalStoreDelegateImpl::OnSyncComplete(const std::map<std::string, std
const SyncStatusCallback &onComplete)
{
std::map<std::string, std::vector<TableStatus>> res;
- for (const auto &[device, tablesStatus] : devicesStatus) {
+ for (const auto &[syncTarget, tablesStatus] : devicesStatus) {
+ for (const auto &tableStatus : tablesStatus) {
+ TableStatus table;
+ table.tableName = tableStatus.tableName;
+ table.status = SyncOperation::DBStatusTrans(tableStatus.status);
+ res[syncTarget].push_back(table);
+ }
+ }
+ if (onComplete) {
+ onComplete(res);
+ }
+}
+
+void RelationalStoreDelegateImpl::OnSyncComplete(const std::map<DeviceSyncTarget, std::vector<TableStatus>> &devicesStatus,
+ const RdbDeviceSyncOnCompleteCallback &onComplete)
+{
+ std::map<DeviceSyncTarget, std::vector<TableStatus>> res;
+ for (const auto &[syncTarget, tablesStatus] : devicesStatus) {
for (const auto &tableStatus : tablesStatus) {
TableStatus table;
table.tableName = tableStatus.tableName;
table.status = SyncOperation::DBStatusTrans(tableStatus.status);
- res[device].push_back(table);
+ res[syncTarget].push_back(table);
}
}
if (onComplete) {
diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h
index f53b07233..d9faa9e69 100644
--- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h
+++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_delegate_impl.h
@@ -34,6 +34,8 @@ public:
DBStatus Sync(const std::vector<std::string> &devices, SyncMode mode,
const Query &query, const SyncStatusCallback &onComplete, bool wait) override;
+ DBStatus Sync(const DeviceSyncParam &param, const RdbDeviceSyncOnCompleteCallback &onComplete) override;
+
DBStatus RemoveDeviceDataInner(const std::string &device, ClearMode mode) override;
DBStatus CreateDistributedTableInner(const std::string &tableName, TableSyncType type) override;
@@ -98,6 +100,8 @@ public:
private:
static void OnSyncComplete(const std::map<std::string, std::vector<TableStatus>> &devicesStatus,
const SyncStatusCallback &onComplete);
+ static void OnSyncComplete(const std::map<DeviceSyncTarget, std::vector<TableStatus>> &devicesStatus,
+ const RdbDeviceSyncOnCompleteCallback &onComplete);
#ifdef USE_DISTRIBUTEDDB_CLOUD
DBStatus ClearWatermark(const ClearMetaDataOption &option);
diff --git a/frameworks/libs/distributeddb/storage/include/kvdb_pragma.h b/frameworks/libs/distributeddb/storage/include/kvdb_pragma.h
index dd47e8fd5..48d9b83a3 100644
--- a/frameworks/libs/distributeddb/storage/include/kvdb_pragma.h
+++ b/frameworks/libs/distributeddb/storage/include/kvdb_pragma.h
@@ -56,10 +56,10 @@ enum : int {
};
struct PragmaSync {
- PragmaSync(const std::vector<std::string> &devices, int mode, const QuerySyncObject &query,
- const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete,
+ PragmaSync(const std::vector<DeviceSyncTarget> &syncTargets, int mode, const QuerySyncObject &query,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> &onComplete,
bool wait = false)
- : devices_(devices),
+ : syncTargets_(syncTargets),
mode_(mode),
onComplete_(onComplete),
wait_(wait),
@@ -68,10 +68,10 @@ struct PragmaSync {
{
}
- PragmaSync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete,
+ PragmaSync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> &onComplete,
bool wait = false)
- : devices_(devices),
+ : syncTargets_(syncTargets),
mode_(mode),
onComplete_(onComplete),
wait_(wait),
@@ -81,8 +81,7 @@ struct PragmaSync {
}
PragmaSync(const DeviceSyncOption &option, const QuerySyncObject &query, const DeviceSyncProcessCallback &onProcess)
- : devices_(option.devices),
- mode_(option.mode),
+ : mode_(option.mode),
wait_(option.isWait),
isQuerySync_(option.isQuery),
onSyncProcess_(onProcess)
@@ -91,21 +90,36 @@ struct PragmaSync {
return;
}
query_ = query;
+ for (const auto &device : option.devices) {
+ syncTargets_.push_back({device, ""});
+ }
}
PragmaSync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess)
- : devices_(option.devices),
- mode_(option.mode),
+ : mode_(option.mode),
wait_(option.isWait),
isQuerySync_(false),
query_(Query::Select()),
onSyncProcess_(onProcess)
+ {
+ for (const auto &device : option.devices) {
+ syncTargets_.push_back({device, ""});
+ }
+ }
+
+ PragmaSync(const DeviceSyncParam &param,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> &onComplete)
+ : mode_(param.mode),
+ wait_(param.isWait),
+ isQuerySync_(false),
+ query_(Query::Select()),
+ onComplete_(onComplete)
{
}
- std::vector<std::string> devices_;
+ std::vector<DeviceSyncTarget> syncTargets_;
int mode_;
- std::function<void(const std::map<std::string, int> &devicesMap)> onComplete_;
+ std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> onComplete_;
bool wait_;
bool isQuerySync_;
QuerySyncObject query_;
diff --git a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h
index 67bdc3548..86846e369 100644
--- a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h
+++ b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h
@@ -32,9 +32,19 @@ using RelationalObserverAction =
class RelationalStoreConnection : public IConnection, public virtual RefObject {
public:
struct SyncInfo {
- const std::vector<std::string> &devices;
+ SyncInfo(const std::vector<DeviceSyncTarget> &syncTargets, SyncMode mode,
+ const RdbDeviceSyncOnCompleteCallback onComplete, const Query &query, bool wait)
+ : syncTargets(syncTargets),
+ mode(mode),
+ onComplete(onComplete),
+ query(query),
+ wait(wait)
+ {
+ }
+
+ const std::vector<DeviceSyncTarget> syncTargets;
SyncMode mode = SYNC_MODE_PUSH_PULL;
- const SyncStatusCallback onComplete = nullptr;
+ const RdbDeviceSyncOnCompleteCallback onComplete = nullptr;
const Query &query;
bool wait = true;
};
diff --git a/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.cpp b/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.cpp
index 94275ffec..170eb91de 100644
--- a/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.cpp
+++ b/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.cpp
@@ -146,16 +146,16 @@ int SyncAbleKvDBConnection::PragmaSyncAction(const PragmaSync *syncParameter)
}
ISyncer::SyncParma syncParam;
- syncParam.devices = syncParameter->devices_;
+ syncParam.syncTargets = syncParameter->syncTargets_;
syncParam.mode = syncParameter->mode_;
syncParam.wait = syncParameter->wait_;
syncParam.isQuerySync = syncParameter->isQuerySync_;
syncParam.syncQuery = syncParameter->query_;
syncParam.onFinalize = [this]() { DecObjRef(this); };
if (syncParameter->onComplete_) {
- syncParam.onComplete = [this, onComplete = syncParameter->onComplete_, wait = syncParameter->wait_](
- const std::map<std::string, int> &statuses) {
- OnSyncComplete(statuses, onComplete, wait);
+ syncParam.onComplete = [this, onComplete = syncParameter->onComplete_](
+ const std::map<DeviceSyncTarget, int> &statuses) {
+ OnSyncComplete(statuses, onComplete);
};
}
if (syncParameter->onSyncProcess_) {
@@ -207,8 +207,8 @@ int SyncAbleKvDBConnection::EnableAutoSync(bool enable)
return E_OK;
}
-void SyncAbleKvDBConnection::OnSyncComplete(const std::map<std::string, int> &statuses,
- const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, bool wait)
+void SyncAbleKvDBConnection::OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> &onComplete)
{
AutoLock lockGuard(this);
if (!IsKilled() && onComplete) {
diff --git a/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.h b/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.h
index 4594b3dd9..70adf608e 100644
--- a/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.h
+++ b/frameworks/libs/distributeddb/storage/src/kv/sync_able_kvdb_connection.h
@@ -65,11 +65,11 @@ private:
// If enable is true, it will enable auto sync
int EnableAutoSync(bool enable);
- void OnSyncComplete(const std::map<std::string, int> &statuses,
- const std::function<void(const std::map<std::string, int> &devicesMap)> &onComplete, bool wait);
+ void OnSyncComplete(const std::map<DeviceSyncTarget, int> &statuses,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> &onComplete);
void OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &syncRecordMap,
- const DeviceSyncProcessCallback &onProcess);
+ const DeviceSyncProcessCallback &onProcess);
int GetQueuedSyncSize(int *queuedSyncSize) const;
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp
index f9db627ac..f6ac30676 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp
@@ -255,7 +255,7 @@ int SQLiteRelationalStoreConnection::SyncToDevice(SyncInfo &info)
}
ISyncer::SyncParma syncParam;
- syncParam.devices = info.devices;
+ syncParam.syncTargets = info.syncTargets;
syncParam.mode = info.mode;
syncParam.wait = info.wait;
syncParam.isQuerySync = true;
diff --git a/frameworks/libs/distributeddb/syncer/include/isyncer.h b/frameworks/libs/distributeddb/syncer/include/isyncer.h
index 61e0c44c4..83f705f15 100644
--- a/frameworks/libs/distributeddb/syncer/include/isyncer.h
+++ b/frameworks/libs/distributeddb/syncer/include/isyncer.h
@@ -36,9 +36,9 @@ struct SyncerBasicInfo {
class ISyncer {
public:
struct SyncParma {
- std::vector<std::string> devices;
- std::function<void(const std::map<std::string, int> &devicesMap)> onComplete;
- SyncStatusCallback relationOnComplete;
+ std::vector<DeviceSyncTarget> syncTargets;
+ std::function<void(const std::map<DeviceSyncTarget, int> &devicesMap)> onComplete;
+ RdbDeviceSyncOnCompleteCallback relationOnComplete;
std::function<void(void)> onFinalize;
int mode = 0;
bool wait = false;
@@ -61,8 +61,8 @@ public:
// param onComplete: The syncer finish callback. set by caller
// param onFinalize: will be callback when this Sync Operation finalized.
// return a Sync id. It will return a positive value if failed,
- virtual int Sync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &)> &onComplete,
+ virtual int Sync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &)> &onComplete,
const std::function<void(void)> &onFinalize, bool wait) = 0;
// Sync function. use SyncParma to reduce parameter.
diff --git a/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h b/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h
index 0f6d5bc7d..eea9152d7 100644
--- a/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h
+++ b/frameworks/libs/distributeddb/syncer/include/syncer_proxy.h
@@ -41,8 +41,8 @@ public:
// param onComplete: The syncer finish callback. set by caller
// param onFinalize: will be callback when this Sync Operation finalized.
// return a Sync id. It will return a positive value if failed,
- int Sync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &)> &onComplete,
+ int Sync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &)> &onComplete,
const std::function<void(void)> &onFinalize, bool wait) override;
// Sync function. use SyncParma to reduce parameter.
diff --git a/frameworks/libs/distributeddb/syncer/src/device/ability_sync.cpp b/frameworks/libs/distributeddb/syncer/src/device/ability_sync.cpp
index 7a4af6fa0..9569ca916 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/ability_sync.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/ability_sync.cpp
@@ -365,7 +365,7 @@ AbilitySync::~AbilitySync()
}
int AbilitySync::Initialize(ICommunicator *inCommunicator, ISyncInterface *inStorage,
- const std::shared_ptr<Metadata> &inMetadata, const std::string &deviceId)
+ const std::shared_ptr<Metadata> &inMetadata, const std::string &deviceId, const std::string &userId)
{
if (inCommunicator == nullptr || inStorage == nullptr || deviceId.empty() || inMetadata == nullptr) {
return -E_INVALID_ARGS;
@@ -374,6 +374,7 @@ int AbilitySync::Initialize(ICommunicator *inCommunicator, ISyncInterface *inSto
storageInterface_ = inStorage;
metadata_ = inMetadata;
deviceId_ = deviceId;
+ userId_ = userId;
return E_OK;
}
@@ -401,7 +402,7 @@ int AbilitySync::SyncStart(uint32_t sessionId, uint32_t sequenceId, uint16_t rem
message->SetSessionId(sessionId);
message->SetSequenceId(sequenceId);
SendConfig conf;
- SetSendConfigParam(storageInterface_->GetDbProperties(), deviceId_, false, SEND_TIME_OUT, conf);
+ SetSendConfigParam(storageInterface_->GetDbProperties(), {deviceId_, userId_}, false, SEND_TIME_OUT, conf);
errCode = communicator_->SendMessage(deviceId_, message, conf, handler);
if (errCode != E_OK) {
LOGE("[AbilitySync][SyncStart] SendPacket failed, err %d", errCode);
@@ -1220,7 +1221,7 @@ int AbilitySync::SendAck(const Message *inMsg, const AbilitySyncAckPacket &ackPa
ackMessage->SetSessionId(inMsg->GetSessionId());
ackMessage->SetSequenceId(inMsg->GetSequenceId());
SendConfig conf;
- SetSendConfigParam(storageInterface_->GetDbProperties(), deviceId_, false, SEND_TIME_OUT, conf);
+ SetSendConfigParam(storageInterface_->GetDbProperties(), {deviceId_, userId_}, false, SEND_TIME_OUT, conf);
errCode = communicator_->SendMessage(deviceId_, ackMessage, conf);
if (errCode != E_OK) {
LOGE("[AbilitySync][SendAck] SendPacket failed, err %d", errCode);
diff --git a/frameworks/libs/distributeddb/syncer/src/device/ability_sync.h b/frameworks/libs/distributeddb/syncer/src/device/ability_sync.h
index cba09fb3d..74625720c 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/ability_sync.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/ability_sync.h
@@ -159,7 +159,7 @@ public:
const CommErrHandler &handler = nullptr, const ISyncTaskContext *context = nullptr);
int Initialize(ICommunicator *inCommunicator, ISyncInterface *inStorage,
- const std::shared_ptr<Metadata> &inMetadata, const std::string &deviceId);
+ const std::shared_ptr<Metadata> &inMetadata, const std::string &deviceId, const std::string &userId);
int AckRecv(const Message *message, ISyncTaskContext *context);
@@ -272,6 +272,7 @@ private:
ISyncInterface *storageInterface_;
std::shared_ptr<Metadata> metadata_;
std::string deviceId_;
+ std::string userId_;
bool syncFinished_;
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.cpp
index 772dee8f9..f6ef90aa1 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.cpp
@@ -146,12 +146,12 @@ int GenericSyncer::Close(bool isClosedOperation)
return errCode;
}
-int GenericSyncer::Sync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &)> &onComplete,
+int GenericSyncer::Sync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &)> &onComplete,
const std::function<void(void)> &onFinalize, bool wait = false)
{
SyncParma param;
- param.devices = devices;
+ param.syncTargets = syncTargets;
param.mode = mode;
param.onComplete = onComplete;
param.onFinalize = onFinalize;
@@ -162,7 +162,11 @@ int GenericSyncer::Sync(const std::vector<std::string> &devices, int mode,
int GenericSyncer::Sync(const InternalSyncParma &param)
{
SyncParma syncParam;
- syncParam.devices = param.devices;
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : param.devices) {
+ syncTargets.push_back({device, ""});
+ }
+ syncParam.syncTargets = syncTargets;
syncParam.mode = param.mode;
syncParam.isQuerySync = param.isQuerySync;
syncParam.syncQuery = param.syncQuery;
@@ -234,8 +238,9 @@ int GenericSyncer::CancelSync(uint32_t syncId)
int GenericSyncer::PrepareSync(const SyncParma &param, uint32_t syncId, uint64_t connectionId)
{
- auto *operation =
- new (std::nothrow) SyncOperation(syncId, param.devices, param.mode, param.onComplete, param.wait);
+ SyncOperation *operation = nullptr;
+ operation = new(std::nothrow) SyncOperation(syncId, param.syncTargets, param.mode, param.onComplete,
+ param.wait);
if (operation == nullptr) {
SubQueuedSyncSize();
return -E_OUT_OF_MEMORY;
@@ -246,8 +251,8 @@ int GenericSyncer::PrepareSync(const SyncParma &param, uint32_t syncId, uint64_t
std::lock_guard<std::mutex> autoLock(syncerLock_);
PerformanceAnalysis::GetInstance()->StepTimeRecordStart(PT_TEST_RECORDS::RECORD_SYNC_TOTAL);
InitSyncOperation(operation, param);
- LOGI("[Syncer] GenerateSyncId %" PRIu32 ", mode = %d, wait = %d, label = %s, devices = %s", syncId, param.mode,
- param.wait, label_.c_str(), GetSyncDevicesStr(param.devices).c_str());
+ LOGI("[Syncer] GenerateSyncId %" PRIu32 ", mode = %d, wait = %d, label = %s, syncTargets = %s",
+ syncId, param.mode, param.wait, label_.c_str(), GetSyncTargetsStr(param.syncTargets).c_str());
engine = syncEngine_;
RefObject::IncObjRef(engine);
}
@@ -536,11 +541,18 @@ int GenericSyncer::SyncConditionCheck(const SyncParma &param, const ISyncEngine
return E_OK;
}
-bool GenericSyncer::IsValidDevices(const std::vector<std::string> &devices) const
+bool GenericSyncer::IsValidDevices(const std::vector<DeviceSyncTarget> &syncTargets) const
{
- if (devices.empty()) {
- LOGE("[Syncer] devices is empty!");
+ if (syncTargets.empty()) {
+ LOGE("[Syncer] syncTargets is empty!");
return false;
+ } else {
+ for (const auto &target : syncTargets) {
+ if (target.device.empty()) {
+ LOGE("[Syncer] there is a device in sync targets is empty!");
+ return false;
+ }
+ }
}
return true;
}
@@ -858,6 +870,21 @@ std::string GenericSyncer::GetSyncDevicesStr(const std::vector<std::string> &dev
return syncDevices.substr(0, syncDevices.size() - 1);
}
+std::string GenericSyncer::GetSyncTargetsStr(const std::vector<DeviceSyncTarget> &syncTargets) const
+{
+ std::string syncTargetsStr;
+ for (const auto &target : syncTargets) {
+ syncTargetsStr += DBCommon::StringMasking(target.device);
+ syncTargetsStr += "-";
+ syncTargetsStr += target.userId;
+ syncTargetsStr += ",";
+ }
+ if (syncTargetsStr.empty()) {
+ return "";
+ }
+ return syncTargetsStr.substr(0, syncTargetsStr.size() - 1);
+}
+
int GenericSyncer::StatusCheck() const
{
if (!initialized_) {
@@ -882,7 +909,7 @@ int GenericSyncer::SyncPreCheck(const SyncParma &param) const
if (errCode != E_OK) {
return errCode;
}
- if (!IsValidDevices(param.devices) || !IsValidMode(param.mode)) { // LCOV_EXCL_BR_LINE
+ if (!IsValidDevices(param.syncTargets) || !IsValidMode(param.mode)) { // LCOV_EXCL_BR_LINE
return -E_INVALID_ARGS;
}
if (IsQueuedManualSyncFull(param.mode, param.wait)) { // LCOV_EXCL_BR_LINE
diff --git a/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.h b/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.h
index 183fbb1fa..1be3d2a99 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/generic_syncer.h
@@ -46,8 +46,8 @@ public:
// param onComplete: The syncer finish callback. set by caller
// param onFinalize: will be callback when this Sync Operation finalized.
// return a Sync id. It will return a positive value if failed,
- int Sync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &)> &onComplete,
+ int Sync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &)> &onComplete,
const std::function<void(void)> &onFinalize, bool wait) override;
// Sync function. use SyncParma to reduce parameter.
@@ -160,7 +160,7 @@ protected:
virtual int SyncConditionCheck(const SyncParma &param, const ISyncEngine *engine, ISyncInterface *storage) const;
// Check if the devices arg is valid
- bool IsValidDevices(const std::vector<std::string> &devices) const;
+ bool IsValidDevices(const std::vector<DeviceSyncTarget> &syncTargets) const;
// Used Clear all SyncOperations.
// isClosedOperation is false while userChanged
@@ -185,6 +185,8 @@ protected:
std::string GetSyncDevicesStr(const std::vector<std::string> &devices) const;
+ std::string GetSyncTargetsStr(const std::vector<DeviceSyncTarget> &syncTargets) const;
+
void InitSyncOperation(SyncOperation *operation, const SyncParma &param);
int StatusCheck() const;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/isync_engine.h b/frameworks/libs/distributeddb/syncer/src/device/isync_engine.h
index 3859a900d..db7d856a4 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/isync_engine.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/isync_engine.h
@@ -78,7 +78,7 @@ public:
virtual void StopAutoSubscribeTimer() = 0;
// Check if number of subscriptions out of limit
- virtual int SubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const = 0;
+ virtual int SubscribeLimitCheck(const std::vector<DeviceSyncTarget> &syncTargets, QuerySyncObject &query) const = 0;
// Check if the Sync Engine is active, some times synchronization is not allowed
virtual bool IsEngineActive() const = 0;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
index 91ed88936..e2e2c5235 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/isync_task_context.h
@@ -35,7 +35,7 @@ public:
enum TASK_EXEC_STATUS { INIT, RUNNING, FAILED, FINISHED };
// Initialize the context
- virtual int Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
+ virtual int Initialize(const std::string &deviceId, const std::string &userId, ISyncInterface *syncInterface,
const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) = 0;
// Add a sync task target with the operation to the queue
@@ -75,6 +75,8 @@ public:
// Get the current task deviceId.
virtual std::string GetDeviceId() const = 0;
+ // Get the current task userId.
+ virtual std::string GetUserId() const = 0;
virtual void SetTaskExecStatus(int status) = 0;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/remote_executor.cpp b/frameworks/libs/distributeddb/syncer/src/device/remote_executor.cpp
index 8aa2d1030..a291f6186 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/remote_executor.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/remote_executor.cpp
@@ -520,7 +520,7 @@ int RemoteExecutor::SendRequestMessage(const std::string &target, Message *messa
return -E_BUSY;
}
SendConfig sendConfig;
- SetSendConfigParam(syncInterface->GetDbProperties(), target, false, REMOTE_EXECUTOR_SEND_TIME_OUT, sendConfig);
+ SetSendConfigParam(syncInterface->GetDbProperties(), {target, ""}, false, REMOTE_EXECUTOR_SEND_TIME_OUT, sendConfig);
RefObject::IncObjRef(this);
int errCode = communicator->SendMessage(target, message, sendConfig,
[this, sessionId](int errCode, bool isDirectEnd) {
@@ -606,7 +606,7 @@ int RemoteExecutor::ResponseStart(RemoteExecutorAckPacket *packet, uint32_t sess
message->SetSequenceId(sequenceId);
message->SetMessageType(TYPE_RESPONSE);
SendConfig sendConfig;
- SetSendConfigParam(storage->GetDbProperties(), device, false, SEND_TIME_OUT, sendConfig);
+ SetSendConfigParam(storage->GetDbProperties(), {device, ""}, false, SEND_TIME_OUT, sendConfig);
errCode = communicator->SendMessage(device, message, sendConfig, nullptr);
RefObject::DecObjRef(communicator);
if (errCode != E_OK) {
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp
index 84f35ce37..22b607b65 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp
@@ -241,7 +241,8 @@ int SingleVerDataSync::Send(SingleVerSyncTaskContext *context, const Message *me
startFeedDogRet = context->StartFeedDogForSync(time, SyncDirectionFlag::SEND);
}
SendConfig sendConfig;
- SetSendConfigParam(storage_->GetDbProperties(), context->GetDeviceId(), false, SEND_TIME_OUT, sendConfig);
+ DeviceSyncTarget syncTarget = {context->GetDeviceId(), context->GetUserId()};
+ SetSendConfigParam(storage_->GetDbProperties(), syncTarget, false, SEND_TIME_OUT, sendConfig);
int errCode = communicateHandle_->SendMessage(context->GetDeviceId(), message, sendConfig, handler);
if (errCode != E_OK) {
LOGE("[DataSync][Send] send message failed, errCode=%d", errCode);
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp
index 986d841b9..31de1ef74 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp
@@ -623,10 +623,11 @@ void SingleVerDataSyncUtils::UpdateSyncProcess(SingleVerSyncTaskContext *context
packet->GetTotalDataCount(), dataSize);
if (packet->GetMode() == SyncModeType::PUSH || packet->GetMode() == SyncModeType::QUERY_PUSH) {
// save total count to sync process
+ DeviceSyncTarget syncTarget = {context->GetDeviceId(), context->GetUserId()};
if (packet->GetTotalDataCount() > 0) {
- context->SetOperationSyncProcessTotal(context->GetDeviceId(), packet->GetTotalDataCount());
+ context->SetOperationSyncProcessTotal(syncTarget, packet->GetTotalDataCount());
}
- context->UpdateOperationFinishedCount(context->GetDeviceId(), static_cast<uint32_t>(dataSize));
+ context->UpdateOperationFinishedCount(syncTarget, static_cast<uint32_t>(dataSize));
}
}
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_kv_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_kv_syncer.cpp
index 31ac7c4b1..3359745bc 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_kv_syncer.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_kv_syncer.cpp
@@ -59,7 +59,11 @@ void SingleVerKVSyncer::EnableAutoSync(bool enable)
LOGI("[Syncer] EnableAutoSync no online devices");
return;
}
- int errCode = Sync(devices, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ int errCode = Sync(syncTargets, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
if (errCode != E_OK) {
LOGE("[Syncer] sync start by EnableAutoSync failed err %d", errCode);
}
@@ -134,11 +138,11 @@ void SingleVerKVSyncer::RemoteDataChanged(const std::string &device)
RefObject::IncObjRef(syncEngine_);
syncInterface_->IncRefCount();
int retCode = RuntimeContext::GetInstance()->ScheduleTask([this, userId, appId, storeId, device] {
- std::vector<std::string> devices;
- devices.push_back(device);
+ std::vector<DeviceSyncTarget> syncTargets;
+ syncTargets.push_back({device, ""});
int errCode = E_OK;
if (RuntimeContext::GetInstance()->IsNeedAutoSync(userId, appId, storeId, device)) {
- errCode = Sync(devices, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
+ errCode = Sync(syncTargets, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
}
if (errCode != E_OK) {
LOGE("[SingleVerKVSyncer] sync start by RemoteDataChanged failed err %d", errCode);
@@ -186,11 +190,11 @@ int SingleVerKVSyncer::SyncConditionCheck(const SyncParma &param, const ISyncEng
LOGE("[SingleVerKVSyncer] subscribe query not support limit,offset or orderby");
return -E_NOT_SUPPORT;
}
- if (param.devices.size() > MAX_DEVICES_NUM) {
+ if (param.syncTargets.size() > MAX_DEVICES_NUM) {
LOGE("[SingleVerKVSyncer] devices is overlimit");
return -E_MAX_LIMITS;
}
- return engine->SubscribeLimitCheck(param.devices, query);
+ return engine->SubscribeLimitCheck(param.syncTargets, query);
}
void SingleVerKVSyncer::TriggerSubscribe(const std::string &device, const QuerySyncObject &query)
@@ -204,7 +208,11 @@ void SingleVerKVSyncer::TriggerSubscribe(const std::string &device, const QueryS
std::vector<std::string> devices;
devices.push_back(device);
SyncParma param;
- param.devices = devices;
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ param.syncTargets = syncTargets;
param.mode = SyncModeType::AUTO_SUBSCRIBE_QUERY;
param.onComplete = nullptr;
param.onFinalize = nullptr;
@@ -233,7 +241,11 @@ bool SingleVerKVSyncer::TryFullSync(const std::vector<std::string> &devices)
LOGD("[Syncer] autoSync no enable");
return false;
}
- int errCode = Sync(devices, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
+ std::vector<DeviceSyncTarget> syncTargets;
+ for (const auto &device : devices) {
+ syncTargets.push_back({device, ""});
+ }
+ int errCode = Sync(syncTargets, SyncModeType::AUTO_PUSH, nullptr, nullptr, false);
if (errCode != E_OK) {
LOGE("[Syncer] sync start by RemoteDataChanged failed err %d", errCode);
return false;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.cpp
index e392bb459..df639fc74 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.cpp
@@ -83,7 +83,7 @@ int SingleVerRelationalSyncer::GenerateEachSyncTask(const SyncParma &param, uint
LOGI("[SingleVerRelationalSyncer] SubSyncId %" PRIu32 " create by SyncId %" PRIu32 ", hashTableName = %s",
subSyncId, syncId, STR_MASK(DBCommon::TransferStringToHex(hashTableName)));
subParam.syncQuery = table;
- subParam.onComplete = [this, subSyncId, syncId, subParam](const std::map<std::string, int> &devicesMap) {
+ subParam.onComplete = [this, subSyncId, syncId, subParam](const std::map<DeviceSyncTarget, int> &devicesMap) {
DoOnSubSyncComplete(subSyncId, syncId, subParam, devicesMap);
};
{
@@ -103,7 +103,7 @@ int SingleVerRelationalSyncer::GenerateEachSyncTask(const SyncParma &param, uint
}
void SingleVerRelationalSyncer::DoOnSubSyncComplete(const uint32_t subSyncId, const uint32_t syncId,
- const SyncParma &param, const std::map<std::string, int> &devicesMap)
+ const SyncParma &param, const std::map<DeviceSyncTarget, int> &devicesMap)
{
bool allFinish = true;
{
@@ -138,8 +138,8 @@ void SingleVerRelationalSyncer::DoOnComplete(const SyncParma &param, uint32_t sy
if (!param.relationOnComplete) {
return;
}
- std::map<std::string, std::vector<TableStatus>> syncRes;
- std::map<std::string, std::vector<TableStatus>> tmpMap;
+ std::map<DeviceSyncTarget, std::vector<TableStatus>> syncRes;
+ std::map<DeviceSyncTarget, std::vector<TableStatus>> tmpMap;
{
std::lock_guard<std::mutex> lockGuard(syncMapLock_);
tmpMap = resMap_[syncId];
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.h b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.h
index df637af8c..a67f4fe2a 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_relational_syncer.h
@@ -46,7 +46,7 @@ private:
void DoOnComplete(const SyncParma &param, uint32_t syncId);
void DoOnSubSyncComplete(const uint32_t subSyncId, const uint32_t syncId,
- const SyncParma &param, const std::map<std::string, int> &devicesMap);
+ const SyncParma &param, const std::map<DeviceSyncTarget, int> &devicesMap);
void SchemaChangeCallback();
@@ -56,7 +56,7 @@ private:
mutable std::mutex syncMapLock_;
std::map<uint32_t, std::set<uint32_t>> fullSyncIdMap_;
- std::map<uint32_t, std::map<std::string, std::vector<TableStatus>>> resMap_;
+ std::map<uint32_t, std::map<DeviceSyncTarget, std::vector<TableStatus>>> resMap_;
};
}
#endif
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_engine.cpp
index c5254c5af..a78f9b3e0 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_engine.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_engine.cpp
@@ -52,10 +52,12 @@ void SingleVerSyncEngine::EnableClearRemoteStaleData(bool enable)
LOGI("[SingleVerSyncEngine][EnableClearRemoteStaleData] enabled %d", enable);
needClearRemoteStaleData_ = enable;
std::unique_lock<std::mutex> lock(contextMapLock_);
- for (auto &iter : syncTaskContextMap_) {
- auto context = static_cast<SingleVerSyncTaskContext *>(iter.second);
- if (context != nullptr) { // LCOV_EXCL_BR_LINE
- context->EnableClearRemoteStaleData(enable);
+ for (auto &deviceIter : syncTaskContextMap_) {
+ for (auto &userIdIter : deviceIter.second) {
+ auto context = static_cast<SingleVerSyncTaskContext *>(userIdIter.second);
+ if (context != nullptr) { // LCOV_EXCL_BR_LINE
+ context->EnableClearRemoteStaleData(enable);
+ }
}
}
}
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_state_machine.cpp
index 205ca3da1..574359842 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_state_machine.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_state_machine.cpp
@@ -138,7 +138,8 @@ int SingleVerSyncStateMachine::Initialize(ISyncTaskContext *context, ISyncInterf
return -E_OUT_OF_MEMORY;
}
- errCode = timeSync_->Initialize(communicator, metaData, syncInterface, context->GetDeviceId());
+ errCode = timeSync_->Initialize(communicator, metaData, syncInterface, context->GetDeviceId(),
+ context->GetUserId());
if (errCode != E_OK) {
goto ERROR_OUT;
}
@@ -146,7 +147,7 @@ int SingleVerSyncStateMachine::Initialize(ISyncTaskContext *context, ISyncInterf
if (errCode != E_OK) {
goto ERROR_OUT;
}
- errCode = abilitySync_->Initialize(communicator, syncInterface, metaData, context->GetDeviceId());
+ errCode = abilitySync_->Initialize(communicator, syncInterface, metaData, context->GetDeviceId(), context->GetUserId());
if (errCode != E_OK) {
goto ERROR_OUT;
}
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
index 9ef639894..901697925 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.cpp
@@ -39,8 +39,8 @@ SingleVerSyncTaskContext::~SingleVerSyncTaskContext()
subManager_ = nullptr;
}
-int SingleVerSyncTaskContext::Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
- const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator)
+int SingleVerSyncTaskContext::Initialize(const std::string &deviceId, const std::string &userId,
+ ISyncInterface *syncInterface, const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator)
{
if (deviceId.empty() || syncInterface == nullptr || metadata == nullptr ||
communicator == nullptr) {
@@ -53,10 +53,14 @@ int SingleVerSyncTaskContext::Initialize(const std::string &deviceId, ISyncInter
return -E_OUT_OF_MEMORY;
}
deviceId_ = deviceId;
+ userId_ = userId;
std::vector<uint8_t> dbIdentifier = syncInterface->GetIdentifier();
dbIdentifier.resize(3); // only show 3 bytes
syncActionName_ = DBDfxAdapter::SYNC_ACTION + "_" +
DBCommon::VectorToHexString(dbIdentifier) + "_" + deviceId_.c_str();
+ if (!userId_.empty()) {
+ syncActionName_.append("_" + userId_);
+ }
TimerAction timeOutCallback;
int errCode = stateMachine_->Initialize(this, syncInterface, metadata, communicator);
if (errCode != E_OK) {
@@ -117,7 +121,7 @@ int SingleVerSyncTaskContext::AddSyncOperation(SyncOperation *operation)
});
if (iter != requestTargetQueue_.end()) {
static_cast<SingleVerSyncTarget *>(*iter)->SetEndWaterMark(timeHelper_->GetTime());
- operation->SetStatus(deviceId_, SyncOperation::OP_FINISHED_ALL);
+ operation->SetStatus({deviceId_, userId_}, SyncOperation::OP_FINISHED_ALL);
return E_OK;
}
}
@@ -231,7 +235,7 @@ void SingleVerSyncTaskContext::Abort(int status)
{
std::lock_guard<std::mutex> lock(operationLock_);
if (syncOperation_ != nullptr) {
- syncOperation_->SetStatus(deviceId_, status, GetCommErrCode());
+ syncOperation_->SetStatus({deviceId_, userId_}, status, GetCommErrCode());
if ((status >= SyncOperation::OP_FINISHED_ALL)) {
UnlockObj();
if (syncOperation_->CheckIsAllFinished()) {
@@ -279,11 +283,8 @@ void SingleVerSyncTaskContext::ClearAllSyncTask()
continue; // not exit this scene
}
LOGI("[SingleVerSyncTaskContext] killing syncId=%d,dev=%s", tmpOperation->GetSyncId(), STR_MASK(deviceId_));
- if (target->IsAutoSync()) {
- tmpOperation->SetStatus(deviceId_, SyncOperation::OP_FINISHED_ALL);
- } else {
- tmpOperation->SetStatus(deviceId_, SyncOperation::OP_COMM_ABNORMAL);
- }
+ int status = target->IsAutoSync() ? SyncOperation::OP_FINISHED_ALL : SyncOperation::OP_COMM_ABNORMAL;
+ tmpOperation->SetStatus({deviceId_, userId_}, status);
if (tmpOperation->CheckIsAllFinished()) {
tmpOperation->Finished();
}
@@ -599,19 +600,19 @@ void SingleVerSyncTaskContext::StopFeedDogForGetData()
stateMachine_->StopFeedDogForGetData();
}
-void SingleVerSyncTaskContext::UpdateOperationFinishedCount(const std::string &deviceId, uint32_t count)
+void SingleVerSyncTaskContext::UpdateOperationFinishedCount(const DeviceSyncTarget &syncTarget, uint32_t count)
{
std::lock_guard<std::mutex> lock(operationLock_);
if (syncOperation_ != nullptr) {
- syncOperation_->UpdateFinishedCount(deviceId, count);
+ syncOperation_->UpdateFinishedCount(syncTarget, count);
}
}
-void SingleVerSyncTaskContext::SetOperationSyncProcessTotal(const std::string &deviceId, uint32_t total)
+void SingleVerSyncTaskContext::SetOperationSyncProcessTotal(const DeviceSyncTarget &syncTarget, uint32_t total)
{
std::lock_guard<std::mutex> lock(operationLock_);
if (syncOperation_ != nullptr) {
- syncOperation_->SetSyncProcessTotal(deviceId, total);
+ syncOperation_->SetSyncProcessTotal(syncTarget, total);
}
}
diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
index 0cb30f516..40642e44a 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_sync_task_context.h
@@ -40,7 +40,7 @@ public:
DISABLE_COPY_ASSIGN_MOVE(SingleVerSyncTaskContext);
// Init SingleVerSyncTaskContext
- int Initialize(const std::string &deviceId, ISyncInterface *syncInterface,
+ int Initialize(const std::string &deviceId, const std::string &userId, ISyncInterface *syncInterface,
const std::shared_ptr<Metadata> &metadata, ICommunicator *communicator) override;
// Add a sync task target with the operation to the queue
@@ -137,8 +137,8 @@ public:
void StartFeedDogForGetData(uint32_t sessionId);
void StopFeedDogForGetData();
- void UpdateOperationFinishedCount(const std::string &deviceId, uint32_t count);
- void SetOperationSyncProcessTotal(const std::string &deviceId, uint32_t total);
+ void UpdateOperationFinishedCount(const DeviceSyncTarget &syncTarget, uint32_t count);
+ void SetOperationSyncProcessTotal(const DeviceSyncTarget &syncTarget, uint32_t total);
void SetInitWaterMark(WaterMark waterMark);
WaterMark GetInitWaterMark() const;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.cpp b/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.cpp
index eb6db37e5..635e8b9b4 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.cpp
@@ -201,12 +201,12 @@ void SubscribeManager::GetRemoteSubscribeQueryIds(const std::string &device,
}
}
-int SubscribeManager::LocalSubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const
+int SubscribeManager::LocalSubscribeLimitCheck(const std::vector<DeviceSyncTarget> &syncTargets, QuerySyncObject &query) const
{
std::shared_lock<std::shared_mutex> lock(localSubscribeMapLock_);
size_t devNum = localSubscribeMap_.size();
- for (const auto &device : devices) {
- if (localSubscribeMap_.find(device) != localSubscribeMap_.end()) {
+ for (const auto &syncTarget : syncTargets) {
+ if (localSubscribeMap_.find(syncTarget.device) != localSubscribeMap_.end()) {
continue;
}
devNum++;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.h b/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.h
index bfbbfcd10..428a3df1b 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/subscribe_manager.h
@@ -84,7 +84,7 @@ public:
bool IsLastRemoteContainSubscribe(const std::string &device, const std::string &queryId) const;
- int LocalSubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const;
+ int LocalSubscribeLimitCheck(const std::vector<DeviceSyncTarget> &syncTargets, QuerySyncObject &query) const;
bool IsQueryExistSubscribe(const std::string &queryId) const;
private:
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
index 5d4a60e55..092ff3c5c 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.cpp
@@ -115,9 +115,11 @@ int SyncEngine::Close()
// Clear SyncContexts
{
std::unique_lock<std::mutex> lock(contextMapLock_);
- for (auto &iter : syncTaskContextMap_) {
- decContext.push_back(iter.second);
- iter.second = nullptr;
+ for (auto &deviceIter : syncTaskContextMap_) {
+ for (auto &userIdIter : deviceIter.second) {
+ decContext.push_back(userIdIter.second);
+ userIdIter.second = nullptr;
+ }
}
syncTaskContextMap_.clear();
}
@@ -163,22 +165,53 @@ int SyncEngine::AddSyncOperation(SyncOperation *operation)
return -E_INVALID_ARGS;
}
- std::vector<std::string> devices = operation->GetDevices();
+ if (operation->GetSyncTargets().empty()) {
+ return AddSyncOperationForDevices(operation);
+ }
+ return AddSyncOperationForSyncTargets(operation);
+}
+
+int SyncEngine::AddSyncOperationForDevices(SyncOperation *operation)
+{
+ std::vector<DeviceSyncTarget> syncTargets = operation->GetSyncTargets();
std::string localDeviceId;
int errCode = GetLocalDeviceId(localDeviceId);
- for (const auto &deviceId : devices) {
+ for (const auto &syncTarget : syncTargets) {
if (errCode != E_OK) {
- operation->SetStatus(deviceId, errCode == -E_BUSY ?
+ operation->SetStatus(syncTarget, errCode == -E_BUSY ?
SyncOperation::OP_BUSY_FAILURE : SyncOperation::OP_FAILED);
continue;
}
- if (!CheckDeviceIdValid(deviceId, localDeviceId)) {
- operation->SetStatus(deviceId, SyncOperation::OP_INVALID_ARGS);
+ if (!CheckDeviceIdValid(syncTarget.device, localDeviceId)) {
+ operation->SetStatus(syncTarget, SyncOperation::OP_INVALID_ARGS);
continue;
}
- operation->SetStatus(deviceId, SyncOperation::OP_WAITING);
- if (AddSyncOperForContext(deviceId, operation) != E_OK) {
- operation->SetStatus(deviceId, SyncOperation::OP_FAILED);
+ operation->SetStatus(syncTarget, SyncOperation::OP_WAITING);
+ if (AddSyncOperForContext(syncTarget.device, operation, syncTarget.userId) != E_OK) {
+ operation->SetStatus(syncTarget, SyncOperation::OP_FAILED);
+ }
+ }
+ return E_OK;
+}
+
+int SyncEngine::AddSyncOperationForSyncTargets(SyncOperation *operation)
+{
+ std::vector<DeviceSyncTarget> syncTargets = operation->GetSyncTargets();
+ std::string localDeviceId;
+ int errCode = GetLocalDeviceId(localDeviceId);
+ for (const auto &syncTarget : syncTargets) {
+ if (errCode != E_OK) {
+ operation->SetStatus(syncTarget, errCode == -E_BUSY ?
+ SyncOperation::OP_BUSY_FAILURE : SyncOperation::OP_FAILED);
+ continue;
+ }
+ if (!CheckDeviceIdValid(syncTarget.device, localDeviceId)) {
+ operation->SetStatus(syncTarget, SyncOperation::OP_INVALID_ARGS);
+ continue;
+ }
+ operation->SetStatus(syncTarget, SyncOperation::OP_WAITING);
+ if (AddSyncOperForContext(syncTarget.device, operation, syncTarget.userId) != E_OK) {
+ operation->SetStatus(syncTarget, SyncOperation::OP_FAILED);
}
}
return E_OK;
@@ -187,10 +220,12 @@ int SyncEngine::AddSyncOperation(SyncOperation *operation)
void SyncEngine::RemoveSyncOperation(int syncId)
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (auto &iter : syncTaskContextMap_) {
- ISyncTaskContext *context = iter.second;
- if (context != nullptr) {
- context->RemoveSyncOperation(syncId);
+ for (auto &deviceIter : syncTaskContextMap_) {
+ for (auto &userIdIter : deviceIter.second) {
+ ISyncTaskContext *context = userIdIter.second;
+ if (context != nullptr) {
+ context->RemoveSyncOperation(syncId);
+ }
}
}
}
@@ -297,7 +332,8 @@ int SyncEngine::InitComunicator(const ISyncInterface *syncInterface)
}
errCode = communicator_->RegOnMessageCallback(
- [this](const std::string &targetDev, Message *inMsg) { MessageReciveCallback(targetDev, inMsg); }, []() {});
+ [this](const std::string &targetDev, const std::string &userId, Message *inMsg)
+ { MessageReciveCallback(targetDev, userId, inMsg); }, []() {});
if (errCode != E_OK) {
LOGE("[SyncEngine] SyncRequestCallback register failed! err = %d", errCode);
communicatorAggregator->ReleaseCommunicator(communicator_, GetUserId(syncInterface));
@@ -320,16 +356,16 @@ int SyncEngine::InitComunicator(const ISyncInterface *syncInterface)
return errCode;
}
-int SyncEngine::AddSyncOperForContext(const std::string &deviceId, SyncOperation *operation)
+int SyncEngine::AddSyncOperForContext(const std::string &deviceId, SyncOperation *operation, const std::string &userId)
{
int errCode = E_OK;
ISyncTaskContext *context = nullptr;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(deviceId);
+ context = FindSyncTaskContext(deviceId, userId);
if (context == nullptr) {
if (!IsKilled()) {
- context = GetSyncTaskContext(deviceId, errCode);
+ context = GetSyncTaskContext(deviceId, userId, errCode);
}
if (context == nullptr) {
return errCode;
@@ -350,8 +386,8 @@ int SyncEngine::AddSyncOperForContext(const std::string &deviceId, SyncOperation
return errCode;
}
-void SyncEngine::MessageReciveCallbackTask(ISyncTaskContext *context, const ICommunicator *communicator,
- Message *inMsg)
+void SyncEngine::MessageReciveCallbackTask(ISyncTaskContext *context, const std::string &userId,
+ const ICommunicator *communicator, Message *inMsg)
{
std::string deviceId = context->GetDeviceId();
@@ -372,10 +408,11 @@ void SyncEngine::MessageReciveCallbackTask(ISyncTaskContext *context, const ICom
delete inMsg;
inMsg = nullptr;
MSG_CALLBACK_OUT_NOT_DEL:
- ScheduleTaskOut(context, communicator);
+ ScheduleTaskOut(context, userId, communicator);
}
-void SyncEngine::RemoteDataChangedTask(ISyncTaskContext *context, const ICommunicator *communicator, Message *inMsg)
+void SyncEngine::RemoteDataChangedTask(ISyncTaskContext *context, const std::string &userId,
+ const ICommunicator *communicator, Message *inMsg)
{
std::string deviceId = context->GetDeviceId();
if (onRemoteDataChanged_ && deviceManager_->IsDeviceOnline(deviceId)) {
@@ -385,18 +422,18 @@ void SyncEngine::RemoteDataChangedTask(ISyncTaskContext *context, const ICommuni
}
delete inMsg;
inMsg = nullptr;
- ScheduleTaskOut(context, communicator);
+ ScheduleTaskOut(context, userId, communicator);
}
-void SyncEngine::ScheduleTaskOut(ISyncTaskContext *context, const ICommunicator *communicator)
+void SyncEngine::ScheduleTaskOut(ISyncTaskContext *context, const std::string &userId, const ICommunicator *communicator)
{
- (void)DealMsgUtilQueueEmpty();
+ (void)DealMsgUtilQueueEmpty(userId);
DecExecTaskCount();
RefObject::DecObjRef(communicator);
RefObject::DecObjRef(context);
}
-int SyncEngine::DealMsgUtilQueueEmpty()
+int SyncEngine::DealMsgUtilQueueEmpty(const std::string &userId)
{
if (!isActive_) {
return -E_BUSY; // db is closing just return
@@ -417,11 +454,11 @@ int SyncEngine::DealMsgUtilQueueEmpty()
// it will deal with the first message in queue, we should increase object reference counts and sure that resources
// could be prevented from destroying by other threads.
do {
- ISyncTaskContext *nextContext = GetContextForMsg(inMsg->GetTarget(), errCode);
+ ISyncTaskContext *nextContext = GetContextForMsg(inMsg->GetTarget(), userId, errCode);
if (errCode != E_OK) {
break;
}
- errCode = ScheduleDealMsg(nextContext, inMsg);
+ errCode = ScheduleDealMsg(nextContext, userId, inMsg);
if (errCode != E_OK) {
RefObject::DecObjRef(nextContext);
}
@@ -434,12 +471,12 @@ int SyncEngine::DealMsgUtilQueueEmpty()
return errCode;
}
-ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, int &errCode)
+ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, const std::string &userId, int &errCode)
{
ISyncTaskContext *context = nullptr;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(targetDev);
+ context = FindSyncTaskContext(targetDev, userId);
if (context != nullptr) { // LCOV_EXCL_BR_LINE
if (context->IsKilled()) {
errCode = -E_OBJ_IS_KILLED;
@@ -450,7 +487,7 @@ ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, int
errCode = -E_OBJ_IS_KILLED;
return nullptr;
}
- context = GetSyncTaskContext(targetDev, errCode);
+ context = GetSyncTaskContext(targetDev, userId, errCode);
if (context == nullptr) {
return nullptr;
}
@@ -461,7 +498,7 @@ ISyncTaskContext *SyncEngine::GetContextForMsg(const std::string &targetDev, int
return context;
}
-int SyncEngine::ScheduleDealMsg(ISyncTaskContext *context, Message *inMsg)
+int SyncEngine::ScheduleDealMsg(ISyncTaskContext *context, const std::string &userId, Message *inMsg)
{
if (inMsg == nullptr) {
LOGE("[SyncEngine] MessageReciveCallback inMsg is null!");
@@ -477,10 +514,11 @@ int SyncEngine::ScheduleDealMsg(ISyncTaskContext *context, Message *inMsg)
int errCode = E_OK;
// deal remote local data changed message
if (inMsg->GetMessageId() == LOCAL_DATA_CHANGED) {
- RemoteDataChangedTask(context, comProxy, inMsg);
+ RemoteDataChangedTask(context, userId, comProxy, inMsg);
} else {
errCode = RuntimeContext::GetInstance()->ScheduleTask(
- [this, context, comProxy, inMsg] { MessageReciveCallbackTask(context, comProxy, inMsg); });
+ [this, context, userId, comProxy, inMsg]
+ { MessageReciveCallbackTask(context, userId, comProxy, inMsg); });
}
if (errCode != E_OK) {
@@ -490,10 +528,10 @@ int SyncEngine::ScheduleDealMsg(ISyncTaskContext *context, Message *inMsg)
return errCode;
}
-void SyncEngine::MessageReciveCallback(const std::string &targetDev, Message *inMsg)
+void SyncEngine::MessageReciveCallback(const std::string &targetDev, const std::string &userId, Message *inMsg)
{
IncExecTaskCount();
- int errCode = MessageReciveCallbackInner(targetDev, inMsg);
+ int errCode = MessageReciveCallbackInner(targetDev, userId, inMsg);
if (errCode != E_OK) {
if (inMsg != nullptr) {
delete inMsg;
@@ -504,7 +542,7 @@ void SyncEngine::MessageReciveCallback(const std::string &targetDev, Message *in
}
}
-int SyncEngine::MessageReciveCallbackInner(const std::string &targetDev, Message *inMsg)
+int SyncEngine::MessageReciveCallbackInner(const std::string &targetDev, const std::string &userId, Message *inMsg)
{
if (targetDev.empty() || inMsg == nullptr) {
LOGE("[SyncEngine][MessageReciveCallback] from a invalid device or inMsg is null ");
@@ -544,12 +582,12 @@ int SyncEngine::MessageReciveCallbackInner(const std::string &targetDev, Message
}
int errCode = E_OK;
- ISyncTaskContext *nextContext = GetContextForMsg(targetDev, errCode);
+ ISyncTaskContext *nextContext = GetContextForMsg(targetDev, userId, errCode);
if (errCode != E_OK) {
return errCode;
}
LOGD("[SyncEngine] MessageReciveCallback MSG ID = %d", inMsg->GetMessageId());
- return ScheduleDealMsg(nextContext, inMsg);
+ return ScheduleDealMsg(nextContext, userId, inMsg);
}
void SyncEngine::PutMsgIntoQueue(const std::string &targetDev, Message *inMsg, int msgSize)
@@ -598,34 +636,41 @@ int SyncEngine::GetMsgSize(const Message *inMsg) const
}
}
-ISyncTaskContext *SyncEngine::FindSyncTaskContext(const std::string &deviceId)
+ISyncTaskContext *SyncEngine::FindSyncTaskContext(const std::string &deviceId, const std::string &userId)
{
- auto iter = syncTaskContextMap_.find(deviceId);
- if (iter != syncTaskContextMap_.end()) {
- ISyncTaskContext *context = iter->second;
- return context;
+ auto deviceIter = syncTaskContextMap_.find(deviceId);
+ if (deviceIter != syncTaskContextMap_.end()) {
+ auto userIdIter = deviceIter->second.find(userId);
+ if (userIdIter != deviceIter->second.end()) {
+ ISyncTaskContext *context = userIdIter->second;
+ return context;
+ }
}
return nullptr;
}
-ISyncTaskContext *SyncEngine::GetSyncTaskContextAndInc(const std::string &deviceId)
+std::map<std::string, ISyncTaskContext *> SyncEngine::GetSyncTaskContextAndInc(const std::string &deviceId)
{
- ISyncTaskContext *context = nullptr;
+ std::map<std::string, ISyncTaskContext *> contexts;
std::lock_guard<std::mutex> lock(contextMapLock_);
- context = FindSyncTaskContext(deviceId);
- if (context == nullptr) {
+ if (syncTaskContextMap_.find(deviceId) == syncTaskContextMap_.end()) {
LOGI("[SyncEngine] dev=%s, context is null, no need to clear sync operation", STR_MASK(deviceId));
- return nullptr;
+ return contexts;
}
- if (context->IsKilled()) { // LCOV_EXCL_BR_LINE
- LOGI("[SyncEngine] context is killing");
- return nullptr;
+ for (const auto &context : syncTaskContextMap_[deviceId]) {
+ if (context.second == nullptr) {
+ continue;
+ }
+ if (context.second->IsKilled()) {
+ LOGI("[SyncEngine] context[%s] is killing", context.first.c_str());
+ }
+ RefObject::IncObjRef(context.second);
+ contexts[context.first] = context.second;
}
- RefObject::IncObjRef(context);
- return context;
+ return contexts;
}
-ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, int &errCode)
+ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, const std::string &userId, int &errCode)
{
auto storage = GetAndIncSyncInterface();
if (storage == nullptr) {
@@ -639,7 +684,7 @@ ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, in
LOGE("[SyncEngine] SyncTaskContext alloc failed, may be no memory available!");
return nullptr;
}
- errCode = context->Initialize(deviceId, storage, metadata_, communicatorProxy_);
+ errCode = context->Initialize(deviceId, userId, storage, metadata_, communicatorProxy_);
if (errCode != E_OK) {
LOGE("[SyncEngine] context init failed err %d, dev %s", errCode, STR_MASK(deviceId));
RefObject::DecObjRef(context);
@@ -647,7 +692,7 @@ ISyncTaskContext *SyncEngine::GetSyncTaskContext(const std::string &deviceId, in
context = nullptr;
return nullptr;
}
- syncTaskContextMap_.insert(std::pair<std::string, ISyncTaskContext *>(deviceId, context));
+ syncTaskContextMap_[deviceId].insert(std::pair<std::string, ISyncTaskContext *>(userId, context));
// IncRef for SyncEngine to make sure SyncEngine is valid when context access
RefObject::IncObjRef(this);
context->OnLastRef([this, deviceId, storage]() {
@@ -759,10 +804,12 @@ void SyncEngine::SetSyncRetry(bool isRetry)
isSyncRetry_ = isRetry;
LOGI("[SyncEngine] SetSyncRetry:%d ok", isRetry);
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (auto &iter : syncTaskContextMap_) {
- ISyncTaskContext *context = iter.second;
- if (context != nullptr) { // LCOV_EXCL_BR_LINE
- context->SetSyncRetry(isRetry);
+ for (auto &deviceIter : syncTaskContextMap_) {
+ for (auto &userIdEntry : deviceIter.second) {
+ ISyncTaskContext *context = userIdEntry.second;
+ if (context != nullptr) { // LCOV_EXCL_BR_LINE
+ context->SetSyncRetry(isRetry);
+ }
}
}
}
@@ -860,7 +907,7 @@ void SyncEngine::OfflineHandleByDevice(const std::string &deviceId, ISyncInterfa
static_cast<SyncGenericInterface *>(storage)->GetDBInfo(dbInfo);
RuntimeContext::GetInstance()->RemoveRemoteSubscribe(dbInfo, deviceId);
// get context and Inc context if context is not nullptr
- ISyncTaskContext *context = GetSyncTaskContextAndInc(deviceId);
+ std::map<std::string, ISyncTaskContext *> contexts = GetSyncTaskContextAndInc(deviceId);
{
std::lock_guard<std::mutex> lock(communicatorProxyLock_);
if (communicatorProxy_ == nullptr) {
@@ -868,25 +915,31 @@ void SyncEngine::OfflineHandleByDevice(const std::string &deviceId, ISyncInterfa
}
if (communicatorProxy_->IsDeviceOnline(deviceId)) { // LCOV_EXCL_BR_LINE
LOGI("[SyncEngine] target dev=%s is online, no need to clear task.", STR_MASK(deviceId));
- RefObject::DecObjRef(context);
+ for (const auto &context : contexts) {
+ RefObject::DecObjRef(context.second);
+ }
return;
}
}
// means device is offline, clear local subscribe
subManager_->ClearLocalSubscribeQuery(deviceId);
// clear sync task
- if (context != nullptr) {
- context->ClearAllSyncTask();
- RefObject::DecObjRef(context);
+ for (const auto &context : contexts) {
+ if (context.second != nullptr) {
+ context.second->ClearAllSyncTask();
+ RefObject::DecObjRef(context.second);
+ }
}
}
void SyncEngine::ClearAllSyncTaskByDevice(const std::string &deviceId)
{
- ISyncTaskContext *context = GetSyncTaskContextAndInc(deviceId);
- if (context != nullptr) {
- context->ClearAllSyncTask();
- RefObject::DecObjRef(context);
+ std::map<std::string, ISyncTaskContext *> contexts = GetSyncTaskContextAndInc(deviceId);
+ for (const auto &context : contexts) {
+ if (context.second != nullptr) {
+ context.second->ClearAllSyncTask();
+ RefObject::DecObjRef(context.second);
+ }
}
}
@@ -932,7 +985,8 @@ ICommunicator *SyncEngine::AllocCommunicator(const std::string &identifier, int
}
errCode = communicator->RegOnMessageCallback(
- [this](const std::string &targetDev, Message *inMsg) { MessageReciveCallback(targetDev, inMsg); }, []() {});
+ [this](const std::string &targetDev, const std::string &userId, Message *inMsg)
+ { MessageReciveCallback(targetDev, userId, inMsg); }, []() {});
if (errCode != E_OK) {
LOGE("[SyncEngine] SyncRequestCallback register failed in SetEqualIdentifier! err = %d", errCode);
communicatorAggregator->ReleaseCommunicator(communicator, userId);
@@ -1030,9 +1084,9 @@ void SyncEngine::StopAutoSubscribeTimer()
{
}
-int SyncEngine::SubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const
+int SyncEngine::SubscribeLimitCheck(const std::vector<DeviceSyncTarget> &syncTargets, QuerySyncObject &query) const
{
- return subManager_->LocalSubscribeLimitCheck(devices, query);
+ return subManager_->LocalSubscribeLimitCheck(syncTargets, query);
}
@@ -1065,13 +1119,15 @@ void SyncEngine::SchemaChange()
std::vector<ISyncTaskContext *> tmpContextVec;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (const auto &entry : syncTaskContextMap_) { // LCOV_EXCL_BR_LINE
- auto context = entry.second;
- if (context == nullptr || context->IsKilled()) {
- continue;
+ for (const auto &deviceEntry : syncTaskContextMap_) { // LCOV_EXCL_BR_LINE
+ for (const auto &userIdEntry : deviceEntry.second) {
+ auto context = userIdEntry.second;
+ if (context == nullptr || context->IsKilled()) {
+ continue;
+ }
+ RefObject::IncObjRef(context);
+ tmpContextVec.push_back(context);
}
- RefObject::IncObjRef(context);
- tmpContextVec.push_back(context);
}
}
for (const auto &entryContext : tmpContextVec) {
@@ -1112,9 +1168,11 @@ void SyncEngine::Dump(int fd)
DBDumpHelper::Dump(fd, "\t]\n\tcontext info [\n");
// dump context info
std::lock_guard<std::mutex> autoLock(contextMapLock_);
- for (const auto &entry : syncTaskContextMap_) {
- if (entry.second != nullptr) {
- entry.second->Dump(fd);
+ for (const auto &deviceEntry : syncTaskContextMap_) {
+ for (const auto &userIdEntry : deviceEntry.second) {
+ if (userIdEntry.second != nullptr) {
+ userIdEntry.second->Dump(fd);
+ }
}
}
DBDumpHelper::Dump(fd, "\t]\n\n");
@@ -1198,17 +1256,19 @@ void SyncEngine::AbortMachineIfNeed(uint32_t syncId)
std::vector<ISyncTaskContext *> abortContexts;
{
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (const auto &entry : syncTaskContextMap_) {
- auto context = entry.second;
- if (context == nullptr || context->IsKilled()) { // LCOV_EXCL_BR_LINE
- continue;
- }
- RefObject::IncObjRef(context);
- if (context->GetSyncId() == syncId) {
+ for (const auto &deviceEntry : syncTaskContextMap_) {
+ for (const auto &userIdEntry : deviceEntry.second) {
+ auto context = userIdEntry.second;
+ if (context == nullptr || context->IsKilled()) { // LCOV_EXCL_BR_LINE
+ continue;
+ }
RefObject::IncObjRef(context);
- abortContexts.push_back(context);
+ if (context->GetSyncId() == syncId) {
+ RefObject::IncObjRef(context);
+ abortContexts.push_back(context);
+ }
+ RefObject::DecObjRef(context);
}
- RefObject::DecObjRef(context);
}
}
for (const auto &abortContext : abortContexts) {
@@ -1276,9 +1336,11 @@ void SyncEngine::TimeChange()
{
// copy context
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (const auto &iter : syncTaskContextMap_) {
- RefObject::IncObjRef(iter.second);
- decContext.push_back(iter.second);
+ for (const auto &deviceIter : syncTaskContextMap_) {
+ for (const auto &userIdIter : deviceIter.second) {
+ RefObject::IncObjRef(userIdIter.second);
+ decContext.push_back(userIdIter.second);
+ }
}
}
for (auto &iter : decContext) {
@@ -1293,9 +1355,11 @@ int32_t SyncEngine::GetResponseTaskCount()
{
// copy context
std::lock_guard<std::mutex> lock(contextMapLock_);
- for (const auto &iter : syncTaskContextMap_) {
- RefObject::IncObjRef(iter.second);
- decContext.push_back(iter.second);
+ for (const auto &deviceIter : syncTaskContextMap_) {
+ for (const auto &userIdIter : deviceIter.second) {
+ RefObject::IncObjRef(userIdIter.second);
+ decContext.push_back(userIdIter.second);
+ }
}
}
int32_t taskCount = 0;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
index 78c931922..b1696900d 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_engine.h
@@ -114,7 +114,7 @@ public:
// used by SingleVerSyncer when remote/local db closed
void StopAutoSubscribeTimer() override;
- int SubscribeLimitCheck(const std::vector<std::string> &devices, QuerySyncObject &query) const override;
+ int SubscribeLimitCheck(const std::vector<DeviceSyncTarget> &syncTargets, QuerySyncObject &query) const override;
bool IsEngineActive() const override;
@@ -142,8 +142,8 @@ protected:
virtual ISyncTaskContext *CreateSyncTaskContext(const ISyncInterface &syncInterface) = 0;
// Find SyncTaskContext from the map
- ISyncTaskContext *FindSyncTaskContext(const std::string &deviceId);
- ISyncTaskContext *GetSyncTaskContextAndInc(const std::string &deviceId);
+ ISyncTaskContext *FindSyncTaskContext(const std::string &deviceId, const std::string &userId);
+ std::map<std::string, ISyncTaskContext *> GetSyncTaskContextAndInc(const std::string &deviceId);
void GetQueryAutoSyncParam(const std::string &device, const QuerySyncObject &query, InternalSyncParma &outParam);
void GetSubscribeSyncParam(const std::string &device, const QuerySyncObject &query, InternalSyncParma &outParam);
@@ -151,12 +151,15 @@ protected:
ISyncInterface *GetAndIncSyncInterface();
void SetSyncInterface(ISyncInterface *syncInterface);
- ISyncTaskContext *GetSyncTaskContext(const std::string &deviceId, int &errCode);
+ ISyncTaskContext *GetSyncTaskContext(const std::string &deviceId, const std::string &userId, int &errCode);
+
+ int AddSyncOperationForDevices(SyncOperation *operation);
+ int AddSyncOperationForSyncTargets(SyncOperation *operation);
std::mutex storageMutex_;
ISyncInterface *syncInterface_;
// Used to store all send sync task infos (such as pull sync response, and push sync request)
- std::map<std::string, ISyncTaskContext *> syncTaskContextMap_;
+ std::map<std::string, std::map<std::string, ISyncTaskContext *>> syncTaskContextMap_;
std::mutex contextMapLock_;
std::shared_ptr<SubscribeManager> subManager_;
std::function<void(const InternalSyncParma &param)> queryAutoSyncCallback_;
@@ -171,20 +174,22 @@ private:
int InitComunicator(const ISyncInterface *syncInterface);
// Add the sync task info to the map.
- int AddSyncOperForContext(const std::string &deviceId, SyncOperation *operation);
+ int AddSyncOperForContext(const std::string &deviceId, SyncOperation *operation, const std::string &userId);
// Sync Request CallbackTask run at a sub thread.
- void MessageReciveCallbackTask(ISyncTaskContext *context, const ICommunicator *communicator, Message *inMsg);
+ void MessageReciveCallbackTask(ISyncTaskContext *context, const std::string &userId,
+ const ICommunicator *communicator, Message *inMsg);
- void RemoteDataChangedTask(ISyncTaskContext *context, const ICommunicator *communicator, Message *inMsg);
+ void RemoteDataChangedTask(ISyncTaskContext *context, const std::string &userId, const ICommunicator *communicator,
+ Message *inMsg);
- void ScheduleTaskOut(ISyncTaskContext *context, const ICommunicator *communicator);
+ void ScheduleTaskOut(ISyncTaskContext *context, const std::string &userId, const ICommunicator *communicator);
// wrapper of MessageReciveCallbackTask
- void MessageReciveCallback(const std::string &targetDev, Message *inMsg);
+ void MessageReciveCallback(const std::string &targetDev, const std::string &userId, Message *inMsg);
// Sync Request Callback
- int MessageReciveCallbackInner(const std::string &targetDev, Message *inMsg);
+ int MessageReciveCallbackInner(const std::string &targetDev, const std::string &userId, Message *inMsg);
// Exec the given SyncTarget. and callback onComplete.
int ExecSyncTask(ISyncTaskContext *context);
@@ -196,12 +201,12 @@ private:
int GetMsgSize(const Message *inMsg) const;
// Do not run MessageReceiveCallbackTask until msgQueue is empty
- int DealMsgUtilQueueEmpty();
+ int DealMsgUtilQueueEmpty(const std::string &userId);
// Handle message in order.
- int ScheduleDealMsg(ISyncTaskContext *context, Message *inMsg);
+ int ScheduleDealMsg(ISyncTaskContext *context, const std::string &userId, Message *inMsg);
- ISyncTaskContext *GetContextForMsg(const std::string &targetDev, int &errCode);
+ ISyncTaskContext *GetContextForMsg(const std::string &targetDev, const std::string &userId, int &errCode);
ICommunicator *AllocCommunicator(const std::string &identifier, int &errCode, std::string userId = "");
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
index 4fd93de50..aa48c934c 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.cpp
@@ -121,7 +121,7 @@ void SyncTaskContext::SetOperationStatus(int status)
}
int finalStatus = status;
- int operationStatus = syncOperation_->GetStatus(deviceId_);
+ int operationStatus = syncOperation_->GetStatus({deviceId_, userId_});
if (status == SyncOperation::OP_SEND_FINISHED && operationStatus == SyncOperation::OP_RECV_FINISHED) {
if (GetTaskErrCode() == -E_EKEYREVOKED) { // LCOV_EXCL_BR_LINE
finalStatus = SyncOperation::OP_EKEYREVOKED_FAILURE;
@@ -135,7 +135,7 @@ void SyncTaskContext::SetOperationStatus(int status)
finalStatus = SyncOperation::OP_FINISHED_ALL;
}
}
- syncOperation_->SetStatus(deviceId_, finalStatus);
+ syncOperation_->SetStatus({deviceId_, userId_}, finalStatus);
if (finalStatus >= SyncOperation::OP_FINISHED_ALL) {
SaveLastPushTaskExecStatus(finalStatus);
}
@@ -215,7 +215,7 @@ int SyncTaskContext::GetOperationStatus() const
if (syncOperation_ == nullptr) {
return SyncOperation::OP_FINISHED_ALL;
}
- return syncOperation_->GetStatus(deviceId_);
+ return syncOperation_->GetStatus({deviceId_, userId_});
}
void SyncTaskContext::SetMode(int mode)
@@ -285,6 +285,12 @@ std::string SyncTaskContext::GetDeviceId() const
return deviceId_;
}
+// Get the current task deviceId.
+std::string SyncTaskContext::GetUserId() const
+{
+ return userId_;
+}
+
void SyncTaskContext::SetTaskExecStatus(int status)
{
taskExecStatus_ = status;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
index 42d53e7dc..1ac06e362 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/sync_task_context.h
@@ -77,6 +77,8 @@ public:
// Get the current task deviceId.
std::string GetDeviceId() const override;
+ // Get the current task userId.
+ std::string GetUserId() const override;
// Set the sync task queue exec status
void SetTaskExecStatus(int status) override;
@@ -260,6 +262,7 @@ protected:
volatile int status_;
volatile int taskExecStatus_;
std::string deviceId_;
+ std::string userId_;
std::string syncActionName_;
ISyncInterface *syncInterface_;
ICommunicator *communicator_;
diff --git a/frameworks/libs/distributeddb/syncer/src/device/syncer_proxy.cpp b/frameworks/libs/distributeddb/syncer/src/device/syncer_proxy.cpp
index 0c8d6fd62..facc73813 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/syncer_proxy.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/syncer_proxy.cpp
@@ -54,14 +54,14 @@ int SyncerProxy::Close(bool isClosedOperation)
return syncer_->Close(isClosedOperation);
}
-int SyncerProxy::Sync(const std::vector<std::string> &devices, int mode,
- const std::function<void(const std::map<std::string, int> &)> &onComplete,
+int SyncerProxy::Sync(const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const std::function<void(const std::map<DeviceSyncTarget, int> &)> &onComplete,
const std::function<void(void)> &onFinalize, bool wait)
{
if (syncer_ == nullptr) { // LCOV_EXCL_BR_LINE
return -E_NOT_INIT;
}
- return syncer_->Sync(devices, mode, onComplete, onFinalize, wait);
+ return syncer_->Sync(syncTargets, mode, onComplete, onFinalize, wait);
}
int SyncerProxy::Sync(const SyncParma &parma, uint64_t connectionId)
diff --git a/frameworks/libs/distributeddb/syncer/src/device/time_sync.cpp b/frameworks/libs/distributeddb/syncer/src/device/time_sync.cpp
index 622c532b8..6e5e04d3f 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/time_sync.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/device/time_sync.cpp
@@ -179,7 +179,7 @@ int TimeSync::RegisterTransformFunc()
}
int TimeSync::Initialize(ICommunicator *communicator, const std::shared_ptr<Metadata> &metadata,
- const ISyncInterface *storage, const DeviceID &deviceId)
+ const ISyncInterface *storage, const DeviceID &deviceId, const std::string &userId)
{
if ((communicator == nullptr) || (storage == nullptr) || (metadata == nullptr)) {
return -E_INVALID_ARGS;
@@ -191,6 +191,7 @@ int TimeSync::Initialize(ICommunicator *communicator, const std::shared_ptr<Meta
communicateHandle_ = communicator;
metadata_ = metadata;
deviceId_ = deviceId;
+ userId_ = userId;
timeHelper_ = std::make_unique<TimeHelper>();
int errCode = timeHelper_->Initialize(storage, metadata_);
@@ -484,7 +485,7 @@ bool TimeSync::IsPacketValid(const Message *inMsg, uint16_t messageType)
int TimeSync::SendPacket(const DeviceID &deviceId, const Message *message, const CommErrHandler &handler)
{
SendConfig conf;
- timeHelper_->SetSendConfig(deviceId, false, SEND_TIME_OUT, conf);
+ timeHelper_->SetSendConfig({deviceId, userId_}, false, SEND_TIME_OUT, conf);
int errCode = communicateHandle_->SendMessage(deviceId, message, conf, handler);
if (errCode != E_OK) {
LOGE("[TimeSync] SendPacket failed, err %d", errCode);
diff --git a/frameworks/libs/distributeddb/syncer/src/device/time_sync.h b/frameworks/libs/distributeddb/syncer/src/device/time_sync.h
index b8ec79919..850c97080 100644
--- a/frameworks/libs/distributeddb/syncer/src/device/time_sync.h
+++ b/frameworks/libs/distributeddb/syncer/src/device/time_sync.h
@@ -82,7 +82,7 @@ public:
static int DeSerialization(const uint8_t *buffer, uint32_t length, Message *inMsg); // register to communicator
int Initialize(ICommunicator *communicator, const std::shared_ptr<Metadata> &metadata,
- const ISyncInterface *storage, const DeviceID &deviceId);
+ const ISyncInterface *storage, const DeviceID &deviceId, const std::string &userId);
virtual int SyncStart(const CommErrHandler &handler = nullptr, uint32_t sessionId = 0); // send timesync request
@@ -153,6 +153,7 @@ protected:
std::shared_ptr<Metadata> metadata_;
std::unique_ptr<TimeHelper> timeHelper_;
DeviceID deviceId_;
+ std::string userId_;
int retryTime_;
TimerId driverTimerId_;
TimerAction driverCallback_;
diff --git a/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp b/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp
index 0e68d5fe6..73b3d662c 100644
--- a/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/sync_operation.cpp
@@ -20,9 +20,9 @@
#include "performance_analysis.h"
namespace DistributedDB {
-SyncOperation::SyncOperation(uint32_t syncId, const std::vector<std::string> &devices,
- int mode, const UserCallback &userCallback, bool isBlockSync)
- : devices_(devices),
+SyncOperation::SyncOperation(uint32_t syncId, const std::vector<DeviceSyncTarget> &syncTargets, int mode,
+ const UserCallback &userCallback, bool isBlockSync)
+ : syncTargets_(syncTargets),
syncId_(syncId),
mode_(mode),
userCallback_(userCallback),
@@ -46,15 +46,15 @@ SyncOperation::~SyncOperation()
int SyncOperation::Initialize()
{
LOGD("[SyncOperation] Init SyncOperation id:%d.", syncId_);
- std::map<std::string, DeviceSyncProcess> tempSyncProcessMap;
+ std::map<DeviceSyncTarget, DeviceSyncProcess> tempSyncProcessMap;
{
AutoLock lockGuard(this);
- for (const std::string &deviceId : devices_) {
- statuses_.insert(std::pair<std::string, int>(deviceId, OP_WAITING));
+ for (const DeviceSyncTarget &syncTarget : syncTargets_) {
+ statuses_.insert(std::pair<DeviceSyncTarget, int>(syncTarget, OP_WAITING));
DeviceSyncProcess processInfo;
processInfo.errCode = static_cast<DBStatus>(OP_WAITING);
processInfo.syncId = syncId_;
- syncProcessMap_.insert(std::pair<std::string, DeviceSyncProcess>(deviceId, processInfo));
+ syncProcessMap_.insert(std::pair<DeviceSyncTarget, DeviceSyncProcess>(syncTarget, processInfo));
}
if (mode_ == AUTO_PUSH) {
@@ -89,9 +89,10 @@ void SyncOperation::SetOnSyncFinished(const OnSyncFinished &callback)
onFinished_ = callback;
}
-void SyncOperation::SetStatus(const std::string &deviceId, int status, int commErrCode)
+void SyncOperation::SetStatus(const DeviceSyncTarget &syncTarget, int status, int commErrCode)
{
- LOGD("[SyncOperation] SetStatus dev %s{private} status %d commErrCode %d", deviceId.c_str(), status, commErrCode);
+ LOGD("[SyncOperation] SetStatus dev %s{private} user %s status %d commErrCode %d", syncTarget.device.c_str(),
+ syncTarget.userId.c_str(), status, commErrCode);
AutoLock lockGuard(this);
if (IsKilled()) {
LOGE("[SyncOperation] SetStatus failed, the SyncOperation has been killed!");
@@ -103,12 +104,15 @@ void SyncOperation::SetStatus(const std::string &deviceId, int status, int commE
}
if (userSyncProcessCallback_) {
- if (syncProcessMap_[deviceId].errCode < static_cast<DBStatus>(OP_FINISHED_ALL)) {
- syncProcessMap_[deviceId].errCode = static_cast<DBStatus>(status);
+ if (syncProcessMap_.find(syncTarget) == syncProcessMap_.end()) {
+ LOGW("[SyncOperation] Not found dev %s{private} user %s in sync process!", syncTarget.device.c_str(),
+ syncTarget.userId.c_str());
+ } else if (syncProcessMap_[syncTarget].errCode < static_cast<DBStatus>(OP_FINISHED_ALL)) {
+ syncProcessMap_[syncTarget].errCode = static_cast<DBStatus>(status);
}
}
- auto iter = statuses_.find(deviceId);
+ auto iter = statuses_.find(syncTarget);
if (iter != statuses_.end()) {
if (iter->second >= OP_FINISHED_ALL) {
return;
@@ -117,7 +121,7 @@ void SyncOperation::SetStatus(const std::string &deviceId, int status, int commE
if (((status != OP_COMM_ABNORMAL) && (status != OP_TIMEOUT)) || (commErrCode == E_OK)) {
return;
}
- commErrCodeMap_.insert(std::pair<std::string, int>(deviceId, commErrCode));
+ commErrCodeMap_.insert(std::pair<DeviceSyncTarget, int>(syncTarget, commErrCode));
}
}
@@ -139,12 +143,18 @@ void SyncOperation::SetUnfinishedDevStatus(int status)
}
item.second = status;
}
+ for (auto &item : statuses_) {
+ if (item.second >= OP_FINISHED_ALL) {
+ continue;
+ }
+ item.second = status;
+ }
}
-int SyncOperation::GetStatus(const std::string &deviceId) const
+int SyncOperation::GetStatus(const DeviceSyncTarget &syncTarget) const
{
AutoLock lockGuard(this);
- auto iter = statuses_.find(deviceId);
+ auto iter = statuses_.find(syncTarget);
if (iter != statuses_.end()) {
return iter->second;
}
@@ -161,14 +171,13 @@ int SyncOperation::GetMode() const
return mode_;
}
-void SyncOperation::ReplaceCommErrCode(std::map<std::string, int> &finishStatus)
+void SyncOperation::ReplaceCommErrCode(std::map<DeviceSyncTarget, int> &finishStatus)
{
for (auto &item : finishStatus) {
if ((item.second != OP_COMM_ABNORMAL) && (item.second != OP_TIMEOUT)) {
continue;
}
- std::string deviceId = item.first;
- auto iter = commErrCodeMap_.find(deviceId);
+ auto iter = commErrCodeMap_.find(item.first);
if (iter != commErrCodeMap_.end()) {
item.second = iter->second;
}
@@ -177,8 +186,8 @@ void SyncOperation::ReplaceCommErrCode(std::map<std::string, int> &finishStatus)
void SyncOperation::Finished()
{
- std::map<std::string, int> tmpStatus;
- std::map<std::string, DeviceSyncProcess> tmpProcessMap;
+ std::map<DeviceSyncTarget, int> tmpStatus;
+ std::map<DeviceSyncTarget, DeviceSyncProcess> tmpProcessMap;
{
AutoLock lockGuard(this);
if (IsKilled() || isFinished_) {
@@ -223,7 +232,16 @@ void SyncOperation::Finished()
const std::vector<std::string> &SyncOperation::GetDevices() const
{
- return devices_;
+ std::vector<std::string> devices;
+ for (const auto &syncTarget : syncTargets_) {
+ devices.push_back(syncTarget.device);
+ }
+ return devices;
+}
+
+const std::vector<DeviceSyncTarget> &SyncOperation::GetSyncTargets() const
+{
+ return syncTargets_;
}
void SyncOperation::WaitIfNeed()
@@ -277,14 +295,18 @@ void SyncOperation::SetSyncProcessCallFun(DeviceSyncProcessCallback callBack)
}
}
-void SyncOperation::ExeSyncProcessCallFun(const std::map<std::string, DeviceSyncProcess> &syncProcessMap)
+void SyncOperation::ExeSyncProcessCallFun(const std::map<DeviceSyncTarget, DeviceSyncProcess> &syncProcessMap)
{
+ std::map<std::string, DeviceSyncProcess> deviceSyncProcessMap;
+ for (const auto &process : syncProcessMap) {
+ deviceSyncProcessMap[process.first.device] = process.second;
+ }
if (IsBlockSync()) {
- userSyncProcessCallback_(syncProcessMap);
+ userSyncProcessCallback_(deviceSyncProcessMap);
} else {
RefObject::IncObjRef(this);
- int errCode = RuntimeContext::GetInstance()->ScheduleQueuedTask(identifier_, [this, syncProcessMap] {
- userSyncProcessCallback_(syncProcessMap);
+ int errCode = RuntimeContext::GetInstance()->ScheduleQueuedTask(identifier_, [this, deviceSyncProcessMap] {
+ userSyncProcessCallback_(deviceSyncProcessMap);
RefObject::DecObjRef(this);
});
if (errCode != E_OK) {
@@ -294,24 +316,25 @@ void SyncOperation::ExeSyncProcessCallFun(const std::map<std::string, DeviceSync
}
}
-void SyncOperation::UpdateFinishedCount(const std::string &deviceId, uint32_t count)
+void SyncOperation::UpdateFinishedCount(const DeviceSyncTarget &syncTarget, uint32_t count)
{
if (this->userSyncProcessCallback_) {
- std::map<std::string, DeviceSyncProcess> tmpMap;
+ std::map<DeviceSyncTarget, DeviceSyncProcess> tmpMap;
{
AutoLock lockGuard(this);
if (IsKilled()) {
return;
}
- LOGD("[UpdateFinishedCount] deviceId %s{private} count %u", deviceId.c_str(), count);
- this->syncProcessMap_[deviceId].pullInfo.finishedCount += count;
+ LOGD("[UpdateFinishedCount] deviceId %s{private} user %s count %u", syncTarget.device.c_str(),
+ syncTarget.userId.c_str(), count);
+ this->syncProcessMap_[syncTarget].pullInfo.finishedCount += count;
tmpMap = this->syncProcessMap_;
}
ExeSyncProcessCallFun(tmpMap);
}
}
-void SyncOperation::SetSyncProcessTotal(const std::string &deviceId, uint32_t total)
+void SyncOperation::SetSyncProcessTotal(const DeviceSyncTarget &syncTarget, uint32_t total)
{
if (this->userSyncProcessCallback_) {
{
@@ -319,8 +342,9 @@ void SyncOperation::SetSyncProcessTotal(const std::string &deviceId, uint32_t to
if (IsKilled()) {
return;
}
- LOGD("[SetSyncProcessTotal] total=%u, syncId=%u, deviceId=%s{private}", total, syncId_, deviceId.c_str());
- this->syncProcessMap_[deviceId].pullInfo.total = total;
+ LOGD("[SetSyncProcessTotal] total=%u, syncId=%u, deviceId=%s{private}, userId=%s", total, syncId_,
+ syncTarget.device.c_str(), syncTarget.userId.c_str());
+ this->syncProcessMap_[syncTarget].pullInfo.total = total;
}
}
}
@@ -471,11 +495,12 @@ ProcessStatus SyncOperation::DBStatusTransProcess(int operationStatus)
return result == std::end(syncOperationProcessStatus) ? FINISHED : result->proStatus;
}
-std::string SyncOperation::GetFinishDetailMsg(const std::map<std::string, int> &finishStatus)
+std::string SyncOperation::GetFinishDetailMsg(const std::map<DeviceSyncTarget, int> &finishStatus)
{
std::string msg = "Sync detail is:";
- for (const auto &[dev, status]: finishStatus) {
- msg += "dev=" + DBCommon::StringMasking(dev);
+ for (const auto &[syncTarget, status]: finishStatus) {
+ msg += "dev=" + DBCommon::StringMasking(syncTarget.device);
+ msg += " user=" + syncTarget.userId;
if ((status > static_cast<int>(OP_FINISHED_ALL)) || (status < E_OK)) {
msg += " sync failed, reason is " + std::to_string(status);
} else {
diff --git a/frameworks/libs/distributeddb/syncer/src/sync_operation.h b/frameworks/libs/distributeddb/syncer/src/sync_operation.h
index f3f00a5de..d867d6e7e 100644
--- a/frameworks/libs/distributeddb/syncer/src/sync_operation.h
+++ b/frameworks/libs/distributeddb/syncer/src/sync_operation.h
@@ -59,11 +59,11 @@ public:
OP_NOTADB_OR_CORRUPTED,
};
- using UserCallback = std::function<void(std::map<std::string, int>)>;
+ using UserCallback = std::function<void(std::map<DeviceSyncTarget, int>)>;
using OnSyncFinished = std::function<void(int)>;
using OnSyncFinalize = std::function<void(void)>;
- SyncOperation(uint32_t syncId, const std::vector<std::string> &devices, int mode,
+ SyncOperation(uint32_t syncId, const std::vector<DeviceSyncTarget> &syncTargets, int mode,
const UserCallback &userCallback, bool isBlockSync);
DISABLE_COPY_ASSIGN_MOVE(SyncOperation);
@@ -78,7 +78,7 @@ public:
void SetOnSyncFinished(const OnSyncFinished &callback);
// Set the sync status, running or finished
- void SetStatus(const std::string &deviceId, int status, int commErrCode = E_OK);
+ void SetStatus(const DeviceSyncTarget &syncTarget, int status, int commErrCode = E_OK);
// Set the unfinished devices sync status, running or finished
void SetUnfinishedDevStatus(int status);
@@ -87,7 +87,7 @@ public:
void SetIdentifier(const std::vector<uint8_t> &identifier);
// Get the sync status, running or finished
- int GetStatus(const std::string &deviceId) const;
+ int GetStatus(const DeviceSyncTarget &syncTarget) const;
// Get the sync id.
uint32_t GetSyncId() const;
@@ -101,6 +101,8 @@ public:
// Get the deviceId of this sync status
const std::vector<std::string> &GetDevices() const;
+ const std::vector<DeviceSyncTarget> &GetSyncTargets() const;
+
// Wait if it's a block sync
void WaitIfNeed();
@@ -137,9 +139,9 @@ public:
void SetSyncProcessCallFun(DeviceSyncProcessCallback callBack);
- void SetSyncProcessTotal(const std::string &deviceId, uint32_t total);
+ void SetSyncProcessTotal(const DeviceSyncTarget &syncTarget, uint32_t total);
- void UpdateFinishedCount(const std::string &deviceId, uint32_t count);
+ void UpdateFinishedCount(const DeviceSyncTarget &syncTarget, uint32_t count);
protected:
virtual ~SyncOperation();
@@ -151,12 +153,12 @@ private:
// called by destruction
void Finalize();
- static std::string GetFinishDetailMsg(const std::map<std::string, int> &finishStatus);
+ static std::string GetFinishDetailMsg(const std::map<DeviceSyncTarget, int> &finishStatus);
- void ReplaceCommErrCode(std::map<std::string, int> &finishStatus);
+ void ReplaceCommErrCode(std::map<DeviceSyncTarget, int> &finishStatus);
// The device list
- const std::vector<std::string> devices_;
+ const std::vector<DeviceSyncTarget> syncTargets_;
// The Syncid
uint32_t syncId_;
@@ -177,10 +179,10 @@ private:
DeviceSyncProcessCallback userSyncProcessCallback_;
// The device id we sync with
- std::map<std::string, int> statuses_;
+ std::map<DeviceSyncTarget, int> statuses_;
// passthrough errCode
- std::map<std::string, int> commErrCodeMap_;
+ std::map<DeviceSyncTarget, int> commErrCodeMap_;
// Is this operation is a block sync
volatile bool isBlockSync_;
@@ -204,12 +206,12 @@ private:
std::string identifier_;
// The device id we syncProcess with
- std::map<std::string, DeviceSyncProcess> syncProcessMap_;
+ std::map<DeviceSyncTarget, DeviceSyncProcess> syncProcessMap_;
// Can be cancelled
bool canCancel_ = false;
- void ExeSyncProcessCallFun(const std::map<std::string, DeviceSyncProcess> &syncProcessMap);
+ void ExeSyncProcessCallFun(const std::map<DeviceSyncTarget, DeviceSyncProcess> &syncProcessMap);
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/syncer/src/time_helper.cpp b/frameworks/libs/distributeddb/syncer/src/time_helper.cpp
index f82841dcc..dfda55a9f 100644
--- a/frameworks/libs/distributeddb/syncer/src/time_helper.cpp
+++ b/frameworks/libs/distributeddb/syncer/src/time_helper.cpp
@@ -135,7 +135,7 @@ TimeOffset TimeHelper::GetLocalTimeOffset() const
return metadata_->GetLocalTimeOffset();
}
-void TimeHelper::SetSendConfig(const std::string &dstTarget, bool nonBlock, uint32_t timeout, SendConfig &sendConf)
+void TimeHelper::SetSendConfig(const DeviceSyncTarget &dstTarget, bool nonBlock, uint32_t timeout, SendConfig &sendConf)
{
SetSendConfigParam(storage_->GetDbProperties(), dstTarget, false, SEND_TIME_OUT, sendConf);
}
diff --git a/frameworks/libs/distributeddb/syncer/src/time_helper.h b/frameworks/libs/distributeddb/syncer/src/time_helper.h
index d3a79e438..919270e17 100644
--- a/frameworks/libs/distributeddb/syncer/src/time_helper.h
+++ b/frameworks/libs/distributeddb/syncer/src/time_helper.h
@@ -56,7 +56,7 @@ public:
// Get local time offset
TimeOffset GetLocalTimeOffset() const;
- void SetSendConfig(const std::string &dstTarget, bool nonBlock, uint32_t timeout, SendConfig &sendConf);
+ void SetSendConfig(const DeviceSyncTarget &dstTarget, bool nonBlock, uint32_t timeout, SendConfig &sendConf);
static Timestamp GetMonotonicTime();
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.cpp b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.cpp
index ec8cf0405..54e37aff4 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.cpp
@@ -444,13 +444,13 @@ void RDBDataGenerator::FillTypeIntoDataValue(const DistributedDB::Field &field,
}
int RDBDataGenerator::PrepareVirtualDeviceEnv(const std::string &tableName, sqlite3 *db,
- DistributedDB::RelationalVirtualDevice *device)
+ DistributedDB::RelationalVirtualDevice *device, const std::string &userId)
{
- return PrepareVirtualDeviceEnv(tableName, tableName, db, device);
+ return PrepareVirtualDeviceEnv(tableName, tableName, db, device, userId);
}
int RDBDataGenerator::PrepareVirtualDeviceEnv(const std::string &scanTable, const std::string &expectTable, sqlite3 *db,
- DistributedDB::RelationalVirtualDevice *device)
+ DistributedDB::RelationalVirtualDevice *device, const std::string &userId)
{
TableInfo tableInfo;
int errCode = SQLiteUtils::AnalysisSchema(db, scanTable, tableInfo);
@@ -458,8 +458,8 @@ int RDBDataGenerator::PrepareVirtualDeviceEnv(const std::string &scanTable, cons
return errCode;
}
tableInfo.SetTableName(expectTable);
- device->SetLocalFieldInfo(tableInfo.GetFieldInfos());
- device->SetTableInfo(tableInfo);
+ device->SetLocalFieldInfo(tableInfo.GetFieldInfos(), userId);
+ device->SetTableInfo(tableInfo, userId);
return E_OK;
}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.h b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.h
index 8d8455ca9..c9d05ee15 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_data_generator.h
@@ -69,10 +69,10 @@ public:
bool syncOnlyPk = false);
static int PrepareVirtualDeviceEnv(const std::string &tableName, sqlite3 *db,
- DistributedDB::RelationalVirtualDevice *device);
+ DistributedDB::RelationalVirtualDevice *device, const std::string &userId = "");
static int PrepareVirtualDeviceEnv(const std::string &scanTable, const std::string &expectTable, sqlite3 *db,
- DistributedDB::RelationalVirtualDevice *device);
+ DistributedDB::RelationalVirtualDevice *device, const std::string &userId = "");
static DistributedDB::TableSchema FlipTableSchema(const DistributedDB::TableSchema &origin);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_deep_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_deep_test.cpp
index 9b0b725ac..79e18610e 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_deep_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_deep_test.cpp
@@ -143,11 +143,13 @@ HWTEST_F(DistributedDBCommunicatorDeepTest, WaitAndRetrySend001, TestSize.Level2
{
// Preset
Message *msgForBB = nullptr;
- g_commBB->RegOnMessageCallback([&msgForBB](const std::string &srcTarget, Message *inMsg) {
+ g_commBB->RegOnMessageCallback([&msgForBB](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
msgForBB = inMsg;
}, nullptr);
Message *msgForCA = nullptr;
- g_commCA->RegOnMessageCallback([&msgForCA](const std::string &srcTarget, Message *inMsg) {
+ g_commCA->RegOnMessageCallback([&msgForCA](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
msgForCA = inMsg;
}, nullptr);
@@ -329,7 +331,8 @@ HWTEST_F(DistributedDBCommunicatorDeepTest, Fragment001, TestSize.Level2)
{
// Preset
Message *recvMsgForBB = nullptr;
- g_commBB->RegOnMessageCallback([&recvMsgForBB](const std::string &srcTarget, Message *inMsg) {
+ g_commBB->RegOnMessageCallback([&recvMsgForBB](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvMsgForBB = inMsg;
}, nullptr);
@@ -384,7 +387,8 @@ HWTEST_F(DistributedDBCommunicatorDeepTest, Fragment002, TestSize.Level2)
{
// Preset
Message *recvMsgForCC = nullptr;
- g_commCC->RegOnMessageCallback([&recvMsgForCC](const std::string &srcTarget, Message *inMsg) {
+ g_commCC->RegOnMessageCallback([&recvMsgForCC](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvMsgForCC = inMsg;
}, nullptr);
@@ -450,7 +454,8 @@ HWTEST_F(DistributedDBCommunicatorDeepTest, Fragment003, TestSize.Level3)
{
// Preset
std::atomic<int> count {0};
- OnMessageCallback callback = [&count](const std::string &srcTarget, Message *inMsg) {
+ OnMessageCallback callback = [&count](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
delete inMsg;
inMsg = nullptr;
count.fetch_add(1, std::memory_order_seq_cst);
@@ -516,7 +521,8 @@ HWTEST_F(DistributedDBCommunicatorDeepTest, Fragment004, TestSize.Level2)
* @tc.steps: step1. connect device A with device B
*/
Message *recvMsgForBB = nullptr;
- g_commBB->RegOnMessageCallback([&recvMsgForBB](const std::string &srcTarget, Message *inMsg) {
+ g_commBB->RegOnMessageCallback([&recvMsgForBB](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvMsgForBB = inMsg;
}, nullptr);
AdapterStub::ConnectAdapterStub(g_envDeviceA.adapterHandle, g_envDeviceB.adapterHandle);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_send_receive_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_send_receive_test.cpp
index b3f7e8ff0..af5b17868 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_send_receive_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_send_receive_test.cpp
@@ -135,7 +135,8 @@ static void CheckRecvMessage(Message *recvMsg, bool isEmpty, uint32_t msgId, uin
string srcTargetFor##src##label; \
Message *recvMsgFor##src##label = nullptr; \
g_comm##src##label->RegOnMessageCallback( \
- [&srcTargetFor##src##label, &recvMsgFor##src##label](const std::string &srcTarget, Message *inMsg) { \
+ [&srcTargetFor##src##label, &recvMsgFor##src##label](const std::string &srcTarget, const std::string &userId, \
+ Message *inMsg) { \
srcTargetFor##src##label = srcTarget; \
recvMsgFor##src##label = inMsg; \
}, nullptr);
@@ -527,7 +528,8 @@ HWTEST_F(DistributedDBCommunicatorSendReceiveTest, ReceiveCheck001, TestSize.Lev
{
// Preset
int recvCount = 0;
- g_commAA->RegOnMessageCallback([&recvCount](const std::string &srcTarget, Message *inMsg) {
+ g_commAA->RegOnMessageCallback([&recvCount](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvCount++;
if (inMsg != nullptr) {
delete inMsg;
@@ -588,7 +590,8 @@ HWTEST_F(DistributedDBCommunicatorSendReceiveTest, ReceiveCheck002, TestSize.Lev
{
// Preset
int recvCount = 0;
- g_commAA->RegOnMessageCallback([&recvCount](const std::string &srcTarget, Message *inMsg) {
+ g_commAA->RegOnMessageCallback([&recvCount](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvCount++;
if (inMsg != nullptr) {
delete inMsg;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_test.cpp
index 8cda98e64..028d4e7bb 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/communicator/distributeddb_communicator_test.cpp
@@ -628,7 +628,8 @@ HWTEST_F(DistributedDBCommunicatorTest, ReportCommunicatorNotFound001, TestSize.
ICommunicator *commBA = g_envDeviceB.commAggrHandle->AllocCommunicator(LABEL_A, errCode);
ASSERT_NE(commBA, nullptr);
Message *recvMsgForBA = nullptr;
- commBA->RegOnMessageCallback([&recvMsgForBA](const std::string &srcTarget, Message *inMsg) {
+ commBA->RegOnMessageCallback([&recvMsgForBA](const std::string &srcTarget, const std::string &userId,
+ Message *inMsg) {
recvMsgForBA = inMsg;
}, nullptr);
commBA->Activate(USER_ID_1);
@@ -670,7 +671,8 @@ HWTEST_F(DistributedDBCommunicatorTest, ReportCommunicatorNotFound001, TestSize.
string srcTargetFor##src##label; \
Message *recvMsgFor##src##label = nullptr; \
comm##src##label->RegOnMessageCallback( \
- [&srcTargetFor##src##label, &recvMsgFor##src##label](const std::string &srcTarget, Message *inMsg) { \
+ [&srcTargetFor##src##label, &recvMsgFor##src##label](const std::string &srcTarget, const std::string &userId, \
+ Message *inMsg) { \
srcTargetFor##src##label = srcTarget; \
recvMsgFor##src##label = inMsg; \
}, nullptr);
@@ -812,7 +814,8 @@ HWTEST_F(DistributedDBCommunicatorTest, ReDeliverMessage002, TestSize.Level1)
ICommunicator *commBA = g_envDeviceB.commAggrHandle->AllocCommunicator(LABEL_A, errCode);
ASSERT_NE(commBA, nullptr);
std::vector<std::pair<std::string, Message *>> msgCallbackForBA;
- commBA->RegOnMessageCallback([&msgCallbackForBA](const std::string &srcTarget, Message *inMsg) {
+ commBA->RegOnMessageCallback([&msgCallbackForBA](const std::string &srcTarget, const std::string &userId,\
+ Message *inMsg) {
msgCallbackForBA.push_back({srcTarget, inMsg});
}, nullptr);
commBA->Activate();
diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_extend_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_extend_test.cpp
index 1eb88f916..b6e7b6fea 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_extend_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_extend_test.cpp
@@ -108,7 +108,7 @@ namespace {
ASSERT_TRUE(devices != nullptr);
syncInterface = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterface != nullptr);
- ASSERT_EQ(devices->Initialize(g_communicatorAggregator, syncInterface), E_OK);
+ ASSERT_EQ(devices->Initialize(g_communicatorAggregator, {{"", syncInterface}}), E_OK);
}
class DistributedDBInterfacesNBDelegateExtendTest : public testing::Test {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_test.cpp
index eec05b15a..f1ba66c82 100755
--- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_nb_delegate_test.cpp
@@ -2775,7 +2775,7 @@ void InitVirtualDevice(const std::string &devId, KvVirtualDevice *&devices,
ASSERT_TRUE(devices != nullptr);
syncInterface = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterface != nullptr);
- ASSERT_EQ(devices->Initialize(g_communicatorAggregator, syncInterface), E_OK);
+ ASSERT_EQ(devices->Initialize(g_communicatorAggregator, {{"", syncInterface}}), E_OK);
}
void FreeVirtualDevice(KvVirtualDevice *&devices)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_sync_test.cpp
index cb07e529d..e3ec95713 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_sync_test.cpp
@@ -176,7 +176,7 @@ void DistributedDBInterfacesRelationalSyncTest::SetUp()
ASSERT_TRUE(g_deviceB != nullptr);
auto *syncInterfaceB = new (std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_test.cpp
index 68b54c11c..622dfa560 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_test.cpp
@@ -159,7 +159,7 @@ void DistributedDBInterfacesRelationalTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
auto *syncInterfaceB = new (std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
return true;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
index ab1212645..a0fd8e6f9 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
@@ -86,7 +86,7 @@ void DistributedDBRDBCollaborationTest::SetUp()
ASSERT_NE(deviceB_, nullptr);
auto syncInterfaceB = new (std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_NE(syncInterfaceB, nullptr);
- ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, syncInterfaceB), E_OK);
+ ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBRDBCollaborationTest::TearDown()
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_syncer_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_syncer_test.cpp
index 9346cfda6..9ae6e2687 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_syncer_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_syncer_test.cpp
@@ -123,7 +123,7 @@ void DistributedDBCloudKvSyncerTest::SetUp()
ASSERT_TRUE(deviceB_ != nullptr);
auto syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, syncInterfaceB), E_OK);
+ ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, {{"", syncInterfaceB}}), E_OK);
GetSingleStore();
}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_test.cpp
index 75aaa034d..5efb41f50 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kv_test.cpp
@@ -129,7 +129,7 @@ void DistributedDBCloudKvTest::SetUp()
ASSERT_TRUE(deviceB_ != nullptr);
auto syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, syncInterfaceB), E_OK);
+ ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBCloudKvTest::TearDown()
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp
index 2cd4b6e46..3c88ef0f8 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_kvstore_test.cpp
@@ -133,7 +133,7 @@ void DistributedDBCloudKvStoreTest::SetUp()
ASSERT_TRUE(deviceB_ != nullptr);
auto syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, syncInterfaceB), E_OK);
+ ASSERT_EQ(deviceB_->Initialize(communicatorAggregator_, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBCloudKvStoreTest::TearDown()
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_ability_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_ability_sync_test.cpp
index 7cc952529..578a79e11 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_ability_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_ability_sync_test.cpp
@@ -395,7 +395,7 @@ HWTEST_F(DistributedDBAbilitySyncTest, SyncStart001, TestSize.Level0)
* @tc.steps: step1. create a AbilitySync
*/
AbilitySync async;
- async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A);
+ async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A, "");
/**
* @tc.steps: step2. call SyncStart
@@ -428,7 +428,7 @@ HWTEST_F(DistributedDBAbilitySyncTest, RequestReceiveTest001, TestSize.Level0)
* @tc.steps: step1. create a AbilitySync
*/
AbilitySync async;
- async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A);
+ async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A, "");
/**
* @tc.steps: step2. call RequestRecv, set inMsg nullptr or set context nullptr
@@ -499,7 +499,7 @@ HWTEST_F(DistributedDBAbilitySyncTest, AckReceiveTest001, TestSize.Level0)
* @tc.steps: step1. create a AbilitySync
*/
AbilitySync async;
- async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A);
+ async.Initialize(g_communicatorB, g_syncInterface, g_meta, DEVICE_A, "");
/**
* @tc.steps: step2. call AckRecv, set inMsg nullptr or set context nullptr
@@ -572,7 +572,7 @@ HWTEST_F(DistributedDBAbilitySyncTest, AckReceiveTest002, TestSize.Level1)
AbilitySync async;
VirtualRelationalVerSyncDBInterface *interface = new(std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_NE(interface, nullptr);
- async.Initialize(g_communicatorB, interface, g_meta, DEVICE_A);
+ async.Initialize(g_communicatorB, interface, g_meta, DEVICE_A, "");
interface->SetPermitCreateDistributedTable(false);
/**
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
index 827a7b8e5..50d412b3e 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_mock_sync_module_test.cpp
@@ -108,7 +108,7 @@ void Init(MockSingleVerStateMachine &stateMachine, MockSyncTaskContext &syncTask
{
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)syncTaskContext.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext.Initialize("device", "", &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(&syncTaskContext, &dbSyncInterface, metadata, &communicator);
}
@@ -117,7 +117,7 @@ void Init(MockSingleVerStateMachine &stateMachine, MockSyncTaskContext *syncTask
{
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(dbSyncInterface), E_OK);
- (void)syncTaskContext->Initialize("device", dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext->Initialize("device", "", dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(syncTaskContext, dbSyncInterface, metadata, &communicator);
}
@@ -368,7 +368,7 @@ void TimeSync001()
const int timeDriverMs = 100;
for (int i = 0; i < loopCount; ++i) {
MockTimeSync timeSync;
- EXPECT_EQ(timeSync.Initialize(communicator, metadata, storage, "DEVICES_A"), E_OK);
+ EXPECT_EQ(timeSync.Initialize(communicator, metadata, storage, "DEVICES_A", ""), E_OK);
EXPECT_CALL(timeSync, SyncStart).WillRepeatedly(Return(E_OK));
timeSync.ModifyTimer(timeDriverMs);
std::this_thread::sleep_for(std::chrono::milliseconds(timeDriverMs));
@@ -907,7 +907,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncDataSync003, TestSize.Level1)
const std::string deviceId = "deviceId";
dataSync.Initialize(&storage, &communicator, metadata, deviceId);
syncTaskContext.SetRemoteSoftwareVersion(SOFTWARE_VERSION_CURRENT);
- syncTaskContext.Initialize(deviceId, &storage, metadata, &communicator);
+ syncTaskContext.Initialize(deviceId, "", &storage, metadata, &communicator);
syncTaskContext.EnableClearRemoteStaleData(true);
/**
@@ -981,7 +981,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, AbilitySync002, TestSize.Level1)
VirtualSingleVerSyncDBInterface syncDBInterface;
std::shared_ptr<Metadata> metaData = std::make_shared<Metadata>();
metaData->Initialize(&syncDBInterface);
- abilitySync.Initialize(&comunicator, &syncDBInterface, metaData, "deviceId");
+ abilitySync.Initialize(&comunicator, &syncDBInterface, metaData, "deviceId", "");
/**
* @tc.steps: step1. set AbilitySyncAckPacket ackCode is E_OK for pass the ack check
@@ -1186,7 +1186,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncLifeTest006, TestSize.Level1)
EXPECT_EQ(syncer->Initialize(syncDBInterface, true), E_OK);
virtualCommunicatorAggregator->OnlineDevice(DEVICE_B);
std::thread writeThread([syncer, &DEVICE_B]() {
- EXPECT_EQ(syncer->Sync({DEVICE_B}, PUSH_AND_PULL, nullptr, nullptr, true), E_OK);
+ EXPECT_EQ(syncer->Sync({{DEVICE_B, ""}}, PUSH_AND_PULL, nullptr, nullptr, true), E_OK);
});
std::thread closeThread([syncer, &syncDBInterface]() {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
@@ -1318,11 +1318,11 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncEngineTest002, TestSize.Level1)
/**
* @tc.steps: step2. add sync operation for DEVICE_A and DEVICE_B. It will create two context for A and B
*/
- std::vector<std::string> devices = {
- "DEVICES_A", "DEVICES_B"
+ std::vector<DeviceSyncTarget> syncTargets = {
+ {"DEVICES_A", ""}, {"DEVICES_B", ""}
};
const int syncId = 1;
- auto operation = new (std::nothrow) SyncOperation(syncId, devices, 0, nullptr, false);
+ auto operation = new (std::nothrow) SyncOperation(syncId, syncTargets, 0, nullptr, false);
if (operation != nullptr) {
enginePtr->AddSyncOperation(operation);
}
@@ -1356,16 +1356,16 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncEngineTest003, TestSize.Level1)
{
auto *enginePtr = new (std::nothrow) MockSyncEngine();
ASSERT_NE(enginePtr, nullptr);
- std::vector<std::string> devices = {
- "DEVICES_A", "DEVICES_B"
+ std::vector<DeviceSyncTarget> syncTargets = {
+ {"DEVICES_A", ""}, {"DEVICES_B", ""}
};
const int syncId = 1;
- auto operation = new (std::nothrow) SyncOperation(syncId, devices, 0, nullptr, true);
+ auto operation = new (std::nothrow) SyncOperation(syncId, syncTargets, 0, nullptr, true);
ASSERT_NE(operation, nullptr);
operation->Initialize();
enginePtr->AddSyncOperation(operation);
- for (const auto &device: devices) {
- EXPECT_EQ(operation->GetStatus(device), static_cast<int>(SyncOperation::OP_BUSY_FAILURE));
+ for (const auto &syncTarget : syncTargets) {
+ EXPECT_EQ(operation->GetStatus(syncTarget), static_cast<int>(SyncOperation::OP_BUSY_FAILURE));
}
RefObject::KillAndDecObjRef(operation);
RefObject::KillAndDecObjRef(enginePtr);
@@ -1383,7 +1383,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncEngineTest004, TestSize.Level0)
auto *enginePtr = new (std::nothrow) MockSyncEngine();
ASSERT_NE(enginePtr, nullptr);
int errCode = E_OK;
- auto *context = enginePtr->CallGetSyncTaskContext("dev", errCode);
+ auto *context = enginePtr->CallGetSyncTaskContext("dev", "", errCode);
EXPECT_EQ(context, nullptr);
EXPECT_EQ(errCode, -E_INVALID_DB);
RefObject::KillAndDecObjRef(enginePtr);
@@ -1700,7 +1700,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck001, TestSize.Leve
MockCommunicator communicator;
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
- (void)syncTaskContext.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)syncTaskContext.Initialize("device", "", &dbSyncInterface, metadata, &communicator);
syncTaskContext.SetLastFullSyncTaskStatus(SyncOperation::Status::OP_FINISHED_ALL);
syncTaskContext.CallSetSyncMode(static_cast<int>(SyncModeType::PUSH));
EXPECT_EQ(syncTaskContext.CallIsCurrentSyncTaskCanBeSkipped(), true);
@@ -1720,7 +1720,8 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck002, TestSize.Leve
*/
auto syncTaskContext = new(std::nothrow) MockSyncTaskContext();
ASSERT_NE(syncTaskContext, nullptr);
- auto operation = new SyncOperation(1u, {}, static_cast<int>(SyncModeType::QUERY_PUSH), nullptr, false);
+ std::vector<DeviceSyncTarget> syncTargets = {};
+ auto operation = new SyncOperation(1u, syncTargets, static_cast<int>(SyncModeType::QUERY_PUSH), nullptr, false);
ASSERT_NE(operation, nullptr);
QuerySyncObject querySyncObject;
operation->SetQuery(querySyncObject);
@@ -1853,7 +1854,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck005, TestSize.Leve
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context->Initialize("device", "", &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(context, &dbSyncInterface, metadata, &communicator);
for (int i = 0; i < 100; ++i) { // 100 sync target
@@ -1909,7 +1910,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck006, TestSize.Leve
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, communicator);
+ (void)context->Initialize("device", "", &dbSyncInterface, metadata, communicator);
/**
* @tc.steps: step2. add sync target into context
*/
@@ -1949,7 +1950,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SyncTaskContextCheck007, TestSize.Leve
VirtualRelationalVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
ASSERT_EQ(metadata->Initialize(&dbSyncInterface), E_OK);
- (void)context->Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context->Initialize("device", "", &dbSyncInterface, metadata, &communicator);
(void)stateMachine.Initialize(context, &dbSyncInterface, metadata, &communicator);
/**
* @tc.steps: step2. prepare table and query
@@ -2300,7 +2301,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, TimeSync002, TestSize.Level1)
MockTimeSync timeSync;
EXPECT_CALL(timeSync, SyncStart).WillRepeatedly(Return(E_OK));
- EXPECT_EQ(timeSync.Initialize(communicator, metadata, storage, "DEVICES_A"), E_OK);
+ EXPECT_EQ(timeSync.Initialize(communicator, metadata, storage, "DEVICES_A", ""), E_OK);
const int loopCount = 100;
const int timeDriverMs = 10;
for (int i = 0; i < loopCount; ++i) {
@@ -2371,7 +2372,7 @@ HWTEST_F(DistributedDBMockSyncModuleTest, SingleVerDataSyncUtils001, TestSize.Le
MockCommunicator communicator;
VirtualSingleVerSyncDBInterface dbSyncInterface;
std::shared_ptr<Metadata> metadata = std::make_shared<Metadata>();
- (void)context.Initialize("device", &dbSyncInterface, metadata, &communicator);
+ (void)context.Initialize("device", "", &dbSyncInterface, metadata, &communicator);
std::vector<SendDataItem> data;
for (int i = 0; i < 2; ++i) { // loop 2 times
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_multi_user_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_multi_user_test.cpp
index 029da88ca..d5be57534 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_multi_user_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_multi_user_test.cpp
@@ -514,12 +514,12 @@ void DistributedDBRelationalMultiUserTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualRelationalVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) RelationalVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualRelationalVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualRelationalVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
}
void DistributedDBRelationalMultiUserTest::TearDown(void)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp
index 4c79a098c..41a8d85f6 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp
@@ -875,9 +875,9 @@ void DistributedDBRelationalVerP2PSyncTest::SetUp(void)
ASSERT_TRUE(syncInterfaceB != nullptr);
ASSERT_TRUE(syncInterfaceC != nullptr);
ASSERT_TRUE(syncInterfaceD != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
- ASSERT_EQ(g_deviceD->Initialize(g_communicatorAggregator, syncInterfaceD), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
+ ASSERT_EQ(g_deviceD->Initialize(g_communicatorAggregator, {{"", syncInterfaceD}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
@@ -1274,7 +1274,7 @@ HWTEST_F(DistributedDBRelationalVerP2PSyncTest, AutoLaunchSync002, TestSize.Leve
* @tc.steps: step4. Call sync expect sync fail
*/
Query query = Query::Select(g_tableName);
- SyncOperation::UserCallback callBack = [](const std::map<std::string, int> &statusMap) {
+ SyncOperation::UserCallback callBack = [](const std::map<DeviceSyncTarget, int> &statusMap) {
for (const auto &entry : statusMap) {
EXPECT_EQ(entry.second, -E_NOT_FOUND);
}
@@ -1316,7 +1316,7 @@ HWTEST_F(DistributedDBRelationalVerP2PSyncTest, AutoLaunchSync003, TestSize.Leve
* @tc.steps: step4. Call sync expect sync fail
*/
Query query = Query::Select(g_tableName);
- SyncOperation::UserCallback callBack = [](const std::map<std::string, int> &statusMap) {
+ SyncOperation::UserCallback callBack = [](const std::map<DeviceSyncTarget, int> &statusMap) {
for (const auto &entry : statusMap) {
EXPECT_EQ(entry.second, -E_NOT_FOUND);
}
@@ -1504,9 +1504,9 @@ HWTEST_F(DistributedDBRelationalVerP2PSyncTest, AbilitySync004, TestSize.Level1)
Query query = Query::Select(g_tableName);
int res = DB_ERROR;
- auto callBack = [&res](std::map<std::string, int> resMap) {
- if (resMap.find("real_device") != resMap.end()) {
- res = resMap["real_device"];
+ auto callBack = [&res](std::map<DeviceSyncTarget, int> resMap) {
+ if (resMap.find({"real_device", ""}) != resMap.end()) {
+ res = resMap[{"real_device", ""}];
}
};
EXPECT_EQ(g_deviceB->GenericVirtualDevice::Sync(DistributedDB::SYNC_MODE_PULL_ONLY, query, callBack, true), E_OK);
@@ -2933,7 +2933,8 @@ HWTEST_F(DistributedDBRelationalVerP2PSyncTest, AutoLaunchSyncAfterRekey_002, Te
*/
HWTEST_F(DistributedDBRelationalVerP2PSyncTest, SyncTargetTest001, TestSize.Level1) {
MockSyncTaskContext syncTaskContext;
- SyncOperation *operation = new SyncOperation(1, {}, 0, nullptr, false);
+ std::vector<DeviceSyncTarget> syncTargets = {};
+ SyncOperation *operation = new SyncOperation(1, syncTargets, 0, nullptr, false);
EXPECT_NE(operation, nullptr);
std::thread addTarget([&syncTaskContext, &operation]() {
auto *newTarget = new (std::nothrow) SingleVerSyncTarget;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_dlp_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_dlp_test.cpp
index 936df57c1..8831c2ee2 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_dlp_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_dlp_test.cpp
@@ -149,7 +149,7 @@ void DistributedDBSingleVerDLPTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBSingleVerDLPTest::TearDown(void)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp
index a5ed97957..a8ed1802c 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp
@@ -251,7 +251,7 @@ void DistributedDBSingleVerMultiSubUserTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBSingleVerMultiSubUserTest::TearDown(void)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_user_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_user_test.cpp
index 146228bb6..5f16f5f14 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_user_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_user_test.cpp
@@ -130,12 +130,12 @@ void DistributedDBSingleVerMultiUserTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
}
void DistributedDBSingleVerMultiUserTest::TearDown(void)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_complex_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_complex_sync_test.cpp
index b2f6fd4c9..2a1cac712 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_complex_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_complex_sync_test.cpp
@@ -238,13 +238,13 @@ void DistributedDBSingleVerP2PComplexSyncTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
@@ -468,14 +468,15 @@ HWTEST_F(DistributedDBSingleVerP2PComplexSyncTest, SametimeSync002, TestSize.Lev
* @tc.expected: step3. sync should return OP_FINISHED_ALL.
*/
std::this_thread::sleep_for(std::chrono::milliseconds(100));
- std::map<std::string, int> virtualResult;
+ std::map<DeviceSyncTarget, int> virtualResult;
g_deviceB->Sync(DistributedDB::SYNC_MODE_PULL_ONLY, query,
- [&virtualResult](const std::map<std::string, int> &map) {
+ [&virtualResult](const std::map<DeviceSyncTarget, int> &map) {
virtualResult = map;
}, true);
EXPECT_TRUE(status == OK);
ASSERT_EQ(virtualResult.size(), devices.size());
- EXPECT_EQ(virtualResult[DEVICE_A], SyncOperation::OP_FINISHED_ALL);
+ int deviceAStatus = virtualResult[{DEVICE_A, ""}];
+ EXPECT_EQ(deviceAStatus, SyncOperation::OP_FINISHED_ALL);
g_communicatorAggregator->RegOnDispatch(nullptr);
subThread.join();
}
@@ -1487,7 +1488,7 @@ HWTEST_F(DistributedDBSingleVerP2PComplexSyncTest, RebuildSync002, TestSize.Leve
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
(void)OS::GetCurrentSysTimeInMicrosecond(currentTime);
EXPECT_EQ(g_deviceB->PutData(key3, value, currentTime, 0), E_OK);
(void)OS::GetCurrentSysTimeInMicrosecond(currentTime);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_permission_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_permission_sync_test.cpp
index 2068e73e0..79a07bc13 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_permission_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_permission_sync_test.cpp
@@ -107,13 +107,13 @@ void DistributedDBSingleVerP2PPermissionSyncTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp
index 6c5e788df..006d3f76f 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp
@@ -150,7 +150,7 @@ void DistributedDBSingleVerP2PQuerySyncTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
}
void DistributedDBSingleVerP2PQuerySyncTest::TearDown(void)
@@ -566,7 +566,7 @@ HWTEST_F(DistributedDBSingleVerP2PQuerySyncTest, NormalSync006, TestSize.Level1)
isError = true;
break;
}
- ASSERT_EQ(virtualDeviceVec[i]->Initialize(g_communicatorAggregator, tmpSyncInterface), E_OK);
+ ASSERT_EQ(virtualDeviceVec[i]->Initialize(g_communicatorAggregator, {{"", tmpSyncInterface}}), E_OK);
devices.push_back(virtualDeviceVec[i]->GetDeviceId());
}
if (isError) {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_simple_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_simple_sync_test.cpp
index 3ab5575b0..9cc6b9bd5 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_simple_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_simple_sync_test.cpp
@@ -133,13 +133,13 @@ void DistributedDBSingleVerP2PSimpleSyncTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
auto permissionCheckCallback = [] (const std::string &userId, const std::string &appId, const std::string &storeId,
const std::string &deviceId, uint8_t flag) -> bool {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp
index bb9b2db60..c154da5ff 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp
@@ -149,12 +149,12 @@ void DistributedDBSingleVerP2PSubscribeSyncTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
}
void DistributedDBSingleVerP2PSubscribeSyncTest::TearDown(void)
@@ -718,8 +718,11 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, SubscribeManager006, TestSi
ASSERT_TRUE(subManager.ReserveRemoteSubscribeQuery(DEVICE_A, queryCommonObj) == E_OK);
ASSERT_TRUE(subManager.ActiveRemoteSubscribeQuery(DEVICE_A, queryCommonObj) == E_OK);
EXPECT_EQ(subManager.IsLastRemoteContainSubscribe(DEVICE_A, queryId), false);
- deviceAQueies.push_back(DEVICE_A);
- EXPECT_EQ(subManager.LocalSubscribeLimitCheck(deviceAQueies, queryCommonObj), E_OK);
+ std::vector<DeviceSyncTarget> deviceAUserQueies;
+ for (const auto &device : deviceAQueies) {
+ deviceAUserQueies.push_back({device, ""});
+ }
+ EXPECT_EQ(subManager.LocalSubscribeLimitCheck(deviceAUserQueies, queryCommonObj), E_OK);
/**
* @tc.steps: step4. add MAX_DEVICES_NUM device, then call LocalSubscribeLimitCheck
@@ -728,7 +731,11 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, SubscribeManager006, TestSi
for (size_t i = 0 ; i < MAX_DEVICES_NUM; i++) {
deviceAQueies.push_back("device_" + std::to_string(i));
}
- EXPECT_EQ(subManager.LocalSubscribeLimitCheck(deviceAQueies, queryCommonObj), -E_MAX_LIMITS);
+ std::vector<DeviceSyncTarget> targets;
+ for (const auto &device : deviceAQueies) {
+ targets.push_back({device, ""});
+ }
+ EXPECT_EQ(subManager.LocalSubscribeLimitCheck(targets, queryCommonObj), -E_MAX_LIMITS);
}
/**
@@ -1134,7 +1141,7 @@ KvVirtualDevice *CreateKvVirtualDevice(const std::string &deviceName)
device = nullptr;
break;
}
- EXPECT_EQ(device->Initialize(g_communicatorAggregator, interface), E_OK);
+ EXPECT_EQ(device->Initialize(g_communicatorAggregator, {{"", interface}}), E_OK);
} while (false);
return device;
}
@@ -1180,9 +1187,10 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, SubscribeSync009, TestSize.
* @tc.steps: step3. 32 unsubscribe
*/
LOGI("============step 3============");
- SyncOperation::UserCallback callback = [](std::map<std::string, int> res) {
+ SyncOperation::UserCallback callback = [](std::map<DeviceSyncTarget, int> res) {
ASSERT_EQ(res.size(), 1u);
- EXPECT_EQ(res["real_device"], SyncOperation::OP_FINISHED_ALL);
+ DeviceSyncTarget target = {"real_device", ""};
+ EXPECT_EQ(res[target], SyncOperation::OP_FINISHED_ALL);
};
for (const auto &dev: devices) {
dev->UnSubscribe(QuerySyncObject(query), true, 1, callback); // sync id is 1
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp
index 19a066635..3631e2c48 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp
@@ -129,7 +129,7 @@ void DistributedDBSingleVerP2PSyncCheckTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
g_syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(g_syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, g_syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", g_syncInterfaceB}}), E_OK);
SecurityOption virtualOption;
virtualOption.securityLabel = option.secOption.securityLabel;
virtualOption.securityFlag = option.secOption.securityFlag;
@@ -139,7 +139,7 @@ void DistributedDBSingleVerP2PSyncCheckTest::SetUp(void)
ASSERT_TRUE(g_deviceC != nullptr);
g_syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(g_syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, g_syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", g_syncInterfaceC}}), E_OK);
g_syncInterfaceC->SetSecurityOption(virtualOption);
RuntimeContext::GetInstance()->ClearAllDeviceTimeInfo();
}
@@ -1946,18 +1946,19 @@ HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, GetDataNotify001, TestSize.Leve
* @tc.expected: step2. sync should return OK. onComplete should be called, deviceB sync TIME_OUT.
*/
std::map<std::string, DBStatus> result;
- std::map<std::string, int> virtualRes;
+ std::map<DeviceSyncTarget, int> virtualRes;
status = g_tool.SyncTest(g_kvDelegatePtr, devices, SYNC_MODE_PULL_ONLY, result, true);
EXPECT_EQ(status, OK);
EXPECT_EQ(result.size(), devices.size());
EXPECT_EQ(result[DEVICE_B], TIME_OUT);
std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS));
Query query = Query::Select();
- g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<std::string, int> resMap) {
+ g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<DeviceSyncTarget, int> resMap) {
virtualRes = std::move(resMap);
}, true);
EXPECT_EQ(virtualRes.size(), devices.size());
- EXPECT_EQ(virtualRes[DEVICE_A], static_cast<int>(SyncOperation::OP_TIMEOUT));
+ DeviceSyncTarget target = {DEVICE_A, ""};
+ EXPECT_EQ(virtualRes[target], static_cast<int>(SyncOperation::OP_TIMEOUT));
std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS));
/**
@@ -1973,11 +1974,11 @@ HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, GetDataNotify001, TestSize.Leve
EXPECT_EQ(result.size(), devices.size());
EXPECT_EQ(result[DEVICE_B], OK);
std::this_thread::sleep_for(std::chrono::seconds(TEN_SECONDS));
- g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<std::string, int> resMap) {
+ g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<DeviceSyncTarget, int> resMap) {
virtualRes = std::move(resMap);
}, true);
EXPECT_EQ(virtualRes.size(), devices.size());
- EXPECT_EQ(virtualRes[DEVICE_A], static_cast<int>(SyncOperation::OP_FINISHED_ALL));
+ EXPECT_EQ(virtualRes[target], static_cast<int>(SyncOperation::OP_FINISHED_ALL));
g_deviceB->DelayGetSyncData(0);
}
@@ -2013,9 +2014,9 @@ HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, GetDataNotify002, TestSize.Leve
* @tc.steps: step3. deviceB call sync and wait
*/
std::thread asyncThread([]() {
- std::map<std::string, int> virtualRes;
+ std::map<DeviceSyncTarget, int> virtualRes;
Query query = Query::Select();
- g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<std::string, int> resMap) {
+ g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, query, [&virtualRes](std::map<DeviceSyncTarget, int> resMap) {
virtualRes = std::move(resMap);
}, true);
});
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_syncer_device_manager_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_syncer_device_manager_test.cpp
index 5b76ae62f..ea8dd69df 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_syncer_device_manager_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_syncer_device_manager_test.cpp
@@ -89,13 +89,13 @@ void DistributedDBSyncerDeviceManagerTest::SetUp(void)
ASSERT_TRUE(g_deviceB != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceB = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceB != nullptr);
- ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, syncInterfaceB), E_OK);
+ ASSERT_EQ(g_deviceB->Initialize(g_communicatorAggregator, {{"", syncInterfaceB}}), E_OK);
g_deviceC = new (std::nothrow) KvVirtualDevice(DEVICE_C);
ASSERT_TRUE(g_deviceC != nullptr);
VirtualSingleVerSyncDBInterface *syncInterfaceC = new (std::nothrow) VirtualSingleVerSyncDBInterface();
ASSERT_TRUE(syncInterfaceC != nullptr);
- ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, syncInterfaceC), E_OK);
+ ASSERT_EQ(g_deviceC->Initialize(g_communicatorAggregator, {{"", syncInterfaceC}}), E_OK);
}
void DistributedDBSyncerDeviceManagerTest::TearDown(void)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
index 245e10744..b96f76218 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_time_sync_test.cpp
@@ -148,7 +148,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync001, TestSize.Level0)
TimeHelper::GetSysCurrentTime() + TimeHelper::BASE_OFFSET + offsetA, 0);
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
g_metadataB->Initialize(g_syncInterfaceB);
@@ -157,13 +157,13 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync001, TestSize.Level0)
g_syncInterfaceB->PutData(DistributedDBUnitTest::KEY_1, DistributedDBUnitTest::VALUE_1,
TimeHelper::GetSysCurrentTime() + TimeHelper::BASE_OFFSET + offsetB, 0);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step3. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
@@ -193,17 +193,17 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync002, TestSize.Level0)
g_metadataA->Initialize(g_syncInterfaceA);
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
g_metadataB->Initialize(g_syncInterfaceB);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step2. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step3. Fetch timeOffset value
@@ -239,7 +239,7 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync003, TestSize.Level0)
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
// set timeOffset for timeSyncA
@@ -248,12 +248,12 @@ HWTEST_F(DistributedDBTimeSyncTest, NormalSync003, TestSize.Level0)
g_metadataB->SaveLocalTimeOffset(offsetB);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step3. Register the OnMessageCallback to virtual communicator
*/
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step4. Fetch timeOffset value
@@ -282,15 +282,15 @@ HWTEST_F(DistributedDBTimeSyncTest, NetDisconnetSyncTest001, TestSize.Level0)
g_metadataA->Initialize(g_syncInterfaceA);
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
g_metadataB->Initialize(g_syncInterfaceB);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
/**
* @tc.steps: step2. Disable the virtual communicator
@@ -320,12 +320,12 @@ HWTEST_F(DistributedDBTimeSyncTest, InvalidMessgeTest001, TestSize.Level0)
g_metadataA->Initialize(g_syncInterfaceA);
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
g_metadataB->Initialize(g_syncInterfaceB);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
@@ -388,14 +388,14 @@ HWTEST_F(DistributedDBTimeSyncTest, InvalidMessgeTest002, TestSize.Level0)
g_metadataA->Initialize(g_syncInterfaceA);
int errCode;
// initialize timeSyncA
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
g_metadataB->Initialize(g_syncInterfaceB);
// initialize timeSyncB
- errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A);
+ errCode = g_timeSyncB->Initialize(g_virtualCommunicator, g_metadataB, g_syncInterfaceB, DEVICE_A, "");
EXPECT_TRUE(errCode == E_OK);
- g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
g_virtualCommunicator->SetTimeSync(g_timeSyncA.get(), g_timeSyncB.get(), DEVICE_A, g_syncTaskContext);
Message *msg = new (std::nothrow) Message();
@@ -452,14 +452,14 @@ HWTEST_F(DistributedDBTimeSyncTest, SyncTimeout001, TestSize.Level2)
// initialize timeSyncA
g_metadataA->Initialize(g_syncInterfaceA);
int errCode;
- errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step1. Initialize the syncTaskContext
* @tc.expected: step1. Initialize syncTaskContext successfully
*/
- errCode = g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ errCode = g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
EXPECT_TRUE(errCode == E_OK);
/**
* @tc.steps: step2. Start the time syc task invoking StartSync() method
@@ -481,14 +481,14 @@ HWTEST_F(DistributedDBTimeSyncTest, CheckRemoteVersion001, TestSize.Level0)
{
// initialize timeSyncA
g_metadataA->Initialize(g_syncInterfaceA);
- int errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ int errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_EQ(errCode, E_OK);
/**
* @tc.steps: step1. Initialize the syncTaskContext
* @tc.expected: step1. Initialize syncTaskContext successfully
*/
- errCode = g_syncTaskContext->Initialize(DEVICE_B, g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
+ errCode = g_syncTaskContext->Initialize(DEVICE_B, "", g_syncInterfaceA, g_metadataA, g_virtualCommunicator);
EXPECT_EQ(errCode, E_OK);
/**
* @tc.steps: step2. Check remote version
@@ -513,7 +513,7 @@ HWTEST_F(DistributedDBTimeSyncTest, SetTimeSyncFinish001, TestSize.Level0)
*/
EXPECT_EQ(g_metadataA->Initialize(g_syncInterfaceA), E_OK);
EXPECT_EQ(g_metadataA->SetTimeSyncFinishMark(DEVICE_B, true), E_OK);
- int errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B);
+ int errCode = g_timeSyncA->Initialize(g_virtualCommunicator, g_metadataA, g_syncInterfaceA, DEVICE_B, "");
EXPECT_EQ(errCode, E_OK);
/**
* @tc.steps: step2. Set time sync finish
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
index b68cae6e7..7054258a4 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.cpp
@@ -23,14 +23,9 @@ namespace DistributedDB {
GenericVirtualDevice::GenericVirtualDevice(std::string deviceId)
: communicateHandle_(nullptr),
communicatorAggregator_(nullptr),
- storage_(nullptr),
- metadata_(nullptr),
deviceId_(std::move(deviceId)),
remoteDeviceId_("real_device"),
- context_(nullptr),
- onRemoteDataChanged_(nullptr),
- subManager_(nullptr),
- executor_(nullptr)
+ onRemoteDataChanged_(nullptr)
{
}
@@ -48,36 +43,47 @@ GenericVirtualDevice::~GenericVirtualDevice()
}
communicatorAggregator_ = nullptr;
- if (context_ != nullptr) {
- ISyncInterface *storage = storage_;
- context_->OnLastRef([storage, &cv, &cvMutex, &finished]() {
- delete storage;
- {
- std::lock_guard<std::mutex> lock(cvMutex);
- finished = true;
- }
- cv.notify_one();
- });
- RefObject::KillAndDecObjRef(context_);
- std::unique_lock<std::mutex> lock(cvMutex);
- cv.wait(lock, [&finished] { return finished; });
- } else {
- delete storage_;
- }
- context_ = nullptr;
- metadata_ = nullptr;
- storage_ = nullptr;
- if (executor_ != nullptr) {
- RefObject::KillAndDecObjRef(executor_);
- executor_ = nullptr;
+ for (const auto &context : context_) {
+ if (context.second != nullptr) {
+ ISyncInterface *storage = storage_[context.first];
+ context.second->OnLastRef([storage, &cv, &cvMutex, &finished]() {
+ delete storage;
+ {
+ std::lock_guard<std::mutex> lock(cvMutex);
+ finished = true;
+ }
+ cv.notify_one();
+ });
+ RefObject::KillAndDecObjRef(context.second);
+ std::unique_lock<std::mutex> lock(cvMutex);
+ cv.wait(lock, [&finished] { return finished; });
+ } else {
+ delete storage_[context.first];
+ }
+ context_[context.first] = nullptr;
+ metadata_[context.first] = nullptr;
+ storage_[context.first] = nullptr;
+ if (executor_[context.first] != nullptr) {
+ RefObject::KillAndDecObjRef(executor_[context.first]);
+ executor_[context.first] = nullptr;
+ }
}
+ context_.clear();
+ storage_.clear();
+ metadata_.clear();
}
-int GenericVirtualDevice::Initialize(VirtualCommunicatorAggregator *comAggregator, ISyncInterface *syncInterface)
+int GenericVirtualDevice::Initialize(VirtualCommunicatorAggregator *comAggregator,
+ std::map<std::string, ISyncInterface *> syncInterfaces)
{
- if ((comAggregator == nullptr) || (syncInterface == nullptr)) {
+ if (comAggregator == nullptr) {
return -E_INVALID_ARGS;
}
+ for (const auto &syncInterface : syncInterfaces) {
+ if (syncInterface.second == nullptr) {
+ return -E_INVALID_ARGS;
+ }
+ }
communicatorAggregator_ = comAggregator;
int errCode = E_OK;
@@ -86,39 +92,47 @@ int GenericVirtualDevice::Initialize(VirtualCommunicatorAggregator *comAggregato
return errCode;
}
- storage_ = syncInterface;
- metadata_ = std::make_shared<Metadata>();
- if (metadata_->Initialize(storage_) != E_OK) {
- LOGE("metadata_ init failed");
- return -E_NOT_SUPPORT;
- }
- if (storage_->GetInterfaceType() == IKvDBSyncInterface::SYNC_SVD) {
- context_ = new (std::nothrow) SingleVerKvSyncTaskContext;
- subManager_ = std::make_shared<SubscribeManager>();
- static_cast<SingleVerSyncTaskContext *>(context_)->SetSubscribeManager(subManager_);
- } else if (storage_->GetInterfaceType() == IKvDBSyncInterface::SYNC_RELATION) {
- context_ = new (std::nothrow) SingleVerRelationalSyncTaskContext;
- } else {
+ for (const auto &syncInterface : syncInterfaces) {
+ std::string userId = syncInterface.first;
+ storage_[userId] = syncInterface.second;
+ metadata_[userId] = std::make_shared<Metadata>();
+ if (metadata_[userId]->Initialize(storage_[userId]) != E_OK) {
+ LOGE("metadata_ init failed");
+ return -E_NOT_SUPPORT;
+ }
+ if (storage_[userId]->GetInterfaceType() == IKvDBSyncInterface::SYNC_SVD) {
+ context_[userId] = new (std::nothrow) SingleVerKvSyncTaskContext;
+ subManager_[userId] = std::make_shared<SubscribeManager>();
+ static_cast<SingleVerSyncTaskContext *>(context_[userId])->SetSubscribeManager(subManager_[userId]);
+ } else if (storage_[userId]->GetInterfaceType() == IKvDBSyncInterface::SYNC_RELATION) {
+ context_[userId] = new (std::nothrow) SingleVerRelationalSyncTaskContext;
+ } else {
#ifndef OMIT_MULTI_VER
- context_ = new (std::nothrow) MultiVerSyncTaskContext;
+ context_ = new (std::nothrow) MultiVerSyncTaskContext;
#else
- return -E_NOT_SUPPORT;
+ return -E_NOT_SUPPORT;
#endif // OMIT_MULTI_VER
+ }
+ if (context_[userId] == nullptr) {
+ return -E_OUT_OF_MEMORY;
+ }
}
- if (context_ == nullptr) {
- return -E_OUT_OF_MEMORY;
- }
+
communicateHandle_->RegOnMessageCallback(
- std::bind(&GenericVirtualDevice::MessageCallback, this, std::placeholders::_1, std::placeholders::_2), []() {});
- context_->Initialize(remoteDeviceId_, storage_, metadata_, communicateHandle_);
- context_->SetRetryStatus(SyncTaskContext::NO_NEED_RETRY);
- context_->RegOnSyncTask(std::bind(&GenericVirtualDevice::StartResponseTask, this));
+ std::bind(&GenericVirtualDevice::MessageCallback, this, std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3), []() {});
+ for (const auto &syncInterface : syncInterfaces) {
+ std::string userId = syncInterface.first;
+ context_[userId]->Initialize(remoteDeviceId_, userId, storage_[userId], metadata_[userId], communicateHandle_);
+ context_[userId]->SetRetryStatus(SyncTaskContext::NO_NEED_RETRY);
+ context_[userId]->RegOnSyncTask([this, &userId] { return StartResponseTask(context_[userId]); });
- executor_ = new (std::nothrow) RemoteExecutor();
- if (executor_ == nullptr) {
- return -E_OUT_OF_MEMORY;
+ executor_[userId] = new(std::nothrow) RemoteExecutor();
+ if (executor_[userId] == nullptr) {
+ return -E_OUT_OF_MEMORY;
+ }
+ executor_[userId]->Initialize(syncInterface.second, communicateHandle_);
}
- executor_->Initialize(syncInterface, communicateHandle_);
return E_OK;
}
@@ -132,7 +146,7 @@ std::string GenericVirtualDevice::GetDeviceId() const
return deviceId_;
}
-int GenericVirtualDevice::MessageCallback(const std::string &deviceId, Message *inMsg)
+int GenericVirtualDevice::MessageCallback(const std::string &deviceId, const std::string &userId, Message *inMsg)
{
if (inMsg->GetMessageId() == LOCAL_DATA_CHANGED) {
if (onRemoteDataChanged_) {
@@ -147,16 +161,16 @@ int GenericVirtualDevice::MessageCallback(const std::string &deviceId, Message *
}
LOGD("[GenericVirtualDevice] onMessage, src %s id %u", deviceId.c_str(), inMsg->GetMessageId());
- if (inMsg->GetMessageId() == REMOTE_EXECUTE_MESSAGE && executor_ != nullptr) {
- RefObject::IncObjRef(executor_);
- executor_->ReceiveMessage(deviceId, inMsg);
- RefObject::DecObjRef(executor_);
+ if (inMsg->GetMessageId() == REMOTE_EXECUTE_MESSAGE && executor_[userId] != nullptr) {
+ RefObject::IncObjRef(executor_[userId]);
+ executor_[userId]->ReceiveMessage(deviceId, inMsg);
+ RefObject::DecObjRef(executor_[userId]);
return E_OK;
}
- RefObject::IncObjRef(context_);
+ RefObject::IncObjRef(context_[userId]);
RefObject::IncObjRef(communicateHandle_);
- SyncTaskContext *context = context_;
+ SyncTaskContext *context = context_[userId];
ICommunicator *communicateHandle = communicateHandle_;
std::thread thread([context, communicateHandle, inMsg]() {
int errCode = context->ReceiveMessageCallback(inMsg);
@@ -187,35 +201,35 @@ void GenericVirtualDevice::Offline()
communicatorAggregator_->OfflineDevice(deviceId_);
}
-int GenericVirtualDevice::StartResponseTask()
+int GenericVirtualDevice::StartResponseTask(SyncTaskContext *context)
{
LOGD("[KvVirtualDevice] StartResponseTask");
- RefObject::AutoLock lockGuard(context_);
- int status = context_->GetTaskExecStatus();
- if ((status == SyncTaskContext::RUNNING) || context_->IsKilled()) {
+ RefObject::AutoLock lockGuard(context);
+ int status = context->GetTaskExecStatus();
+ if ((status == SyncTaskContext::RUNNING) || context->IsKilled()) {
LOGD("[KvVirtualDevice] StartResponseTask status:%d", status);
return -E_NOT_SUPPORT;
}
- if (context_->IsTargetQueueEmpty()) {
+ if (context->IsTargetQueueEmpty()) {
LOGD("[KvVirtualDevice] StartResponseTask IsTargetQueueEmpty is empty");
return E_OK;
}
- context_->SetTaskExecStatus(ISyncTaskContext::RUNNING);
- context_->MoveToNextTarget(DBConstant::MIN_TIMEOUT);
+ context->SetTaskExecStatus(ISyncTaskContext::RUNNING);
+ context->MoveToNextTarget(DBConstant::MIN_TIMEOUT);
LOGI("[KvVirtualDevice] machine StartSync");
- context_->UnlockObj();
- int errCode = context_->StartStateMachine();
- context_->LockObj();
+ context->UnlockObj();
+ int errCode = context->StartStateMachine();
+ context->LockObj();
if (errCode != E_OK) {
LOGE("[KvVirtualDevice] machine StartSync failed");
- context_->SetOperationStatus(SyncOperation::OP_FAILED);
+ context->SetOperationStatus(SyncOperation::OP_FAILED);
}
return errCode;
}
-TimeOffset GenericVirtualDevice::GetLocalTimeOffset() const
+TimeOffset GenericVirtualDevice::GetLocalTimeOffset(const std::string &userId) const
{
- return metadata_->GetLocalTimeOffset();
+ return metadata_.at(userId)->GetLocalTimeOffset();
}
void GenericVirtualDevice::OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &processMap,
@@ -236,7 +250,7 @@ void GenericVirtualDevice::OnDeviceSyncProcess(const std::map<std::string, Devic
int GenericVirtualDevice::Sync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess)
{
- auto operation = new (std::nothrow) SyncOperation(1, {remoteDeviceId_}, option.mode, nullptr, option.isWait);
+ auto operation = new (std::nothrow) SyncOperation(1, {{remoteDeviceId_, ""}}, option.mode, nullptr, option.isWait);
if (operation == nullptr) {
return -E_OUT_OF_MEMORY;
}
@@ -256,7 +270,7 @@ int GenericVirtualDevice::Sync(const DeviceSyncOption &option, const DeviceSyncP
}
operation->SetQuery(querySyncObject);
}
- errCode = context_->AddSyncOperation(operation);
+ errCode = context_[""]->AddSyncOperation(operation);
operation->WaitIfNeed();
RefObject::KillAndDecObjRef(operation);
return errCode;
@@ -264,7 +278,7 @@ int GenericVirtualDevice::Sync(const DeviceSyncOption &option, const DeviceSyncP
int GenericVirtualDevice::Sync(SyncMode mode, bool wait)
{
- auto operation = new (std::nothrow) SyncOperation(1, {remoteDeviceId_}, mode, nullptr, wait);
+ auto operation = new (std::nothrow) SyncOperation(1, {{remoteDeviceId_, ""}}, mode, nullptr, wait);
if (operation == nullptr) {
return -E_OUT_OF_MEMORY;
}
@@ -272,7 +286,7 @@ int GenericVirtualDevice::Sync(SyncMode mode, bool wait)
operation->SetOnSyncFinished([operation](int id) {
operation->NotifyIfNeed();
});
- context_->AddSyncOperation(operation);
+ context_[""]->AddSyncOperation(operation);
operation->WaitIfNeed();
RefObject::KillAndDecObjRef(operation);
return E_OK;
@@ -286,7 +300,7 @@ int GenericVirtualDevice::Sync(SyncMode mode, const Query &query, bool wait)
int GenericVirtualDevice::Sync(SyncMode mode, const Query &query,
const SyncOperation::UserCallback &callBack, bool wait)
{
- auto operation = new (std::nothrow) SyncOperation(1, {remoteDeviceId_}, mode, callBack, wait);
+ auto operation = new (std::nothrow) SyncOperation(1, {{remoteDeviceId_, ""}}, mode, callBack, wait);
if (operation == nullptr) {
return -E_OUT_OF_MEMORY;
}
@@ -300,7 +314,7 @@ int GenericVirtualDevice::Sync(SyncMode mode, const Query &query,
return errCode;
}
operation->SetQuery(querySyncObject);
- context_->AddSyncOperation(operation);
+ context_[""]->AddSyncOperation(operation);
operation->WaitIfNeed();
RefObject::KillAndDecObjRef(operation);
return errCode;
@@ -309,11 +323,11 @@ int GenericVirtualDevice::Sync(SyncMode mode, const Query &query,
int GenericVirtualDevice::RemoteQuery(const std::string &device, const RemoteCondition &condition,
uint64_t timeout, std::shared_ptr<ResultSet> &result)
{
- if (executor_ == nullptr) {
+ if (executor_[""] == nullptr) {
result = nullptr;
return TransferDBErrno(-E_BUSY);
}
- int errCode = executor_->RemoteQuery(device, condition, timeout, 1u, result);
+ int errCode = executor_[""]->RemoteQuery(device, condition, timeout, 1u, result);
if (errCode != E_OK) {
result = nullptr;
}
@@ -322,8 +336,8 @@ int GenericVirtualDevice::RemoteQuery(const std::string &device, const RemoteCon
void GenericVirtualDevice::SetClearRemoteStaleData(bool isStaleData)
{
- if (context_ != nullptr) {
- static_cast<SingleVerSyncTaskContext *>(context_)->EnableClearRemoteStaleData(isStaleData);
+ if (context_[""] != nullptr) {
+ static_cast<SingleVerSyncTaskContext *>(context_[""])->EnableClearRemoteStaleData(isStaleData);
LOGD("set clear remote stale data mark");
}
}
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
index 462dd6948..dac3eeb8b 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/generic_virtual_device.h
@@ -31,15 +31,15 @@ public:
explicit GenericVirtualDevice(std::string deviceId);
virtual ~GenericVirtualDevice();
- int Initialize(VirtualCommunicatorAggregator *comAggregator, ISyncInterface *syncInterface);
+ int Initialize(VirtualCommunicatorAggregator *comAggregator, std::map<std::string, ISyncInterface *> syncInterfaces);
void SetDeviceId(const std::string &deviceId);
std::string GetDeviceId() const;
- int MessageCallback(const std::string &deviceId, Message *inMsg);
+ int MessageCallback(const std::string &deviceId, const std::string &userId, Message *inMsg);
void OnRemoteDataChanged(const std::function<void(const std::string &)> &callback);
void Online();
void Offline();
- int StartResponseTask();
- TimeOffset GetLocalTimeOffset() const;
+ int StartResponseTask(SyncTaskContext *context);
+ TimeOffset GetLocalTimeOffset(const std::string &userId = "") const;
void OnDeviceSyncProcess(const std::map<std::string, DeviceSyncProcess> &processMap,
const DeviceSyncProcessCallback &onProcess) const;
virtual int Sync(const DeviceSyncOption &option, const DeviceSyncProcessCallback &onProcess);
@@ -52,15 +52,15 @@ public:
protected:
ICommunicator *communicateHandle_;
VirtualCommunicatorAggregator *communicatorAggregator_;
- ISyncInterface *storage_;
- std::shared_ptr<Metadata> metadata_;
+ std::map<std::string, ISyncInterface *> storage_;
+ std::map<std::string, std::shared_ptr<Metadata>> metadata_;
std::string deviceId_;
std::string remoteDeviceId_;
- SyncTaskContext *context_;
+ std::map<std::string, SyncTaskContext *> context_;
std::function<void(const std::string &)> onRemoteDataChanged_;
- std::shared_ptr<SubscribeManager> subManager_;
- RemoteExecutor *executor_;
+ std::map<std::string, std::shared_ptr<SubscribeManager>> subManager_;
+ std::map<std::string, RemoteExecutor *> executor_;
};
}
#endif // GENERIC_VIRTUAL_DEVICE_H
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp
index c2b58e7b8..e22e4733e 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.cpp
@@ -26,40 +26,41 @@ KvVirtualDevice::~KvVirtualDevice()
{
}
-int KvVirtualDevice::GetData(const Key &key, VirtualDataItem &item)
+int KvVirtualDevice::GetData(const Key &key, VirtualDataItem &item, const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
return syncAble->GetSyncData(key, item);
}
-int KvVirtualDevice::PutData(const Key &key, const Value &value, const Timestamp &time, int flag)
+int KvVirtualDevice::PutData(const Key &key, const Value &value, const Timestamp &time, int flag,
+ const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
LOGI("dev %s put data time %" PRIu64, deviceId_.c_str(), time);
return syncAble->PutData(key, value, time, flag);
}
-void KvVirtualDevice::SetSaveDataDelayTime(uint64_t milliDelayTime)
+void KvVirtualDevice::SetSaveDataDelayTime(uint64_t milliDelayTime, const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncInterface->SetSaveDataDelayTime(milliDelayTime);
}
-void KvVirtualDevice::DelayGetSyncData(uint64_t milliDelayTime)
+void KvVirtualDevice::DelayGetSyncData(uint64_t milliDelayTime, const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncInterface->DelayGetSyncData(milliDelayTime);
}
-void KvVirtualDevice::SetGetDataErrCode(int whichTime, int errCode, bool isGetDataControl)
+void KvVirtualDevice::SetGetDataErrCode(int whichTime, int errCode, bool isGetDataControl, const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncInterface->SetGetDataErrCode(whichTime, errCode, isGetDataControl);
}
-void KvVirtualDevice::ResetDataControl()
+void KvVirtualDevice::ResetDataControl(const std::string &userId)
{
- VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ VirtualSingleVerSyncDBInterface *syncInterface = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncInterface->ResetDataControl();
}
@@ -95,9 +96,9 @@ int KvVirtualDevice::Commit()
}
#endif // OMIT_MULTI_VER
-int KvVirtualDevice::Subscribe(QuerySyncObject query, bool wait, int id)
+int KvVirtualDevice::Subscribe(QuerySyncObject query, bool wait, int id, const std::string &userId)
{
- auto operation = new (std::nothrow) SyncOperation(id, {remoteDeviceId_}, SUBSCRIBE_QUERY, nullptr, wait);
+ auto operation = new (std::nothrow) SyncOperation(id, {{remoteDeviceId_, userId}}, SUBSCRIBE_QUERY, nullptr, wait);
if (operation == nullptr) {
return -E_OUT_OF_MEMORY;
}
@@ -106,21 +107,21 @@ int KvVirtualDevice::Subscribe(QuerySyncObject query, bool wait, int id)
operation->NotifyIfNeed();
});
operation->SetQuery(query);
- context_->AddSyncOperation(operation);
+ context_[userId]->AddSyncOperation(operation);
operation->WaitIfNeed();
RefObject::KillAndDecObjRef(operation);
return E_OK;
}
-int KvVirtualDevice::UnSubscribe(QuerySyncObject query, bool wait, int id)
+int KvVirtualDevice::UnSubscribe(QuerySyncObject query, bool wait, int id, const std::string &userId)
{
- return UnSubscribe(query, wait, id, nullptr);
+ return UnSubscribe(query, wait, id, nullptr, userId);
}
int KvVirtualDevice::UnSubscribe(const QuerySyncObject &query, bool wait, int id,
- const SyncOperation::UserCallback &callback)
+ const SyncOperation::UserCallback &callback, const std::string &userId)
{
- auto operation = new (std::nothrow) SyncOperation(id, {remoteDeviceId_}, UNSUBSCRIBE_QUERY, callback, wait);
+ auto operation = new (std::nothrow) SyncOperation(id, {{remoteDeviceId_, userId}}, UNSUBSCRIBE_QUERY, callback, wait);
if (operation == nullptr) {
return -E_OUT_OF_MEMORY;
}
@@ -129,26 +130,27 @@ int KvVirtualDevice::UnSubscribe(const QuerySyncObject &query, bool wait, int id
operation->NotifyIfNeed();
});
operation->SetQuery(query);
- context_->AddSyncOperation(operation);
+ context_[userId]->AddSyncOperation(operation);
operation->WaitIfNeed();
RefObject::KillAndDecObjRef(operation);
return E_OK;
}
-void KvVirtualDevice::SetSaveDataCallback(const std::function<void()> &callback)
+void KvVirtualDevice::SetSaveDataCallback(const std::function<void()> &callback, const std::string &userId)
{
- auto *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ auto *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncAble->SetSaveDataCallback(callback);
}
-void KvVirtualDevice::EraseWaterMark(const std::string &dev)
+void KvVirtualDevice::EraseWaterMark(const std::string &dev, const std::string &userId)
{
- metadata_->EraseDeviceWaterMark(dev, true);
+ metadata_.at(userId)->EraseDeviceWaterMark(dev, true);
}
-void KvVirtualDevice::SetPushNotifier(const std::function<void(const std::string &)> &pushNotifier)
+void KvVirtualDevice::SetPushNotifier(const std::function<void(const std::string &)> &pushNotifier,
+ const std::string &userId)
{
- auto *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_);
+ auto *syncAble = static_cast<VirtualSingleVerSyncDBInterface *>(storage_[userId]);
syncAble->SetPushNotifier(pushNotifier);
}
} // namespace DistributedDB
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h
index 80e266c42..65f04ccce 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/kv_virtual_device.h
@@ -25,26 +25,27 @@ public:
explicit KvVirtualDevice(const std::string &deviceId);
~KvVirtualDevice() override;
- int GetData(const Key &key, VirtualDataItem &item);
+ int GetData(const Key &key, VirtualDataItem &item, const std::string &userId = "");
int GetData(const Key &key, Value &value);
- int PutData(const Key &key, const Value &value, const Timestamp &time, int flag);
+ int PutData(const Key &key, const Value &value, const Timestamp &time, int flag, const std::string &userId = "");
int PutData(const Key &key, const Value &value);
int DeleteData(const Key &key);
int StartTransaction();
int Commit();
- void SetSaveDataDelayTime(uint64_t milliDelayTime);
- void DelayGetSyncData(uint64_t milliDelayTime);
- void SetGetDataErrCode(int whichTime, int errCode, bool isGetDataControl);
- void ResetDataControl();
+ void SetSaveDataDelayTime(uint64_t milliDelayTime, const std::string &userId = "");
+ void DelayGetSyncData(uint64_t milliDelayTime, const std::string &userId = "");
+ void SetGetDataErrCode(int whichTime, int errCode, bool isGetDataControl, const std::string &userId = "");
+ void ResetDataControl(const std::string &userId = "");
- int Subscribe(QuerySyncObject query, bool wait, int id);
- int UnSubscribe(QuerySyncObject query, bool wait, int id);
- int UnSubscribe(const QuerySyncObject &query, bool wait, int id, const SyncOperation::UserCallback &callback);
+ int Subscribe(QuerySyncObject query, bool wait, int id, const std::string &userId = "");
+ int UnSubscribe(QuerySyncObject query, bool wait, int id, const std::string &userId = "");
+ int UnSubscribe(const QuerySyncObject &query, bool wait, int id, const SyncOperation::UserCallback &callback,
+ const std::string &userId = "");
- void SetSaveDataCallback(const std::function<void()> &callback);
- void EraseWaterMark(const std::string &dev);
+ void SetSaveDataCallback(const std::function<void()> &callback, const std::string &userId = "");
+ void EraseWaterMark(const std::string &dev, const std::string &userId = "");
- void SetPushNotifier(const std::function<void(const std::string &)> &pushNotifier);
+ void SetPushNotifier(const std::function<void(const std::string &)> &pushNotifier, const std::string &userId = "");
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
index 1545ea636..fa6f8f0df 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_sync_engine.h
@@ -29,9 +29,9 @@ public:
subManager_ = std::make_shared<SubscribeManager>();
}
- ISyncTaskContext *CallGetSyncTaskContext(const std::string &deviceId, int &errCode)
+ ISyncTaskContext *CallGetSyncTaskContext(const std::string &deviceId, const std::string &userId, int &errCode)
{
- return SyncEngine::GetSyncTaskContext(deviceId, errCode);
+ return SyncEngine::GetSyncTaskContext(deviceId, userId, errCode);
}
};
} // namespace DistributedDB
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.cpp
index 96b5f5417..ab0edc0b3 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.cpp
@@ -24,25 +24,28 @@ RelationalVirtualDevice::~RelationalVirtualDevice()
{
}
-int RelationalVirtualDevice::PutData(const std::string &tableName, const std::vector<VirtualRowData> &dataList)
+int RelationalVirtualDevice::PutData(const std::string &tableName, const std::vector<VirtualRowData> &dataList,
+ const std::string &userId)
{
- return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->PutLocalData(dataList, tableName);
+ return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->PutLocalData(dataList, tableName);
}
-int RelationalVirtualDevice::GetAllSyncData(const std::string &tableName, std::vector<VirtualRowData> &data)
+int RelationalVirtualDevice::GetAllSyncData(const std::string &tableName, std::vector<VirtualRowData> &data,
+ const std::string &userId)
{
- return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->GetAllSyncData(tableName, data);
+ return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->GetAllSyncData(tableName, data);
}
int RelationalVirtualDevice::GetSyncData(const std::string &tableName,
- const std::string &hashKey, VirtualRowData &data)
+ const std::string &hashKey, VirtualRowData &data, const std::string &userId)
{
- return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->GetVirtualSyncData(tableName, hashKey, data);
+ return static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->GetVirtualSyncData(tableName, hashKey, data);
}
-void RelationalVirtualDevice::SetLocalFieldInfo(const std::vector<FieldInfo> &localFieldInfo)
+void RelationalVirtualDevice::SetLocalFieldInfo(const std::vector<FieldInfo> &localFieldInfo,
+ const std::string &userId)
{
- static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->SetLocalFieldInfo(localFieldInfo);
+ static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->SetLocalFieldInfo(localFieldInfo);
}
int RelationalVirtualDevice::Sync(SyncMode mode, bool wait)
@@ -50,24 +53,25 @@ int RelationalVirtualDevice::Sync(SyncMode mode, bool wait)
return -E_NOT_SUPPORT;
}
-void RelationalVirtualDevice::EraseSyncData(const std::string &tableName)
+void RelationalVirtualDevice::EraseSyncData(const std::string &tableName, const std::string &userId)
{
- static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->EraseSyncData(tableName);
+ static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->EraseSyncData(tableName);
}
-void RelationalVirtualDevice::SetTableInfo(const TableInfo &tableInfo)
+void RelationalVirtualDevice::SetTableInfo(const TableInfo &tableInfo, const std::string &userId)
{
- static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->SetTableInfo(tableInfo);
+ static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->SetTableInfo(tableInfo);
}
-void RelationalVirtualDevice::SetDistributedSchema(const DistributedDB::DistributedSchema &schema)
+void RelationalVirtualDevice::SetDistributedSchema(const DistributedDB::DistributedSchema &schema,
+ const std::string &userId)
{
- static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->SetDistributedSchema(schema);
+ static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->SetDistributedSchema(schema);
}
-void RelationalVirtualDevice::SetGetSyncDataResult(int errCode)
+void RelationalVirtualDevice::SetGetSyncDataResult(int errCode, const std::string &userId)
{
- static_cast<VirtualRelationalVerSyncDBInterface *>(storage_)->SetGetSyncDataResult(errCode);
+ static_cast<VirtualRelationalVerSyncDBInterface *>(storage_[userId])->SetGetSyncDataResult(errCode);
}
} // DistributedDB
#endif
\ No newline at end of file
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.h
index 45d0f5486..23e6d949c 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/relational_virtual_device.h
@@ -28,15 +28,18 @@ public:
explicit RelationalVirtualDevice(const std::string &deviceId);
~RelationalVirtualDevice() override;
- int PutData(const std::string &tableName, const std::vector<VirtualRowData> &dataList);
- int GetAllSyncData(const std::string &tableName, std::vector<VirtualRowData> &data);
- int GetSyncData(const std::string &tableName, const std::string &hashKey, VirtualRowData &data);
- void SetLocalFieldInfo(const std::vector<FieldInfo> &localFieldInfo);
- void SetTableInfo(const TableInfo &tableInfo);
+ int PutData(const std::string &tableName, const std::vector<VirtualRowData> &dataList,
+ const std::string &userId = "");
+ int GetAllSyncData(const std::string &tableName, std::vector<VirtualRowData> &data,
+ const std::string &userId = "");
+ int GetSyncData(const std::string &tableName, const std::string &hashKey, VirtualRowData &data,
+ const std::string &userId = "");
+ void SetLocalFieldInfo(const std::vector<FieldInfo> &localFieldInfo, const std::string &userId = "");
+ void SetTableInfo(const TableInfo &tableInfo, const std::string &userId = "");
int Sync(SyncMode mode, bool wait) override;
- void EraseSyncData(const std::string &tableName);
- void SetDistributedSchema(const DistributedSchema &schema);
- void SetGetSyncDataResult(int errCode);
+ void EraseSyncData(const std::string &tableName, const std::string &userId = "");
+ void SetDistributedSchema(const DistributedSchema &schema, const std::string &userId = "");
+ void SetGetSyncDataResult(int errCode, const std::string &userId = "");
template<typename T>
void PutDeviceData(const std::string &tableName, const std::vector<T> &data)
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
index 9d6df07de..f47185ea9 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.cpp
@@ -69,7 +69,7 @@ int VirtualCommunicator::SendMessage(const std::string &dstTarget, const Message
Message *message = nullptr;
int errCode = TranslateMsg(inMsg, message);
if (errCode == -E_NOT_REGISTER) {
- communicatorAggregator_->DispatchMessage(deviceId_, dstTarget, inMsg, onEnd);
+ communicatorAggregator_->DispatchMessage(deviceId_, dstTarget, inMsg, onEnd, config.paramInfo.targetUserId);
return E_OK;
}
if (errCode != E_OK) {
@@ -77,7 +77,7 @@ int VirtualCommunicator::SendMessage(const std::string &dstTarget, const Message
}
delete inMsg;
inMsg = nullptr;
- communicatorAggregator_->DispatchMessage(deviceId_, dstTarget, message, onEnd);
+ communicatorAggregator_->DispatchMessage(deviceId_, dstTarget, message, onEnd, config.paramInfo.targetUserId);
return E_OK;
}
@@ -92,12 +92,12 @@ int VirtualCommunicator::GetRemoteCommunicatorVersion(const std::string &deviceI
return E_OK;
}
-void VirtualCommunicator::CallbackOnMessage(const std::string &srcTarget, Message *inMsg)
+void VirtualCommunicator::CallbackOnMessage(const std::string &srcTarget, Message *inMsg, const std::string &userId)
{
std::lock_guard<std::mutex> lock(onMessageLock_);
if (isEnable_ && onMessage_ && (srcTarget != deviceId_) && ((inMsg->GetMessageId() != dropMsgId_) ||
(dropMsgTimes_ == 0))) {
- onMessage_(srcTarget, inMsg);
+ onMessage_(srcTarget, userId, inMsg);
} else {
LOGD("drop msg from dev=%s, localDev=%s", srcTarget.c_str(), deviceId_.c_str());
if (dropMsgTimes_ > 0) {
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
index f904df098..78efd9b60 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator.h
@@ -61,7 +61,7 @@ public:
int GetRemoteCommunicatorVersion(const std::string &deviceId, uint16_t &version) const override;
- void CallbackOnMessage(const std::string &srcTarget, Message *inMsg);
+ void CallbackOnMessage(const std::string &srcTarget, Message *inMsg, const std::string &userId = "");
void CallbackOnConnect(const std::string &target, bool isConnect) const;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.cpp
index ddc3d9c5c..22a022e6e 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.cpp
@@ -175,7 +175,7 @@ ICommunicator *VirtualCommunicatorAggregator::GetCommunicator(const std::string
}
void VirtualCommunicatorAggregator::DispatchMessage(const std::string &srcTarget, const std::string &dstTarget,
- const Message *inMsg, const OnSendEnd &onEnd)
+ const Message *inMsg, const OnSendEnd &onEnd, const std::string &userId)
{
if (VirtualCommunicatorAggregator::GetBlockValue()) {
std::unique_lock<std::mutex> lock(blockLock_);
@@ -191,11 +191,11 @@ void VirtualCommunicatorAggregator::DispatchMessage(const std::string &srcTarget
if (beforeDispatch_) {
beforeDispatch_(dstTarget, inMsg);
}
- DispatchMessageInner(srcTarget, dstTarget, inMsg, onEnd);
+ DispatchMessageInner(srcTarget, dstTarget, inMsg, onEnd, userId);
}
void VirtualCommunicatorAggregator::DispatchMessageInner(const std::string &srcTarget, const std::string &dstTarget,
- const Message *inMsg, const OnSendEnd &onEnd)
+ const Message *inMsg, const OnSendEnd &onEnd, const std::string &userId)
{
std::lock_guard<std::mutex> lock(communicatorsLock_);
auto iter = communicators_.find(dstTarget);
@@ -216,14 +216,14 @@ void VirtualCommunicatorAggregator::DispatchMessageInner(const std::string &srcT
bool isNeedDelay = ((sendDelayTime_ > 0) && (delayTimes_ > 0) && (messageId == delayMessageId_) &&
(delayDevices_.count(dstTarget) > 0) && (skipTimes_ == 0));
uint32_t sendDelayTime = sendDelayTime_;
- std::thread thread([communicator, srcTarget, dstTarget, msg, isNeedDelay, sendDelayTime, onDispatch]() {
+ std::thread thread([communicator, srcTarget, dstTarget, msg, isNeedDelay, sendDelayTime, onDispatch, userId]() {
if (isNeedDelay) {
std::this_thread::sleep_for(std::chrono::milliseconds(sendDelayTime));
}
if (onDispatch) {
onDispatch(dstTarget, msg);
}
- communicator->CallbackOnMessage(srcTarget, msg);
+ communicator->CallbackOnMessage(srcTarget, msg, userId);
RefObject::DecObjRef(communicator);
});
DelayTimeHandle(messageId, dstTarget);
diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.h
index b92e48845..57ec7482c 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.h
+++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_communicator_aggregator.h
@@ -54,7 +54,7 @@ public:
void OfflineDevice(const std::string &deviceId) const;
void DispatchMessage(const std::string &srcTarget, const std::string &dstTarget, const Message *inMsg,
- const OnSendEnd &onEnd);
+ const OnSendEnd &onEnd, const std::string &userId = "");
// If not success, return nullptr and set outErrorNo
ICommunicator *AllocCommunicator(const std::string &deviceId, int &outErrorNo);
@@ -114,7 +114,7 @@ private:
void CallSendEnd(int errCode, const OnSendEnd &onEnd);
void DelayTimeHandle(uint32_t messageId, const std::string &dstTarget);
void DispatchMessageInner(const std::string &srcTarget, const std::string &dstTarget, const Message *inMsg,
- const OnSendEnd &onEnd);
+ const OnSendEnd &onEnd, const std::string &userId);
mutable std::mutex communicatorsLock_;
std::map<std::string, VirtualCommunicator *> communicators_;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liao-yonghuang/lyh.git
git@gitee.com:liao-yonghuang/lyh.git
liao-yonghuang
lyh
lyh
master

搜索帮助