edits
[iotcloud.git] / version2 / src / C / Table.h
index 7cc98abc2ff24dae7f6be3a777b36c2ed0a8d591..99abb55faf25417ed493280873f6e6d62c58d77a 100644 (file)
@@ -3,6 +3,8 @@
 #include "common.h"
 #include "Pair.h"
 #include "ThreeTuple.h"
+#include "IoTString.h"
+
 /**
  * IoTTable data structure.  Provides client interface.
  * @author Brian Demsky
@@ -22,7 +24,7 @@ private:
        /* Helper Objects */
        SlotBuffer *buffer;
        CloudComm *cloud;
-       Random *random;
+       SecureRandom *random;
        TableStatus *liveTableStatus;
        PendingTransaction *pendingTransactionBuilder;  // Pending Transaction used in building a Pending Transaction
        Transaction *lastPendingTransactionSpeculatedOn;        // Last transaction that was speculated on from the pending transaction
@@ -58,21 +60,21 @@ private:
 
 
        /* Data Structures  */
-       Hashtable<IoTString *, KeyValue *> *committedKeyValueTable;// Table of committed key value pairs
-       Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable;    // Table of speculated key value pairs, if there is a speculative value
-       Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable;  // Table of speculated key value pairs, if there is a speculative value from the pending transactions
-       Hashtable<IoTString *, NewKey *> *liveNewKeyTable;      // Table of live new keys
-       Hashtable<int64_t, Pair<int64_t, Liveness *> > *lastMessageTable;       // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
+       Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *committedKeyValueTable;// Table of committed key value pairs
+       Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *speculatedKeyValueTable;    // Table of speculated key value pairs, if there is a speculative value
+       Hashtable<IoTString *, KeyValue *, uintptr_t, 0, hashString, StringEquals> *pendingTransactionSpeculatedKeyValueTable;  // Table of speculated key value pairs, if there is a speculative value from the pending transactions
+       Hashtable<IoTString *, NewKey *, uintptr_t, 0, hashString, StringEquals> *liveNewKeyTable;      // Table of live new keys
+       Hashtable<int64_t, Pair<int64_t, Liveness *> *> *lastMessageTable;      // Last message sent by a client machine id -> (Seq Num, Slot or LastMessage);
        Hashtable<int64_t, Hashset<RejectedMessage *> *> *rejectedMessageWatchVectorTable;      // Table of machine Ids and the set of rejected messages they have not seen yet
-       Hashtable<IoTString *, int64_t> *arbitratorTable;// Table of keys and their arbitrators
-       Hashtable<Pair<int64_t, int64_t>, Abort *, uintptr_t, 0, pairHashFunction, pairEquals> *liveAbortTable;// Table live abort messages
-       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newTransactionParts;    // transaction parts that are seen in this latest round of slots from the server
-       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newCommitParts;      // commit parts that are seen in this latest round of slots from the server
+       Hashtable<IoTString *, int64_t, uintptr_t, 0, hashString, StringEquals> *arbitratorTable;// Table of keys and their arbitrators
+       Hashtable<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals> *liveAbortTable;// Table live abort messages
+       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newTransactionParts;  // transaction parts that are seen in this latest round of slots from the server
+       Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *newCommitParts;    // commit parts that are seen in this latest round of slots from the server
        Hashtable<int64_t, int64_t> *lastArbitratedTransactionNumberByArbitratorTable;  // Last transaction sequence number that an arbitrator arbitrated on
        Hashtable<int64_t, Transaction *> *liveTransactionBySequenceNumberTable;        // live transaction grouped by the sequence number
-       Hashtable<Pair<int64_t, int64_t>, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals> *liveTransactionByTransactionIdTable;      // live transaction grouped by the transaction ID
-       Hashtable<int64_t, Hashtable<int64_t, Commit *> > *liveCommitsTable;
-       Hashtable<IoTString *, Commit *> *liveCommitsByKeyTable;
+       Hashtable<Pair<int64_t, int64_t> *, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals> *liveTransactionByTransactionIdTable;    // live transaction grouped by the transaction ID
+       Hashtable<int64_t, Hashtable<int64_t, Commit *> *> *liveCommitsTable;
+       Hashtable<IoTString *, Commit *, uintptr_t, 0, hashString, StringEquals> *liveCommitsByKeyTable;
        Hashtable<int64_t, int64_t> *lastCommitSeenSequenceNumberByArbitratorTable;
        Vector<int64_t> *rejectedSlotVector;    // Vector of rejected slots that have yet to be sent to the server
        Vector<Transaction *> *pendingTransactionQueue;
@@ -81,8 +83,8 @@ private:
        Hashtable<Transaction *, Vector<int32_t> *> *transactionPartsSent;
        Hashtable<int64_t, TransactionStatus *> *outstandingTransactionStatus;
        Hashtable<int64_t, Abort *> *liveAbortsGeneratedByLocal;
-       Hashset<Pair<int64_t, int64_t>, uintptr_t, 0, pairHashFunction, pairEquals> *offlineTransactionsCommittedAndAtServer;
-       Hashtable<int64_t, Pair<IoTString *, int32_t> > *localCommunicationTable;
+       Hashset<Pair<int64_t, int64_t> *, uintptr_t, 0, pairHashFunction, pairEquals> *offlineTransactionsCommittedAndAtServer;
+       Hashtable<int64_t, Pair<IoTString *, int32_t> *> *localCommunicationTable;
        Hashtable<int64_t, int64_t> *lastTransactionSeenFromMachineFromServer;
        Hashtable<int64_t, int64_t> *lastArbitrationDataLocalSequenceNumberSeenFromArbitrator;
        bool lastInsertedNewKey;
@@ -95,9 +97,10 @@ private:
         */
        void setResizeThreshold();
        bool sendToServer(NewKey *newKey);
+       NewKey * handlePartialSend(NewKey * newKey);
        bool updateFromLocal(int64_t machineId);
        Pair<bool, bool> sendTransactionToLocal(Transaction *transaction);
-       ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsToServer(Slot *slot, int newSize, bool isNewKey);
+       bool sendSlotsToServer(Slot *slot, int newSize, bool isNewKey, bool * wasInserted, Array<Slot *> **array);
        /**
         * Returns false if a resize was needed
         */
@@ -239,6 +242,7 @@ private:
 public:
        Table(IoTString *baseurl, IoTString *password, int64_t _localMachineId, int listeningPort);
        Table(CloudComm *_cloud, int64_t _localMachineId);
+       ~Table();
 
        /**
         * Initialize the table by inserting a table status as the first entry into the table status