1 / 77

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. aaa.scheme.

freira
Télécharger la présentation

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. aaa.scheme Name type min max end Barhop float 1.000000 5000.000000 0 Budapest integer 1 5000 0 Buxton integer 1 5000 0 Chang integer 1 5000 0 Colombians integer 1 5000 0 Erie float 1.000000 5000.000000 0 Finnegan float 1.000000 5000.000000 0 Flemish float 1.000000 5000.000000 0 Gambia integer 1 5000 0 Laotian integer 1 5000 0

  5. aaa.subscription astride 3842 5000 monolithic 2387.500000 5000.000000 radiations 1 2568 retractions 3179.0 3179.0 Laotian 1 687 retractions 1.000000 784.000000 bureaucracy 565 565 retractions 1.000000 3063.500000 aback 1.000000 1417.000000 graces 1.000000 4595.500000 pretends 1.000000 2630.500000 Colombians 1 4660 Erie 1422.000000 5000.000000 alternates 1771.000000 5000.000000 baptizing 1 4752 miners 1 4406 radiations 1 2160 victimized 1 1406 league 2783 5000 retractions 848.500000 5000.000000 tomography 516 5000 retractions 1.000000 3749.000000 abjections 1 675 astride 392 5000 centralize 1024 5000 cottonwood 2867.000000 5000.000000 Colombians 2898 5000 aback 1.000000 3437.500000 alternates 2654.500000 5000.000000 Name min max

  6. aaa.event aback 3169.000000 astronautics 366 mergers 2393 retractions 4782.500000 Laotian 1744 centralize 4798 league 2999 mergers 2132 moron 2994 retractions 2434.000000 Chang 4078 Colombians 2573 Laotian 3541 Mesopotamia 534 Riverview 4464 aback 1108.500000 alternates 2539.000000 astronautics 2247 cottonwood 1605.500000 exiled 4115.000000 graces 2042.000000 rectangles 2983.000000 refuses 3860.500000 retractions 2203.000000 snail 1753 solidifying 3388 tomography 3922 unintentionally 2759 regrouping 4204.500000 Colombians 3778 Mundt 4966 alternates 3389.500000 appliance 3828.000000 monolithic 2504.500000 retractions 636.000000 steeling 433.000000 to mography 1620 aback 4117.000000 baptizing 908 cargo 800.500000 maximizes 3637.500000 mergers 2256 retractions 1266.500000 squeaked 3991.500000 retractions 3609.500000 truncated 445 victimized 3424 Colombians 896 aback 353.500000 mergers 1062 monolithic 4996.500000 moron 4470 pilers 1970 result 797.000000 retractions 3106.500000 squeaked 4225.000000 victimized 2063 concrete 2087 forwarder 924 graces 308.000000 league 1202 rectangles 1929.500000 retractions 2166.000000 tomography 4117 victimized 861 Finnegan 4092.500000 Laotian 3574 Rawlings 2611.000000 aback 1754.500000 baptizing 3377 campus 462.000000 forwarder 1840 monolithic 693.500000 moron 2549 retractions 2763.000000 tomography 1001 truncated 3750 Indulge 26 grist 39 Tomography 30 Name value

  7. 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; } aaa.scheme:Barhop float 1.000000 5000.000000 0 Attribute1 { name:Barhop Min= 1.000000 max= 5000.000000 Type= float } map<string, Attribute*> Scheme={<Barhop, >,…}

  8. Data Structure of Subscription class Subscription { double SubscriberID; set<Predicates*> pds; } 一個subscription儲存的例子 aaa.subscription: Laotian 1 687 retractions 1.000000 784.000000 SubscriberID=0.5842 (random選出) set<Predicates*> ={(Laotian , retractions) } set<Predicate*>={Laotian , retractions} class Predicate { string Smin; string Smax; double min; double max; bool value; string attr; } attr=“Laotian ” min=1 max=687 attr=“retractions” min=1.000000 max=784.000000 class Predicates { char op; set<Predicate*> p; }

  9. Main program • 先選出RP node • 根據RP node個數,將整個網路切成等分,得到每個區間的大小(separate_range) • 由sourceKey開始,將之作為第一個RP node,然後sourceKey+ separate_range得到第二個RP node,依此類推 • 讀取subscription file,然後隨機選node發佈,存到網路上 • 開始讀取event file,然後隨機挑一node發佈event開始matching&deliver

  10. Main program int main (int argc, char **argv) { while (!finished) { 1.choose RP Node 2.subscriptions publish & install 3.event match & publish } }

  11. 1.挑選RP node 參數 NumOfSubStation:RP node個數 • 1.1 根據RP node個數,將整個網路切成等分,得到每個區間的大小(separate_range) • 1.2 由sourceKey開始,將之作為第一個RP node,然後sourceKey+ separate_range得到第二個RP node,依此類推 sourceKey:挑選RP node的起始點,隨機決定

  12. 1.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; } 1.1 1.2 7 個 RP node sourceKey //每個等距選出一個Node 為 RP node separate_range

  13. Main program int main (int argc, char **argv) { while (!finished) { 1.choose RP Node 2.subscriptions publish & install 3.event match & publish } }

  14. 2. subscriptions publish & install • 2.1 分析subscription 是不是case1 • 2.2 確定subscription 是case1 開始儲存 • 2.3 分析subscription 是不是case2 • 2.4 確定subscription 是case2 開始儲存 • 2.5 其他case3 開始儲存

  15. 2.subscriptions publish & install 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); } … } } //分析是否有equality-type的 attribute 2.1 2.2 2.3 2.4 2.5

  16. 2.1AnalysisSubsComponentExceptBoolofEqual 分析是否有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

  17. 2.2 subscriptions publish & install aaa.subscription: bureaucracy 565 565 retractions 1.000000 3063.500000 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); } … } } 2.1 Hash(brueaucracy,565) 2.2 2.3 2.4 2.5 //case 1:此subscription至少有一個equal type 針對equality type處裡 // equality-type subscription :使用attribute name + value 為key 值 hash( name, value)

  18. Case 1: Any one operator is an equality operator 1<retractions <3063.5 bureaucracy= 565 subscription 0.93 0.18 bureaucracy= 565 0.82 0.38 0.39 0.71 install 0.44 0.64 0.46 0.63 0.51 0.59

  19. 2.2 subscription至少有一個equal type 針對equality type處裡 • 2.2.1 hash(name,value) 找出subscription要存在哪個SSM node • 2.2.2 routing到SSM node 然後將subscription存入

  20. 2.2equality-type subscription :使用name + value 為key 值 hash( name, value) aaa.subscription: bureaucracy 565 565 retractions 1.000000 3063.500000 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(brueaucracy,565) 2.2.1 pickKEYofSubscription Publish node 2.2.2 pickKEYofSubscription install 找到node後 將subscription存入 Hash(name+value)找出要存放subscription的node

  21. 2.3.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 2.1 2.2 2.3 2.4 2.5 //處理range-query-type subscription

  22. 2.3AnalysisSubsComponentNotHotAnalysisSubsComponent aaa.subscription: astride 3842 5000 monolithic 2387.500000 5000.000000 radiations 1 2568 retractions 3179.000000 3179.000000 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; } 2.3.1 subsComponents: astride 3842 5000 monolithic 2387.500000 5000.000000 radiations 1 2568 //挑出非熱門的attribute 2.3.2 subsComponents: retractions 3179.000000 3179.000000 //挑出熱門的attribute AttributeToIndex(name) >= 0  popular AttributeToIndex(name) < 0  not popular //挑出非熱門的attribute 2.3.1 2.3.2 //挑出熱門的attribute

  23. 2.4subscriptions publish & install aaa.subscription: retractions 1.000000 3749.000000 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存在系統 } } 2.1 2.2 2.3 2.4 2.5 Case 2:所有attribute皆為熱門attribute使用Kautz Graph

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

  25. 2.4 使用kautz tree之前 先把subscription集中存入在tree root • 2.4.1 分析subscription 是屬於哪個kautz tree • 2.4.2 若找不到負責的kautz tree,則新增此kautz tree • 2.4.3 找到負責的kautz tree • 2.4.4 將subscription存入負責的kautz tree

  26. 2.4使用kautz tree之前 先把subscription集中存入在tree root 2.4.1 2.4.2 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 2.4.3 Publish node 2.4.4 1<retractions < 3749 Set(retraction) Sp node for (retraction) install

  27. Subscriptions installation using Kautz Partition Tree • 建立kautz tree

  28. 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)

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

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

  31. //記錄前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; //記錄被劃分的範圍 ….續下頁

  32. 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); • } • } 到這行為止的進度如下頁的圖

  33. 執行完到上一頁指定的進度時,已經建立好一棵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

  34. //每個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); }

  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? Retraction? Tomography 決定好要以哪個Attribute來建分割範圍 以這邊為例,因為已經跑過retraction, 所以換成Tomography //建立分支 createSubKautzTree(2, 4, 1, [1,2], <reraction,Tomography>, “Tomography”, display) retraction Tomography

  36. //建立分支 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(); …..(接下頁)

  37. 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); }

  38. 執行完到上一頁指定的進度 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

  39. 執行完到上一頁指定的進度 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)

  40. 執行完到上一頁指定的進度 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)

  41. 執行完到上一頁指定的進度 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

  42. 執行完到上一頁指定的進度 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

  43. 執行完到上一頁指定的進度 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

  44. 執行完到上一頁指定的進度 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

  45. 執行完到上一頁指定的進度 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

  46. //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

  47. //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(); } 先取得上下限值

  48. 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

  49. //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找出來

  50. 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用三進位的方式列出所有的數字 去掉數字中有任兩相鄰的位數數字一樣者

More Related