1 / 64

Fleet An Effective System for PublishSubscribe Service over Structured P2P Networks

Fleet An Effective System for PublishSubscribe Service over Structured P2P Networks. 蔡佳良 M9615041. Fleet LPNF-Name subscription_installation () algorithm. Fleet LPNF-Name publish_event () algorithm. Data Structure of Scheme.

demi
Download Presentation

Fleet An Effective System for PublishSubscribe Service over Structured P2P Networks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fleet An Effective System for PublishSubscribe Service over Structured P2P Networks 蔡佳良 M9615041

  2. Fleet LPNF-Namesubscription_installation() algorithm

  3. Fleet LPNF-Namepublish_event () algorithm

  4. Data Structure of Scheme map<string, Attribute*> Scheme //一開始系統會讀入所有的attribute存在scheme中 class Attribute {//每個attribute 有他的最大最小值的範圍 還有他的型態 private: string Smin; string Smax; double min; double max; bool value; public: string Name; int type; } Attribute name:Indulge Min=0 max=99 Type= integer

  5. Data Structure of Subscription 一個subscription儲存的例子 class Subscription { double SubscriberID; set<Predicates*> pds; } Value:0~100 Subscription A Indulge= 26 Welch > 24 SubscriberID=0.5842 set<Predicates*> ={(Indulge , Welch) } set<Predicate*>={Indulge , Welch} class Predicate { string Smin; string Smax; double min; double max; bool value; string attr; } class Predicates { char op; set<Predicate*> p; } attr=“Ingulge” min=26 max=26 attr=“Welch” min=24 max=100 range-query-type equality-type

  6. Main program int main (int argc, char **argv) { while (!finished) { choose RP Node subscriptions publish & install while( event != end){ event match & publish } } }

  7. choose RP Node Random 決定 set<double> chooseSubStationNodes(int NumOfSubStation, double sourceKey) { set<double> subStation;//存最後選出來的RP node key double separate_range = (double) 1 / NumOfSubStation; //將整個chord ring 切成N等分 map<double, VirtualServer*>::iterator p = vServers.lower_bound(sourceKey);//從sourceKey開始 if (p == vServers.end()) p = vServers.begin(); subStation.insert(p->first); for (int i = 1; i < NumOfSubStation; i++) { p = vServers.lower_bound((p->first + separate_range > 1.0) ? (p->first + separate_range - 1) : (p->first + separate_range)); if (p == vServers.end()) p = vServers.begin(); subStation.insert(p->first); } return subStation; } 7 個 RP node sourceKey //每個等距選出一個Node 為 RP node separate_range

  8. Main program int main (int argc, char **argv) { while (!finished) { choose RP Node subscriptions publish & install while( event != end){ event match & publish } } }

  9. subscriptions publish & install //分析是否有equality-type的 attribute if(useFleetmethod2){ double subKey = s->first;//目前發布的subscription Subscription *thisSub = s->second; string thissubsAttr; set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) { … continue; }else{ subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ … continue; }else{ Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … } }

  10. AnalysisSubsComponentExceptBoolofEqual 分析是否有equality-type的 attribute set<string> VirtualServer::AnalysisSubsComponentExceptBoolofEqual(Subscription *s){ set<Predicates*> thisPds = s->getPredicates(); set<Predicate*> thisPd = (*(thisPds.begin()))->getPredicate(); set<string> subsComponents; subsComponents.clear(); for (set<Predicate*>::iterator thisPdp = thisPd.begin(); thisPdp != thisPd.end(); thisPdp++) {//查看subscription中的每個attribute Predicate *thisPred = *thisPdp; string name=thisPred->attr; if(Scheme.find(name)->second->type != 1 ){//string 必為equality-type if(Scheme.find(thisPred->attr)->second->type==0&& subsComponents.find(thisPred->attr) == subsComponents.end()){ subsComponents.insert(thisPred->attr); }elseif(Scheme.find(thisPred->attr)->second->type==2&& subsComponents.find(thisPred->attr) == subsComponents.end()){ if(thisPred->getmax()==thisPred->getmin())//double 若 min=max 則也屬於equality-type subsComponents.insert(thisPred->attr); } } } return subsComponents; } string  type = 0 boolean  type = 1 double  type = 2

  11. subscriptions publish & install Subscription A retractions = 45 grist = 39 if(useFleetmethod2){ double subKey = s->first; Subscription *thisSub = s->second; string thissubsAttr; set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) { … continue; }else{ subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ … continue; }else{ Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … } } Subscription B retractions > 92 Palestine = 47.25 Subscription C retractions = 40 Barhop < 13 //case 1:此subscription至少有一個equal type 針對equality type處裡 // equality-type subscription :使用attribute name + value 為key 值 hash( name, value)

  12. Case 1: Any one operator is an equality operator retractions > 92 Palestine = 47.25 subscription 0.93 0.18 Palestine = 47.25 0.82 0.38 0.39 0.71 install 0.44 0.64 0.46 0.63 0.51 0.59

  13. equality-type subscription :使用attribute name + value 為key 值 hash( name, value) Subscription A retractions = 45 grist = 39 Random pick out retractions = 45 if (!subsComponent.empty()) { int whichattribute=rand()%subsComponent.size(); … int choosedattributetype=getattributetype((*thisPdit)->attr); //分析此attribute為string type or value type if(choosedattributetype==0){//若為string type attribute string hashstring=(*thisPdit)->attr+(*thisPdit)->getSmax(); pickKEYofSubscription=returnHashStringToNode(hashstring); //hash( name + value) } elseif(choosedattributetype==2){//若為value type attribute sprintf(temp, "%f", (*thisPdit)->getmax()); string s(temp); string hashstring=(*thisPdit)->attr+s; pickKEYofSubscription=returnHashStringToNode(hashstring); //hash( name + value) } bool routeSuccess = vServers[thisSub->getSubscriberID()]->customer_route(pickKEYofSubscription, notDisplay); //從publish node 傳subscription到 pick node if (routeSuccess) { vServers[pickKEYofSubscription]->fleetaddSubs(subKey,thissubsAttr,thisSubsValue); } } Hash(retractions,45) pickKEYofSubscription Publish node pickKEYofSubscription install 找到node後 將subscription存入 Hash(name+value)找出要存放subscription的node

  14. subscriptions publish & install if(useFleetmethod2){ double subKey = s->first;//目前發布的subscription Subscription *thisSub = s->second; string thissubsAttr; //分析是否有equality-type的 attribute set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) {//此subscription至少有一個equal type …// equality-type subscription:使用attribute name + value 為key 值 hash( name, value) continue; }else{ subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); //分析是否存在非熱門的attribute set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); //分析是否存在熱門的attribute if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ …//所有attribute皆為熱門attribute使用Kautz Graph continue; }else{ //挑選出非熱門attribute set中 其value 範圍值最小之attribute Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … //range-query-type subscription:分割value值成value1,value2,…,valuen , //用attribute name + valuei為key值 hash(name, valuei) 然後複製N份subscriptions存在系統 } } 先判斷是不是熱門的attribute //處理range-query-type subscription

  15. AnalysisSubsComponentNotHotAnalysisSubsComponent set<string> VirtualServer::AnalysisSubsComponentNotHot(Subscription *s) { … for (set<Predicate*>::iterator thisPdp = thisPd.begin(); thisPdp != thisPd.end(); thisPdp++) { Predicate *thisPred = *thisPdp; if(AttributeToIndex(thisPred->attr) < 0 && subsComponents.find(thisPred->attr) == subsComponents.end()) subsComponents.insert(thisPred->attr); } return subsComponents; } set<string> VirtualServer::AnalysisSubsComponent(Subscription *s) { … for (set<Predicate*>::iterator thisPdp = thisPd.begin(); thisPdp != thisPd.end(); thisPdp++) { Predicate *thisPred = *thisPdp; if(AttributeToIndex(thisPred->attr) >= 0 && subsComponents.find(thisPred->attr) == subsComponents.end()) subsComponents.insert(thisPred->attr); } return subsComponents; } //挑出非熱門的attribute //挑出熱門的attribute AttributeToIndex(name) >= 0  popular AttributeToIndex(name) < 0  not popular

  16. subscriptions publish & install Subscription A Tomography< 26 if(useFleetmethod2){ double subKey = s->first;//目前發布的subscription Subscription *thisSub = s->second; string thissubsAttr; //分析是否有equality-type的 attribute set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) {//此subscription至少有一個equal type …// equality-type subscription :使用attribute name + value 為key 值 hash( name, value) continue; }else{//處理range-query-type subscription subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); //分析是否存在非熱門的attribute set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); //分析是否存在熱門的attribute if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ …// continue; }else{ //挑選出非熱門attribute set中 其value 範圍值最小之attribute Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … // range-query-type subscription:分割value值成value1,value2,…,valuen , //用attribute name + valuei為key值 hash(name, valuei) 然後複製N份subscriptions存在系統 } } Subscription B retractions < 12 Tomography > 1 Case 2:所有attribute皆為熱門attribute使用Kautz Graph

  17. Tomography Case 2: All attributes are hot Tomography < 21.75 subscription 0.93 0.18 Tomography 21.75 0 100 install 0.38 0.39 0.71 0.44 0.64 0.46 0.63 0.51 0.59

  18. 使用kautz tree之前 先把subscription集中存入在tree root if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); map<set<string> , double>::iterator spp = SPnodes.find(subsComponent); if (spp == SPnodes.end()) {//若此熱門attribute尚未有負責的SP node string concateSubs = ""; //挑選一個node作為此熱門attribute的SP node for (set<string>::iterator scp = subsComponent.begin(); scp != subsComponent.end(); scp++) concateSubs += *scp; double mapToDHTnode = (double) (BKDRHash(concateSubs) % 1000000 + 1) / 1000000; map<double, VirtualServer*>::iterator findsucc = vServers.lower_bound(mapToDHTnode); while(!succ->SPNodeKautzSubs.empty()){ //SP node不重複挑選 ,分散loading findsucc++; succ = findsucc->second; } } else {//之前的subscription已有過此組合 succ = vServers[spp->second]; } bool routeSuccess = vServers[thisSub->getSubscriberID()]->customer_route(succ->getKey(), notDisplay); if (routeSuccess) succ->addKautzSubs(subKey); continue; } 之前尚未建立這個kautz tree 新增一個 若這Kautz tree已經建立好了 就先將subs 存在root之後再分配到leaf Publish node retractions < 12 Tomography > 1 Set(retraction,Tomography) Sp node for (retraction,Tomography) install

  19. Subscriptions installation using Kautz Partition Tree • 黃俊維_08-11-21_Subscriptions installation using Kautz Partition Tree.ppt

  20. Definition • Kautz string: length kand base d • a string u1u2…ukwhere ui belongs to an alphabet of d + 1 symbols (0,l,2, . . , d} • ui≠ui+l (1 ≦ i ≦ k - 1)

  21. Data Structure of Kautz Node Add some structures in “Virtual Server” structure

  22. preparation • 取出前n名的組合 • create Kautz Partition Tree • push Subscription to Kautz node

  23. //記錄前n名組合 map<set<string> , double> chooseSP //取出前n名的組合 chooseSP = getTopNComponent(TopN); //create Kautz Partition Tree createKautzTree(KautzDegree, KautzLength, chooseSP, Display); voidcreateKautzTree(int degree, int length, map<set<string> , double> TopNComponents, bool display) { for (map<set<string> , double>::iterator tncp = TopNComponents.begin(); tncp != TopNComponents.end(); tncp++) {//對於所有的組合都建立一棵樹 double rootKey = tncp->second; VirtualServer *root = vServers[rootKey];//取出某組合的root set<string> thisSubsComponent = tncp->first; //取出此組合 Attribute *attr = Scheme[*(thisSubsComponent.begin())]; //先取出此組合的其中一個attribute double min = attr->getmin(); double max = attr->getmax(); double partOfQuota = (max - min) / (degree + 1);//欲切割這一層每一部分的大小 double thisMin = min; double thisMax = min + partOfQuota; set<double> choosedKey; choosedKey.insert(rootKey);//記錄那些vs已經被選為這棵樹的node map<int, double> branch; //記錄建立了那些分支 map<string, Predicate*> thisPred; //記錄被劃分的範圍 ….續下頁

  24. voidcreateKautzTree(int degree, int length, map<set<string> , double> TopNComponents, bool display) { • for (map<set<string> , double>::iterator tncp = TopNComponents.begin(); tncp != TopNComponents.end(); tncp++) {//對於所有的組合都建立一棵樹 • …..(接續上一頁) • for (int i = 0; i <= degree; i++) { //第一層從ROOT開始切割 • //隨機選擇一點,不能重複 • map<double, VirtualServer*>::iterator vp= vServers.lower_bound(randPct()); • while(choosedKey.find(vp->first) != choosedKey.end()) • vp++; • branch[i] = vp->first; • choosedKey.insert(vp->first);//記錄那些vs已經被選為這棵樹的node • //配置此attribute的範圍 • thisPred.clear(); • thisPred[attr->Name] = new Predicate(attr->Name,thisMin,thisMax); • for(set<string>::iterator tscp = thisSubsComponent.begin();tscp != thisSubsComponent.end();tscp++){ • if(attr->Name.compare(*tscp) == 0) • continue; • Attribute *otherAttr = Scheme[*tscp]; • thisPred[*tscp] = new Predicate(otherAttr->Name,otherAttr->getmin(),otherAttr->getmax()); • } • (vp->second->KautzPred)[thisSubsComponent] = thisPred; //儲存範圍至此node • thisMin = thisMax; //下一個兄弟node範圍開始值為前一個範圍的結束值 • if(i != degree) //下一個兄弟node範圍結束值=前一個範圍的結束值+每一個切割的部分的大小 • thisMax = thisMaX + partOfQuota; • else // 最後一個兄弟範圍的結束值為此attribute的最大值 • thisMax = max; • } • (root->KautzBranch)[thisSubsComponent] = branch; • //每個CHILD各自去執行建立分支的動作 • for(map<int,double>::iterator bp = branch.begin();bp != branch.end();bp++) • vServers[bp->second]->createSubKautzTree(degree, length, 1, bp->first, thisSubsComponent,display); • } • } 到這行為止的進度如下頁的圖

  25. 執行完到上一頁指定的進度時,已經建立好一棵tree如下圖執行完到上一頁指定的進度時,已經建立好一棵tree如下圖 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction createSubKautzTree(2, 4, 1, 0, <reractions,Tomography>, display) Tomography createSubKautzTree(2, 4, 1, 1, <reractions,Tomography>, display) createSubKautzTree(2, 4, 1, 2, <reractions,Tomography>, display) retraction Tomography

  26. //每個CHILD各自去執行建立分支的動作 傳入參數:degree<->d length <->base b level <->目前建立的是第幾層 branch <->parent所屬的是那個分支(0,1,2,…) subComponent<-> 建立的是那一種組合的node voidVirtualServer::createSubKautzTree(int degree, int length, int level, int branch, set<string> subComponent, bool display) { string attr = ""; //先選出目前是輪到組合中的那一個attribute if(subComponent.size() > 1) { int chooseComponent = level % subComponent.size(); int countOfComponent = 0; for (set<string>::iterator scp = subComponent.begin(); scp != subComponent.end(); scp++, countOfComponent++) if (countOfComponent == chooseComponent) { attr = *scp; break; } ASSERT(!attr.empty()); } else //此組合為single attribute attr = *(subComponent.begin()); //建立分支,傳入參數只比此function多一個attr <-> 要分割範圍的attribute createSubKautzTree(degree, length, level, branch, subComponent, attr, display); }

  27. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography? Retraction? Tomography 決定好要以哪個Attribute來建分割範圍 以這邊為例,因為已經跑過retraction, 所以換成Tomography //建立分支 createSubKautzTree(2, 4, 1, [1,2], <reraction,Tomography>, “Tomography”, display) retraction Tomography

  28. //建立分支 voidVirtualServer::createSubKautzTree(int degree, int length, int level, int branch, set<string> subComponent, string attr, bool display) { Predicate *thispred = KautzPred[subComponent][attr]; double min = thispred->getmin(); double max = thispred->getmax(); double partOfQuota = (max - min) / degree; double thisMin = min; double thisMax = min + partOfQuota; map<int,double> thisBranch; map<string,Predicate*> thisPred; for (int i = 0; i <= degree; i++) { if (i == branch) continue; //隨機選擇一點,不能重複 map<double, VirtualServer*>::iterator vp= vServers.lower_bound(randPct()); VirtualServer *thisKautzNode = vp->second; While (thisKautzNode->KautzPred.find(subComponent) != thisKautzNode->KautzPred.end() || thisKautzNode->getKey() == SPnodes[subComponent]) { vp++; if (vp == vServers.end()) vp = vServers.begin(); thisKautzNode = vp->second; } //決定好這個分支要建立在那個vs上 thisBranch[i] = thisKautzNode->getKey(); …..(接下頁)

  29. voidVirtualServer::createSubKautzTree(int degree, int length, int level, int branch, set<string> subComponent, string attr, bool display) { ….. for (int i = 0; i <= degree; i++) { …...(接續上一頁) thisPred.clear(); //配置此attribute的範圍 thisPred[attr] = new Predicate(attr,thisMin,thisMax); for (set<string>::iterator scp = subComponent.begin(); scp != subComponent.end(); scp++) { if(attr.compare(*scp) == 0) continue; thisPred[*scp] = KautzPred[subComponent][*scp]; } (thisKautzNode->KautzPred)[subComponent] = thisPred; //配置下一個兄弟node的範圍起始與結束值 thisMin = thisMax; if(i != degree) thisMax = thisMin + partOfQuota; else thisMax = max; } KautzBranch[subComponent] = thisBranch; level++; //配置完這層的node後就將level+1 if (level < length) //檢查是不是已經所有的level都配置完畢,沒有的話就回到選擇屬性的function for(map<int,double>::iterator tbp = thisBranch.begin();tbp != thisBranch.end();tbp++) vServers[tbp->second]->createSubKautzTree(degree, length, level, tbp->first, subComponent,display); }

  30. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography 因為現在還沒到設定的最底層第4層, 所以繼續重複選Attribute與分割範圍 retraction Tomography

  31. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography Tomography? Retraction? retraction 決定好要以哪個Attribute來建分割範圍 以這邊為例,因為已經跑過Tomography, 所以換成retraction Tomography createSubKautzTree(2, 4, 2, [0,2], <reraction,Tomography>,display) createSubKautzTree(2, 4, 2, [0,2], <reraction,Tomography>,“retraction”, display)

  32. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography createSubKautzTree(2, 4, 3, [1,2], <reraction,Tomography>,display) retraction Retraction? Tomography? 決定好要以哪個Attribute來建分割範圍 以這邊為例,因為已經跑過retraction, 所以換成Tomography Tomography createSubKautzTree(2, 4, 3, [1,2], <reraction,Tomography>,“Tomography”, display)

  33. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography retraction 已經到達設定的最底層第四層, 所以停止分割範圍 Tomography

  34. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography retraction 其他尚未執行完的建Tree動作 繼續執行 Tomography

  35. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography 其他尚未執行完的建Tree動作 繼續執行 retraction Tomography

  36. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography retraction 其他尚未執行完的建Tree動作 繼續執行 Tomography

  37. 執行完到上一頁指定的進度 P(2,4) retraction, Tomography (66~99],[1~49.75] [0~33],[1~49.75] (33~66],[1~49.75] 1 0 2 [0~33], [1~25.375] [0~33], (25.375~49.75] (33~66], (25.375~49.75] (33~66], [1~25.375] (66~99], [1~25.375] (66~99], (25.375~49.75] 10 12 01 02 20 21 (33~49.5], (25.375~49.75] (66~82.5], (25.375~49.75] [0~16.5], (25.375~49.75] (16.5~33], [1~25.375] (33~49.5], [1~25.375] (49.5~66], [1~25.375] [0~16.5], [1~25.375] (66~82.5], [1~25.375] (82.5~99], [1~25.375] (49.5~66], (25.375~49.75] (16.5~33], (25.375~49.75] (82.5~99], (25.375~49.75] 101 102 120 121 010 012 020 021 201 202 210 212 1020 1012 1201 1210 1021 1202 1212 0120 1010 2020 0102 0201 0210 2012 2101 2120 0121 0202 2021 2102 0212 2121 0101 2010 retraction Tomography retraction 其他分支依照相同動作繼續下去 Tomography

  38. //push Subscription to Kautz node for (map<set<string> , double>::iterator cspp = chooseSP.begin(); cspp != chooseSP.end(); cspp++) { //三棵建立好的空tree double spKey = cspp->second; VirtualServer *thisSp = vServers[spKey]; //取得某一棵樹的root set<string> thisSubsComponent = cspp->first; //取得這是屬於那一個組合的tree set<double> thisSubs = thisSp->subs; for(set<double>::iterator subp = thisSubs.begin();subp != thisSubs.end();subp++){ //對於目前在root上所有的subscriptions //取出此subscriptions的內容 Subscription* thisSub = SubsBASE[*subp]; set<Predicates*> thisPds = thisSub->getPredicates(); set<Predicate*> thisPd = (*(thisPds.begin()))->getPredicate(); map<string, double> lowValue,highValue; //找出這個subscriptions的內容中屬於此組合的predicate for (set<string>::iterator tscp = thisSubsComponent.begin(); tscp != thisSubsComponent.end(); tscp++) { string thisAttr = *tscp; for (set<Predicate*>::iterator thisPdp = thisPd.begin(); thisPdp != thisPd.end(); thisPdp++) { Predicate *thisPred = *thisPdp; if (thisAttr.compare(thisPred->attr) != 0) continue; lowValue[thisPred->attr] = thisPred->getmin(); highValue[thisPred->attr] = thisPred->getmax(); break; } } …..(接下頁) 25<=retraction<50 2.5<=Tomography<10 取得 lowValue,highValue 的值 highValue lowValue

  39. //push Subscription to Kautz node for (map<set<string> , double>::iterator cspp = chooseSP.begin(); cspp != chooseSP.end(); cspp++) { …. for(set<double>::iterator subp = thisSubs.begin();subp != thisSubs.end();subp++){ …...(接續上一頁) //取得下限值 string lowT = getKautzString(thisSubsComponent, lowValue, KautzLength, notDisplay); //取得上限值 string highT = getKautzString(thisSubsComponent, highValue, KautzLength, notDisplay); //包含下限值到上限值中間的所有Tree Node set<string> DestCopyNode = getAllKautzString(lowT, highT, KautzDegree, notDisplay); //將subscriptions 複製到Tree Node上 for (set<string>::iterator dcnp = DestCopyNode.begin(); dcnp != DestCopyNode.end(); dcnp++) { //先取得欲設置subscription的vs的key double dstVsKey = getKautzResponsibleKey(thisSubsComponent ,*dcnp); (vServers[dstVsKey]->KautzSubs)[thisSubsComponent].insert(*subp); } } thisSp->subs.clear(); } 先取得上下限值

  40. string getKautzString(set<string> subsComponent, map<string, double> componentValue, int length , bool display) { string T = ""; VirtualServer *componentVs = vServers[SPnodes[subsComponent]]; //取得組合的root for (int i = 0; i < length; i++) { map<int, double> thisBranch = (componentVs->KautzBranch)[subsComponent]; int thisBranchSize = thisBranch.size(); int countOfBranch = 1; for (map<int, double>::iterator tbp = thisBranch.begin(); tbp != thisBranch.end(); tbp++,countOfBranch++) { VirtualServer *thisBranchVs = vServers[tbp->second]; map<string, Predicate*> thisBranchPred = (thisBranchVs->KautzPred)[subsComponent]; bool isSatisified = true; for (map<string, double>::iterator cvp = componentValue.begin(); cvp != componentValue.end(); cvp++) { Predicate *thispred = thisBranchPred[cvp->first]; if (!(thispred->getmin() <= cvp->second && cvp->second <= thispred->getmax())) { isSatisified = false; break; } } if (countOfBranch == thisBranchSize) isSatisified = true; if (isSatisified) { T += int2str(tbp->first); componentVs = thisBranchVs; break; } } } ASSERT(!T.empty() && T.length() == (unsigned)length); return T; } P(2,3) root [0~33],[0~49] (33~66],[0~49] (66~99],[0~49] retraction 1 0 2 (66~99], (24.5~49] (66~99], [0~24.5] (33~66], (24.5~49] (33~66], [0~24.5] [0~33], (24.5~49] [0~33], [0~24.5] 10 12 01 02 20 21 Tomography (33~49.5], [0~24.5] [0~16.5], [0~24.5] [16.5~33], [0~24.5] (49.5~66], [0~24.5] 101 102 120 121 010 012 020 021 201 202 210 212 retraction lowValue highValue 在這邊我們取得的是012與102

  41. //push Subscription to Kautz node for (map<set<string> , double>::iterator cspp = chooseSP.begin(); cspp != chooseSP.end(); cspp++) { …. for(set<double>::iterator subp = thisSubs.begin();subp != thisSubs.end();subp++){ …...(接續上一頁) //取得下限值 string lowT = getKautzString(thisSubsComponent, lowValue, KautzLength, notDisplay); //取得上限值 string highT = getKautzString(thisSubsComponent, highValue, KautzLength, notDisplay); //包含下限值到上限值中間的所有Tree Node set<string> DestCopyNode = getAllKautzString(lowT, highT, KautzDegree, notDisplay); //將subscriptions 複製到Tree Node上 for (set<string>::iterator dcnp = DestCopyNode.begin(); dcnp != DestCopyNode.end(); dcnp++) { //先取得欲設置subscription的vs的key double dstVsKey = getKautzResponsibleKey(thisSubsComponent ,*dcnp); (vServers[dstVsKey]->KautzSubs)[thisSubsComponent].insert(*subp); } } thisSp->subs.clear(); } 接著是把介於012與102之間的Tree Node找出來

  42. set<string> getAllKautzString(string LowT, string HighT, int degree, bool display) { set<string> tempComponentString; tempComponentString.clear(); if (!LowT.empty()) tempComponentString.insert(LowT); if (!HighT.empty()) tempComponentString.insert(HighT); int *LOW = newint[LowT.length()]; for (int i = 0; (unsigned) i < LowT.length(); i++) LOW[i] = LowT[i] - 48; int *HIGH = newint[HighT.length()]; for (int i = 0; (unsigned) i < HighT.length(); i++) HIGH[i] = HighT[i] - 48; string thisGenT = ""; int bit = LowT.length() - 1; if (LowT.compare(HighT) != 0) { do { thisGenT.clear(); LOW[bit]++; for (int i = bit; i > 0; i--) { if (LOW[i] <= degree) break; elseif (LOW[i] > degree) { LOW[i] = LOW[i] % (degree + 1); LOW[i - 1]++; } } bool legalstring = true; for (int n = 1; (unsigned)n < LowT.length(); n++) if (LOW[n] == LOW[n - 1]) { legalstring = false; break; } for (int k = 0; (unsigned)k < LowT.length(); k++) thisGenT += int2str(LOW[k]); ASSERT(!thisGenT.empty()); if (legalstring && tempComponentString.find(thisGenT) == tempComponentString.end()) tempComponentString.insert(thisGenT); } while (thisGenT.compare(HighT) != 0); } return tempComponentString; } 先把012到102用三進位的方式列出所有的數字 去掉數字中有任兩相鄰的位數數字一樣者

  43. 由getAllKautzString()所運算出來的節點剛好就是底下括弧裡的節點由getAllKautzString()所運算出來的節點剛好就是底下括弧裡的節點 212 101 120 021 102 25<=retraction<50 2.5<=Tomography<10 Hash 202 retraction 010 Subscriptions 020 P(2,3) 210 201 root 012 [0~33],[0~49] (33~66],[0~49] (66~99],[0~49] 121 retraction 1 0 2 (66~99], (24.5~49] (66~99], [0~24.5] (33~66], (24.5~49] (33~66], [0~24.5] [0~33], (24.5~49] [0~33], [0~24.5] 10 12 01 02 20 21 Tomography (33~49.5], [0~24.5] [0~16.5], [0~24.5] [16.5~33], [0~24.5] (49.5~66], [0~24.5] 101 102 120 121 010 012 020 021 201 202 210 212 retraction Put this subscription to each of these nodes

  44. //push Subscription to Kautz node for (map<set<string> , double>::iterator cspp = chooseSP.begin(); cspp != chooseSP.end(); cspp++) { …. for(set<double>::iterator subp = thisSubs.begin();subp != thisSubs.end();subp++){ …...(接續上一頁) //取得下限值 string lowT = getKautzString(thisSubsComponent, lowValue, KautzLength, notDisplay); //取得上限值 string highT = getKautzString(thisSubsComponent, highValue, KautzLength, notDisplay); //包含下限值到上限值中間的所有Tree Node set<string> DestCopyNode = getAllKautzString(lowT, highT, KautzDegree, notDisplay); //將subscriptions 複製到Tree Node上 for (set<string>::iterator dcnp = DestCopyNode.begin(); dcnp != DestCopyNode.end(); dcnp++) { //先取得欲設置subscription的vs的key double dstVsKey = getKautzResponsibleKey(thisSubsComponent ,*dcnp); (vServers[dstVsKey]->KautzSubs)[thisSubsComponent].insert(*subp); } } thisSp->subs.clear(); } 利用剛才所找到節點的id來取得vs的key放置subscriptions

  45. doublegetKautzResponsibleKey(set<string> subsComponent ,string T) { double returnKey = -1; VirtualServer *componentVs = vServers[SPnodes[subsComponent]]; for (int i = 0; (unsigned) i < T.length(); i++) { double nextVsKey = (componentVs->KautzBranch)[subsComponent][T[i] - 48]; componentVs = vServers[nextVsKey]; } returnKey = componentVs->getKey(); ASSERT(returnKey >= 0); return returnKey; } 212 101 120 021 102 202 retraction 010 25<=retraction<50 2.5<=Tomography<10 020 210 每找到此id對應的vs就複製此subscriptions到這些點上 201 Subscriptions 012 121

  46. subscriptions publish & install Indulge< 26 Welch > 24 if(useFleetmethod2){ double subKey = s->first;//目前發布的subscription Subscription *thisSub = s->second; string thissubsAttr; //分析是否有equality-type的 attribute set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) {//此subscription至少有一個equal type …// equality-type subscription :使用attribute name + value 為key 值 hash( name, value) continue; }else{//處理range-query-type subscription subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); //分析是否存在非熱門的attribute set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); //分析是否存在熱門的attribute if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ …//所有attribute皆為熱門attribute 使用Kautz Graph continue; }else{ //挑選出非熱門attribute set中 其value 範圍值最小之attribute Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … // range-query-type subscription:分割value值成value1,value2,…,valuen , //用attribute name + valuei為key值 hash(name, valuei) 然後複製N份subscriptions存在系統 } } grist < 8 Tomography > 21.75 Welch < 73 Indulge > 26 Tomography > 39.25 retractions < 53.99 針對subscription Case 3的subscription 處裡

  47. AnalysisSubsComponentwitheMinRange 找出範圍最小的attribute string VirtualServer::AnalysisSubsComponentwitheMinRange(Subscription *s){///[catkill] … Predicate *minPred;//MinRange attribute for (set<Predicate*>::iterator thisPdp = thisPd.begin(); thisPdp != thisPd.end(); thisPdp++) { Predicate *thisPred = *thisPdp; string name=thisPred->attr; … if(((thisPred->getmax()-thisPred->getmin()) <(minPred->getmax()-minPred->getmin()))){ minPred=*thisPdp; } } string theMinRangeName=(*minPred).attr; ASSERT(theMinRangeName.compare("NULL")!=0); return (*minPred).attr; }

  48. subscriptions publish & install if(useFleetmethod2){ double subKey = s->first;//目前發布的subscription Subscription *thisSub = s->second; string thissubsAttr; //分析是否有equality-type的 attribute set<string> subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentExceptBoolofEqual(thisSub); if (!subsComponent.empty()) {//此subscription至少有一個equal type …// equality-type subscription:使用attribute name + value 為key 值 hash( name, value) continue; }else{//處理range-query-type subscription subsComponent = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentNotHot(thisSub); //分析是否存在非熱門的attribute set<string> subsComponent2 = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponent(thisSub); //分析是否存在熱門的attribute if(useKautzPartitionTree && subsComponent.empty() && !subsComponent2.empty()){ …//所有attribute皆為熱門attribute使用Kautz Graph continue; }else{ //挑選出非熱門attribute set中 其value 範圍值最小之attribute Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); } … //range-query-type subscription:分割value值成value1,value2,…,valuen , //用attribute name + valuei為key值 hash(name, valuei) 然後複製N份subscriptions存在系統 } } Case 3:找出範圍最小的attribute之後 然後開始分割將subscription存入

  49. 8 0 10 20 30 100 Case 3: Any attribute combination is cold grist < 8 Tomography < 21.75 Welch < 73 subscription 0.93 grist<8 0.18 0.82 0.38 install 0.39 0.71 0.44 0.64 0.46 0.63 0.51 0.59

  50. //取得value的範圍 以方便分割 0<Indulge< 26 24<Welch <84 選出value範圍值最小者 設定不同的起始點 0<Indulge< 26 Component = vServers[thisSub->getSubscriberID()]->AnalysisSubsComponentwitheMinRange(thisSub); //找出其value range為最小的attribute,以得最少複製 … double thisAttMax=Scheme.find(thisPred->attr)->second->getmax(); double thisAttmin=Scheme.find(thisPred->attr)->second->getmin(); int IIMstartValue = BKDRHash(thisPred->attr) % 10 + 1; //假設value 的範圍為0~100,未避免key值為0的subscription過多 //依據attribute name設定分割起始點,將同一類的subscription更分散地儲存 double interval=(thisAttMax-thisAttmin)/IIMinterval; if(IIMstartValue>=thisPred->getmin() && 0<= string hashstring=(*thisPditthisPred->getmax()){ … string hashstring=(*thisPdit)->attr+s; pickKEYofSubscription=returnHashStringToNode(hashstring); bool routeSuccess = vServers[thisSub->getSubscriberID()]->customer_route(pickKEYofSubscription,notDisplay); if(routeSuccess) { vServers[pickKEYofSubscription]->fleetaddSubs(subKey,thissubsAttr,thisSubsValue); } } for(double i=IIMstartValue;i<thisAttMax;i+=interval){// if((i+interval)>=thisPred->getmin() && i<=thisPred->getmax()){ … string hashstring=(*thisPdit)->attr+s; pickKEYofSubscription=returnHashStringToNode(hashstring); bool routeSuccess = vServers[thisSub->getSubscriberID()]->customer_route(pickKEYofSubscription,notDisplay); if(routeSuccess) { vServers[pickKEYofSubscription]->fleetaddSubs(subKey,thissubsAttr,thisSubsValue); } } } } //針對起始點為0的複製 每個attr的起始點不同 IIMstartValue=hash(Indulge) 0 10 20 30 40 50 60 …….. interval Key=hash(Indulge,IIMstartValue) Key=hash(Indulge,IIMstartValue+interval) … 針對每個區間的複製 26<IIMstartValue+interval

More Related