delete speculatedKeyValueTable;
delete pendingTransactionSpeculatedKeyValueTable;
delete liveNewKeyTable;
- delete lastMessageTable;
- delete rejectedMessageWatchVectorTable;
+ {
+ SetIterator<int64_t, Pair<int64_t, Liveness *> *> *lmit = getKeyIterator(lastMessageTable);
+ while (lmit->hasNext()) {
+ Pair<int64_t, Liveness *> * pair = lastMessageTable->get(lmit->next());
+ }
+ delete lmit;
+ delete lastMessageTable;
+ }
+ if (pendingTransactionBuilder != NULL)
+ delete pendingTransactionBuilder;
+ {
+ SetIterator<int64_t, Hashset<RejectedMessage *> *> *rmit = getKeyIterator(rejectedMessageWatchVectorTable);
+ while(rmit->hasNext()) {
+ int64_t machineid = rmit->next();
+ Hashset<RejectedMessage *> * rmset = rejectedMessageWatchVectorTable->get(machineid);
+ SetIterator<RejectedMessage *, RejectedMessage *> * mit = rmset->iterator();
+ while (mit->hasNext()) {
+ RejectedMessage * rm = mit->next();
+ delete rm;
+ }
+ delete mit;
+ delete rmset;
+ }
+ delete rmit;
+ delete rejectedMessageWatchVectorTable;
+ }
delete arbitratorTable;
delete liveAbortTable;
- delete newTransactionParts;
- delete newCommitParts;
+ {
+ SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *partsit = getKeyIterator(newTransactionParts);
+ while (partsit->hasNext()) {
+ int64_t machineId = partsit->next();
+ Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
+ delete parts;
+ }
+ delete partsit;
+ delete newTransactionParts;
+ }
+ {
+ SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *partsit = getKeyIterator(newCommitParts);
+ while (partsit->hasNext()) {
+ int64_t machineId = partsit->next();
+ Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newCommitParts->get(machineId);
+ delete parts;
+ }
+ delete partsit;
+ delete newCommitParts;
+ }
delete lastArbitratedTransactionNumberByArbitratorTable;
delete liveTransactionBySequenceNumberTable;
delete liveTransactionByTransactionIdTable;
- delete liveCommitsTable;
+ {
+ 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);
+ {
+ SetIterator<int64_t, Commit *> *clientit = getKeyIterator(commitForClientTable);
+ while (clientit->hasNext()) {
+ int64_t id = clientit->next();
+ delete commitForClientTable->get(id);
+ }
+ delete clientit;
+ }
+
+ delete commitForClientTable;
+ }
+ delete liveit;
+ delete liveCommitsTable;
+ }
delete liveCommitsByKeyTable;
delete lastCommitSeenSequenceNumberByArbitratorTable;
delete rejectedSlotVector;
- delete pendingTransactionQueue;
+ {
+ uint size = pendingTransactionQueue->size();
+ for (uint iter = 0; iter < size; iter++) {
+ delete pendingTransactionQueue->get(iter);
+ }
+ delete pendingTransactionQueue;
+ }
delete pendingSendArbitrationEntriesToDelete;
delete transactionPartsSent;
delete outstandingTransactionStatus;
delete offlineTransactionsCommittedAndAtServer;
delete localCommunicationTable;
delete lastTransactionSeenFromMachineFromServer;
- delete pendingSendArbitrationRounds;
+ {
+ for(uint i = 0; i < pendingSendArbitrationRounds->size(); i++) {
+ delete pendingSendArbitrationRounds->get(i);
+ }
+ delete pendingSendArbitrationRounds;
+ }
+ if (lastTransactionPartsSent != NULL)
+ delete lastTransactionPartsSent;
delete lastArbitrationDataLocalSequenceNumberSeenFromArbitrator;
}
array->set(0, s);
// update local block chain
validateAndUpdate(array, true);
+ delete array;
} else if (array->length() == 1) {
// in case we did push the slot BUT we failed to init it
validateAndUpdate(array, true);
+ delete array;
} else {
+ delete array;
throw new Error("Error on initialization");
}
}
// Just pull the latest slots from the server
Array<Slot *> *newslots = cloud->getSlots(sequenceNumber + 1);
validateAndUpdate(newslots, true);
+ delete newslots;
sendToServer(NULL);
updateLiveTransactionsAndStatus();
}
KeyValue *kv = committedKeyValueTable->get(key);
if (kv != NULL) {
- return kv->getValue();
+ return new IoTString(kv->getValue());
} else {
return NULL;
}
}
if (kv != NULL) {
- return kv->getValue();
+ return new IoTString(kv->getValue());
} else {
return NULL;
}
if (kv != NULL) {
pendingTransactionBuilder->addKVGuard(new KeyValue(key, kv->getValue()));
- return kv->getValue();
+ return new IoTString(kv->getValue());
} else {
pendingTransactionBuilder->addKVGuard(new KeyValue(key, NULL));
return NULL;
if (kv != NULL) {
pendingTransactionBuilder->addKVGuard(new KeyValue(key, kv->getValue()));
- return kv->getValue();
+ return new IoTString(kv->getValue());
} else {
pendingTransactionBuilder->addKVGuard(new KeyValue(key, NULL));
return NULL;
try {
Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
validateAndUpdate(newSlots, false);
+ delete newSlots;
sendToServer(NULL);
updateLiveTransactionsAndStatus();
return true;
void Table::startTransaction() {
// Create a new transaction, invalidates any old pending transactions.
+ if (pendingTransactionBuilder != NULL)
+ delete pendingTransactionBuilder;
pendingTransactionBuilder = new PendingTransaction(localMachineId);
}
-void Table::addKV(IoTString *key, IoTString *value) {
-
+void Table::put(IoTString *key, IoTString *value) {
// Make sure it is a valid key
if (!arbitratorTable->contains(key)) {
throw new Error("Key not Found.");
}
// Add the key value to this transaction
- KeyValue *kv = new KeyValue(key, value);
+ KeyValue *kv = new KeyValue(new IoTString(key), new IoTString(value));
pendingTransactionBuilder->addKV(kv);
}
pendingTransactionQueue->add(newTransaction);
} else {
arbitrateOnLocalTransaction(newTransaction);
+ delete newTransaction;
updateLiveStateFromLocal();
}
-
+ if (pendingTransactionBuilder != NULL)
+ delete pendingTransactionBuilder;
+
pendingTransactionBuilder = new PendingTransaction(localMachineId);
try {
if (sendReturn.getSecond()) {
// did arbitrate
+ delete transaction;
oldindex--;
}
}
// insert into the local block chain
validateAndUpdate(newSlots, true);
}
- // continue;
} else {
if (checkSend(newSlots, lastSlotAttemptedToSend)) {
if (newKey != NULL) {
// insert into the local block chain
validateAndUpdate(newSlots, true);
}
+ delete newSlots;
return newKey;
}
}
// Create the slot
- Slot *slot = new Slot(this, sequenceNumber + 1, localMachineId, buffer->getSlot(sequenceNumber)->getHMAC(), localSequenceNumber);
+ Slot *slot = new Slot(this, sequenceNumber + 1, localMachineId, new Array<char>(buffer->getSlot(sequenceNumber)->getHMAC()), localSequenceNumber);
localSequenceNumber++;
// Try to fill the slot with data
lastInsertedNewKey = insertedNewKey;
lastNewSize = newSize;
lastNewKey = newKey;
+ if (lastTransactionPartsSent != NULL)
+ delete lastTransactionPartsSent;
lastTransactionPartsSent = transactionPartsSent->clone();
lastPendingSendArbitrationEntriesToDelete = new Vector<Entry *>(pendingSendArbitrationEntriesToDelete);
//Add part back in
pendingSendArbitrationRounds->set(oldcount++,
pendingSendArbitrationRounds->get(i));
- }
+ } else
+ delete pendingSendArbitrationRounds->get(i);
}
pendingSendArbitrationRounds->setSize(oldcount);
// insert into the local block chain
validateAndUpdate(newSlots, true);
}
+ delete newSlots;
}
} catch (ServerException *e) {
if (e->getType() != ServerException_TypeInputTimeout) {
s->addEntry(liveentry);
else {
skipcount++;
- if (skipcount > Table_SKIP_THRESHOLD)
+ if (skipcount > Table_SKIP_THRESHOLD) {
+ delete liveentries;
goto donesearch;
+ }
}
}
+ delete liveentries;
}
donesearch:
;
updateExpectedSize();
}
}
-
+ delete indexer;
+
// If there is a gap, check to see if the server sent us
// everything->
if (firstSeqNum != (sequenceNumber + 1)) {
// must have a last message message-> If not then the server is
// hiding slots
if (!machineSet->isEmpty()) {
+ delete machineSet;
throw new Error("Missing record for machines: ");
}
}
-
+ delete machineSet;
// Update the size of our local block chain->
commitNewMaxSize();
if (transaction == NULL) {
// This is a new transaction that we dont have so make a new one
transaction = new Transaction();
+
+ // Add that part to the transaction
+ transaction->addPartDecode(part);
// Insert this new transaction into the live tables
liveTransactionBySequenceNumberTable->put(part->getSequenceNumber(), transaction);
- liveTransactionByTransactionIdTable->put(new Pair<int64_t, int64_t>(part->getTransactionId()), transaction);
+ liveTransactionByTransactionIdTable->put(transaction->getId(), transaction);
}
-
- // Add that part to the transaction
- transaction->addPartDecode(part);
}
delete ptit;
}
delete tpit;
// Clear all the new transaction parts in preparation for the next
// time the server sends slots
- newTransactionParts->clear();
+ {
+ SetIterator<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *> *partsit = getKeyIterator(newTransactionParts);
+ while (partsit->hasNext()) {
+ int64_t machineId = partsit->next();
+ Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
+ delete parts;
+ }
+ delete partsit;
+ newTransactionParts->clear();
+ }
}
void Table::arbitrateFromServer() {
continue;
}
-
if (!transaction->isComplete()) {
// Will arbitrate in incorrect order if we continue so just break
// Most likely this
break;
}
-
// update the largest transaction seen by arbitrator from server
if (!lastTransactionSeenFromMachineFromServer->contains(transaction->getMachineId())) {
lastTransactionSeenFromMachineFromServer->put(transaction->getMachineId(), transaction->getClientLocalSequenceNumber());
if (transaction->evaluateGuard(committedKeyValueTable, speculativeTableTmp, NULL)) {
// Guard evaluated as true
-
// Update the local changes so we can make the commit
SetIterator<KeyValue *, KeyValue *> *kvit = transaction->getKeyValueUpdateSet()->iterator();
while (kvit->hasNext()) {
newCommit->addKV(kv);
}
delete spit;
-
+
// create the commit parts
newCommit->createCommitParts();
processEntry(commitPart);
}
}
+ delete speculativeTableTmp;
if ((newCommit != NULL) || (generatedAborts->size() > 0)) {
ArbitrationRound *arbitrationRound = new ArbitrationRound(newCommit, generatedAborts);
}
/**
- * Compacts the arbitration data my merging commits and aggregating
+ * Compacts the arbitration data by merging commits and aggregating
* aborts so that a single large push of commits can be done instead
* of many small updates
*/
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);
+ if (round->getCommit() == newCommit)
+ round->setCommit(NULL);
+
+ if (lastRound->getCommit() != NULL) {
+ Commit * oldcommit = lastRound->getCommit();
+ lastRound->setCommit(NULL);
+ delete oldcommit;
+ }
lastRound->setCommit(newCommit);
lastRound->addAborts(round->getAborts());
gotNewCommit = true;
if (numberToDelete != 1) {
// If there is a compaction
// Delete the previous pieces that are now in the new compacted piece
- if (numberToDelete == pendingSendArbitrationRounds->size()) {
- pendingSendArbitrationRounds->clear();
- } else {
- for (uint i = 0; i < numberToDelete; i++) {
- pendingSendArbitrationRounds->removeIndex(pendingSendArbitrationRounds->size() - 1);
- }
+ for (uint i = 2; i <= numberToDelete; i++) {
+ delete pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size()-i);
}
+ pendingSendArbitrationRounds->setSize(pendingSendArbitrationRounds->size() - numberToDelete);
- // Add the new compacted into the pending to send list
pendingSendArbitrationRounds->add(lastRound);
// Should reinsert into the commit processor
commit->addPartDecode(part);
}
delete pairit;
+ delete parts;
}
delete partsit;
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)) {
// Delete it and move on
commit->setDead();
commitForClientTable->remove(commit->getSequenceNumber());
+ delete commit;
continue;
}
}
// We have already seen this commit before so need to do the
// full processing on this commit
if (commit->getSequenceNumber() <= lastCommitSeenSequenceNumber) {
-
// Update the last transaction that was updated if we can
if (commit->getTransactionSequenceNumber() != -1) {
int64_t lastTransactionNumber = lastArbitratedTransactionNumberByArbitratorTable->get(commit->getMachineId());
lastArbitratedTransactionNumberByArbitratorTable->put(commit->getMachineId(), commit->getTransactionSequenceNumber());
}
}
-
continue;
}
// if the commit is now dead then remove it
if (!previousCommit->isLive()) {
commitForClientTable->remove(previousCommit->getSequenceNumber());
+ delete previousCommit;
}
}
}
delete commitit;
+ delete commitsToEdit;
// Update the last seen sequence number from this arbitrator
if (lastCommitSeenSequenceNumberByArbitratorTable->contains(commit->getMachineId())) {
// Remove the transaction from the live table
iter->remove();
liveTransactionByTransactionIdTable->remove(transaction->getId());
+ delete transaction;
}
}
delete iter;
if (deviceWatchSet->isEmpty()) {
// This rejected message has been seen by all the clients so
entry->setDead();
+ delete deviceWatchSet;
} else {
// We need to watch this rejected message
entry->setWatchSet(deviceWatchSet);
void Table::processEntry(CommitPart *entry) {
// Update the last transaction that was updated if we can
if (entry->getTransactionSequenceNumber() != -1) {
- if (!lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getMachineId() || lastArbitratedTransactionNumberByArbitratorTable->get(entry->getMachineId()) < entry->getTransactionSequenceNumber())) {
+ if (!lastArbitratedTransactionNumberByArbitratorTable->contains(entry->getMachineId()) ||
+ lastArbitratedTransactionNumberByArbitratorTable->get(entry->getMachineId()) < entry->getTransactionSequenceNumber()) {
lastArbitratedTransactionNumberByArbitratorTable->put(entry->getMachineId(), entry->getTransactionSequenceNumber());
}
}
}
// Update the part and set dead ones we have already seen (got a
// rescued version)
- CommitPart *previouslySeenPart = commitPart->put(new Pair<int64_t, int32_t>(entry->getPartId()), entry);
+ CommitPart *previouslySeenPart = commitPart->put(entry->getPartId(), entry);
if (previouslySeenPart != NULL) {
previouslySeenPart->setDead();
}