more edits
authorbdemsky <bdemsky@uci.edu>
Fri, 19 Jan 2018 01:26:20 +0000 (17:26 -0800)
committerbdemsky <bdemsky@uci.edu>
Fri, 19 Jan 2018 01:26:20 +0000 (17:26 -0800)
version2/src/C/NewKey.cc
version2/src/C/NewKey.h
version2/src/C/PendingTransaction.cc
version2/src/C/PendingTransaction.h
version2/src/C/SlotIndexer.cc
version2/src/C/SlotIndexer.h
version2/src/C/ThreeTuple.cc [deleted file]
version2/src/C/ThreeTuple.h
version2/src/C/TimingSingleton.cc [deleted file]
version2/src/C/TimingSingleton.h
version2/src/C/common.h

index 745f22d977d31d072ff9dc35b4a5a44147e9cfdd..85a5234a94b58b4af202534a42a394deb7a63efe 100644 (file)
@@ -1,59 +1,22 @@
+#include "NewKey.h"
+#include "ByteBuffer.h"
+
+Entry * decode(Slot * slot, ByteBuffer * bb) {
+       int keylength = bb->getInt();
+       Array<char> * key = new Array<char>(keylength);
+       bb->get(key);
+       int64_t machineid = bb->getLong();
+       
+       return new NewKey(slot, IoTString.shallow(key), machineid);
+}
 
+void NewKey::encode(ByteBuffer * bb) {
+       bb->put(TypeNewKey);
+       bb->putInt(key->length());
+       bb->put(key->internalBytes());
+       bb->putLong(machineid);
+}
 
