edits
authorbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 02:58:32 +0000 (18:58 -0800)
committerbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 02:58:32 +0000 (18:58 -0800)
version2/src/C/CommitPart.cc
version2/src/C/Transaction.cc
version2/src/C/Transaction.h
version2/src/C/TransactionPart.cc
version2/src/C/TransactionPart.h
version2/src/C/hashtable.h

index d137a75..ea7c36e 100644 (file)
@@ -20,7 +20,7 @@ int CommitPart::getSize() {
        return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data->length();
 }
 
-void CommitPart::setSlot(Slots) {
+void CommitPart::setSlot(Slot *s) {
        parentslot = s;
 }
 
index 691a78f..8dba5a3 100644 (file)
@@ -1,4 +1,9 @@
 #include "Transaction.h"
+#include "TransactionPart.h"
+#include "KeyValue.h"
+#include "ByteBuffer.h"
+#include "IoTString.h"
+#include "TransactionStatus.h"
 
 Transaction::Transaction() :
        parts(new Hashtable<int32_t, TransactionPart *>()),
@@ -43,7 +48,7 @@ void Transaction::addPartDecode(TransactionPart *newPart) {
        clientLocalSequenceNumber = newPart->getClientLocalSequenceNumber();
        machineId = newPart->getMachineId();
 
-       TransactionPart previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
+       TransactionPart previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
 
        if (previoslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
@@ -117,7 +122,7 @@ TransactionPart *Transaction::getNextPartToSend() {
        if ((partsPendingSend->size() == 0) || (partsPendingSend->size() == nextPartToSend)) {
                return NULL;
        }
-       TransactionPart part = parts->get(partsPendingSend->get(nextPartToSend));
+       TransactionPart *part = parts->get(partsPendingSend->get(nextPartToSend));
        nextPartToSend++;
        return part;
 }
@@ -193,7 +198,7 @@ void Transaction::setDead() {
 
        // Make all the parts of this transaction dead
        for (int32_t partNumber : parts->keySet()) {
-               TransactionPart part = parts->get(partNumber);
+               TransactionPart* part = parts->get(partNumber);
                part->setDead();
        }
 }
@@ -207,22 +212,22 @@ void Transaction::decodeTransactionData() {
        // Calculate the size of the data section
        int dataSize = 0;
        for (int i = 0; i < parts->keySet()->size(); i++) {
-               TransactionPart tp = parts->get(i);
+               TransactionPart *tp = parts->get(i);
                dataSize += tp->getDataSize();
        }
 
-       Array<char> *combinedData = new char[dataSize];
+       Array<char> *combinedData = new Array<char>(dataSize);
        int currentPosition = 0;
 
        // Stitch all the data sections together
        for (int i = 0; i < parts->keySet()->size(); i++) {
-               TransactionPart tp = parts->get(i);
+               TransactionPart *tp = parts->get(i);
                System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
                currentPosition += tp->getDataSize();
        }
 
        // Decoder Object
-       ByteBuffer bbDecode = ByteBuffer_wrap(combinedData);
+       ByteBuffer* bbDecode = ByteBuffer_wrap(combinedData);
 
        // Decode how many key value pairs need to be decoded
        int numberOfKVGuards = bbDecode->getInt();
@@ -230,13 +235,13 @@ void Transaction::decodeTransactionData() {
 
        // Decode all the guard key values
        for (int i = 0; i < numberOfKVGuards; i++) {
-               KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+               KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
                keyValueGuardSet->add(kv);
        }
 
        // Decode all the updates key values
        for (int i = 0; i < numberOfKVUpdates; i++) {
-               KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+               KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
                keyValueUpdateSet->add(kv);
        }
 }
@@ -245,7 +250,7 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKey
        for (KeyValue *kvGuard : keyValueGuardSet) {
 
                // First check if the key is in the speculative table, this is the value of the latest assumption
-               KeyValue * kv = NULL;
+               KeyValue *kv = NULL;
 
                // If we have a speculation table then use it first
                if (pendingTransactionSpeculatedKeyValueTable != NULL) {
@@ -268,9 +273,9 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKey
 
 
                                if (kv != NULL) {
-                                       System.out.println(kvGuard->getValue() + "       " + kv->getValue());
+                                       printf("%s      %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
                                } else {
-                                       System.out.println(kvGuard->getValue() + "       " + kv);
+                                       printf("%s      null\n", kvGuard->getValue()->internalBytes()->internalArray());
                                }
 
                                return false;
index 2f0e3dd..f18bd70 100644 (file)
@@ -17,7 +17,7 @@ private:
        int64_t clientLocalSequenceNumber;
        int64_t arbitratorId;
        int64_t machineId;
-       Pair<uint64_t, uint64_t> *transactionId;
+       Pair<int64_t, int64_t> *transactionId;
        int nextPartToSend;
        bool flddidSendAPartToServer;
        TransactionStatus *transactionStatus;
index 1b47b06..fef588e 100644 (file)
@@ -68,7 +68,7 @@ Entry *TransactionPart_decode(Slot *s, ByteBuffer *bb) {
        Array<char> *data = new Array<char>(dataSize);
        bb->get(data);
 
-       TransactionPart * returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
+       TransactionPart *returnTransactionPart = new TransactionPart(s, machineId, arbitratorId, clientLocalSequenceNumber, partNumber, data, isLastPart);
        returnTransactionPart->setSequenceNumber(sequenceNumber);
 
        return returnTransactionPart;
index c7b6a8a..51f8f88 100644 (file)
@@ -35,7 +35,7 @@ public:
        }
 
        int getSize();
-       void setSlot(Slots);
+       void setSlot(Slot *s);
        Pair<int64_t, int64_t> *getTransactionId();
        int64_t getArbitratorId();
        Pair<int64_t, int32_t> *getPartId();
index 513d311..c642804 100644 (file)
@@ -190,16 +190,19 @@ public:
         * @param key The key for the new value; must not be 0 or NULL
         * @param val The value to store in the table
         */
-       void put(_Key key, _Val val) {
+       _Val put(_Key key, _Val val) {
                /* Hashtable cannot handle 0 as a key */
                if (!key) {
+                       _Val oldval;
                        if (!zero) {
                                zero = (struct Hashlistnode<_Key, _Val> *)ourmalloc(sizeof(struct Hashlistnode<_Key, _Val>));
                                size++;
-                       }
+                               oldval = (_Val) 0;
+                       } else
+                               oldval = zero->val;
                        zero->key = key;
                        zero->val = val;
-                       return;
+                       return oldval;
                }
 
                if (size > threshold)
@@ -218,8 +221,9 @@ public:
                        }
                        if (search->hashcode == hashcode)
                                if (equals(search->key, key)) {
+                                       _Val oldval = search->val;
                                        search->val = val;
-                                       return;
+                                       return oldval;
                                }
                        index++;
                } while (true);
@@ -228,6 +232,7 @@ public:
                search->val = val;
                search->hashcode = hashcode;
                size++;
+               return (_Val) 0;
        }
 
        /**