Conversation
if(newValue != null && newValue instanceof VoteContext){ | ||
VoteContext voteContext = (VoteContext) newValue; | ||
voteContextMap.put(voteContext.getVoteId(),voteContext); | ||
if(gossipManager.getMyself().getId().equals("4")) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)){ |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 +"==================================================================>>"); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(() -> { |
There was a problem hiding this comment.
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) -> { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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
No description provided.