edits
[iotcloud.git] / version2 / src / C / Table.cc
index f4280aa0de6cee2406638bff972f746268ce064d..7c3fde05215cfeb3b547f59d8064e38039b7ef51 100644 (file)
@@ -10,7 +10,7 @@
 #include "TransactionStatus.h"
 #include "Transaction.h"
 #include "LastMessage.h"
-#include "Random.h"
+#include "SecureRandom.h"
 #include "ByteBuffer.h"
 #include "Abort.h"
 #include "CommitPart.h"
@@ -21,9 +21,9 @@
 #include "SlotIndexer.h"
 #include <stdlib.h>
 
-int compareInt64(const void * a, const void *b) {
-       const int64_t * pa = (const int64_t *) a;
-       const int64_t * pb = (const int64_t *) b;
+int compareInt64(const void *a, const void *b) {
+       const int64_t *pa = (const int64_t *) a;
+       const int64_t *pb = (const int64_t *) b;
        if (*pa < *pb)
                return -1;
        else if (*pa > *pb)
@@ -46,6 +46,7 @@ Table::Table(IoTString *baseurl, IoTString *password, int64_t _localMachineId, i
        oldestLiveSlotSequenceNumver(1),
        localMachineId(_localMachineId),
        sequenceNumber(0),
+       localSequenceNumber(0),
        localTransactionSequenceNumber(0),
        lastTransactionSequenceNumberSpeculatedOn(0),
        oldestTransactionSequenceNumberSpeculatedOn(0),
@@ -108,6 +109,7 @@ Table::Table(CloudComm *_cloud, int64_t _localMachineId) :
        oldestLiveSlotSequenceNumver(1),
        localMachineId(_localMachineId),
        sequenceNumber(0),
+       localSequenceNumber(0),
        localTransactionSequenceNumber(0),
        lastTransactionSequenceNumberSpeculatedOn(0),
        oldestTransactionSequenceNumberSpeculatedOn(0),
@@ -156,22 +158,56 @@ Table::Table(CloudComm *_cloud, int64_t _localMachineId) :
        init();
 }
 
+Table::~Table() {
+       delete cloud;
+       delete random;
+       delete buffer;
+       // init data structs
+       delete committedKeyValueTable;
+       delete speculatedKeyValueTable;
+       delete pendingTransactionSpeculatedKeyValueTable;
+       delete liveNewKeyTable;
+       delete lastMessageTable;
+       delete rejectedMessageWatchVectorTable;
+       delete arbitratorTable;
+       delete liveAbortTable;
+       delete newTransactionParts;
+       delete newCommitParts;
+       delete lastArbitratedTransactionNumberByArbitratorTable;
+       delete liveTransactionBySequenceNumberTable;
+       delete liveTransactionByTransactionIdTable;
+       delete liveCommitsTable;
+       delete liveCommitsByKeyTable;
+       delete lastCommitSeenSequenceNumberByArbitratorTable;
+       delete rejectedSlotVector;
+       delete pendingTransactionQueue;
+       delete pendingSendArbitrationEntriesToDelete;
+       delete transactionPartsSent;
+       delete outstandingTransactionStatus;
+       delete liveAbortsGeneratedByLocal;
+       delete offlineTransactionsCommittedAndAtServer;
+       delete localCommunicationTable;
+       delete lastTransactionSeenFromMachineFromServer;
+       delete pendingSendArbitrationRounds;
+       delete lastArbitrationDataLocalSequenceNumberSeenFromArbitrator;
+}
+
 /**
  * Init all the stuff needed for for table usage
  */
 void Table::init() {
        // Init helper objects
-       random = new Random();
+       random = new SecureRandom();
        buffer = new SlotBuffer();
 
        // init data structs
-       committedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
-       speculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
-       pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
-       liveNewKeyTable = new Hashtable<IoTString *, NewKey *>();
+       committedKeyValueTable = new Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals>();
+       speculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals>();
+       pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals>();
+       liveNewKeyTable = new Hashtable<IoTString *, NewKey *, uintptr_t, 0, hashString, StringEquals >();
        lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> * >();
        rejectedMessageWatchVectorTable = new Hashtable<int64_t, Hashset<RejectedMessage *> * >();
-       arbitratorTable = new Hashtable<IoTString *, int64_t>();
+       arbitratorTable = new Hashtable<IoTString *, int64_t, uintptr_t, 0, hashString, StringEquals>();
        liveAbortTable = new Hashtable<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals>();
        newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
        newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
@@ -179,7 +215,7 @@ void Table::init() {
        liveTransactionBySequenceNumberTable = new Hashtable<int64_t, Transaction *>();
        liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t> *, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals>();
        liveCommitsTable = new Hashtable<int64_t, Hashtable<int64_t, Commit *> * >();
-       liveCommitsByKeyTable = new Hashtable<IoTString *, Commit *>();
+       liveCommitsByKeyTable = new Hashtable<IoTString *, Commit *, uintptr_t, 0, hashString, StringEquals>();
        lastCommitSeenSequenceNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
        rejectedSlotVector = new Vector<int64_t>();
        pendingTransactionQueue = new Vector<Transaction *>();
@@ -246,7 +282,7 @@ int64_t Table::getArbitrator(IoTString *key) {
 }
 
 void Table::close() {
-       cloud->close();
+       cloud->closeCloud();
 }
 
 IoTString *Table::getCommitted(IoTString *key)  {
@@ -350,7 +386,7 @@ bool Table::update()  {
 
 bool Table::createNewKey(IoTString *keyName, int64_t machineId) {
        while (true) {
-               if (!arbitratorTable->contains(keyName)) {
+               if (arbitratorTable->contains(keyName)) {
                        // There is already an arbitrator
                        return false;
                }
@@ -420,7 +456,7 @@ TransactionStatus *Table::commitTransaction() {
                Hashset<int64_t> *arbitratorTriedAndFailed = new Hashset<int64_t>();
                uint size = pendingTransactionQueue->size();
                uint oldindex = 0;
-               for (int iter = 0; iter < size; iter++) {
+               for (uint iter = 0; iter < size; iter++) {
                        Transaction *transaction = pendingTransactionQueue->get(iter);
                        pendingTransactionQueue->set(oldindex++, pendingTransactionQueue->get(iter));
 
@@ -464,228 +500,224 @@ int64_t Table::getLocalSequenceNumber() {
        return localSequenceNumber;
 }
 
-bool Table::sendToServer(NewKey *newKey) {
-       bool fromRetry = false;
-       try {
-               if (hadPartialSendToServer) {
-                       Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
-                       if (newSlots->length() == 0) {
-                               fromRetry = true;
-                               ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey);
-
-                               if (sendSlotsReturn.getFirst()) {
-                                       if (newKey != NULL) {
-                                               if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
-                                                       newKey = NULL;
-                                               }
-                                       }
-
-                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
-                                       while (trit->hasNext()) {
-                                               Transaction *transaction = trit->next();
-                                               transaction->resetServerFailure();
-                                               // Update which transactions parts still need to be sent
-                                               transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
-                                               // Add the transaction status to the outstanding list
-                                               outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
-
-                                               // Update the transaction status
-                                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
-
-                                               // Check if all the transaction parts were successfully
-                                               // sent and if so then remove it from pending
-                                               if (transaction->didSendAllParts()) {
-                                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
-                                                       pendingTransactionQueue->remove(transaction);
-                                               }
-                                       }
-                                       delete trit;
-                               } else {
-                                       newSlots = sendSlotsReturn.getThird();
-                                       bool isInserted = false;
-                                       for (uint si = 0; si < newSlots->length(); si++) {
-                                               Slot *s = newSlots->get(si);
-                                               if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+NewKey * Table::handlePartialSend(NewKey * newKey) {
+       //Didn't receive acknowledgement for last send
+       //See if the server has received a newer slot
+       
+       Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
+       if (newSlots->length() == 0) {
+               //Retry sending old slot
+               bool wasInserted = false;
+               bool sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey, &wasInserted, &newSlots);
+               
+               if (sendSlotsReturn) {
+                       if (newKey != NULL) {
+                               if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
+                                       newKey = NULL;
+                               }
+                       }
+                       
+                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
+                       while (trit->hasNext()) {
+                               Transaction *transaction = trit->next();
+                               transaction->resetServerFailure();
+                               // Update which transactions parts still need to be sent
+                               transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
+                               // Add the transaction status to the outstanding list
+                               outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
+                               
+                               // Update the transaction status
+                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
+                               
+                               // Check if all the transaction parts were successfully
+                               // sent and if so then remove it from pending
+                               if (transaction->didSendAllParts()) {
+                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
+                                       pendingTransactionQueue->remove(transaction);
+                               }
+                       }
+                       delete trit;
+               } else {
+                       bool isInserted = false;
+                       for (uint si = 0; si < newSlots->length(); si++) {
+                               Slot *s = newSlots->get(si);
+                               if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+                                       isInserted = true;
+                                       break;
+                               }
+                       }
+                       
+                       for (uint si = 0; si < newSlots->length(); si++) {
+                               Slot *s = newSlots->get(si);
+                               if (isInserted) {
+                                       break;
+                               }
+                               
+                               // Process each entry in the slot
+                               Vector<Entry *> *ventries = s->getEntries();
+                               uint vesize = ventries->size();
+                               for (uint vei = 0; vei < vesize; vei++) {
+                                       Entry *entry = ventries->get(vei);
+                                       if (entry->getType() == TypeLastMessage) {
+                                               LastMessage *lastMessage = (LastMessage *)entry;
+                                               if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
                                                        isInserted = true;
                                                        break;
                                                }
                                        }
-
-                                       for (uint si = 0; si < newSlots->length(); si++) {
-                                               Slot *s = newSlots->get(si);
-                                               if (isInserted) {
-                                                       break;
-                                               }
-
-                                               // Process each entry in the slot
-                                               Vector<Entry *> *ventries = s->getEntries();
-                                               uint vesize = ventries->size();
-                                               for (uint vei = 0; vei < vesize; vei++) {
-                                                       Entry *entry = ventries->get(vei);
-                                                       if (entry->getType() == TypeLastMessage) {
-                                                               LastMessage *lastMessage = (LastMessage *)entry;
-                                                               if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
-                                                                       isInserted = true;
-                                                                       break;
-                                                               }
-                                                       }
-                                               }
-                                       }
-
-                                       if (isInserted) {
-                                               if (newKey != NULL) {
-                                                       if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
-                                                               newKey = NULL;
-                                                       }
-                                               }
-
-                                               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
-                                               while (trit->hasNext()) {
-                                                       Transaction *transaction = trit->next();
-                                                       transaction->resetServerFailure();
-
-                                                       // Update which transactions parts still need to be sent
-                                                       transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
-
-                                                       // Add the transaction status to the outstanding list
-                                                       outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
-
-                                                       // Update the transaction status
-                                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
-
-                                                       // Check if all the transaction parts were successfully sent and if so then remove it from pending
-                                                       if (transaction->didSendAllParts()) {
-                                                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
-                                                               pendingTransactionQueue->remove(transaction);
-                                                       } else {
-                                                               transaction->resetServerFailure();
-                                                               // Set the transaction sequence number back to nothing
-                                                               if (!transaction->didSendAPartToServer()) {
-                                                                       transaction->setSequenceNumber(-1);
-                                                               }
-                                                       }
-                                               }
-                                               delete trit;
+                               }
+                       }
+                       
+                       if (isInserted) {
+                               if (newKey != NULL) {
+                                       if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
+                                               newKey = NULL;
                                        }
                                }
-
+                               
                                SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
                                while (trit->hasNext()) {
                                        Transaction *transaction = trit->next();
                                        transaction->resetServerFailure();
-                                       // Set the transaction sequence number back to nothing
-                                       if (!transaction->didSendAPartToServer()) {
-                                               transaction->setSequenceNumber(-1);
+                                       
+                                       // Update which transactions parts still need to be sent
+                                       transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
+                                       
+                                       // Add the transaction status to the outstanding list
+                                       outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
+                                       
+                                       // Update the transaction status
+                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
+                                       
+                                       // Check if all the transaction parts were successfully sent and if so then remove it from pending
+                                       if (transaction->didSendAllParts()) {
+                                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
+                                               pendingTransactionQueue->remove(transaction);
+                                       } else {
+                                               transaction->resetServerFailure();
+                                               // Set the transaction sequence number back to nothing
+                                               if (!transaction->didSendAPartToServer()) {
+                                                       transaction->setSequenceNumber(-1);
+                                               }
                                        }
                                }
                                delete trit;
-
-                               if (sendSlotsReturn.getThird()->length() != 0) {
-                                       // insert into the local block chain
-                                       validateAndUpdate(sendSlotsReturn.getThird(), true);
-                               }
-                               // continue;
-                       } else {
-                               bool isInserted = false;
-                               for (uint si = 0; si < newSlots->length(); si++) {
-                                       Slot *s = newSlots->get(si);
-                                       if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+                       }
+               }
+               
+               SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
+               while (trit->hasNext()) {
+                       Transaction *transaction = trit->next();
+                       transaction->resetServerFailure();
+                       // Set the transaction sequence number back to nothing
+                       if (!transaction->didSendAPartToServer()) {
+                               transaction->setSequenceNumber(-1);
+                       }
+               }
+               delete trit;
+               
+               if (newSlots->length() != 0) {
+                       // insert into the local block chain
+                       validateAndUpdate(newSlots, true);
+               }
+               // continue;
+       } else {
+               bool isInserted = false;
+               for (uint si = 0; si < newSlots->length(); si++) {
+                       Slot *s = newSlots->get(si);
+                       if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+                               isInserted = true;
+                               break;
+                       }
+               }
+               
+               for (uint si = 0; si < newSlots->length(); si++) {
+                       Slot *s = newSlots->get(si);
+                       if (isInserted) {
+                               break;
+                       }
+                       
+                       // Process each entry in the slot
+                       Vector<Entry *> *entries = s->getEntries();
+                       uint eSize = entries->size();
+                       for (uint ei = 0; ei < eSize; ei++) {
+                               Entry *entry = entries->get(ei);
+                               
+                               if (entry->getType() == TypeLastMessage) {
+                                       LastMessage *lastMessage = (LastMessage *)entry;
+                                       if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
                                                isInserted = true;
                                                break;
                                        }
                                }
-
-                               for (uint si = 0; si < newSlots->length(); si++) {
-                                       Slot *s = newSlots->get(si);
-                                       if (isInserted) {
-                                               break;
-                                       }
-
-                                       // Process each entry in the slot
-                                       Vector<Entry *> *entries = s->getEntries();
-                                       uint eSize = entries->size();
-                                       for(uint ei=0; ei < eSize; ei++) {
-                                               Entry * entry = entries->get(ei);
-                                               
-                                               if (entry->getType() == TypeLastMessage) {
-                                                       LastMessage *lastMessage = (LastMessage *)entry;
-                                                       if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
-                                                               isInserted = true;
-                                                               break;
-                                                       }
-                                               }
-                                       }
+                       }
+               }
+               
+               if (isInserted) {
+                       if (newKey != NULL) {
+                               if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
+                                       newKey = NULL;
                                }
-
-                               if (isInserted) {
-                                       if (newKey != NULL) {
-                                               if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
-                                                       newKey = NULL;
-                                               }
-                                       }
-
-                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
-                                       while (trit->hasNext()) {
-                                               Transaction *transaction = trit->next();
-                                               transaction->resetServerFailure();
-
-                                               // Update which transactions parts still need to be sent
-                                               transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
-
-                                               // Add the transaction status to the outstanding list
-                                               outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
-
-                                               // Update the transaction status
-                                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
-
-                                               // Check if all the transaction parts were successfully sent and if so then remove it from pending
-                                               if (transaction->didSendAllParts()) {
-                                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
-                                                       pendingTransactionQueue->remove(transaction);
-                                               } else {
-                                                       transaction->resetServerFailure();
-                                                       // Set the transaction sequence number back to nothing
-                                                       if (!transaction->didSendAPartToServer()) {
-                                                               transaction->setSequenceNumber(-1);
-                                                       }
-                                               }
-                                       }
-                                       delete trit;
+                       }
+                       
+                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
+                       while (trit->hasNext()) {
+                               Transaction *transaction = trit->next();
+                               transaction->resetServerFailure();
+                               
+                               // Update which transactions parts still need to be sent
+                               transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
+                               
+                               // Add the transaction status to the outstanding list
+                               outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
+                               
+                               // Update the transaction status
+                               transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
+                               
+                               // Check if all the transaction parts were successfully sent and if so then remove it from pending
+                               if (transaction->didSendAllParts()) {
+                                       transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
+                                       pendingTransactionQueue->remove(transaction);
                                } else {
-                                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
-                                       while (trit->hasNext()) {
-                                               Transaction *transaction = trit->next();
-                                               transaction->resetServerFailure();
-                                               // Set the transaction sequence number back to nothing
-                                               if (!transaction->didSendAPartToServer()) {
-                                                       transaction->setSequenceNumber(-1);
-                                               }
+                                       transaction->resetServerFailure();
+                                       // Set the transaction sequence number back to nothing
+                                       if (!transaction->didSendAPartToServer()) {
+                                               transaction->setSequenceNumber(-1);
                                        }
-                                       delete trit;
                                }
-
-                               // insert into the local block chain
-                               validateAndUpdate(newSlots, true);
                        }
+                       delete trit;
+               } else {
+                       SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
+                       while (trit->hasNext()) {
+                               Transaction *transaction = trit->next();
+                               transaction->resetServerFailure();
+                               // Set the transaction sequence number back to nothing
+                               if (!transaction->didSendAPartToServer()) {
+                                       transaction->setSequenceNumber(-1);
+                               }
+                       }
+                       delete trit;
                }
-       } catch (ServerException *e) {
-               throw e;
+               
+               // insert into the local block chain
+               validateAndUpdate(newSlots, true);
        }
+       return newKey;
+}
 
-
+bool Table::sendToServer(NewKey *newKey) {
+       if (hadPartialSendToServer) {
+               newKey = handlePartialSend(newKey);
+       }
 
        try {
                // While we have stuff that needs inserting into the block chain
                while ((pendingTransactionQueue->size() > 0) || (pendingSendArbitrationRounds->size() > 0) || (newKey != NULL)) {
-
-                       fromRetry = false;
-
                        if (hadPartialSendToServer) {
                                throw new Error("Should Be error free");
                        }
-
-
-
+                       
                        // If there is a new key with same name then end
                        if ((newKey != NULL) && arbitratorTable->contains(newKey->getKey())) {
                                return false;
@@ -731,10 +763,11 @@ bool Table::sendToServer(NewKey *newKey) {
                        lastTransactionPartsSent = transactionPartsSent->clone();
                        lastPendingSendArbitrationEntriesToDelete = new Vector<Entry *>(pendingSendArbitrationEntriesToDelete);
 
-                       ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(slot, newSize, newKey != NULL);
-
-                       if (sendSlotsReturn.getFirst()) {
+                       Array<Slot *> * newSlots = NULL;
+                       bool wasInserted = false;
+                       bool sendSlotsReturn = sendSlotsToServer(slot, newSize, newKey != NULL, &wasInserted, &newSlots);
 
+                       if (sendSlotsReturn) {
                                // Did insert into the block chain
 
                                if (insertedNewKey) {
@@ -799,9 +832,9 @@ bool Table::sendToServer(NewKey *newKey) {
                        pendingSendArbitrationEntriesToDelete->clear();
                        transactionPartsSent->clear();
 
-                       if (sendSlotsReturn.getThird()->length() != 0) {
+                       if (newSlots->length() != 0) {
                                // insert into the local block chain
-                               validateAndUpdate(sendSlotsReturn.getThird(), true);
+                               validateAndUpdate(newSlots, true);
                        }
                }
 
@@ -846,7 +879,7 @@ bool Table::updateFromLocal(int64_t machineId) {
        if (!localCommunicationTable->contains(machineId))
                return false;
 
-       Pair<IoTString *, int32_t> * localCommunicationInformation = localCommunicationTable->get(machineId);
+       Pair<IoTString *, int32_t> *localCommunicationInformation = localCommunicationTable->get(machineId);
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
@@ -897,16 +930,16 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        // Get the devices local communications
        if (!localCommunicationTable->contains(transaction->getArbitrator()))
                return Pair<bool, bool>(true, false);
-       
-       Pair<IoTString *, int32_t> * localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
+
+       Pair<IoTString *, int32_t> *localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
 
        // Get the size of the send data
        int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
        {
-               Vector<TransactionPart *> * tParts = transaction->getParts();
+               Vector<TransactionPart *> *tParts = transaction->getParts();
                uint tPartsSize = tParts->size();
                for (uint i = 0; i < tPartsSize; i++) {
-                       TransactionPart * part = tParts->get(i);
+                       TransactionPart *part = tParts->get(i);
                        sendDataSize += part->getSize();
                }
        }
@@ -924,10 +957,10 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        bbEncode->putLong(lastArbitrationDataLocalSequenceNumber);
        bbEncode->putInt(transaction->getParts()->size());
        {
-               Vector<TransactionPart *> * tParts = transaction->getParts();
+               Vector<TransactionPart *> *tParts = transaction->getParts();
                uint tPartsSize = tParts->size();
                for (uint i = 0; i < tPartsSize; i++) {
-                       TransactionPart * part = tParts->get(i);
+                       TransactionPart *part = tParts->get(i);
                        part->encode(bbEncode);
                }
        }
@@ -967,14 +1000,14 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
        updateLiveStateFromLocal();
 
        if (couldArbitrate) {
-               TransactionStatus * status =  transaction->getTransactionStatus();
+               TransactionStatus *status =  transaction->getTransactionStatus();
                if (didCommit) {
                        status->setStatus(TransactionStatus_StatusCommitted);
                } else {
                        status->setStatus(TransactionStatus_StatusAborted);
                }
        } else {
-               TransactionStatus * status =  transaction->getTransactionStatus();
+               TransactionStatus *status =  transaction->getTransactionStatus();
                if (foundAbort) {
                        status->setStatus(TransactionStatus_StatusAborted);
                } else {
@@ -1026,20 +1059,20 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
        Vector<int64_t> *abortLocalSequenceNumbers = new Vector<int64_t>();
        {
                SetIterator<int64_t, Abort *> *abortit = getKeyIterator(liveAbortsGeneratedByLocal);
-               while(abortit->hasNext())
+               while (abortit->hasNext())
                        abortLocalSequenceNumbers->add(abortit->next());
                delete abortit;
        }
-       
+
        qsort(abortLocalSequenceNumbers->expose(), abortLocalSequenceNumbers->size(), sizeof(int64_t), compareInt64);
 
        uint asize = abortLocalSequenceNumbers->size();
-       for(uint i=0; i<asize; i++) {
+       for (uint i = 0; i < asize; i++) {
                int64_t localSequenceNumber = abortLocalSequenceNumbers->get(i);
                if (localSequenceNumber <= lastArbitratedSequenceNumberSeen) {
                        continue;
                }
-               
+
                Abort *abort = liveAbortsGeneratedByLocal->get(localSequenceNumber);
                unseenArbitrations->add(abort);
                returnDataSize += abort->getSize();
@@ -1051,14 +1084,14 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
                Vector<int64_t> *commitLocalSequenceNumbers = new Vector<int64_t>();
                {
                        SetIterator<int64_t, Commit *> *commitit = getKeyIterator(commitForClientTable);
-                       while(commitit->hasNext())
+                       while (commitit->hasNext())
                                commitLocalSequenceNumbers->add(commitit->next());
                        delete commitit;
                }
                qsort(commitLocalSequenceNumbers->expose(), commitLocalSequenceNumbers->size(), sizeof(int64_t), compareInt64);
 
                uint clsSize = commitLocalSequenceNumbers->size();
-               for(uint clsi = 0; clsi < clsSize; clsi++) {
+               for (uint clsi = 0; clsi < clsSize; clsi++) {
                        int64_t localSequenceNumber = commitLocalSequenceNumbers->get(clsi);
                        Commit *commit = commitForClientTable->get(localSequenceNumber);
 
@@ -1067,10 +1100,10 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
                        }
 
                        {
-                               Vector<CommitPart *> * parts = commit->getParts();
+                               Vector<CommitPart *> *parts = commit->getParts();
                                uint nParts = parts->size();
-                               for(uint i=0; i<nParts; i++) {
-                                       CommitPart * commitPart = parts->get(i);
+                               for (uint i = 0; i < nParts; i++) {
+                                       CommitPart *commitPart = parts->get(i);
                                        unseenArbitrations->add(commitPart);
                                        returnDataSize += commitPart->getSize();
                                }
@@ -1114,73 +1147,72 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
        return returnData;
 }
 
-ThreeTuple<bool, bool, Array<Slot *> *> Table::sendSlotsToServer(Slot *slot, int newSize, bool isNewKey) {
-       bool attemptedToSendToServerTmp = attemptedToSendToServer;
-       attemptedToSendToServer = true;
 
-       bool inserted = false;
-       bool lastTryInserted = false;
+/** Method tries to send slot to server.  Returns status in tuple.
+               isInserted returns whether last un-acked send (if any) was
+               successful.  Returns whether send was confirmed.x
+ */
 
-       Array<Slot *> *array = cloud->putSlot(slot, newSize);
-       if (array == NULL) {
-               array = new Array<Slot *>();
-               array->set(0, slot);
+bool Table::sendSlotsToServer(Slot *slot, int newSize, bool isNewKey, bool *isInserted, Array<Slot *> **array) {
+       attemptedToSendToServer = true;
+
+       *array = cloud->putSlot(slot, newSize);
+       if (*array == NULL) {
+               *array = new Array<Slot *>(1);
+               (*array)->set(0, slot);
                rejectedSlotVector->clear();
-               inserted = true;
+               *isInserted = false;
+               return true;
        } else {
-               if (array->length() == 0) {
+               if ((*array)->length() == 0) {
                        throw new Error("Server Error: Did not send any slots");
                }
 
-               // if (attemptedToSendToServerTmp) {
                if (hadPartialSendToServer) {
-
-                       bool isInserted = false;
-                       uint size = array->length();
+                       *isInserted = false;
+                       uint size = (*array)->length();
                        for (uint i = 0; i < size; i++) {
-                               Slot *s = array->get(i);
+                               Slot *s = (*array)->get(i);
                                if ((s->getSequenceNumber() == slot->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
-                                       isInserted = true;
+                                       *isInserted = true;
                                        break;
                                }
                        }
 
-                       for (uint i = 0; i < size; i++) {
-                               Slot *s = array->get(i);
-                               if (isInserted) {
-                                       break;
-                               }
-
-                               // Process each entry in the slot
-                               Vector<Entry *> *entries = s->getEntries();
-                               uint eSize = entries->size();
-                               for(uint ei=0; ei < eSize; ei++) {
-                                       Entry * entry = entries->get(ei);
-
-                                       if (entry->getType() == TypeLastMessage) {
-                                               LastMessage *lastMessage = (LastMessage *)entry;
-
-                                               if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == slot->getSequenceNumber())) {
-                                                       isInserted = true;
-                                                       break;
+                       //Also need to see if other machines acknowledged our message
+                       if (!(*isInserted)) {
+                               for (uint i = 0; i < size; i++) {
+                                       Slot *s = (*array)->get(i);
+                                       
+                                       // Process each entry in the slot
+                                       Vector<Entry *> *entries = s->getEntries();
+                                       uint eSize = entries->size();
+                                       for (uint ei = 0; ei < eSize; ei++) {
+                                               Entry *entry = entries->get(ei);
+                                               
+                                               if (entry->getType() == TypeLastMessage) {
+                                                       LastMessage *lastMessage = (LastMessage *)entry;
+                                                       
+                                                       if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == slot->getSequenceNumber())) {
+                                                               *isInserted = true;
+                                                               goto done;
+                                                       }
                                                }
                                        }
                                }
                        }
-
-                       if (!isInserted) {
+               done:
+                       if (!(*isInserted)) {
                                rejectedSlotVector->add(slot->getSequenceNumber());
-                               lastTryInserted = false;
-                       } else {
-                               lastTryInserted = true;
                        }
+                       
+                       return false;
                } else {
                        rejectedSlotVector->add(slot->getSequenceNumber());
-                       lastTryInserted = false;
+                       *isInserted = false;
+                       return false;
                }
        }
-
-       return ThreeTuple<bool, bool, Array<Slot *> *>(inserted, lastTryInserted, array);
 }
 
 /**
@@ -1307,7 +1339,7 @@ void Table::doRejectedMessages(Slot *s) {
                        s->addEntry(rm);
                } else {
                        int64_t prev_seqn = -1;
-                       int i = 0;
+                       uint i = 0;
                        /* Go through list of missing messages */
                        for (; i < rejectedSlotVector->size(); i++) {
                                int64_t curr_seqn = rejectedSlotVector->get(i);
@@ -1348,7 +1380,7 @@ ThreeTuple<bool, bool, int64_t> Table::doMandatoryResuce(Slot *slot, bool resize
 
        // Mandatory Rescue
        for (; currentSequenceNumber < threshold; currentSequenceNumber++) {
-               Slot * previousSlot = buffer->getSlot(currentSequenceNumber);
+               Slot *previousSlot = buffer->getSlot(currentSequenceNumber);
                // Push slot number forward
                if (!seenLiveSlot) {
                        oldestLiveSlotSequenceNumver = currentSequenceNumber;
@@ -1366,8 +1398,8 @@ ThreeTuple<bool, bool, int64_t> Table::doMandatoryResuce(Slot *slot, bool resize
 
                // Iterate over all the live entries and try to rescue them
                uint lESize = liveEntries->size();
-               for (uint i=0; i< lESize; i++) {
-                       Entry * liveEntry = liveEntries->get(i);
+               for (uint i = 0; i < lESize; i++) {
+                       Entry *liveEntry = liveEntries->get(i);
                        if (slot->hasSpace(liveEntry)) {
                                // Enough space to rescue the entry
                                slot->addEntry(liveEntry);
@@ -1388,7 +1420,6 @@ void Table::doOptionalRescue(Slot *s, bool seenliveslot, int64_t seqn, bool resi
         * for SKIP_THRESHOLD consecutive entries*/
        int skipcount = 0;
        int64_t newestseqnum = buffer->getNewestSeqNum();
-search:
        for (; seqn <= newestseqnum; seqn++) {
                Slot *prevslot = buffer->getSlot(seqn);
                //Push slot number forward
@@ -1400,8 +1431,8 @@ search:
                seenliveslot = true;
                Vector<Entry *> *liveentries = prevslot->getLiveEntries(resize);
                uint lESize = liveentries->size();
-               for (uint i=0; i< lESize; i++) {
-                       Entry * liveentry = liveentries->get(i);
+               for (uint i = 0; i < lESize; i++) {
+                       Entry *liveentry = liveentries->get(i);
                        if (s->hasSpace(liveentry))
                                s->addEntry(liveentry);
                        else {
@@ -1411,7 +1442,7 @@ search:
                        }
                }
        }
- donesearch:
+donesearch:
        ;
 }
 
@@ -1442,8 +1473,8 @@ void Table::validateAndUpdate(Array<Slot *> *newSlots, bool acceptUpdatesToLocal
        // Set to keep track of messages from clients
        Hashset<int64_t> *machineSet = new Hashset<int64_t>();
        {
-               SetIterator<int64_t, Pair<int64_t, Liveness *> *> * lmit=getKeyIterator(lastMessageTable);
-               while(lmit->hasNext())
+               SetIterator<int64_t, Pair<int64_t, Liveness *> *> *lmit = getKeyIterator(lastMessageTable);
+               while (lmit->hasNext())
                        machineSet->add(lmit->next());
                delete lmit;
        }
@@ -1451,7 +1482,7 @@ void Table::validateAndUpdate(Array<Slot *> *newSlots, bool acceptUpdatesToLocal
        // Process each slots data
        {
                uint numSlots = newSlots->length();
-               for(uint i=0; i<numSlots; i++) {
+               for (uint i = 0; i < numSlots; i++) {
                        Slot *slot = newSlots->get(i);
                        processSlot(indexer, slot, acceptUpdatesToLocal, machineSet);
                        updateExpectedSize();
@@ -1480,12 +1511,12 @@ void Table::validateAndUpdate(Array<Slot *> *newSlots, bool acceptUpdatesToLocal
        // Commit new to slots to the local block chain->
        {
                uint numSlots = newSlots->length();
-               for(uint i=0; i<numSlots; i++) {
+               for (uint i = 0; i < numSlots; i++) {
                        Slot *slot = newSlots->get(i);
-                       
+
                        // Insert this slot into our local block chain copy->
                        buffer->putSlot(slot);
-                       
+
                        // Keep track of how many slots are currently live (have live data
                        // in them)->
                        liveSlotCount++;
@@ -1598,15 +1629,15 @@ void Table::processNewTransactionParts() {
 
        // Iterate through all the machine Ids that we received new parts
        // for
-       SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> * tpit= getKeyIterator(newTransactionParts);
-       while(tpit->hasNext()) {
+       SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *tpit = getKeyIterator(newTransactionParts);
+       while (tpit->hasNext()) {
                int64_t machineId = tpit->next();
                Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
 
                SetIterator<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *ptit = getKeyIterator(parts);
                // Iterate through all the parts for that machine Id
-               while(ptit->hasNext()) {
-                       Pair<int64_t, int32_t> * partId = ptit->next();
+               while (ptit->hasNext()) {
+                       Pair<int64_t, int32_t> *partId = ptit->next();
                        TransactionPart *part = parts->get(partId);
 
                        if (lastArbitratedTransactionNumberByArbitratorTable->contains(part->getArbitratorId())) {
@@ -1617,7 +1648,7 @@ void Table::processNewTransactionParts() {
                                        continue;
                                }
                        }
-                       
+
                        // Get the transaction object for that sequence number
                        Transaction *transaction = liveTransactionBySequenceNumberTable->get(part->getSequenceNumber());
 
@@ -1651,21 +1682,21 @@ void Table::arbitrateFromServer() {
        // Get the transaction sequence numbers and sort from oldest to newest
        Vector<int64_t> *transactionSequenceNumbers = new Vector<int64_t>();
        {
-               SetIterator<int64_t, Transaction *> * trit = getKeyIterator(liveTransactionBySequenceNumberTable);
-               while(trit->hasNext())
+               SetIterator<int64_t, Transaction *> *trit = getKeyIterator(liveTransactionBySequenceNumberTable);
+               while (trit->hasNext())
                        transactionSequenceNumbers->add(trit->next());
                delete trit;
        }
        qsort(transactionSequenceNumbers->expose(), transactionSequenceNumbers->size(), sizeof(int64_t), compareInt64);
 
        // Collection of key value pairs that are
-       Hashtable<IoTString *, KeyValue *> * speculativeTableTmp = new Hashtable<IoTString *, KeyValue *>();
+       Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *speculativeTableTmp = new Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals>();
 
        // The last transaction arbitrated on
        int64_t lastTransactionCommitted = -1;
        Hashset<Abort *> *generatedAborts = new Hashset<Abort *>();
        uint tsnSize = transactionSequenceNumbers->size();
-       for(uint i=0; i<tsnSize; i++) {
+       for (uint i = 0; i < tsnSize; i++) {
                int64_t transactionSequenceNumber = transactionSequenceNumbers->get(i);
                Transaction *transaction = liveTransactionBySequenceNumberTable->get(transactionSequenceNumber);
 
@@ -1712,7 +1743,7 @@ void Table::arbitrateFromServer() {
                                speculativeTableTmp->put(kv->getKey(), kv);
                        }
                        delete kvit;
-                       
+
                        // Update what the last transaction committed was for use in batch commit
                        lastTransactionCommitted = transactionSequenceNumber;
                } else {
@@ -1743,24 +1774,24 @@ void Table::arbitrateFromServer() {
                localArbitrationSequenceNumber++;
 
                // Add all the new keys to the commit
-               SetIterator<IoTString *, KeyValue *> * spit = getKeyIterator(speculativeTableTmp);
-               while(spit->hasNext()) {
-                       IoTString * string = spit->next();
-                       KeyValue * kv = speculativeTableTmp->get(string);
+               SetIterator<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *spit = getKeyIterator(speculativeTableTmp);
+               while (spit->hasNext()) {
+                       IoTString *string = spit->next();
+                       KeyValue *kv = speculativeTableTmp->get(string);
                        newCommit->addKV(kv);
                }
                delete spit;
-               
+
                // create the commit parts
                newCommit->createCommitParts();
 
                // Append all the commit parts to the end of the pending queue
                // waiting for sending to the server
                // Insert the commit so we can process it
-               Vector<CommitPart *> * parts = newCommit->getParts();
+               Vector<CommitPart *> *parts = newCommit->getParts();
                uint partsSize = parts->size();
-               for(uint i=0; i<partsSize; i++) {
-                       CommitPart * commitPart = parts->get(i);
+               for (uint i = 0; i < partsSize; i++) {
+                       CommitPart *commitPart = parts->get(i);
                        processEntry(commitPart);
                }
        }
@@ -1772,10 +1803,10 @@ void Table::arbitrateFromServer() {
                if (compactArbitrationData()) {
                        ArbitrationRound *newArbitrationRound = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - 1);
                        if (newArbitrationRound->getCommit() != NULL) {
-                               Vector<CommitPart *> * parts = newArbitrationRound->getCommit()->getParts();
+                               Vector<CommitPart *> *parts = newArbitrationRound->getCommit()->getParts();
                                uint partsSize = parts->size();
-                               for(uint i=0; i<partsSize; i++) {
-                                       CommitPart * commitPart = parts->get(i);
+                               for (uint i = 0; i < partsSize; i++) {
+                                       CommitPart *commitPart = parts->get(i);
                                        processEntry(commitPart);
                                }
                        }
@@ -1820,7 +1851,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                        newCommit->addKV(kv);
                }
                delete kvit;
-               
+
                // create the commit parts
                newCommit->createCommitParts();
 
@@ -1831,18 +1862,18 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
 
                if (compactArbitrationData()) {
                        ArbitrationRound *newArbitrationRound = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - 1);
-                       Vector<CommitPart *> * parts = newArbitrationRound->getCommit()->getParts();
+                       Vector<CommitPart *> *parts = newArbitrationRound->getCommit()->getParts();
                        uint partsSize = parts->size();
-                       for(uint i=0; i<partsSize; i++) {
-                               CommitPart * commitPart = parts->get(i);
+                       for (uint i = 0; i < partsSize; i++) {
+                               CommitPart *commitPart = parts->get(i);
                                processEntry(commitPart);
                        }
                } else {
                        // Insert the commit so we can process it
-                       Vector<CommitPart *> * parts = newCommit->getParts();
+                       Vector<CommitPart *> *parts = newCommit->getParts();
                        uint partsSize = parts->size();
-                       for(uint i=0; i<partsSize; i++) {
-                               CommitPart * commitPart = parts->get(i);
+                       for (uint i = 0; i < partsSize; i++) {
+                               CommitPart *commitPart = parts->get(i);
                                processEntry(commitPart);
                        }
                }
@@ -1860,7 +1891,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                if (transaction->getMachineId() == localMachineId) {
                        // For locally created messages update the status
                        // Guard evaluated was false so create abort
-                       TransactionStatus * status = transaction->getTransactionStatus();
+                       TransactionStatus *status = transaction->getTransactionStatus();
                        if (status != NULL) {
                                status->setStatus(TransactionStatus_StatusAborted);
                        }
@@ -1885,10 +1916,10 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                        if (compactArbitrationData()) {
                                ArbitrationRound *newArbitrationRound = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - 1);
 
-                               Vector<CommitPart *> * parts = newArbitrationRound->getCommit()->getParts();
+                               Vector<CommitPart *> *parts = newArbitrationRound->getCommit()->getParts();
                                uint partsSize = parts->size();
-                               for(uint i=0; i<partsSize; i++) {
-                                       CommitPart * commitPart = parts->get(i);
+                               for (uint i = 0; i < partsSize; i++) {
+                                       CommitPart *commitPart = parts->get(i);
                                        processEntry(commitPart);
                                }
                        }
@@ -1918,7 +1949,7 @@ bool Table::compactArbitrationData() {
        bool hadCommit = (lastRound->getCommit() == NULL);
        bool gotNewCommit = false;
 
-       int numberToDelete = 1;
+       uint numberToDelete = 1;
        while (numberToDelete < pendingSendArbitrationRounds->size()) {
                ArbitrationRound *round = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - numberToDelete - 1);
 
@@ -1938,7 +1969,7 @@ bool Table::compactArbitrationData() {
                        lastRound->addAborts(round->getAborts());
                } else {
                        // Create a new larger commit
-                       Commit * newCommit = Commit_merge(lastRound->getCommit(), round->getCommit(), localArbitrationSequenceNumber);
+                       Commit *newCommit = Commit_merge(lastRound->getCommit(), round->getCommit(), localArbitrationSequenceNumber);
                        localArbitrationSequenceNumber++;
 
                        // Create the commit parts so that we can count them
@@ -1969,7 +2000,7 @@ bool Table::compactArbitrationData() {
                if (numberToDelete == pendingSendArbitrationRounds->size()) {
                        pendingSendArbitrationRounds->clear();
                } else {
-                       for (int i = 0; i < numberToDelete; i++) {
+                       for (uint i = 0; i < numberToDelete; i++) {
                                pendingSendArbitrationRounds->removeIndex(pendingSendArbitrationRounds->size() - 1);
                        }
                }
@@ -1998,15 +2029,15 @@ bool Table::updateCommittedTable() {
        }
 
        // Iterate through all the machine Ids that we received new parts for
-       SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> * partsit=getKeyIterator(newCommitParts);
-       while(partsit->hasNext()) {
+       SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *partsit = getKeyIterator(newCommitParts);
+       while (partsit->hasNext()) {
                int64_t machineId = partsit->next();
                Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newCommitParts->get(machineId);
 
                // Iterate through all the parts for that machine Id
-               SetIterator<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> * pairit=getKeyIterator(parts);
-               while(pairit->hasNext()) {
-                       Pair<int64_t, int32_t> * partId = pairit->next();
+               SetIterator<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *pairit = getKeyIterator(parts);
+               while (pairit->hasNext()) {
+                       Pair<int64_t, int32_t> *partId = pairit->next();
                        CommitPart *part = parts->get(partId);
 
                        // Get the transaction object for that sequence number
@@ -2034,7 +2065,7 @@ bool Table::updateCommittedTable() {
                delete pairit;
        }
        delete partsit;
-       
+
        // Clear all the new commits parts in preparation for the next time
        // the server sends slots
        newCommitParts->clear();
@@ -2043,7 +2074,7 @@ bool Table::updateCommittedTable() {
        bool didProcessANewCommit = false;
 
        // Process the commits one by one
-       SetIterator<int64_t, Hashtable<int64_t, Commit *> *> * liveit = getKeyIterator(liveCommitsTable);
+       SetIterator<int64_t, Hashtable<int64_t, Commit *> *> *liveit = getKeyIterator(liveCommitsTable);
        while (liveit->hasNext()) {
                int64_t arbitratorId = liveit->next();
 
@@ -2053,8 +2084,8 @@ bool Table::updateCommittedTable() {
                // Sort the commits in order
                Vector<int64_t> *commitSequenceNumbers = new Vector<int64_t>();
                {
-                       SetIterator<int64_t, Commit *> * clientit = getKeyIterator(commitForClientTable);
-                       while(clientit->hasNext())
+                       SetIterator<int64_t, Commit *> *clientit = getKeyIterator(commitForClientTable);
+                       while (clientit->hasNext())
                                commitSequenceNumbers->add(clientit->next());
                        delete clientit;
                }
@@ -2068,7 +2099,7 @@ bool Table::updateCommittedTable() {
                }
 
                // Go through each new commit one by one
-               for (int i = 0; i < commitSequenceNumbers->size(); i++) {
+               for (uint i = 0; i < commitSequenceNumbers->size(); i++) {
                        int64_t commitSequenceNumber = commitSequenceNumbers->get(i);
                        Commit *commit = commitForClientTable->get(commitSequenceNumber);
 
@@ -2131,10 +2162,10 @@ bool Table::updateCommittedTable() {
                        // have live values for their keys
                        Hashset<Commit *> *commitsToEdit = new Hashset<Commit *>();
                        {
-                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = commit->getKeyValueUpdateSet()->iterator();
                                while (kvit->hasNext()) {
                                        KeyValue *kv = kvit->next();
-                                       Commit * commit = liveCommitsByKeyTable->get(kv->getKey());
+                                       Commit *commit = liveCommitsByKeyTable->get(kv->getKey());
                                        if (commit != NULL)
                                                commitsToEdit->add(commit);
                                }
@@ -2142,8 +2173,8 @@ bool Table::updateCommittedTable() {
                        }
 
                        // Update each previous commit that needs to be updated
-                       SetIterator<Commit *, Commit *> * commitit = commitsToEdit->iterator();
-                       while(commitit->hasNext()) {
+                       SetIterator<Commit *, Commit *> *commitit = commitsToEdit->iterator();
+                       while (commitit->hasNext()) {
                                Commit *previousCommit = commitit->next();
 
                                // Only bother with live commits (TODO: Maybe remove this check)
@@ -2151,14 +2182,14 @@ bool Table::updateCommittedTable() {
 
                                        // Update which keys in the old commits are still live
                                        {
-                                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = commit->getKeyValueUpdateSet()->iterator();
                                                while (kvit->hasNext()) {
                                                        KeyValue *kv = kvit->next();
                                                        previousCommit->invalidateKey(kv->getKey());
                                                }
                                                delete kvit;
                                        }
-                                       
+
                                        // if the commit is now dead then remove it
                                        if (!previousCommit->isLive()) {
                                                commitForClientTable->remove(previousCommit->getSequenceNumber());
@@ -2181,7 +2212,7 @@ bool Table::updateCommittedTable() {
 
                        // Update the committed table of keys and which commit is using which key
                        {
-                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, equalsKeyValue> *kvit = commit->getKeyValueUpdateSet()->iterator();
+                               SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = commit->getKeyValueUpdateSet()->iterator();
                                while (kvit->hasNext()) {
                                        KeyValue *kv = kvit->next();
                                        committedKeyValueTable->put(kv->getKey(), kv);
@@ -2189,9 +2220,9 @@ bool Table::updateCommittedTable() {
                                }
                                delete kvit;
                        }
-         }
-}
-delete liveit;
+               }
+       }
+       delete liveit;
 
        return didProcessANewCommit;
 }
@@ -2210,12 +2241,12 @@ bool Table::updateSpeculativeTable(bool didProcessNewCommits) {
        // from oldest to newest
        Vector<int64_t> *transactionSequenceNumbersSorted = new Vector<int64_t>();
        {
-               SetIterator<int64_t, Transaction *> * trit = getKeyIterator(liveTransactionBySequenceNumberTable);
-               while(trit->hasNext())
+               SetIterator<int64_t, Transaction *> *trit = getKeyIterator(liveTransactionBySequenceNumberTable);
+               while (trit->hasNext())
                        transactionSequenceNumbersSorted->add(trit->next());
                delete trit;
        }
-       
+
        qsort(transactionSequenceNumbersSorted->expose(), transactionSequenceNumbersSorted->size(), sizeof(int64_t), compareInt64);
 
        bool hasGapInTransactionSequenceNumbers = transactionSequenceNumbersSorted->get(0) != oldestTransactionSequenceNumberSpeculatedOn;
@@ -2237,13 +2268,13 @@ bool Table::updateSpeculativeTable(bool didProcessNewCommits) {
        oldestTransactionSequenceNumberSpeculatedOn = transactionSequenceNumbersSorted->get(0);
 
        // Find where to start arbitration from
-       int startIndex = 0;
+       uint startIndex = 0;
 
-       for(; startIndex < transactionSequenceNumbersSorted->size(); startIndex++)
+       for (; startIndex < transactionSequenceNumbersSorted->size(); startIndex++)
                if (transactionSequenceNumbersSorted->get(startIndex) == lastTransactionSequenceNumberSpeculatedOn)
                        break;
        startIndex++;
-                               
+
        if (startIndex >= transactionSequenceNumbersSorted->size()) {
                // Make sure we are not out of bounds
                return false;           // did not speculate
@@ -2252,7 +2283,7 @@ bool Table::updateSpeculativeTable(bool didProcessNewCommits) {
        Hashset<int64_t> *incompleteTransactionArbitrator = new Hashset<int64_t>();
        bool didSkip = true;
 
-       for (int i = startIndex; i < transactionSequenceNumbersSorted->size(); i++) {
+       for (uint i = startIndex; i < transactionSequenceNumbersSorted->size(); i++) {
                int64_t transactionSequenceNumber = transactionSequenceNumbersSorted->get(i);
                Transaction *transaction = liveTransactionBySequenceNumberTable->get(transactionSequenceNumber);
 
@@ -2312,18 +2343,18 @@ void Table::updatePendingTransactionSpeculativeTable(bool didProcessNewCommitsOr
        }
 
        // Find where to start arbitration from
-       int startIndex = 0;
+       uint startIndex = 0;
 
-       for(; startIndex < pendingTransactionQueue->size(); startIndex++)
+       for (; startIndex < pendingTransactionQueue->size(); startIndex++)
                if (pendingTransactionQueue->get(startIndex) == firstPendingTransaction)
                        break;
-       
+
        if (startIndex >= pendingTransactionQueue->size()) {
                // Make sure we are not out of bounds
                return;
        }
 
-       for (int i = startIndex; i < pendingTransactionQueue->size(); i++) {
+       for (uint i = startIndex; i < pendingTransactionQueue->size(); i++) {
                Transaction *transaction = pendingTransactionQueue->get(i);
 
                lastPendingTransactionSpeculatedOn = transaction;
@@ -2347,16 +2378,16 @@ void Table::updatePendingTransactionSpeculativeTable(bool didProcessNewCommitsOr
 void Table::updateLiveTransactionsAndStatus() {
        // Go through each of the transactions
        {
-               SetIterator<int64_t, Transaction *> * iter = getKeyIterator(liveTransactionBySequenceNumberTable);
-               while(iter->hasNext()) {
+               SetIterator<int64_t, Transaction *> *iter = getKeyIterator(liveTransactionBySequenceNumberTable);
+               while (iter->hasNext()) {
                        int64_t key = iter->next();
                        Transaction *transaction = liveTransactionBySequenceNumberTable->get(key);
-                       
+
                        // Check if the transaction is dead
                        if (lastArbitratedTransactionNumberByArbitratorTable->contains(transaction->getArbitrator()) && lastArbitratedTransactionNumberByArbitratorTable->get(transaction->getArbitrator() >= transaction->getSequenceNumber())) {
                                // Set dead the transaction
                                transaction->setDead();
-                               
+
                                // Remove the transaction from the live table
                                iter->remove();
                                liveTransactionByTransactionIdTable->remove(transaction->getId());
@@ -2364,20 +2395,20 @@ void Table::updateLiveTransactionsAndStatus() {
                }
                delete iter;
        }
-       
+
        // Go through each of the transactions
        {
-               SetIterator<int64_t, TransactionStatus *> * iter = getKeyIterator(outstandingTransactionStatus);
-               while(iter->hasNext()) {
+               SetIterator<int64_t, TransactionStatus *> *iter = getKeyIterator(outstandingTransactionStatus);
+               while (iter->hasNext()) {
                        int64_t key = iter->next();
                        TransactionStatus *status = outstandingTransactionStatus->get(key);
 
                        // Check if the transaction is dead
                        if (lastArbitratedTransactionNumberByArbitratorTable->contains(status->getTransactionArbitrator()) && (lastArbitratedTransactionNumberByArbitratorTable->get(status->getTransactionArbitrator()) >= status->getTransactionSequenceNumber())) {
-                               
+
                                // Set committed
                                status->setStatus(TransactionStatus_StatusCommitted);
-                               
+
                                // Remove
                                iter->remove();
                        }
@@ -2397,8 +2428,8 @@ void Table::processSlot(SlotIndexer *indexer, Slot *slot, bool acceptUpdatesToLo
        // Process each entry in the slot
        Vector<Entry *> *entries = slot->getEntries();
        uint eSize = entries->size();
-       for(uint ei=0; ei < eSize; ei++) {
-               Entry * entry = entries->get(ei);
+       for (uint ei = 0; ei < eSize; ei++) {
+               Entry *entry = entries->get(ei);
                switch (entry->getType()) {
                case TypeCommitPart:
                        processEntry((CommitPart *)entry);
@@ -2457,7 +2488,7 @@ void Table::processEntry(NewKey *entry) {
  * seen in this current round of updating the local copy of the block
  * chain
  */
-void Table::processEntry(TableStatus * entry, int64_t seq) {
+void Table::processEntry(TableStatus *entry, int64_t seq) {
        int newNumSlots = entry->getMaxSlots();
        updateCurrMaxSize(newNumSlots);
        initExpectedSize(seq, newNumSlots);
@@ -2502,8 +2533,8 @@ void Table::processEntry(RejectedMessage *entry, SlotIndexer *indexer) {
        // Create a list of clients to watch until they see this rejected
        // message entry->
        Hashset<int64_t> *deviceWatchSet = new Hashset<int64_t>();
-       SetIterator<int64_t, Pair<int64_t, Liveness*> *> * iter = getKeyIterator(lastMessageTable);
-       while(iter->hasNext()) {
+       SetIterator<int64_t, Pair<int64_t, Liveness *> *> *iter = getKeyIterator(lastMessageTable);
+       while (iter->hasNext()) {
                // Machine ID for the last message entry
                int64_t lastMessageEntryMachineId = iter->next();
 
@@ -2513,7 +2544,7 @@ void Table::processEntry(RejectedMessage *entry, SlotIndexer *indexer) {
                        continue;
                }
 
-               Pair<int64_t, Liveness *> * lastMessageValue = lastMessageTable->get(lastMessageEntryMachineId);
+               Pair<int64_t, Liveness *> *lastMessageValue = lastMessageTable->get(lastMessageEntryMachineId);
                int64_t entrySequenceNumber = lastMessageValue->getFirst();
 
                if (entrySequenceNumber < seq) {
@@ -2526,7 +2557,7 @@ void Table::processEntry(RejectedMessage *entry, SlotIndexer *indexer) {
                }
        }
        delete iter;
-       
+
        if (deviceWatchSet->isEmpty()) {
                // This rejected message has been seen by all the clients so
                entry->setDead();
@@ -2551,6 +2582,7 @@ void Table::processEntry(Abort *entry) {
 
        // Abort has not been seen by the client it is for yet so we need to
        // keep track of it
+
        Abort *previouslySeenAbort = liveAbortTable->put(new Pair<int64_t, int64_t>(entry->getAbortId()), entry);
        if (previouslySeenAbort != NULL) {
                previouslySeenAbort->setDead();         // Delete old version of the abort since we got a rescued newer version
@@ -2563,7 +2595,8 @@ void Table::processEntry(Abort *entry) {
        if ((entry->getSequenceNumber() != -1) && (lastMessageTable->get(entry->getTransactionMachineId())->getFirst() >= entry->getSequenceNumber())) {
                // The machine already saw this so it is dead
                entry->setDead();
-               liveAbortTable->remove(&entry->getAbortId());
+               Pair<int64_t, int64_t> abortid = entry->getAbortId();
+               liveAbortTable->remove(&abortid);
 
                if (entry->getTransactionArbitrator() == localMachineId) {
                        liveAbortsGeneratedByLocal->remove(entry->getArbitratorLocalSequenceNumber());
@@ -2584,15 +2617,17 @@ void Table::processEntry(Abort *entry) {
        }
 
        // Set dead a transaction if we can
-       Transaction *transactionToSetDead = liveTransactionByTransactionIdTable->remove(Pair<int64_t, int64_t>(entry->getTransactionMachineId(), entry->getTransactionClientLocalSequenceNumber()));
+       Pair<int64_t, int64_t> deadPair = Pair<int64_t, int64_t>(entry->getTransactionMachineId(), entry->getTransactionClientLocalSequenceNumber());
+
+       Transaction *transactionToSetDead = liveTransactionByTransactionIdTable->remove(&deadPair);
        if (transactionToSetDead != NULL) {
                liveTransactionBySequenceNumberTable->remove(transactionToSetDead->getSequenceNumber());
        }
 
        // Update the last transaction sequence number that the arbitrator
        // arbitrated on
-       int64_t lastTransactionNumber = lastArbitratedTransactionNumberByArbitratorTable->get(entry->getTransactionArbitrator());
-       if ((lastTransactionNumber == NULL) || (lastTransactionNumber < entry->getTransactionSequenceNumber())) {
+       if (!lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getTransactionArbitrator()) ||
+                       (lastArbitratedTransactionNumberByArbitratorTable->get(entry->getTransactionArbitrator()) < entry->getTransactionSequenceNumber())) {
                // Is a valid one
                if (entry->getTransactionSequenceNumber() != -1) {
                        lastArbitratedTransactionNumberByArbitratorTable->put(entry->getTransactionArbitrator(), entry->getTransactionSequenceNumber());
@@ -2607,8 +2642,7 @@ void Table::processEntry(Abort *entry) {
 void Table::processEntry(TransactionPart *entry) {
        // Check if we have already seen this transaction and set it dead OR
        // if it is not alive
-       int64_t lastTransactionNumber = lastArbitratedTransactionNumberByArbitratorTable->get(entry->getArbitratorId());
-       if ((lastTransactionNumber != NULL) && (lastTransactionNumber >= entry->getSequenceNumber())) {
+       if (lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getArbitratorId()) && (lastArbitratedTransactionNumberByArbitratorTable->get(entry->getArbitratorId()) >= entry->getSequenceNumber())) {
                // This transaction is dead, it was already committed or aborted
                entry->setDead();
                return;
@@ -2637,7 +2671,7 @@ void Table::processEntry(TransactionPart *entry) {
 void Table::processEntry(CommitPart *entry) {
        // Update the last transaction that was updated if we can
        if (entry->getTransactionSequenceNumber() != -1) {
-               if (!lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getMachineId() || lastArbitratedTransactionNumberByArbitratorTable->get(entry->getMachineId()) < entry->getTransactionSequenceNumber())) {
+               if (!lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getMachineId() || lastArbitratedTransactionNumberByArbitratorTable->get(entry->getMachineId()) < entry->getTransactionSequenceNumber())) {
                        lastArbitratedTransactionNumberByArbitratorTable->put(entry->getMachineId(), entry->getTransactionSequenceNumber());
                }
        }
@@ -2676,7 +2710,7 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
                // seen yet
 
                SetIterator<RejectedMessage *, RejectedMessage *> *rmit = watchset->iterator();
-               while(rmit->hasNext()) {
+               while (rmit->hasNext()) {
                        RejectedMessage *rm = rmit->next();
                        // If this machine Id has seen this rejected message->->->
                        if (rm->getSequenceNumber() <= seqNum) {
@@ -2690,20 +2724,24 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
        }
 
        // Set dead the abort
-       for (Iterator<Map->Entry<Pair<int64_t, int64_t>, Abort *> > i = liveAbortTable->entrySet()->iterator(); i->hasNext();) {
-               Abort *abort = i->next()->getValue();
+       SetIterator<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals> *abortit = getKeyIterator(liveAbortTable);
+
+       while (abortit->hasNext()) {
+               Pair<int64_t, int64_t> *key = abortit->next();
+               Abort *abort = liveAbortTable->get(key);
                if ((abort->getTransactionMachineId() == machineId) && (abort->getSequenceNumber() <= seqNum)) {
                        abort->setDead();
-                       i->remove();
+                       abortit->remove();
                        if (abort->getTransactionArbitrator() == localMachineId) {
                                liveAbortsGeneratedByLocal->remove(abort->getArbitratorLocalSequenceNumber());
                        }
                }
        }
+       delete abortit;
        if (machineId == localMachineId) {
                // Our own messages are immediately dead->
                char livenessType = liveness->getType();
-               if (livenessType==TypeLastMessage) {
+               if (livenessType == TypeLastMessage) {
                        ((LastMessage *)liveness)->setDead();
                } else if (livenessType == TypeSlot) {
                        ((Slot *)liveness)->setDead();
@@ -2712,7 +2750,7 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
                }
        }
        // Get the old last message for this device
-       Pair<int64_t, Liveness *> * lastMessageEntry = lastMessageTable->put(machineId, new Pair<int64_t, Liveness *>(seqNum, liveness));
+       Pair<int64_t, Liveness *> *lastMessageEntry = lastMessageTable->put(machineId, new Pair<int64_t, Liveness *>(seqNum, liveness));
        if (lastMessageEntry == NULL) {
                // If no last message then there is nothing else to process
                return;
@@ -2721,11 +2759,11 @@ void Table::updateLastMessage(int64_t machineId, int64_t seqNum, Liveness *liven
        int64_t lastMessageSeqNum = lastMessageEntry->getFirst();
        Liveness *lastEntry = lastMessageEntry->getSecond();
        delete lastMessageEntry;
-       
+
        // If it is not our machine Id since we already set ours to dead
        if (machineId != localMachineId) {
                char lastEntryType = lastEntry->getType();
-               
+
                if (lastEntryType == TypeLastMessage) {
                        ((LastMessage *)lastEntry)->setDead();
                } else if (lastEntryType == TypeSlot) {
@@ -2773,7 +2811,7 @@ void Table::addWatchVector(int64_t machineId, RejectedMessage *entry) {
  * Check if the HMAC chain is not violated
  */
 void Table::checkHMACChain(SlotIndexer *indexer, Array<Slot *> *newSlots) {
-       for (int i = 0; i < newSlots->length(); i++) {
+       for (uint i = 0; i < newSlots->length(); i++) {
                Slot *currSlot = newSlots->get(i);
                Slot *prevSlot = indexer->getSlot(currSlot->getSequenceNumber() - 1);
                if (prevSlot != NULL &&