From b7ed1849727b50e226f3b9d1c432d3071d739368 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 15 Mar 2018 05:48:41 -0700 Subject: [PATCH] edits --- version2/src/C/Commit.cc | 13 +++++++------ version2/src/C/Commit.h | 2 +- version2/src/C/KeyValue.h | 9 +++++++++ version2/src/C/Table.cc | 14 +++++--------- version2/src/java/iotcloud/CloudComm.java | 2 +- version2/src/java/iotcloud/Table.java | 4 ++-- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/version2/src/C/Commit.cc b/version2/src/C/Commit.cc index 6c46fed..a24e014 100644 --- a/version2/src/C/Commit.cc +++ b/version2/src/C/Commit.cc @@ -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 *Commit::convertDataToBytes() { return bbEncode->array(); } -void Commit::setKVsMap(Hashset *newKVs) { +void Commit::setKVsMap(Hashset *newKVs) { keyValueUpdateSet->clear(); - keyValueUpdateSet->addAll(newKVs); liveKeys->clear(); - SetIterator *kvit = newKVs->iterator(); + SetIterator *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 *kvSet = new Hashset(); + Hashset *kvSet = new Hashset(); SetIterator *kvit = older->getKeyValueUpdateSet()->iterator(); while (kvit->hasNext()) { KeyValue *kv = kvit->next(); diff --git a/version2/src/C/Commit.h b/version2/src/C/Commit.h index df263ae..b8d69fa 100644 --- a/version2/src/C/Commit.h +++ b/version2/src/C/Commit.h @@ -17,7 +17,7 @@ private: int64_t transactionSequenceNumber; Hashset *liveKeys; Array *convertDataToBytes(); - void setKVsMap(Hashset *newKVs); + void setKVsMap(Hashset *newKVs); public: Commit(); diff --git a/version2/src/C/KeyValue.h b/version2/src/C/KeyValue.h index 06f514b..f0b0fe2 100644 --- a/version2/src/C/KeyValue.h +++ b/version2/src/C/KeyValue.h @@ -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 diff --git a/version2/src/C/Table.cc b/version2/src/C/Table.cc index 15dee76..531337c 100644 --- a/version2/src/C/Table.cc +++ b/version2/src/C/Table.cc @@ -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 *> *liveit = getKeyIterator(liveCommitsTable); while (liveit->hasNext()) { int64_t arbitratorId = liveit->next(); - // Get all the commits for a specific arbitrator Hashtable *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 *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); } diff --git a/version2/src/java/iotcloud/CloudComm.java b/version2/src/java/iotcloud/CloudComm.java index c08d4b2..f12c276 100644 --- a/version2/src/java/iotcloud/CloudComm.java +++ b/version2/src/java/iotcloud/CloudComm.java @@ -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. */ diff --git a/version2/src/java/iotcloud/Table.java b/version2/src/java/iotcloud/Table.java index 25b6775..e446152 100644 --- a/version2/src/java/iotcloud/Table.java +++ b/version2/src/java/iotcloud/Table.java @@ -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 -- 2.34.1