edits
[iotcloud.git] / version2 / src / C / Table.cc
index 22d62a250b63bfab30dd294108f16c3dfb6222c8..d598f15cfda3939f9d65c9f6fbf6876530c18622 100644 (file)
@@ -150,15 +150,15 @@ void Table::init() {
        speculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
        pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
        liveNewKeyTable = new Hashtable<IoTString *, NewKey *>();
-       lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> *>();
+       lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> >();
        rejectedMessageWatchVectorTable = new Hashtable<int64_t, Hashset<RejectedMessage *> * >();
        arbitratorTable = new Hashtable<IoTString *, int64_t>();
-       liveAbortTable = new Hashtable<Pair<int64_t, int64_t> *, Abort *>();
-       newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *> *>();
-       newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *>();
+       liveAbortTable = new Hashtable<Pair<int64_t, int64_t>, Abort *>();
+       newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, TransactionPart *> *>();
+       newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, CommitPart *> *>();
        lastArbitratedTransactionNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
        liveTransactionBySequenceNumberTable = new Hashtable<int64_t, Transaction *>();
-       liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t> *, Transaction *>();
+       liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t>, Transaction *>();
        liveCommitsTable = new Hashtable<int64_t, Hashtable<int64_t, Commit *> >();
        liveCommitsByKeyTable = new Hashtable<IoTString *, Commit *>();
        lastCommitSeenSequenceNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
@@ -168,7 +168,7 @@ void Table::init() {
        transactionPartsSent = new Hashtable<Transaction *, Vector<int32_t> *>();
        outstandingTransactionStatus = new Hashtable<int64_t, TransactionStatus *>();
        liveAbortsGeneratedByLocal = new Hashtable<int64_t, Abort *>();
-       offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t> *>();
+       offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t> >();
        localCommunicationTable = new Hashtable<int64_t, Pair<IoTString *, int32_t> >();
        lastTransactionSeenFromMachineFromServer = new Hashtable<int64_t, int64_t>();
        pendingSendArbitrationRounds = new Vector<ArbitrationRound *>();
@@ -411,7 +411,7 @@ TransactionStatus *Table::commitTransaction() {
                                continue;
                        }
 
-                       Pair<bool, bool> *sendReturn = sendTransactionToLocal(transaction);
+                       Pair<bool, bool> sendReturn = sendTransactionToLocal(transaction);
 
                        if (sendReturn->getFirst()) {
                                // Failed to contact over local
@@ -456,7 +456,7 @@ bool Table::sendToServer(NewKey *newKey) {
                        Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
                        if (newSlots->length() == 0) {
                                fromRetry = true;
-                               ThreeTuple<bool, bool, Array<Slot *> *> *sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey);
+                               ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey);
 
                                if (sendSlotsReturn->getFirst()) {
                                        if (newKey != NULL) {
@@ -850,7 +850,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        if (localCommunicationInformation == NULL) {
                // Cant talk to that device locally so do nothing
-               return new Pair<bool, bool>(true, false);
+               return Pair<bool, bool>(true, false);
        }
 
        // Get the size of the send data
@@ -882,7 +882,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
 
        if (returnData == NULL) {
                // Could not contact server
-               return new Pair<bool, bool>(true, false);
+               return Pair<bool, bool>(true, false);
        }
 
        // Decode the data
@@ -926,7 +926,7 @@ Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
                }
        }
 
-       return new Pair<bool, bool>(false, true);
+       return Pair<bool, bool>(false, true);
 }
 
 Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
@@ -1036,7 +1036,7 @@ Array<char> *Table::acceptDataFromLocal(Array<char> *data) {
        return returnData;
 }
 
-ThreeTuple<bool, bool, Array<Slot *> *> *Table::sendSlotsToServer(Slot *slot, int newSize, bool isNewKey) {
+ThreeTuple<bool, bool, Array<Slot *> *> Table::sendSlotsToServer(Slot *slot, int newSize, bool isNewKey) {
        bool attemptedToSendToServerTmp = attemptedToSendToServer;
        attemptedToSendToServer = true;
 
@@ -1096,13 +1096,13 @@ ThreeTuple<bool, bool, Array<Slot *> *> *Table::sendSlotsToServer(Slot *slot, in
                }
        }
 
-       return new ThreeTuple<bool, bool, Array<Slot *> *>(inserted, lastTryInserted, array);
+       return ThreeTuple<bool, bool, Array<Slot *> *>(inserted, lastTryInserted, array);
 }
 
 /**
  * Returns false if a resize was needed
  */
-ThreeTuple<bool, int32_t, bool> *Table::fillSlot(Slot *slot, bool resize, NewKey *newKeyEntry) {
+ThreeTuple<bool, int32_t, bool> Table::fillSlot(Slot *slot, bool resize, NewKey *newKeyEntry) {
 
 
        int newSize = 0;
@@ -1130,7 +1130,7 @@ ThreeTuple<bool, int32_t, bool> *Table::fillSlot(Slot *slot, bool resize, NewKey
 
        if (needsResize && !resize) {
                // We need to resize but we are not resizing so return false
-               return new ThreeTuple<bool, int32_t, bool>(true, NULL, NULL);
+               return ThreeTuple<bool, int32_t, bool>(true, NULL, NULL);
        }
 
        bool inserted = false;
@@ -1216,7 +1216,7 @@ ThreeTuple<bool, int32_t, bool> *Table::fillSlot(Slot *slot, bool resize, NewKey
        // Fill the remainder of the slot with rescue data
        doOptionalRescue(slot, seenLiveSlot, currentRescueSequenceNumber, resize);
 
-       return new ThreeTuple<bool, int32_t, bool>(false, newSize, inserted);
+       return ThreeTuple<bool, int32_t, bool>(false, newSize, inserted);
 }
 
 void Table::doRejectedMessages(Slot *s) {
@@ -1298,14 +1298,14 @@ ThreeTuple<bool, bool, int64_t> Table::doMandatoryResuce(Slot *slot, bool resize
                        } else if (currentSequenceNumber == firstIfFull) {
                                //if there's no space but the entry is about to fall off the queue
                                System->out->println("B");      //?
-                               return new ThreeTuple<bool, bool, int64_t>(true, seenLiveSlot, currentSequenceNumber);
+                               return ThreeTuple<bool, bool, int64_t>(true, seenLiveSlot, currentSequenceNumber);
 
                        }
                }
        }
 
        // Did not resize
-       return new ThreeTuple<bool, bool, int64_t>(false, seenLiveSlot, currentSequenceNumber);
+       return ThreeTuple<bool, bool, int64_t>(false, seenLiveSlot, currentSequenceNumber);
 }
 
 void Table::doOptionalRescue(Slot *s, bool seenliveslot, int64_t seqn, bool resize) {
@@ -1518,10 +1518,10 @@ void Table::processNewTransactionParts() {
 
        // Iterate through all the machine Ids that we received new parts for
        for (int64_t machineId : newTransactionParts->keySet()) {
-               Hashtable<Pair<int64_t int32_t> *, TransactionPart *> *parts = newTransactionParts->get(machineId);
+               Hashtable<Pair<int64_t int32_t>, TransactionPart *> *parts = newTransactionParts->get(machineId);
 
                // Iterate through all the parts for that machine Id
-               for (Pair<int64_t, int32_t> *partId : parts->keySet()) {
+               for (Pair<int64_t, int32_t> partId : parts->keySet()) {
                        TransactionPart *part = parts->get(partId);
 
                        int64_t lastTransactionNumber = lastArbitratedTransactionNumberByArbitratorTable->get(part->getArbitratorId());
@@ -1684,13 +1684,13 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
 
        // Check if this machine arbitrates for this transaction if not then we cant arbitrate this transaction
        if (transaction->getArbitrator() != localMachineId) {
-               return new Pair<bool, bool>(false, false);
+               return Pair<bool, bool>(false, false);
        }
 
        if (!transaction->isComplete()) {
                // Will arbitrate in incorrect order if we continue so just break
                // Most likely this
-               return new Pair<bool, bool>(false, false);
+               return Pair<bool, bool>(false, false);
        }
 
        if (transaction->getMachineId() != localMachineId) {
@@ -1698,7 +1698,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                if (lastTransactionSeenFromMachineFromServer->get(transaction->getMachineId()) != NULL) {
                        if (lastTransactionSeenFromMachineFromServer->get(transaction->getMachineId()) > transaction->getClientLocalSequenceNumber()) {
                                // We've have already seen this from the server
-                               return new Pair<bool, bool>(false, false);
+                               return Pair<bool, bool>(false, false);
                        }
                }
        }
@@ -1742,7 +1742,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                }
 
                updateLiveStateFromLocal();
-               return new Pair<bool, bool>(true, true);
+               return Pair<bool, bool>(true, true);
        } else {
 
                if (transaction->getMachineId() == localMachineId) {
@@ -1782,7 +1782,7 @@ Pair<bool, bool> Table::arbitrateOnLocalTransaction(Transaction *transaction) {
                }
 
                updateLiveStateFromLocal();
-               return new Pair<bool, bool>(true, false);
+               return Pair<bool, bool>(true, false);
        }
 }
 
@@ -1889,10 +1889,10 @@ bool Table::updateCommittedTable() {
 
        // Iterate through all the machine Ids that we received new parts for
        for (int64_t machineId : newCommitParts->keySet()) {
-               Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *parts = newCommitParts->get(machineId);
+               Hashtable<Pair<int64_t, int32_t>, CommitPart *> *parts = newCommitParts->get(machineId);
 
                // Iterate through all the parts for that machine Id
-               for (Pair<int64_t, int32_t> *partId : parts->keySet()) {
+               for (Pair<int64_t, int32_t> partId : parts->keySet()) {
                        CommitPart *part = parts->get(partId);
 
                        // Get the transaction object for that sequence number
@@ -2323,7 +2323,7 @@ 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>();
-       for (Map->Entry<int64_t, Pair<int64_t, Liveness *> *> *lastMessageEntry : lastMessageTable->entrySet()) {
+       for (Map->Entry<int64_t, Pair<int64_t, Liveness *> > *lastMessageEntry : lastMessageTable->entrySet()) {
 
                // Machine ID for the last message entry
                int64_t lastMessageEntryMachineId = lastMessageEntry->getKey();
@@ -2334,7 +2334,7 @@ void Table::processEntry(RejectedMessage *entry, SlotIndexer *indexer) {
                        continue;
                }
 
-               Pair<int64_t, Liveness *> *lastMessageValue = lastMessageEntry->getValue();
+               Pair<int64_t, Liveness *> lastMessageValue = lastMessageEntry->getValue();
                int64_t entrySequenceNumber = lastMessageValue->getFirst();
 
                if (entrySequenceNumber < seq) {
@@ -2409,7 +2409,7 @@ void Table::processEntry(Abort *entry) {
 
 
        // Set dead a transaction if we can
-       Transaction *transactionToSetDead = liveTransactionByTransactionIdTable->remove(new Pair<int64_t, int64_t>(entry->getTransactionMachineId(), entry->getTransactionClientLocalSequenceNumber()));
+       Transaction *transactionToSetDead = liveTransactionByTransactionIdTable->remove(Pair<int64_t, int64_t>(entry->getTransactionMachineId(), entry->getTransactionClientLocalSequenceNumber()));
        if (transactionToSetDead != NULL) {
                liveTransactionBySequenceNumberTable->remove(transactionToSetDead->getSequenceNumber());
        }
@@ -2438,11 +2438,11 @@ void Table::processEntry(TransactionPart *entry) {
        }
 
        // This part is still alive
-       Hashtable<Pair<int64_t, int32_t> *, TransactionPart *> *transactionPart = newTransactionParts->get(entry->getMachineId());
+       Hashtable<Pair<int64_t, int32_t>, TransactionPart *> *transactionPart = newTransactionParts->get(entry->getMachineId());
 
        if (transactionPart == NULL) {
                // Dont have a table for this machine Id yet so make one
-               transactionPart = new Hashtable<Pair<int64_t, int32_t> *, TransactionPart *>();
+               transactionPart = new Hashtable<Pair<int64_t, int32_t>, TransactionPart *>();
                newTransactionParts->put(entry->getMachineId(), transactionPart);
        }
 
@@ -2470,11 +2470,11 @@ void Table::processEntry(CommitPart *entry) {
 
 
 
-       Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
+       Hashtable<Pair<int64_t, int32_t>, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
 
        if (commitPart == NULL) {
                // Don't have a table for this machine Id yet so make one
-               commitPart = new Hashtable<Pair<int64_t, int32_t> *, CommitPart *>();
+               commitPart = new Hashtable<Pair<int64_t, int32_t>, CommitPart *>();
                newCommitParts->put(entry->getMachineId(), commitPart);
        }
 
@@ -2520,7 +2520,7 @@ 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();) {
+       for (Iterator<Map->Entry<Pair<int64_t, int64_t>, Abort *> > i = liveAbortTable->entrySet()->iterator(); i->hasNext();) {
                Abort *abort = i->next()->getValue();
 
                if ((abort->getTransactionMachineId() == machineId) && (abort->getSequenceNumber() <= seqNum)) {
@@ -2547,7 +2547,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, Pair<int64_t, Liveness *>(seqNum, liveness));
        if (lastMessageEntry == NULL) {
                // If no last message then there is nothing else to process
                return;