edit
[iotcloud.git] / version2 / src / C / Table.cc
index 07923d58fc2ca67852265a3928340e58e713791f..0a70459dfb16688895694441cac3c8739df9e637 100644 (file)
@@ -48,39 +48,39 @@ final class Table {
        Slot lastSlotAttemptedToSend = NULL;
        bool lastIsNewKey = false;
        int lastNewSize = 0;
-       Map<Transaction, List<Integer>> lastTransactionPartsSent = NULL;
+       Hashtable<Transaction, List<Integer>> lastTransactionPartsSent = NULL;
        List<Entry> lastPendingSendArbitrationEntriesToDelete = NULL;
        NewKey lastNewKey = NULL;
 
 
        /* Data Structures  */
-       Map<IoTString, KeyValue> committedKeyValueTable = NULL; // Table of committed key value pairs
-       Map<IoTString, KeyValue> speculatedKeyValueTable = NULL; // Table of speculated key value pairs, if there is a speculative value
-       Map<IoTString, KeyValue> pendingTransactionSpeculatedKeyValueTable = NULL; // Table of speculated key value pairs, if there is a speculative value from the pending transactions
-       Map<IoTString, NewKey> liveNewKeyTable = NULL; // Table of live new keys
-       HashMap<Long, Pair<Long, Liveness>> lastMessageTable = NULL; // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
-       HashMap<Long, HashSet<RejectedMessage>> rejectedMessageWatchListTable = NULL; // Table of machine Ids and the set of rejected messages they have not seen yet
-       Map<IoTString, Long> arbitratorTable = NULL; // Table of keys and their arbitrators
-       Map<Pair<int64_t, int64_t>, Abort> liveAbortTable = NULL; // Table live abort messages
-       Map<Long, Map<Pair<Long, Integer>, TransactionPart>> newTransactionParts = NULL; // transaction parts that are seen in this latest round of slots from the server
-       Map<Long, Map<Pair<Long, Integer>, CommitPart>> newCommitParts = NULL; // commit parts that are seen in this latest round of slots from the server
-       Map<int64_t, int64_t> lastArbitratedTransactionNumberByArbitratorTable = NULL; // Last transaction sequence number that an arbitrator arbitrated on
-       Map<Long, Transaction> liveTransactionBySequenceNumberTable = NULL; // live transaction grouped by the sequence number
-       Map<Pair<int64_t, int64_t>, Transaction> liveTransactionByTransactionIdTable = NULL; // live transaction grouped by the transaction ID
-       Map<Long, Map<Long, Commit>> liveCommitsTable = NULL;
-       Map<IoTString, Commit> liveCommitsByKeyTable = NULL;
-       Map<int64_t, int64_t> lastCommitSeenSequenceNumberByArbitratorTable = NULL;
+       Hashtable<IoTString, KeyValue> committedKeyValueTable = NULL; // Table of committed key value pairs
+       Hashtable<IoTString, KeyValue> speculatedKeyValueTable = NULL; // Table of speculated key value pairs, if there is a speculative value
+       Hashtable<IoTString, KeyValue> pendingTransactionSpeculatedKeyValueTable = NULL; // Table of speculated key value pairs, if there is a speculative value from the pending transactions
+       Hashtable<IoTString, NewKey> liveNewKeyTable = NULL; // Table of live new keys
+       Hashtable<Long, Pair<Long, Liveness>> lastMessageTable = NULL; // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
+       Hashtable<Long, HashSet<RejectedMessage>> rejectedMessageWatchListTable = NULL; // Table of machine Ids and the set of rejected messages they have not seen yet
+       Hashtable<IoTString, Long> arbitratorTable = NULL; // Table of keys and their arbitrators
+       Hashtable<Pair<int64_t, int64_t>, Abort> liveAbortTable = NULL; // Table live abort messages
+       Hashtable<Long, Hashtable<Pair<Long, Integer>, TransactionPart>> newTransactionParts = NULL; // transaction parts that are seen in this latest round of slots from the server
+       Hashtable<Long, Hashtable<Pair<Long, Integer>, CommitPart>> newCommitParts = NULL; // commit parts that are seen in this latest round of slots from the server
+       Hashtable<int64_t, int64_t> lastArbitratedTransactionNumberByArbitratorTable = NULL; // Last transaction sequence number that an arbitrator arbitrated on
+       Hashtable<Long, Transaction> liveTransactionBySequenceNumberTable = NULL; // live transaction grouped by the sequence number
+       Hashtable<Pair<int64_t, int64_t>, Transaction> liveTransactionByTransactionIdTable = NULL; // live transaction grouped by the transaction ID
+       Hashtable<Long, Hashtable<Long, Commit>> liveCommitsTable = NULL;
+       Hashtable<IoTString, Commit> liveCommitsByKeyTable = NULL;
+       Hashtable<int64_t, int64_t> lastCommitSeenSequenceNumberByArbitratorTable = NULL;
        Vector<Long> rejectedSlotList = NULL; // List of rejected slots that have yet to be sent to the server
        List<Transaction> pendingTransactionQueue = NULL;
        List<ArbitrationRound> pendingSendArbitrationRounds = NULL;
        List<Entry> pendingSendArbitrationEntriesToDelete = NULL;
-       Map<Transaction, List<Integer>> transactionPartsSent = NULL;
-       Map<Long, TransactionStatus> outstandingTransactionStatus = NULL;
-       Map<Long, Abort> liveAbortsGeneratedByLocal = NULL;
+       Hashtable<Transaction, List<Integer>> transactionPartsSent = NULL;
+       Hashtable<Long, TransactionStatus> outstandingTransactionStatus = NULL;
+       Hashtable<Long, Abort> liveAbortsGeneratedByLocal = NULL;
        Set<Pair<int64_t, int64_t>> offlineTransactionsCommittedAndAtServer = NULL;
-       Map<Long, Pair<String, Integer>> localCommunicationTable = NULL;
-       Map<int64_t, int64_t> lastTransactionSeenFromMachineFromServer = NULL;
-       Map<int64_t, int64_t> lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = NULL;
+       Hashtable<Long, Pair<String, Integer>> localCommunicationTable = NULL;
+       Hashtable<int64_t, int64_t> lastTransactionSeenFromMachineFromServer = NULL;
+       Hashtable<int64_t, int64_t> lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = NULL;
 
 
        Table(String baseurl, String password, int64_t _localMachineId, int listeningPort) {
@@ -110,33 +110,33 @@ final class Table {
                oldestLiveSlotSequenceNumver = 1;
 
                // init data structs
-               committedKeyValueTable = new HashMap<IoTString, KeyValue>();
-               speculatedKeyValueTable = new HashMap<IoTString, KeyValue>();
-               pendingTransactionSpeculatedKeyValueTable = new HashMap<IoTString, KeyValue>();
-               liveNewKeyTable = new HashMap<IoTString, NewKey>();
-               lastMessageTable = new HashMap<Long, Pair<Long, Liveness>>();
-               rejectedMessageWatchListTable = new HashMap<Long, HashSet<RejectedMessage>>();
-               arbitratorTable = new HashMap<IoTString, Long>();
-               liveAbortTable = new HashMap<Pair<int64_t, int64_t>, Abort>();
-               newTransactionParts = new HashMap<Long, Map<Pair<Long, Integer>, TransactionPart>>();
-               newCommitParts = new HashMap<Long, Map<Pair<Long, Integer>, CommitPart>>();
-               lastArbitratedTransactionNumberByArbitratorTable = new HashMap<int64_t, int64_t>();
-               liveTransactionBySequenceNumberTable = new HashMap<Long, Transaction>();
-               liveTransactionByTransactionIdTable = new HashMap<Pair<int64_t, int64_t>, Transaction>();
-               liveCommitsTable = new HashMap<Long, Map<Long, Commit>>();
-               liveCommitsByKeyTable = new HashMap<IoTString, Commit>();
-               lastCommitSeenSequenceNumberByArbitratorTable = new HashMap<int64_t, int64_t>();
+               committedKeyValueTable = new Hashtable<IoTString, KeyValue>();
+               speculatedKeyValueTable = new Hashtable<IoTString, KeyValue>();
+               pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString, KeyValue>();
+               liveNewKeyTable = new Hashtable<IoTString, NewKey>();
+               lastMessageTable = new Hashtable<Long, Pair<Long, Liveness>>();
+               rejectedMessageWatchListTable = new Hashtable<Long, HashSet<RejectedMessage>>();
+               arbitratorTable = new Hashtable<IoTString, Long>();
+               liveAbortTable = new Hashtable<Pair<int64_t, int64_t>, Abort>();
+               newTransactionParts = new Hashtable<Long, Hashtable<Pair<Long, Integer>, TransactionPart>>();
+               newCommitParts = new Hashtable<Long, Hashtable<Pair<Long, Integer>, CommitPart>>();
+               lastArbitratedTransactionNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
+               liveTransactionBySequenceNumberTable = new Hashtable<Long, Transaction>();
+               liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t>, Transaction>();
+               liveCommitsTable = new Hashtable<Long, Hashtable<Long, Commit>>();
+               liveCommitsByKeyTable = new Hashtable<IoTString, Commit>();
+               lastCommitSeenSequenceNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
                rejectedSlotList = new Vector<Long>();
                pendingTransactionQueue = new ArrayList<Transaction>();
                pendingSendArbitrationEntriesToDelete = new ArrayList<Entry>();
-               transactionPartsSent = new HashMap<Transaction, List<Integer>>();
-               outstandingTransactionStatus = new HashMap<Long, TransactionStatus>();
-               liveAbortsGeneratedByLocal = new HashMap<Long, Abort>();
+               transactionPartsSent = new Hashtable<Transaction, List<Integer>>();
+               outstandingTransactionStatus = new Hashtable<Long, TransactionStatus>();
+               liveAbortsGeneratedByLocal = new Hashtable<Long, Abort>();
                offlineTransactionsCommittedAndAtServer = new HashSet<Pair<int64_t, int64_t>>();
-               localCommunicationTable = new HashMap<Long, Pair<String, Integer>>();
-               lastTransactionSeenFromMachineFromServer = new HashMap<int64_t, int64_t>();
+               localCommunicationTable = new Hashtable<Long, Pair<String, Integer>>();
+               lastTransactionSeenFromMachineFromServer = new Hashtable<int64_t, int64_t>();
                pendingSendArbitrationRounds = new ArrayList<ArbitrationRound>();
-               lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = new HashMap<int64_t, int64_t>();
+               lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = new Hashtable<int64_t, int64_t>();
 
 
                // Other init stuff
@@ -761,7 +761,7 @@ final class Table {
                                lastInsertedNewKey = insertedNewKey;
                                lastNewSize = newSize;
                                lastNewKey = newKey;
-                               lastTransactionPartsSent = new HashMap<Transaction, List<Integer>>(transactionPartsSent);
+                               lastTransactionPartsSent = new Hashtable<Transaction, List<Integer>>(transactionPartsSent);
                                lastPendingSendArbitrationEntriesToDelete = new ArrayList<Entry>(pendingSendArbitrationEntriesToDelete);
 
 
@@ -880,7 +880,7 @@ final class Table {
 
 
                                // if (!fromRetry) {
-                               //      lastTransactionPartsSent = new HashMap<Transaction, List<Integer>>(transactionPartsSent);
+                               //      lastTransactionPartsSent = new Hashtable<Transaction, List<Integer>>(transactionPartsSent);
                                //      lastPendingSendArbitrationEntriesToDelete = new ArrayList<Entry>(pendingSendArbitrationEntriesToDelete);
                                // }
 
@@ -1089,7 +1089,7 @@ final class Table {
                }
 
                // Get the commits to send back
-               Map<Long, Commit> commitForClientTable = liveCommitsTable.get(localMachineId);
+               Hashtable<Long, Commit> commitForClientTable = liveCommitsTable.get(localMachineId);
                if (commitForClientTable != NULL) {
                        List<Long> commitLocalSequenceNumbers = new ArrayList<Long>(commitForClientTable.keySet());
                        Collections.sort(commitLocalSequenceNumbers);
@@ -1626,7 +1626,7 @@ final class Table {
 
                // Iterate through all the machine Ids that we received new parts for
                for (Long machineId : newTransactionParts.keySet()) {
-                       Map<Pair<Long, Integer>, TransactionPart> parts = newTransactionParts.get(machineId);
+                       Hashtable<Pair<Long, Integer>, TransactionPart> parts = newTransactionParts.get(machineId);
 
                        // Iterate through all the parts for that machine Id
                        for (Pair<Long, Integer> partId : parts.keySet()) {
@@ -1675,7 +1675,7 @@ final class Table {
                Collections.sort(transactionSequenceNumbers);
 
                // Collection of key value pairs that are
-               Map<IoTString, KeyValue> speculativeTableTmp = new HashMap<IoTString, KeyValue>();
+               Hashtable<IoTString, KeyValue> speculativeTableTmp = new Hashtable<IoTString, KeyValue>();
 
                // The last transaction arbitrated on
                int64_t lastTransactionCommitted = -1;
@@ -2000,18 +2000,18 @@ final class Table {
 
                // Iterate through all the machine Ids that we received new parts for
                for (Long machineId : newCommitParts.keySet()) {
-                       Map<Pair<Long, Integer>, CommitPart> parts = newCommitParts.get(machineId);
+                       Hashtable<Pair<Long, Integer>, CommitPart> parts = newCommitParts.get(machineId);
 
                        // Iterate through all the parts for that machine Id
                        for (Pair<Long, Integer> partId : parts.keySet()) {
                                CommitPart part = parts.get(partId);
 
                                // Get the transaction object for that sequence number
-                               Map<Long, Commit> commitForClientTable = liveCommitsTable.get(part.getMachineId());
+                               Hashtable<Long, Commit> commitForClientTable = liveCommitsTable.get(part.getMachineId());
 
                                if (commitForClientTable == NULL) {
                                        // This is the first commit from this device
-                                       commitForClientTable = new HashMap<Long, Commit>();
+                                       commitForClientTable = new Hashtable<Long, Commit>();
                                        liveCommitsTable.put(part.getMachineId(), commitForClientTable);
                                }
 
@@ -2040,7 +2040,7 @@ final class Table {
                for (Long arbitratorId : liveCommitsTable.keySet()) {
 
                        // Get all the commits for a specific arbitrator
-                       Map<Long, Commit> commitForClientTable = liveCommitsTable.get(arbitratorId);
+                       Hashtable<Long, Commit> commitForClientTable = liveCommitsTable.get(arbitratorId);
 
                        // Sort the commits in order
                        List<Long> commitSequenceNumbers = new ArrayList<Long>(commitForClientTable.keySet());
@@ -2553,11 +2553,11 @@ final class Table {
                }
 
                // This part is still alive
-               Map<Pair<Long, Integer>, TransactionPart> transactionPart = newTransactionParts.get(entry.getMachineId());
+               Hashtable<Pair<Long, Integer>, TransactionPart> transactionPart = newTransactionParts.get(entry.getMachineId());
 
                if (transactionPart == NULL) {
                        // Dont have a table for this machine Id yet so make one
-                       transactionPart = new HashMap<Pair<Long, Integer>, TransactionPart>();
+                       transactionPart = new Hashtable<Pair<Long, Integer>, TransactionPart>();
                        newTransactionParts.put(entry.getMachineId(), transactionPart);
                }
 
@@ -2587,11 +2587,11 @@ final class Table {
 
 
 
-               Map<Pair<Long, Integer>, CommitPart> commitPart = newCommitParts.get(entry.getMachineId());
+               Hashtable<Pair<Long, Integer>, CommitPart> commitPart = newCommitParts.get(entry.getMachineId());
 
                if (commitPart == NULL) {
                        // Don't have a table for this machine Id yet so make one
-                       commitPart = new HashMap<Pair<Long, Integer>, CommitPart>();
+                       commitPart = new Hashtable<Pair<Long, Integer>, CommitPart>();
                        newCommitParts.put(entry.getMachineId(), commitPart);
                }