From: bdemsky Date: Sat, 20 Jan 2018 02:58:32 +0000 (-0800) Subject: edits X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=commitdiff_plain;h=f3fdb1f3b472981933d32c8f707f0cdc0db2f050;ds=sidebyside edits --- diff --git a/version2/src/C/CommitPart.cc b/version2/src/C/CommitPart.cc index d137a75..ea7c36e 100644 --- a/version2/src/C/CommitPart.cc +++ b/version2/src/C/CommitPart.cc @@ -20,7 +20,7 @@ int CommitPart::getSize() { return (3 * sizeof(int64_t)) + (2 * sizeof(int32_t)) + (2 * sizeof(char)) + data->length(); } -void CommitPart::setSlot(Slot* s) { +void CommitPart::setSlot(Slot *s) { parentslot = s; } diff --git a/version2/src/C/Transaction.cc b/version2/src/C/Transaction.cc index 691a78f..8dba5a3 100644 --- a/version2/src/C/Transaction.cc +++ b/version2/src/C/Transaction.cc @@ -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()), @@ -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 *combinedData = new char[dataSize]; + Array *combinedData = new Array(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 *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 *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; diff --git a/version2/src/C/Transaction.h b/version2/src/C/Transaction.h index 2f0e3dd..f18bd70 100644 --- a/version2/src/C/Transaction.h +++ b/version2/src/C/Transaction.h @@ -17,7 +17,7 @@ private: int64_t clientLocalSequenceNumber; int64_t arbitratorId; int64_t machineId; - Pair *transactionId; + Pair *transactionId; int nextPartToSend; bool flddidSendAPartToServer; TransactionStatus *transactionStatus; diff --git a/version2/src/C/TransactionPart.cc b/version2/src/C/TransactionPart.cc index 1b47b06..fef588e 100644 --- a/version2/src/C/TransactionPart.cc +++ b/version2/src/C/TransactionPart.cc @@ -68,7 +68,7 @@ Entry *TransactionPart_decode(Slot *s, ByteBuffer *bb) { Array *data = new Array(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; diff --git a/version2/src/C/TransactionPart.h b/version2/src/C/TransactionPart.h index c7b6a8a..51f8f88 100644 --- a/version2/src/C/TransactionPart.h +++ b/version2/src/C/TransactionPart.h @@ -35,7 +35,7 @@ public: } int getSize(); - void setSlot(Slot* s); + void setSlot(Slot *s); Pair *getTransactionId(); int64_t getArbitratorId(); Pair *getPartId(); diff --git a/version2/src/C/hashtable.h b/version2/src/C/hashtable.h index 513d311..c642804 100644 --- a/version2/src/C/hashtable.h +++ b/version2/src/C/hashtable.h @@ -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; } /**