X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=blobdiff_plain;f=version2%2Fsrc%2FC%2FPendingTransaction.cc;h=f4532190bca1e43d490cc4717c200f1827c1a98d;hp=84bef5ecaec59ff6ebc451291e2f8172be2f35de;hb=9c3fa5cbce287df14626d262bd0179e994338869;hpb=a578eebaebcddd7f6b2a1b2edeed739bef657d5a diff --git a/version2/src/C/PendingTransaction.cc b/version2/src/C/PendingTransaction.cc index 84bef5e..f453219 100644 --- a/version2/src/C/PendingTransaction.cc +++ b/version2/src/C/PendingTransaction.cc @@ -14,27 +14,30 @@ PendingTransaction::PendingTransaction(int64_t _machineId) : currentDataSize(0) { } +PendingTransaction::~PendingTransaction() { + delete keyValueUpdateSet; + delete keyValueGuardSet; +} + /** * Add a new key value to the updates * */ void PendingTransaction::addKV(KeyValue *newKV) { - - KeyValue * rmKV = NULL; + KeyValue *rmKV = NULL; // Make sure there are no duplicates - SetIterator * kvit = keyValueUpdateSet->iterator(); - while(kvit->hasNext()) { + SetIterator *kvit = keyValueUpdateSet->iterator(); + while (kvit->hasNext()) { KeyValue *kv = kvit->next(); if (kv->getKey()->equals(newKV->getKey())) { - // Remove key if we are adding a newer version of the same key rmKV = kv; break; } } delete kvit; - + // Remove key if we are adding a newer version of the same key if (rmKV != NULL) { keyValueUpdateSet->remove(rmKV); @@ -64,29 +67,28 @@ bool PendingTransaction::checkArbitrator(int64_t arb) { arbitrator = arb; return true; } - return arb == arbitrator; } -bool PendingTransaction::evaluateGuard(Hashtable * keyValTableCommitted, Hashtable * keyValTableSpeculative, Hashtable * keyValTablePendingTransSpeculative) { - SetIterator * kvit = keyValueGuardSet->iterator(); - while(kvit->hasNext()) { +bool PendingTransaction::evaluateGuard(Hashtable *keyValTableCommitted, Hashtable *keyValTableSpeculative, Hashtable *keyValTablePendingTransSpeculative) { + SetIterator *kvit = keyValueGuardSet->iterator(); + while (kvit->hasNext()) { KeyValue *kvGuard = kvit->next(); - - // First check if the key is in the speculative table, this is the value of the latest assumption - KeyValue * kv = keyValTablePendingTransSpeculative->get(kvGuard->getKey()); + // 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 + // 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 + // 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()); } @@ -114,23 +116,20 @@ Transaction *PendingTransaction::createTransaction() { Array *charData = convertDataToBytes(); int currentPosition = 0; - int remaining = charData->length(); - - while (remaining > 0) { - + for (int remaining = charData->length(); remaining > 0;) { bool 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 + isLastPart = true;//last bit of data so last part } // Copy to a smaller version Array *partData = new Array(copySize); System_arraycopy(charData, currentPosition, partData, 0, copySize); - TransactionPart * part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart); + TransactionPart *part = new TransactionPart(NULL, machineId, arbitrator, clientLocalSequenceNumber, transactionPartCount, partData, isLastPart); newTransaction->addPartEncode(part); // Update position, count and remaining @@ -140,16 +139,16 @@ Transaction *PendingTransaction::createTransaction() { } // Add the Guard Conditions - SetIterator * kvit = keyValueGuardSet->iterator(); - while(kvit->hasNext()) { + SetIterator *kvit = keyValueGuardSet->iterator(); + while (kvit->hasNext()) { KeyValue *kv = kvit->next(); newTransaction->addGuardKV(kv); } delete kvit; - + // Add the updates kvit = keyValueUpdateSet->iterator(); - while(kvit->hasNext()) { + while (kvit->hasNext()) { KeyValue *kv = kvit->next(); newTransaction->addUpdateKV(kv); } @@ -171,21 +170,20 @@ Array *PendingTransaction::convertDataToBytes() { bbEncode->putInt(keyValueUpdateSet->size()); // Encode all the guard conditions - SetIterator * kvit = keyValueGuardSet->iterator(); - while(kvit->hasNext()) { + SetIterator *kvit = keyValueGuardSet->iterator(); + while (kvit->hasNext()) { KeyValue *kv = kvit->next(); kv->encode(bbEncode); } delete kvit; - + // Encode all the updates kvit = keyValueUpdateSet->iterator(); - while(kvit->hasNext()) { + while (kvit->hasNext()) { KeyValue *kv = kvit->next(); kv->encode(bbEncode); } delete kvit; - + return bbEncode->array(); } -