edits
authorbdemsky <bdemsky@uci.edu>
Thu, 15 Mar 2018 12:48:41 +0000 (05:48 -0700)
committerbdemsky <bdemsky@uci.edu>
Thu, 15 Mar 2018 12:48:41 +0000 (05:48 -0700)
version2/src/C/Commit.cc
version2/src/C/Commit.h
version2/src/C/KeyValue.h
version2/src/C/Table.cc
version2/src/java/iotcloud/CloudComm.java
version2/src/java/iotcloud/Table.java

index 6c46fed..a24e014 100644 (file)
@@ -34,7 +34,7 @@ Commit::Commit(int64_t _sequenceNumber, int64_t _machineId, int64_t _transaction
 Commit::~Commit() {
        delete parts;
        delete keyValueUpdateSet;
-       delete liveKeys;
+       delete liveKeys;
        if (missingParts != NULL)
                delete missingParts;
 }
@@ -231,13 +231,14 @@ Array<char> *Commit::convertDataToBytes() {
        return bbEncode->array();
 }
 
-void Commit::setKVsMap(Hashset<KeyValue *, uintptr_t, 0> *newKVs) {
+void Commit::setKVsMap(Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, KeyValueEquals> *newKVs) {
        keyValueUpdateSet->clear();
-       keyValueUpdateSet->addAll(newKVs);
        liveKeys->clear();
-       SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = newKVs->iterator();
+       SetIterator<KeyValue *, KeyValue *, uintptr_t, 0, hashKeyValue, KeyValueEquals> *kvit = newKVs->iterator();
        while (kvit->hasNext()) {
-               liveKeys->add(kvit->next()->getKey());
+               KeyValue *kv = kvit->next();
+               liveKeys->add(kv->getKey());
+               keyValueUpdateSet->add(kv);
        }
        delete kvit;
 }
@@ -248,7 +249,7 @@ Commit *Commit_merge(Commit *newer, Commit *older, int64_t newSequenceNumber) {
        } else if (newer == NULL) {
                return older;
        }
-       Hashset<KeyValue *, uintptr_t, 0> *kvSet = new Hashset<KeyValue *, uintptr_t, 0>();
+       Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, KeyValueEquals> *kvSet = new Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, KeyValueEquals>();
        SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = older->getKeyValueUpdateSet()->iterator();
        while (kvit->hasNext()) {
                KeyValue *kv = kvit->next();
index df263ae..b8d69fa 100644 (file)
@@ -17,7 +17,7 @@ private:
        int64_t transactionSequenceNumber;
        Hashset<IoTString *> *liveKeys;
        Array<char> *convertDataToBytes();
-       void setKVsMap(Hashset<KeyValue *, uintptr_t, 0> *newKVs);
+       void setKVsMap(Hashset<KeyValue *, uintptr_t, 0, hashKeyValue, KeyValueEquals> *newKVs);
 
 public:
        Commit();
index 06f514b..f0b0fe2 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef KEYVALUE_H
 #define KEYVALUE_H
 #include "common.h"
+#include "IoTString.h"
 
 /**
  * KeyValue entry for Slot.
@@ -28,4 +29,12 @@ public:
 };
 
 KeyValue *KeyValue_decode(ByteBuffer *bb);
+
+inline unsigned int hashKeyValue(KeyValue *a) {
+       return a->getKey()->hashValue();
+}
+
+inline bool KeyValueEquals(KeyValue *a, KeyValue *b) {
+       return a->getKey()->equals(b->getKey());
+}
 #endif
index 15dee76..531337c 100644 (file)
@@ -1988,6 +1988,7 @@ bool Table::compactArbitrationData() {
        bool gotNewCommit = false;
 
        uint numberToDelete = 1;
+       
        while (numberToDelete < pendingSendArbitrationRounds->size()) {
                ArbitrationRound *round = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - numberToDelete - 1);
 
@@ -2019,10 +2020,12 @@ bool Table::compactArbitrationData() {
                        newSize += round->getAbortsCount();
 
                        if (newSize > ArbitrationRound_MAX_PARTS) {
-                               // Cant compact since it would be too large
+                               // Can't compact since it would be too large
+                               if (lastRound->getCommit() != newCommit &&
+                                               round->getCommit() != newCommit)
+                                       delete newCommit;
                                break;
                        }
-
                        // Set the new compacted part
                        if (lastRound->getCommit() == newCommit)
                                lastRound->setCommit(NULL);
@@ -2121,7 +2124,6 @@ bool Table::updateCommittedTable() {
        SetIterator<int64_t, Hashtable<int64_t, Commit *> *> *liveit = getKeyIterator(liveCommitsTable);
        while (liveit->hasNext()) {
                int64_t arbitratorId = liveit->next();
-
                // Get all the commits for a specific arbitrator
                Hashtable<int64_t, Commit *> *commitForClientTable = liveCommitsTable->get(arbitratorId);
 
@@ -2146,7 +2148,6 @@ bool Table::updateCommittedTable() {
                for (uint i = 0; i < commitSequenceNumbers->size(); i++) {
                        int64_t commitSequenceNumber = commitSequenceNumbers->get(i);
                        Commit *commit = commitForClientTable->get(commitSequenceNumber);
-
                        // Special processing if a commit is not complete
                        if (!commit->isComplete()) {
                                if (i == (commitSequenceNumbers->size() - 1)) {
@@ -2260,11 +2261,6 @@ bool Table::updateCommittedTable() {
                                SetIterator<KeyValue *, KeyValue *, uintptr_t, 0> *kvit = commit->getKeyValueUpdateSet()->iterator();
                                while (kvit->hasNext()) {
                                        KeyValue *kv = kvit->next();
-                                       printf("Commited KeyValue Table update for %p\n", this);
-                                       kv->getKey()->print();
-                                       printf("\n");
-                                       kv->getValue()->print();
-                                       printf("\n");
                                        committedKeyValueTable->put(kv->getKey(), kv);
                                        liveCommitsByKeyTable->put(kv->getKey(), commit);
                                }
index c08d4b2..f12c276 100644 (file)
@@ -21,7 +21,7 @@ import java.util.*;
 
 class CloudComm {
        private static final int SALT_SIZE = 8;
-       private static final int TIMEOUT_MILLIS = 5000; // 100
+       private static final int TIMEOUT_MILLIS = 2000; // 100
        public static final int IV_SIZE = 16;
 
        /** Sets the size for the HMAC. */
index 25b6775..e446152 100644 (file)
@@ -1982,7 +1982,7 @@ final public class Table {
                                pendingSendArbitrationRounds.clear();
                        } else {
                                for (int i = 0; i < numberToDelete; i++) {
-                                       pendingSendArbitrationRounds.removeIndex(pendingSendArbitrationRounds.size() - 1);
+                                       pendingSendArbitrationRounds.remove(pendingSendArbitrationRounds.size() - 1);
                                }
                        }
 
@@ -2745,4 +2745,4 @@ final public class Table {
                                throw new Error("Server Error: Invalid HMAC Chain" + currSlot + " " + prevSlot);
                }
        }
-}
+}
\ No newline at end of file