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 6c46fed4a036301c8fe2fe89d40b721dc2926d35..a24e0148df376b6180c7bd574ff499c6c6b37519 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 df263ae393ef44832ae5e8ef5289e99a483bf1e3..b8d69faea40039a8e95c3402b54755d6710db394 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 06f514b577e096bc59692b9b406a20c3159419d4..f0b0fe2474b430a88bd8d9efbfa60419ee77249a 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 15dee7683a05545c1c9f0aea98484ba4a0d114d3..531337cc5336f1c69dac6aed68018b2899355c98 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 c08d4b2e9db766fc49dae177a270c8ea0f4fbed1..f12c2764e0a04520c94b6a094fd25c43266cf4f0 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 25b677565f89d8db56c69e4ed30c4d52e1ba6e9c..e4461523c02bf3d5d9f82827a00fdd648c032af7 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