-/**
- * This Entry records the abort sent by a given machine.
- * @author Ali Younis <ayounis@uci.edu>
- * @version 1.0
- */
-
-
-class NewKey extends Entry {
-       IoTString key;
-       int64_t machineid;
-
-       NewKey(Slot slot, IoTString _key, int64_t _machineid) {
-               super(slot);
-               key = _key;
-               machineid = _machineid;
-       }
-
-       int64_t getMachineID() {
-               return machineid;
-       }
-
-       IoTString getKey() {
-               return key;
-       }
-
-       void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       static Entry decode(Slot slot, ByteBuffer bb) {
-               int keylength = bb.getInt();
-               char[] key = new char[keylength];
-               bb.get(key);
-               int64_t machineid = bb.getLong();
-
-               return new NewKey(slot, IoTString.shallow(key), machineid);
-       }
-
-       void encode(ByteBuffer bb) {
-               bb.put(Entry.TypeNewKey);
-               bb.putInt(key.length());
-               bb.put(key.internalBytes());
-               bb.putLong(machineid);
-       }
-
-       int getSize() {
-               return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
-       }
-
-       char getType() {
-               return Entry.TypeNewKey;
-       }
-
-       Entry getCopy(Slot s) {
-               return new NewKey(s, key, machineid);
-       }
+int NewKey::getSize() {
+       return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
 }
index 73c6400e7f78a075a2b7a4208137c6b4329b01cd..53a8f8c37d272d23cc8537a16d25f752d0146c36 100644 (file)
@@ -1,4 +1,5 @@
-
+#ifndef NEWKEY_H
+#define NEWKEY_H
 
 /**
  * This Entry records the abort sent by a given machine.
@@ -7,53 +8,30 @@
  */
 
 
-class NewKey extends Entry {
-       private IoTString key;
-       private int64_t machineid;
-
-       public NewKey(Slot slot, IoTString _key, int64_t _machineid) {
-               super(slot);
-               key = _key;
-               machineid = _machineid;
-       }
-
-       public int64_t getMachineID() {
-               return machineid;
-       }
-
-       public IoTString getKey() {
-               return key;
-       }
-
-       public void setSlot(Slot s) {
-               parentslot = s;
-       }
-
-       static Entry decode(Slot slot, ByteBuffer bb) {
-               int keylength = bb.getInt();
-               char[] key = new char[keylength];
-               bb.get(key);
-               int64_t machineid = bb.getLong();
-
-               return new NewKey(slot, IoTString.shallow(key), machineid);
-       }
-
-       public void encode(ByteBuffer bb) {
-               bb.put(Entry.TypeNewKey);
-               bb.putInt(key.length());
-               bb.put(key.internalBytes());
-               bb.putLong(machineid);
-       }
-
-       public int getSize() {
-               return sizeof(int64_t) + sizeof(char) + sizeof(int32_t) + key.length();
-       }
-
-       public char getType() {
-               return Entry.TypeNewKey;
-       }
-
-       public Entry getCopy(Slot s) {
-               return new NewKey(s, key, machineid);
-       }
-}
+class NewKey : public Entry {
+ private:
+       IoTString * key;
+       int64_t machineid;
+
+
+ public:
+ NewKey(Slot * slot, IoTString * _key, int64_t _machineid) :
+       Entry(slot),
+               key(_key),
+               machineid(_machineid) {
+               }
+       
+       int64_t getMachineID() { return machineid; }
+       IoTString * getKey() { return key; }
+       void setSlot(Slot * s) { parentslot = s; }
+       
+
+       void encode(ByteBuffer * bb);
+       int getSize();
+       char getType() { return TypeNewKey; }
+        
+       Entry * getCopy(Slot * s) { return new NewKey(s, key, machineid); }
+};
+
+Entry * NewKey_decode(Slot *slot, ByteBuffer *bb);
+
index 5495e35bdfc0b690f09089a46c0b657f6f5999ac..0d45dc2a853caa4d4d29d4bc7b07c8f2144a933f 100644 (file)
+#include "PendingTransaction.h"
+
+PendingTransaction::PendingTransaction(int64_t _machineId) :
+       keyValueUpdateSet(new Hashset<KeyValue*>()),
+       keyValueGuardSet(new HashSet<KeyValue*>()),
+       arbitrator(-1),
+       clientLocalSequenceNumber(-1),
+       machineId(_machineId),
+       currentDataSize(0) {
+}
 
+/**
+ * Add a new key value to the updates
+ *
+ */
+void PendingTransaction::addKV(KeyValue * newKV) {
+
+       KeyValue rmKV = NULL;
+
+       // Make sure there are no duplicates
+       for (KeyValue kv : keyValueUpdateSet) {
+               if (kv.getKey().equals(newKV.getKey())) {
+                       
+                       // Remove key if we are adding a newer version of the same key
+                       rmKV = kv;
+                       break;
+               }
+       }
+       
+       // Remove key if we are adding a newer version of the same key
+       if (rmKV != NULL) {
+               keyValueUpdateSet.remove(rmKV);
+               currentDataSize -= rmKV.getSize();
+       }
+       
+       // Add the key to the hash set
+       keyValueUpdateSet.add(newKV);
+       currentDataSize += newKV.getSize();
+}
 
+/**
+ * Add a new key value to the guard set
+ *
+ */
+void PendingTransaction::addKVGuard(KeyValue * newKV) {
+       // Add the key to the hash set
+       keyValueGuardSet.add(newKV);
+       currentDataSize += newKV.getSize();
+}
 
+/**
+ * Checks if the arbitrator is the same
+ */
+bool PendingTransaction::checkArbitrator(int64_t arb) {
+       if (arbitrator == -1) {
+               arbitrator = arb;
+               return true;
+       }
+       
+       return arb == arbitrator;
+}
 
-class PendingTransaction {
-
-    Set<KeyValue> keyValueUpdateSet = NULL;
-    Set<KeyValue> keyValueGuardSet = NULL;
-    int64_t arbitrator = -1;
-    int64_t clientLocalSequenceNumber = -1;
-    int64_t machineId = -1;
-
-    int currentDataSize = 0;
-
-    PendingTransaction(int64_t _machineId) {
-        machineId = _machineId;
-        keyValueUpdateSet = new HashSet<KeyValue>();
-        keyValueGuardSet = new HashSet<KeyValue>();
-    }
-
-    /**
-     * Add a new key value to the updates
-     *
-     */
-    void addKV(KeyValue newKV) {
-
-        KeyValue rmKV = NULL;
-
-        // Make sure there are no duplicates
-        for (KeyValue kv : keyValueUpdateSet) {
-            if (kv.getKey().equals(newKV.getKey())) {
-
-                // Remove key if we are adding a newer version of the same key
-                rmKV = kv;
-                break;
-            }
-        }
-
-        // Remove key if we are adding a newer version of the same key
-        if (rmKV != NULL) {
-            keyValueUpdateSet.remove(rmKV);
-            currentDataSize -= rmKV.getSize();
-        }
-
-        // Add the key to the hash set
-        keyValueUpdateSet.add(newKV);
-        currentDataSize += newKV.getSize();
-    }
-
-    /**
-     * Add a new key value to the guard set
-     *
-     */
-    void addKVGuard(KeyValue newKV) {
-        // Add the key to the hash set
-        keyValueGuardSet.add(newKV);
-        currentDataSize += newKV.getSize();
-    }
-
-    /**
-     * Checks if the arbitrator is the same
-     */
-    bool checkArbitrator(int64_t arb) {
-        if (arbitrator == -1) {
-            arbitrator = arb;
-            return true;
-        }
-
-        return arb == arbitrator;
-    }
-
-    /**
-     * Get the transaction arbitrator
-     */
-    int64_t getArbitrator() {
-        return arbitrator;
-    }
-
-    /**
-     * Get the key value update set
-     */
-    Set<KeyValue> getKVUpdates() {
-        return keyValueUpdateSet;
-    }
-
-    /**
-     * Get the key value update set
-     */
-    Set<KeyValue> getKVGuard() {
-        return keyValueGuardSet;
-    }
-
-    void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) {
-        clientLocalSequenceNumber = _clientLocalSequenceNumber;
-    }
-
-    int64_t getClientLocalSequenceNumber() {
-        return clientLocalSequenceNumber;
-    }
-
-    int64_t getMachineId() {
-        return machineId;
-    }
-
-    bool evaluateGuard(Map<IoTString, KeyValue> keyValTableCommitted, Map<IoTString, KeyValue> keyValTableSpeculative, Map<IoTString, KeyValue> keyValTablePendingTransSpeculative) {
-        for (KeyValue kvGuard : keyValueGuardSet) {
-
-            // First check if the key is in the speculative table, this is the value of the latest assumption
-            KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
-
-
-            if (kv == NULL) {
-                // if it is not in the pending trans table then check the speculative table and use that
-                // value as our latest assumption
-                kv = keyValTableSpeculative.get(kvGuard.getKey());
-            }
-
-
-            if (kv == NULL) {
-                // if it is not in the speculative table then check the committed table and use that
-                // value as our latest assumption
-                kv = keyValTableCommitted.get(kvGuard.getKey());
-            }
-
-            if (kvGuard.getValue() != NULL) {
-                if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
-                    return false;
-                }
-            } else {
-                if (kv != NULL) {
-                    return false;
-                }
-            }
+bool PendingTransaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> keyValTableCommitted, Hashtable<IoTString *, KeyValue *> keyValTableSpeculative, Hashtable<IoTString *, KeyValue *> keyValTablePendingTransSpeculative) {
+       for (KeyValue kvGuard : keyValueGuardSet) {
+               
+               // First check if the key is in the speculative table, this is the value of the latest assumption
+               KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
+               
+               
+               if (kv == NULL) {
+                       // if it is not in the pending trans table then check the speculative table and use that
+                       // value as our latest assumption
+                       kv = keyValTableSpeculative.get(kvGuard.getKey());
+               }
+               
+               
+               if (kv == NULL) {
+                       // if it is not in the speculative table then check the committed table and use that
+                       // value as our latest assumption
+                       kv = keyValTableCommitted.get(kvGuard.getKey());
+               }
+               
+               if (kvGuard.getValue() != NULL) {
+                       if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
+                               return false;
+                       }
+               } else {
+                       if (kv != NULL) {
+                               return false;
+                       }
+               }
         }
-        return true;
-    }
-
-    Transaction createTransaction() {
-
-        Transaction newTransaction = new Transaction();
-        int transactionPartCount = 0;
-
-        // Convert all the data into a char array so we can start partitioning
-        char[] charData = convertDataToBytes();
-
-        int currentPosition = 0;
-        int remaining = charData.length;
-
-        while (remaining > 0) {
-
-            Boolean isLastPart = false;
-            // determine how much to copy
-            int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
-            if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
-                copySize = remaining;
-                isLastPart = true; // last bit of data so last part
-            }
-
-            // Copy to a smaller version
-            char[] partData = new char[copySize];
-            System.arraycopy(charData, currentPosition, partData, 0, copySize);
-
-            TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
-            newTransaction.addPartEncode(part);
+       return true;
+}
 
