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 d137a75e1611b1e36cc02700f8baa14061355b95..ea7c36e13827f2aee97c1545f4852d60167461c0 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 691a78f9609118aa8d00c3467606bb8380dbf825..8dba5a3ad99fa71045bbc1141d2a73ace5f14083 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 2f0e3dde4623ca82846be88a42c80e9a4318bff3..f18bd70f6e0db72add125e1370a3f7e94ccaff7e 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 1b47b06d488d66e5fd4c336ce621fde6a311329b..fef588e529564e434c95ce9cddc9304da3ed3d99 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 c7b6a8a04dd1c773f233beb69b5c42f8417d7c34..51f8f888f81e2f491b4629277de15496c17d6373 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 513d31198e5e379b6576c941a353e5b789080240..c642804f99433c1ab221ae6c220c2345459d2346 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;
        }
 
        /**