private Set<KeyValue> keyValueUpdateSet;
private Guard guard;
+ private long arbitrator = -1;
public PendingTransaction() {
keyValueUpdateSet = new HashSet<KeyValue>();
*/
public void addKV(KeyValue newKV) {
+ KeyValue rmKV = null;
+
// Make sure there are no duplicates
for (KeyValue kv : keyValueUpdateSet) {
if (kv.getKey().equals(newKV.getKey())) {
// Remove key if we are adding a newer version of the same key
- keyValueUpdateSet.remove(kv);
+ rmKV = kv;
break;
}
}
+ // Remove key if we are adding a newer version of the same key
+ if (rmKV != null) {
+ keyValueUpdateSet.remove(rmKV);
+ }
+
// Add the key to the hash set
keyValueUpdateSet.add(newKV);
}
+ public boolean checkArbitrator(long arb) {
+ if (arbitrator == -1) {
+ arbitrator = arb;
+ return true;
+ }
+
+ return arb == arbitrator;
+ }
+
+
+
/**
* Get the key value update set
*