+Transaction * PendingTransaction::createTransaction() {
+       Transaction * newTransaction = new Transaction();
+       int transactionPartCount = 0;
+       
+       // Convert all the data into a char array so we can start partitioning
+       Array<char> * charData = convertDataToBytes();
+       
+       int currentPosition = 0;
+       int remaining = charData.length;
+       
+       while (remaining > 0) {
+               
+               Boolean isLastPart = false;
+               // determine how much to copy
+               int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
+               if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
+                       copySize = remaining;
+                       isLastPart = true; // last bit of data so last part
+               }
+               
+               // Copy to a smaller version
+               char[] partData = new char[copySize];
+               System.arraycopy(charData, currentPosition, partData, 0, copySize);
+               
+               TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
+               newTransaction.addPartEncode(part);
+               
             // Update position, count and remaining
-            currentPosition += copySize;
-            transactionPartCount++;
-            remaining -= copySize;
-        }
-
-        // Add the Guard Conditions
-        for (KeyValue kv : keyValueGuardSet) {
-            newTransaction.addGuardKV(kv);
-        }
-
-        //  Add the updates
-        for (KeyValue kv : keyValueUpdateSet) {
-            newTransaction.addUpdateKV(kv);
-        }
-
-        return newTransaction;
-    }
-
-    char[] convertDataToBytes() {
-
-        // Calculate the size of the data
-        int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
-        sizeOfData += currentDataSize;
-
-        // Data handlers and storage
-        char[] dataArray = new char[sizeOfData];
-        ByteBuffer bbEncode = ByteBuffer.wrap(dataArray);
-
-        // Encode the size of the updates and guard sets
-        bbEncode.putInt(keyValueGuardSet.size());
-        bbEncode.putInt(keyValueUpdateSet.size());
-
-        // Encode all the guard conditions
-        for (KeyValue kv : keyValueGuardSet) {
-            kv.encode(bbEncode);
-        }
-
-        // Encode all the updates
-        for (KeyValue kv : keyValueUpdateSet) {
-            kv.encode(bbEncode);
-        }
+               currentPosition += copySize;
+               transactionPartCount++;
+               remaining -= copySize;
+       }
+       
+       // Add the Guard Conditions
+       for (KeyValue kv : keyValueGuardSet) {
+               newTransaction.addGuardKV(kv);
+       }
+       
+       //  Add the updates
+       for (KeyValue kv : keyValueUpdateSet) {
+               newTransaction.addUpdateKV(kv);
+       }
+       
+       return newTransaction;
+}
 
