Commit::~Commit() {
delete parts;
delete keyValueUpdateSet;
- delete liveKeys;
+ delete liveKeys;
if (missingParts != NULL)
delete missingParts;
}
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;
}
} 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();
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();
#ifndef KEYVALUE_H
#define KEYVALUE_H
#include "common.h"
+#include "IoTString.h"
/**
* KeyValue entry for Slot.
};
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
bool gotNewCommit = false;
uint numberToDelete = 1;
+
while (numberToDelete < pendingSendArbitrationRounds->size()) {
ArbitrationRound *round = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - numberToDelete - 1);
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);
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);
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)) {
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);
}
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. */
pendingSendArbitrationRounds.clear();
} else {
for (int i = 0; i < numberToDelete; i++) {
- pendingSendArbitrationRounds.removeIndex(pendingSendArbitrationRounds.size() - 1);
+ pendingSendArbitrationRounds.remove(pendingSendArbitrationRounds.size() - 1);
}
}
throw new Error("Server Error: Invalid HMAC Chain" + currSlot + " " + prevSlot);
}
}
-}
+}
\ No newline at end of file