/** * FUNCTION NAME: updateRing * * DESCRIPTION: This function does the following: * 1) Gets the current membership list from the Membership Protocol (MP1Node) * The membership list is returned as a vector of Nodes. See Node class in Nodne.h * 2) Constructs the ring based on the membership list * 3) Calls the Stabilization Protocol */ void MP2Node::updateRing() { /* * Implement this. Parts of it are already implemented */ vector<Node> curMemList; bool change = false; /* * Step 1. Get the current membership list from Membership Protocol / MP1 */ curMemList = getMembershipList(); /* * Step 2: Construct the ring */ // Sort the list based on the hashCode sort(curMemList.begin(), curMemList.end()); //else ring remians the same if (!equalRing(curMemList, ring)) { change = true; ring = curMemList; //hasMyReplicas = findNodes(); } /* * Step 3: Run the stabilization protocol IF REQUIRED */ // Run stabilization protocol if the hash table size is greater than zero and if there has been a changed in the ring if ((!ht->isEmpty()) && change) stabilizationProtocol(); }
/** * FUNCTION NAME: updateRing * * DESCRIPTION: This function does the following: * 1) Gets the current membership list from the Membership Protocol (MP1Node) * The membership list is returned as a vector of Nodes. See Node class in Node.h * 2) Constructs the ring based on the membership list * 3) Calls the Stabilization Protocol */ void MP2Node::updateRing() { /* * Implement this. Parts of it are already implemented */ vector<Node> curMemList; bool change = false; /* * Step 1. Get the current membership list from Membership Protocol / MP1 */ curMemList = getMembershipList(); /* * Step 2: Construct the ring */ // Sort the list based on the hashCode sort(curMemList.begin(), curMemList.end()); //check if stablization required or not by checking the change in ring change = isRingSame(curMemList); //If the ring has changed or it was empty before assign ring the new Member List if (ring.empty() || change) ring = curMemList; //Initially when hasMyReplicas and haveReplicasOf is empty initialize those variables for this node if (hasMyReplicas.empty() || haveReplicasOf.empty()) assignReplicationNodes(); /* * Step 3: Run the stabilization protocol IF REQUIRED */ //Run stabilization protocol if the hash table size is greater than zero and if there has been a changed in the ring cout << "Stablization required = " << change << endl; // If stablization is required run stablization protocol. if (change && !ht->isEmpty()) stabilizationProtocol(); }