-        return bbEncode.array();
-    }
+Arrar<char> * PendingTransaction::convertDataToBytes() {
+       // Calculate the size of the data
+       int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
+       sizeOfData += currentDataSize;
+       
+       // Data handlers and storage
+       Array<char> * dataArray = new Array<char>(sizeOfData);
+       ByteBuffer * bbEncode = ByteBuffer_wrap(dataArray);
+       
+       // Encode the size of the updates and guard sets
+       bbEncode->putInt(keyValueGuardSet.size());
+       bbEncode->putInt(keyValueUpdateSet.size());
+       
+       // Encode all the guard conditions
+       for (KeyValue kv : keyValueGuardSet) {
+               kv->encode(bbEncode);
+       }
+
+       // Encode all the updates
+       for (KeyValue kv : keyValueUpdateSet) {
+               kv->encode(bbEncode);
+       }
+
+       return bbEncode->array();
 }
+
index 0e4249ba196ee9790f5c4cd5c81df6d89bd701d0..7e60ce865a25adcefebaf34fba9f5df73cfdff83 100644 (file)
+#ifndef PENDINGTRANSACTION_H
+#define PENDINGTRANSACTION_H
 
-
-
+#include "common.h"
 
 class PendingTransaction {
-
-    private Set<KeyValue> keyValueUpdateSet = NULL;
-    private Set<KeyValue> keyValueGuardSet = NULL;
-    private int64_t arbitrator = -1;
-    private int64_t clientLocalSequenceNumber = -1;
-    private int64_t machineId = -1;
-
-    private int currentDataSize = 0;
-
-    public PendingTransaction(int64_t _machineId) {
-        machineId = _machineId;
-        keyValueUpdateSet = new HashSet<KeyValue>();
-        keyValueGuardSet = new HashSet<KeyValue>();
-    }
-
-    /**
-     * Add a new key value to the updates
-     *
-     */
-    public void addKV(KeyValue newKV) {
-
-        KeyValue rmKV = NULL;
-
-        // Make sure there are no duplicates
-        for (KeyValue kv : keyValueUpdateSet) {
-            if (kv.getKey().equals(newKV.getKey())) {
-
-                // Remove key if we are adding a newer version of the same key
-                rmKV = kv;
-                break;
-            }
-        }
-
-        // Remove key if we are adding a newer version of the same key
-        if (rmKV != NULL) {
-            keyValueUpdateSet.remove(rmKV);
-            currentDataSize -= rmKV.getSize();
-        }
-
-        // Add the key to the hash set
-        keyValueUpdateSet.add(newKV);
-        currentDataSize += newKV.getSize();
-    }
-
-    /**
-     * Add a new key value to the guard set
-     *
-     */
-    public void addKVGuard(KeyValue newKV) {
-        // Add the key to the hash set
-        keyValueGuardSet.add(newKV);
-        currentDataSize += newKV.getSize();
-    }
-
-    /**
-     * Checks if the arbitrator is the same
-     */
-    public bool checkArbitrator(int64_t arb) {
-        if (arbitrator == -1) {
-            arbitrator = arb;
-            return true;
-        }
-
-        return arb == arbitrator;
-    }
-
-    /**
-     * Get the transaction arbitrator
-     */
-    public int64_t getArbitrator() {
-        return arbitrator;
-    }
-
-    /**
-     * Get the key value update set
-     */
-    public Set<KeyValue> getKVUpdates() {
-        return keyValueUpdateSet;
-    }
-
-    /**
-     * Get the key value update set
-     */
-    public Set<KeyValue> getKVGuard() {
-        return keyValueGuardSet;
-    }
-
-    public void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) {
-        clientLocalSequenceNumber = _clientLocalSequenceNumber;
-    }
-
-    public int64_t getClientLocalSequenceNumber() {
-        return clientLocalSequenceNumber;
-    }
-
-    public int64_t getMachineId() {
-        return machineId;
-    }
-
-    public bool evaluateGuard(Map<IoTString, KeyValue> keyValTableCommitted, Map<IoTString, KeyValue> keyValTableSpeculative, Map<IoTString, KeyValue> keyValTablePendingTransSpeculative) {
-        for (KeyValue kvGuard : keyValueGuardSet) {
-
-            // First check if the key is in the speculative table, this is the value of the latest assumption
-            KeyValue kv = keyValTablePendingTransSpeculative.get(kvGuard.getKey());
-
-
-            if (kv == NULL) {
-                // if it is not in the pending trans table then check the speculative table and use that
-                // value as our latest assumption
-                kv = keyValTableSpeculative.get(kvGuard.getKey());
-            }
-
-
-            if (kv == NULL) {
-                // if it is not in the speculative table then check the committed table and use that
-                // value as our latest assumption
-                kv = keyValTableCommitted.get(kvGuard.getKey());
-            }
-
-            if (kvGuard.getValue() != NULL) {
-                if ((kv == NULL) || (!kvGuard.getValue().equals(kv.getValue()))) {
-                    return false;
-                }
-            } else {
-                if (kv != NULL) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    public Transaction createTransaction() {
-
-        Transaction newTransaction = new Transaction();
-        int transactionPartCount = 0;
-
-        // Convert all the data into a char array so we can start partitioning
-        char[] charData = convertDataToBytes();
-
-        int currentPosition = 0;
-        int remaining = charData.length;
-
-        while (remaining > 0) {
-
-            Boolean isLastPart = false;
-            // determine how much to copy
-            int copySize = TransactionPart.MAX_NON_HEADER_SIZE;
-            if (remaining <= TransactionPart.MAX_NON_HEADER_SIZE) {
-                copySize = remaining;
-                isLastPart = true; // last bit of data so last part
-            }
-
-            // Copy to a smaller version
-            char[] partData = new char[copySize];
-            System.arraycopy(charData, currentPosition, partData, 0, copySize);
-
-            TransactionPart part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart);
-            newTransaction.addPartEncode(part);
-
-            // Update position, count and remaining
-            currentPosition += copySize;
-            transactionPartCount++;
-            remaining -= copySize;
-        }
-
-        // Add the Guard Conditions
-        for (KeyValue kv : keyValueGuardSet) {
-            newTransaction.addGuardKV(kv);
-        }
-
-        //  Add the updates
-        for (KeyValue kv : keyValueUpdateSet) {
-            newTransaction.addUpdateKV(kv);
-        }
-
-        return newTransaction;
-    }
-
-    private char[] convertDataToBytes() {
-
-        // Calculate the size of the data
-        int sizeOfData = 2 * sizeof(int32_t); // Number of Update KV's and Guard KV's
-        sizeOfData += currentDataSize;
-
-        // Data handlers and storage
-        char[] dataArray = new char[sizeOfData];
-        ByteBuffer bbEncode = ByteBuffer.wrap(dataArray);
-
-        // Encode the size of the updates and guard sets
-        bbEncode.putInt(keyValueGuardSet.size());
-        bbEncode.putInt(keyValueUpdateSet.size());
-
-        // Encode all the guard conditions
-        for (KeyValue kv : keyValueGuardSet) {
-            kv.encode(bbEncode);
-        }
-
-        // Encode all the updates
-        for (KeyValue kv : keyValueUpdateSet) {
-            kv.encode(bbEncode);
-        }
-
-        return bbEncode.array();
-    }
-}
+ private:
+       Hashset<KeyValue*> * keyValueUpdateSet = NULL;
+       Hashset<KeyValue*> * keyValueGuardSet = NULL;
+       int64_t arbitrator = -1;
+       int64_t clientLocalSequenceNumber = -1;
+  int64_t machineId = -1;
+       int32_T currentDataSize = 0;
+
+ public:
+       PendingTransaction(int64_t _machineId);
+       /**
+        * Add a new key value to the updates
+        *
+        */
+       void addKV(KeyValue newKV);
+       /**
+        * Add a new key value to the guard set
+        *
+        */
+       void addKVGuard(KeyValue newKV);
+       /**
+        * Checks if the arbitrator is the same
+        */
+       bool checkArbitrator(int64_t arb);
+       /**
+        * Get the transaction arbitrator
+        */
+       int64_t getArbitrator();
+       /**
+        * Get the key value update set
+        */
+       Hashset<KeyValue*> * getKVUpdates() { return keyValueUpdateSet; }
+
+       /**
+        * Get the key value update set
+        */
+       public Hashset<KeyValue *> * getKVGuard() { return keyValueGuardSet; }
+
+       void setClientLocalSequenceNumber(int64_t _clientLocalSequenceNumber) { clientLocalSequenceNumber = _clientLocalSequenceNumber; }
+
+       int64_t getClientLocalSequenceNumber() { return clientLocalSequenceNumber; }
+
+       int64_t getMachineId() { return machineId; }
+
+       bool evaluateGuard(Hashtable<IoTString *, KeyValue *> keyValTableCommitted, Hashtable<IoTString *, KeyValue *> keyValTableSpeculative, Hashtable<IoTString *, KeyValue *> keyValTablePendingTransSpeculative);
+
+       Transaction * createTransaction();
+
+       Array<char> * convertDataToBytes();
+};
+#endif
index f093c40c3dfb9f9760c3856fe650ff85101c6cb5..0fa6449a6b7c7ac25bff0611f9fd8a7334706b29 100644 (file)
@@ -1,3 +1,4 @@
+#include "SlotIndexer.h"
 
 /**
  * Slot indexer allows slots in both the slot buffer and the new
@@ -6,25 +7,19 @@
  * @version 1.0
  */
 
-class SlotIndexer {
-       Slot[] updates;
-       SlotBuffer buffer;
-       int64_t firstslotseqnum;
-
-       SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
-               buffer = _buffer;
-               updates = _updates;
-               firstslotseqnum = updates[0].getSequenceNumber();
-       }
+SlotIndexer::SlotIndexer(Array<Slot*> * _updates, SlotBuffer * _buffer) :
+       buffer(_buffer),
+       updates(_updates),
+       firstslotseqnum(updates->get(0)->getSequenceNumber()) {
+}
 
-       Slot getSlot(int64_t seqnum) {
-               if (seqnum >= firstslotseqnum) {
-                       int offset = (int) (seqnum - firstslotseqnum);
-                       if (offset >= updates.length)
-                               throw new Error("Invalid Slot Sequence Number Reference");
-                       else
-                               return updates[offset];
-               } else
-                       return buffer.getSlot(seqnum);
-       }
+Slot * SlotIndexer::getSlot(int64_t seqnum) {
+       if (seqnum >= firstslotseqnum) {
+               int32_t offset = (int32_t) (seqnum - firstslotseqnum);
+               if (offset >= updates->length())
+                       throw new Error("Invalid Slot Sequence Number Reference");
+               else
+                       return updates->get(offset);
+       } else
+               return buffer->getSlot(seqnum);
 }
index b69a8b89f0a2f9f3485ae67f27be55831a0a0457..c4f54eb35a7a4d8052565c8af725e95e2759ab04 100644 (file)
@@ -1,4 +1,6 @@
-
+#ifndef SLOTINDEXER_H
+#define SLOTINDEXER_H
+#include "common.h"
 /**
  * Slot indexer allows slots in both the slot buffer and the new
  * server response to looked up in a consistent fashion.
@@ -7,24 +9,13 @@
  */
 
 class SlotIndexer {
-       private Slot[] updates;
-       private SlotBuffer buffer;
-       private int64_t firstslotseqnum;
-
-       SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
-               buffer = _buffer;
-               updates = _updates;
-               firstslotseqnum = updates[0].getSequenceNumber();
-       }
+ private:
+       Array<Slot*> * updates;
+       SlotBuffer * buffer;
+       int64_t firstslotseqnum;
 
-       Slot getSlot(int64_t seqnum) {
-               if (seqnum >= firstslotseqnum) {
-                       int offset = (int) (seqnum - firstslotseqnum);
-                       if (offset >= updates.length)
-                               throw new Error("Invalid Slot Sequence Number Reference");
-                       else
-                               return updates[offset];
-               } else
-                       return buffer.getSlot(seqnum);
-       }
-}
+ public:
+       SlotIndexer(Array<Slot*> * _updates, SlotBuffer * _buffer);
+       Slot* getSlot(int64_t seqnum);
+};
+#endif;
diff --git a/version2/src/C/ThreeTuple.cc b/version2/src/C/ThreeTuple.cc
deleted file mode 100644 (file)
index eed94d0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-
-class ThreeTuple<A, B, C> {
-    A a;
-    B b;
-    C c;
-
-    ThreeTuple(A a, B b, C c) {
-        this.a = a;
-        this.b = b;
-        this.c = c;
-    }
-
-    A getFirst() {
-        return a;
-    }
-
-    B getSecond() {
-        return b;
-    }
-
-    C getThird() {
-        return c;
-    }
-
-    String toString() {
-        return "<" + a + "," + b + "," + c + ">";
-    }
-}
index 5522121c91300070d238d539406422a0265e7ba8..ef5bcb535366bc963d83eb8f9ed9cc8135b71eef 100644 (file)
@@ -1,28 +1,27 @@
+#ifndef THREETUPLE_H
+#define THREETUPLE_H
 
-class ThreeTuple<A, B, C> {
-    private A a;
-    private B b;
-    private C c;
+template<typename A, typename B, typename C>
+       class ThreeTuple {
+ private:
+       A a;
+       B b;
+       C c;
 
-    ThreeTuple(A a, B b, C c) {
-        this.a = a;
-        this.b = b;
-        this.c = c;
-    }
-
-    A getFirst() {
-        return a;
-    }
-
-    B getSecond() {
-        return b;
-    }
-
-    C getThird() {
-        return c;
-    }
-
-    public String toString() {
-        return "<" + a + "," + b + "," + c + ">";
-    }
-}
+ public:
+ ThreeTuple(A _a, B _b, C _c) :
+       a(_a),
+               b(_b),
+               c(_c) {
+               }
+       A getFirst() {
+               return a;
+       }
+       B getSecond() {
+               return b;
+       }
+       C getThird() {
+               return c;
+       }
+};
+#endif
diff --git a/version2/src/C/TimingSingleton.cc b/version2/src/C/TimingSingleton.cc
deleted file mode 100644 (file)
index 57e4f04..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-class TimingSingleton {
-    static TimingSingleton singleton = new TimingSingleton( );
-    static int64_t startTime = 0;
-
-    static int64_t totalTime = 0;
-
-    TimingSingleton() {
-
-    }
-
-    static TimingSingleton getInstance( ) {
-        return singleton;
-    }
-
-
-    static void startTime( ) {
-        startTime = System.nanoTime();
-    }
-
-    static void endTime( ) {
-        totalTime += System.nanoTime() - startTime;
-
-    }
-
-    static int64_t getTime( ) {
-        return totalTime;
-    }
-
-
-}
index a6e1aac5cd9cd7f4d1a60dd3276cf89121a932de..4983f81a16032b94ec1f1e3bce9e866730c7b3f8 100644 (file)
@@ -1,32 +1,40 @@
-
+#ifndef TIMINGSINGLETON_H
+#define TIMINGSINGLETON_H
+#include <sys/time.h>
 
 class TimingSingleton {
-    private static TimingSingleton singleton = new TimingSingleton( );
-    private static int64_t startTime = 0;
-
-    private static int64_t totalTime = 0;
-
-    private TimingSingleton() {
-
-    }
-
-    public static TimingSingleton getInstance( ) {
-        return singleton;
-    }
-
-
-    public static void startTime( ) {
-        startTime = System.nanoTime();
-    }
-
-    public static void endTime( ) {
-        totalTime += System.nanoTime() - startTime;
-
-    }
-
-    public static int64_t getTime( ) {
-        return totalTime;
-    }
-
-
+ private:
+       static TimingSingleton singleton = new TimingSingleton( );
+       int64_t startTime = 0;
+       int64_t totalTime = 0;
+       
+ TimingSingleton() : startTime(0),
+               totalTime(0) {
+       }
+
+       int64_t nanoTime() {
+               int64_t time;
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+               return tv.tv_sec*1000000000+tv.tv_usec*1000;
+       }
+       
+ public:
+       void startTime() {
+               startTime = nanoTime();
+       }
+       
+       void endTime() {
+               totalTime += nanoTime() - startTime;
+       }
+
+       int64_t getTime() {
+               return totalTime;
+       }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton * TimingSingleton_getInstance() {
+       return &t_singleton;
 }
+#endif
index 4803b60324198e17d8a96f5dbe02cf688a7bd4c4..764c2f283658f57561922bab995cdafd65414f4b 100644 (file)
@@ -10,7 +10,7 @@ typedef uint32_t uint;
 #include "array.h"
 
 
-
+class TimingSingleton;
 class Abort;
 class Entry;
 class Slot;
@@ -22,5 +22,6 @@ class ArbitrationRound;
 class KeyValue;
 class IoTString;
 class RejectedMessage;
+class PendingTransaction;
 
 #endif