Another file
authorbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 22:06:59 +0000 (14:06 -0800)
committerbdemsky <bdemsky@uci.edu>
Sat, 20 Jan 2018 22:06:59 +0000 (14:06 -0800)
version2/src/C/Table.cc
version2/src/C/Transaction.cc
version2/src/C/Transaction.h
version2/src/C/vector.h

index 5e69e13..4c0331e 100644 (file)
@@ -174,7 +174,6 @@ void Table::init() {
        pendingSendArbitrationRounds = new Vector<ArbitrationRound *>();
        lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = new Hashtable<int64_t, int64_t>();
 
-
        // Other init stuff
        numberOfSlots = buffer->capacity();
        setResizeThreshold();
@@ -1316,7 +1315,6 @@ search:
  * Checks for malicious activity and updates the local copy of the block chain->
  */
 void Table::validateAndUpdate(Array<Slot *> *newSlots, bool acceptUpdatesToLocal) {
-
        // The cloud communication layer has checked slot HMACs already
        // before decoding
        if (newSlots->length() == 0) {
index a3083ee..2398544 100644 (file)
@@ -6,7 +6,8 @@
 #include "TransactionStatus.h"
 
 Transaction::Transaction() :
-       parts(new Hashtable<int32_t, TransactionPart *>()),
+       parts(new Vector<TransactionPart *>()),
+       partCount(0),
        missingParts(NULL),
        partsPendingSend(new Vector<int32_t>()),
        fldisComplete(false),
@@ -18,12 +19,14 @@ Transaction::Transaction() :
        clientLocalSequenceNumber(-1),
        arbitratorId(-1),
        machineId(-1),
-       transactionId(NULL),
+       transactionId(Pair<int64_t, int64_t>(0,0)),
        hadServerFailure(false) {
 }
 
 void Transaction::addPartEncode(TransactionPart *newPart) {
-       parts->put(newPart->getPartNumber(), newPart);
+       TransactionPart * old=parts->setExpand(newPart->getPartNumber(), newPart);
+       if (old == NULL)
+               partCount++;
        partsPendingSend->add(newPart->getPartNumber());
 
        sequenceNumber = newPart->getSequenceNumber();
@@ -48,11 +51,13 @@ void Transaction::addPartDecode(TransactionPart *newPart) {
        clientLocalSequenceNumber = newPart->getClientLocalSequenceNumber();
        machineId = newPart->getMachineId();
 
-       TransactionPart *previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
-
-       if (previoslySeenPart != NULL) {
+       TransactionPart *previouslySeenPart = parts->setExpand(newPart->getPartNumber(), newPart);
+       if (previouslySeenPart == NULL)
+               partCount++;
+       
+       if (previouslySeenPart != NULL) {
                // Set dead the old one since the new one is a rescued version of this part
-               previoslySeenPart->setDead();
+               previouslySeenPart->setDead();
        } else if (newPart->isLastPart()) {
                missingParts = new Hashset<int32_t>();
                hasLastPart = true;
@@ -96,9 +101,11 @@ int64_t Transaction::getSequenceNumber() {
 
 void Transaction::setSequenceNumber(int64_t _sequenceNumber) {
        sequenceNumber = _sequenceNumber;
-
-       for (int32_t i : parts->keySet()) {
-               parts->get(i)->setSequenceNumber(sequenceNumber);
+       
+       for (int32_t i = 0; i < parts->size(); i++) {
+               TransactionPart * tp = parts->get(i);
+               if (tp !=NULL)
+                       tp->setSequenceNumber(sequenceNumber);
        }
 }
 
@@ -106,7 +113,7 @@ int64_t Transaction::getClientLocalSequenceNumber() {
        return clientLocalSequenceNumber;
 }
 
-Hashtable<int32_t, TransactionPart *> *Transaction::getParts() {
+Vector<TransactionPart *> *Transaction::getParts() {
        return parts;
 }
 
@@ -152,8 +159,23 @@ TransactionStatus *Transaction::getTransactionStatus() {
 
 void Transaction::removeSentParts(Vector<int32_t> *sentParts) {
        nextPartToSend = 0;
-       if (partsPendingSend->removeAll(sentParts))
-       {
+       bool changed = false;
+       uint lastusedindex = 0;
+       for(uint i=0; i < partsPendingSend->size(); i++) {
+               int32_t parti = partsPendingSend->get(i);
+               for(uint j=0; j < sentParts->size(); j++) {
+                       int32_t partj = sentParts->get(j);
+                       if (parti == partj) {
+                               changed = true;
+                               goto NextElement;
+                       }
+               }
+               partsPendingSend->set(lastusedindex++, parti);
+       NextElement:
+               ;
+       }
+       if (changed) {
+               partsPendingSend->setSize(lastusedindex);
                flddidSendAPartToServer = true;
                transactionStatus->setTransactionSequenceNumber(sequenceNumber);
        }
@@ -168,7 +190,7 @@ Hashset<KeyValue *> *Transaction::getKeyValueUpdateSet() {
 }
 
 int Transaction::getNumberOfParts() {
-       return parts->size();
+       return partCount;
 }
 
 int64_t Transaction::getMachineId() {
@@ -197,9 +219,10 @@ void Transaction::setDead() {
        isDead = true;
 
        // Make all the parts of this transaction dead
-       for (int32_t partNumber : parts->keySet()) {
+       for (int32_t partNumber = 0; partNumber < parts->size(); partNumber ++) {
                TransactionPart *part = parts->get(partNumber);
-               part->setDead();
+               if (part != NULL)
+                       part->setDead();
        }
 }
 
@@ -208,10 +231,9 @@ TransactionPart *Transaction::getPart(int index) {
 }
 
 void Transaction::decodeTransactionData() {
-
        // Calculate the size of the data section
        int dataSize = 0;
-       for (int i = 0; i < parts->keySet()->size(); i++) {
+       for (int i = 0; i < parts->size(); i++) {
                TransactionPart *tp = parts->get(i);
                dataSize += tp->getDataSize();
        }
@@ -220,7 +242,7 @@ void Transaction::decodeTransactionData() {
        int currentPosition = 0;
 
        // Stitch all the data sections together
-       for (int i = 0; i < parts->keySet()->size(); i++) {
+       for (int i = 0; i < parts->size(); i++) {
                TransactionPart *tp = parts->get(i);
                System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
                currentPosition += tp->getDataSize();
@@ -247,8 +269,9 @@ void Transaction::decodeTransactionData() {
 }
 
 bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKeyValueTable, Hashtable<IoTString *, KeyValue *> *speculatedKeyValueTable, Hashtable<IoTString *, KeyValue *> *pendingTransactionSpeculatedKeyValueTable) {
-       for (KeyValue *kvGuard : keyValueGuardSet) {
-
+       SetIterator<KeyValue *>* 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 = NULL;
 
@@ -277,15 +300,17 @@ bool Transaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *committedKey
                                } else {
                                        printf("%s      null\n", kvGuard->getValue()->internalBytes()->internalArray());
                                }
-
+                               delete kvit;
                                return false;
                        }
                } else {
                        if (kv != NULL) {
+                               delete kvit;
                                return false;
                        }
                }
        }
+       delete kvit;
        return true;
 }
 
index 4be64ff..f635a7a 100644 (file)
@@ -5,7 +5,8 @@
 
 class Transaction {
 private:
-       Hashtable<int32_t, TransactionPart *> *parts;
+       Vector<TransactionPart *> *parts;
+       uint partCount;
        Hashset<int32_t> *missingParts;
        Vector<int32_t> *partsPendingSend;
        bool fldisComplete;
@@ -33,7 +34,7 @@ public:
        int64_t getSequenceNumber();
        void setSequenceNumber(int64_t _sequenceNumber);
        int64_t getClientLocalSequenceNumber();
-       Hashtable<int32_t, TransactionPart *> *getParts();
+       Vector<TransactionPart *> *getParts();
        bool didSendAPartToServer();
        void resetNextPartToSend();
        TransactionPart *getNextPartToSend();
index 00ff962..fcdbe0c 100644 (file)
@@ -65,10 +65,14 @@ public:
                return array[index];
        }
 
-       void setExpand(uint index, type item) {
+       type setExpand(uint index, type item) {
+               type retval = (type) 0;
                if (index >= fldsize)
                        setSize(index + 1);
+               else
+                       retval = array[index];
                set(index, item);
+               return retval;
        }
 
        void set(uint index, type item) {