Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

GOSSIP-75 Voting interface #62

Merged
merged 1 commit into from Sep 3, 2017
Merged

GOSSIP-75 Voting interface #62

merged 1 commit into from Sep 3, 2017

Conversation

Mirage20
Copy link
Contributor

No description provided.

if(newValue != null && newValue instanceof VoteContext){
VoteContext voteContext = (VoteContext) newValue;
voteContextMap.put(voteContext.getVoteId(),voteContext);
if(gossipManager.getMyself().getId().equals("4")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcode here

VoteContext voteContext = (VoteContext) newValue;
voteContextMap.put(voteContext.getVoteId(),voteContext);
if(gossipManager.getMyself().getId().equals("4")) {
System.out.println(voteContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use loggers not println

}
}
}
System.out.println("lock aquired");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove println

d.setTimestamp(System.currentTimeMillis());
gossipManager.gossipSharedData(d);

while (true){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add counters here so we see how much loop contention we have

@@ -0,0 +1,65 @@
package org.apache.gossip.lock.vote;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need apache licence headers

import java.util.List;

/**
* Created by miraj on 7/13/17.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No @author commetns

clients.get(5).gossipSharedData(sharedNodeData("category", "distributed"));

clients.get(5).acquireSharedDataLock("category");
Thread.sleep(20000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Tunit to avoid Thread.sleep

*/
package org.apache.gossip.lock;

import com.sun.org.apache.xpath.internal.SourceTree;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in use?

long passedCandidates = voteResultMap.values().stream().filter(aBoolean -> aBoolean).count();

String myNodeId = gossipManager.getMyself().getId();
System.out.println("Node " + myNodeId + " vote map " + voteResultMap + " pass " + passedCandidates);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove println use log.debug or add counters

majorityVoteCache.put(generateLockKey(key), majorityVoteResult);
}
}
}else if(passedCandidates == 1 && voteResultMap.containsKey(myNodeId)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

voteCount++;
}
}
// System.out.println("Node " + nodeId + ", VoteCount " + voteCount + ", Participants " + voteContextSet.size() + " " + voteContextSet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dead code

}

// System.out.println(myNodeId +"=====>>"+ mySuccessVotes);
System.out.println(myNodeId +"==================================================================>>");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove println

return false;
}
// Set of nodes that receive this node is going to donate
List<String> donateCandidateIds= voteCandidates.keySet().stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

@Test
public void differentCandidateMergeTest(){
Map<String, VoteCandidate> voteCandidateMap1 = new HashMap<>();
VoteCandidate candidateA = new VoteCandidate("1","key1",generateVotes(1,2,true,true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

import java.util.stream.Collector;
import java.util.stream.Collectors;

public class StandAloneVoteBasedLock {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not match the other stand-alone examples. It should only be launching one instance of gossiper

// Adding new data to Node 1
clients.get(0).gossipSharedData(sharedNodeData("category", "distributed"));

// Thread voters = new Thread(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up the comments

GossipManager gossipService = GossipManagerBuilder.newBuilder().cluster(cluster).uri(uri)
.id(i + "").gossipMembers(startupMembers).gossipSettings(settings).build();
final int nodeId = i;
gossipService.registerSharedDataSubscriber((key, oldValue, newValue) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look like it is needed

// TODO: 7/16/17 check for possibility and handle multiple passed candidates
}

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value needs to be at least defined as a constant.

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont print here

* limitations under the License.
*/
package org.apache.gossip.lock.exceptions;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHen is this thrown and why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception is thrown when the locking is failed. Otherwise acquire lock will continue even when voting is failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with JavaDoc

return mergeResult;
}

private Vote mergeVote(Vote firstVote,Vote secondVote){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

public class Vote {
private final String votingNode;
private final Boolean voteValue; // TODO: 7/16/17 weight?
private Boolean voteExchange;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather using true false to vote, I thought about adding some weight to each nodes vote as an improvement (Need to discuss whether this is required).
For example a leader node can have higher weight (say 10) than normal node (say 2). If the leader votes for node A and 3 normal node votes for node B, Node A is the winner.


import java.util.Set;

public interface VoteSelector {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are users of this interface supposed to implement javadoc

MajorityVote second = new MajorityVote(voteCandidateMap2);

MajorityVote result = first.merge(second);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear up these extra spaces

@Mirage20 Mirage20 changed the title [WIP] GOSSIP-75 Voting interface GOSSIP-75 Voting interface Aug 16, 2017
@asfgit asfgit merged commit 5ed3ed8 into apache:master Sep 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants