#include "ByteBuffer.h"
#include "Abort.h"
#include "CommitPart.h"
-
+#include "ArbitrationRound.h"
+#include "TransactionPart.h"
+#include "Commit.h"
+#include "RejectedMessage.h"
+#include "SlotIndexer.h"
Table::Table(IoTString *baseurl, IoTString *password, int64_t _localMachineId, int listeningPort) :
buffer(NULL),
speculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
pendingTransactionSpeculatedKeyValueTable = new Hashtable<IoTString *, KeyValue *>();
liveNewKeyTable = new Hashtable<IoTString *, NewKey *>();
- lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> >();
+ lastMessageTable = new Hashtable<int64_t, Pair<int64_t, Liveness *> * >();
rejectedMessageWatchVectorTable = new Hashtable<int64_t, Hashset<RejectedMessage *> * >();
arbitratorTable = new Hashtable<IoTString *, int64_t>();
- liveAbortTable = new Hashtable<Pair<int64_t, int64_t>, Abort *, uintptr_t, 0, pairHashFunction, pairEquals>();
- newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
- newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t>, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
+ liveAbortTable = new Hashtable<Pair<int64_t, int64_t> *, Abort *, uintptr_t, 0, pairHashFunction, pairEquals>();
+ newTransactionParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
+ newCommitParts = new Hashtable<int64_t, Hashtable<Pair<int64_t, int32_t> *, CommitPart *, uintptr_t, 0, pairHashFunction, pairEquals> *>();
lastArbitratedTransactionNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
liveTransactionBySequenceNumberTable = new Hashtable<int64_t, Transaction *>();
- liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t>, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals>();
+ liveTransactionByTransactionIdTable = new Hashtable<Pair<int64_t, int64_t> *, Transaction *, uintptr_t, 0, pairHashFunction, pairEquals>();
liveCommitsTable = new Hashtable<int64_t, Hashtable<int64_t, Commit *> >();
liveCommitsByKeyTable = new Hashtable<IoTString *, Commit *>();
lastCommitSeenSequenceNumberByArbitratorTable = new Hashtable<int64_t, int64_t>();
transactionPartsSent = new Hashtable<Transaction *, Vector<int32_t> *>();
outstandingTransactionStatus = new Hashtable<int64_t, TransactionStatus *>();
liveAbortsGeneratedByLocal = new Hashtable<int64_t, Abort *>();
- offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t>, uintptr_t, 0, pairHashFunction, pairEquals>();
- localCommunicationTable = new Hashtable<int64_t, Pair<IoTString *, int32_t> >();
+ offlineTransactionsCommittedAndAtServer = new Hashset<Pair<int64_t, int64_t> *, uintptr_t, 0, pairHashFunction, pairEquals>();
+ localCommunicationTable = new Hashtable<int64_t, Pair<IoTString *, int32_t> *>();
lastTransactionSeenFromMachineFromServer = new Hashtable<int64_t, int64_t>();
pendingSendArbitrationRounds = new Vector<ArbitrationRound *>();
lastArbitrationDataLocalSequenceNumberSeenFromArbitrator = new Hashtable<int64_t, int64_t>();
}
void Table::addLocalCommunication(int64_t arbitrator, IoTString *hostName, int portNumber) {
- localCommunicationTable->put(arbitrator, Pair<IoTString *, int32_t>(hostName, portNumber));
+ localCommunicationTable->put(arbitrator, new Pair<IoTString *, int32_t>(hostName, portNumber));
}
int64_t Table::getArbitrator(IoTString *key) {
updateLiveTransactionsAndStatus();
return true;
} catch (Exception *e) {
- SetIterator<int64_t> * kit = getKeyIterator(localCommunicationTable);
- while(kit->hasNext()) {
+ SetIterator<int64_t> *kit = getKeyIterator(localCommunicationTable);
+ while (kit->hasNext()) {
int64_t m = kit->next();
updateFromLocal(m);
}
Hashset<int64_t> *arbitratorTriedAndFailed = new Hashset<int64_t>();
uint size = pendingTransactionQueue->size();
uint oldindex = 0;
- for(int iter = 0; iter < size; iter++) {
+ for (int iter = 0; iter < size; iter++) {
Transaction *transaction = pendingTransactionQueue->get(iter);
pendingTransactionQueue->set(oldindex++, pendingTransactionQueue->get(iter));
-
+
if (arbitratorTriedAndFailed->contains(transaction->getArbitrator())) {
// Already contacted this client so ignore all attempts to contact this client
// to preserve ordering for arbitrator
}
pendingTransactionQueue->setSize(oldindex);
}
-
+
updateLiveStateFromLocal();
return transactionStatus;
}
}
- SetIterator<Transaction *> * trit = getKeyIterator(lastTransactionPartsSent);
- while(trit->hasNext()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Update which transactions parts still need to be sent
}
// Process each entry in the slot
- Vector<Entry *> * ventries=s->getEntries();
+ Vector<Entry *> *ventries = s->getEntries();
uint vesize = ventries->size();
- for(uint vei = 0; vei < vesize; vei++) {
+ for (uint vei = 0; vei < vesize; vei++) {
Entry *entry = ventries->get(vei);
if (entry->getType() == TypeLastMessage) {
LastMessage *lastMessage = (LastMessage *)entry;
}
}
- for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Update which transactions parts still need to be sent
}
}
}
+ delete trit;
}
}
- for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Set the transaction sequence number back to nothing
if (!transaction->didSendAPartToServer()) {
transaction->setSequenceNumber(-1);
}
}
+ delete trit;
if (sendSlotsReturn.getThird()->length() != 0) {
// insert into the local block chain
}
// Process each entry in the slot
- for (Entry *entry : s->getEntries()) {
-
+ Vector<Entry *> *entries = s->getEntries();
+ uint eSize = entries->size();
+ for(uint ei=0; ei < eSize; ei++) {
+ Entry * entry = entries->get(ei);
+
if (entry->getType() == TypeLastMessage) {
LastMessage *lastMessage = (LastMessage *)entry;
if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {
}
}
- for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Update which transactions parts still need to be sent
}
}
}
+ delete trit;
} else {
- for (Transaction *transaction : lastTransactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Set the transaction sequence number back to nothing
if (!transaction->didSendAPartToServer()) {
transaction->setSequenceNumber(-1);
}
}
+ delete trit;
}
// insert into the local block chain
if (needsResize) {
// Reset which transaction to send
- for (Transaction *transaction : transactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetNextPartToSend();
// Set the transaction sequence number back to nothing
transaction->setSequenceNumber(-1);
}
}
+ delete trit;
// Clear the sent data since we are trying again
pendingSendArbitrationEntriesToDelete->clear();
lastInsertedNewKey = insertedNewKey;
lastNewSize = newSize;
lastNewKey = newKey;
- lastTransactionPartsSent = new Hashtable<Transaction *, Vector<int32_t> * >(transactionPartsSent);
+ lastTransactionPartsSent = transactionPartsSent->clone();
lastPendingSendArbitrationEntriesToDelete = new Vector<Entry *>(pendingSendArbitrationEntriesToDelete);
-
ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(slot, newSize, newKey != NULL);
if (sendSlotsReturn.getFirst()) {
// Remove the aborts and commit parts that were sent from the pending to send queue
uint size = pendingSendArbitrationRounds->size();
uint oldcount = 0;
- for (uint i=0; i < size; i++)
- ArbitrationRound *round = pendingSendArbitrartionRounds->get(i);
+ for (uint i = 0; i < size; i++) {
+ ArbitrationRound *round = pendingSendArbitrationRounds->get(i);
round->removeParts(pendingSendArbitrationEntriesToDelete);
if (!round->isDoneSending()) {
// Sent all the parts
- pendingSendArbitrartionRounds->set(oldcount++,
- pendingSendArbitrartionRounds->get(i));
+ pendingSendArbitrationRounds->set(oldcount++,
+ pendingSendArbitrationRounds->get(i));
}
}
- pendingSendArbitrationRounds->setSize(oldcount);
+ pendingSendArbitrationRounds->setSize(oldcount);
- for (Transaction *transaction : transactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetServerFailure();
// Update which transactions parts still need to be sent
pendingTransactionQueue->remove(transaction);
}
}
+ delete trit;
} else {
// Reset which transaction to send
- for (Transaction *transaction : transactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetNextPartToSend();
// Set the transaction sequence number back to nothing
transaction->setSequenceNumber(-1);
}
}
+ delete trit;
}
// Clear the sent data in preparation for next send
}
} catch (ServerException *e) {
-
if (e->getType() != ServerException->TypeInputTimeout) {
// Nothing was able to be sent to the server so just clear these data structures
- for (Transaction *transaction : transactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetNextPartToSend();
// Set the transaction sequence number back to nothing
transaction->setSequenceNumber(-1);
}
}
+ delete trit;
} else {
// There was a partial send to the server
hadPartialSendToServer = true;
// Nothing was able to be sent to the server so just clear these data structures
- for (Transaction *transaction : transactionPartsSent->keySet()) {
+ SetIterator<Transaction *> *trit = getKeyIterator(transactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
transaction->resetNextPartToSend();
transaction->setServerFailure();
}
+ delete trit;
}
pendingSendArbitrationEntriesToDelete->clear();
}
bool Table::updateFromLocal(int64_t machineId) {
- Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(machineId);
- if (localCommunicationInformation == NULL) {
- // Cant talk to that device locally so do nothing
+ if (!localCommunicationTable->contains(machineId))
return false;
- }
+
+ Pair<IoTString *, int32_t> * localCommunicationInformation = localCommunicationTable->get(machineId);
// Get the size of the send data
int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
for (int i = 0; i < numberOfEntries; i++) {
char type = bbDecode->get();
if (type == TypeAbort) {
- Abort *abort = (Abort*)Abort_decode(NULL, bbDecode);
+ Abort *abort = (Abort *)Abort_decode(NULL, bbDecode);
processEntry(abort);
} else if (type == TypeCommitPart) {
- CommitPart *commitPart = (CommitPart*)CommitPart_decode(NULL, bbDecode);
+ CommitPart *commitPart = (CommitPart *)CommitPart_decode(NULL, bbDecode);
processEntry(commitPart);
}
}
Pair<bool, bool> Table::sendTransactionToLocal(Transaction *transaction) {
// Get the devices local communications
- Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
-
- if (localCommunicationInformation == NULL) {
- // Cant talk to that device locally so do nothing
+ if (!localCommunicationTable->contains(machineId))
return Pair<bool, bool>(true, false);
- }
+
+ Pair<IoTString *, int32_t> localCommunicationInformation = localCommunicationTable->get(transaction->getArbitrator());
// Get the size of the send data
int sendDataSize = sizeof(int32_t) + sizeof(int64_t);
// Make the send data size
Array<char> *sendData = new Array<char>(sendDataSize);
- ByteBuffer *bbEncode = ByteBuffer.wrap(sendData);
+ ByteBuffer *bbEncode = ByteBuffer_wrap(sendData);
// Encode the data
bbEncode->putLong(lastArbitrationDataLocalSequenceNumber);
for (int i = 0; i < numberOfEntries; i++) {
char type = bbDecode->get();
if (type == TypeAbort) {
- Abort *abort = (Abort*)Abort_decode(NULL, bbDecode);
+ Abort *abort = (Abort *)Abort_decode(NULL, bbDecode);
if ((abort->getTransactionMachineId() == localMachineId) && (abort->getTransactionClientLocalSequenceNumber() == transaction->getClientLocalSequenceNumber())) {
foundAbort = true;
processEntry(abort);
} else if (type == TypeCommitPart) {
- CommitPart *commitPart = (CommitPart*)CommitPart_decode(NULL, bbDecode);
+ CommitPart *commitPart = (CommitPart *)CommitPart_decode(NULL, bbDecode);
processEntry(commitPart);
}
}
updateLiveStateFromLocal();
if (couldArbitrate) {
- TransactionStatus status = transaction->getTransactionStatus();
+ TransactionStatus * status = transaction->getTransactionStatus();
if (didCommit) {
status->setStatus(TransactionStatus_StatusCommitted);
} else {
status->setStatus(TransactionStatus_StatusAborted);
}
} else {
- TransactionStatus status = transaction->getTransactionStatus();
+ TransactionStatus * status = transaction->getTransactionStatus();
if (foundAbort) {
status->setStatus(TransactionStatus_StatusAborted);
} else {
Transaction *transaction = new Transaction();
for (int i = 0; i < numberOfParts; i++) {
bbDecode->get();
- TransactionPart *newPart = (TransactionPart)TransactionPart.decode(NULL, bbDecode);
+ TransactionPart *newPart = (TransactionPart *)TransactionPart_decode(NULL, bbDecode);
transaction->addPartDecode(newPart);
}
// Get the aborts to send back
Vector<int64_t> *abortLocalSequenceNumbers = new Vector<int64_t>(liveAbortsGeneratedByLocal->keySet());
Collections->sort(abortLocalSequenceNumbers);
- for (int64_t localSequenceNumber : abortLocalSequenceNumbers) {
+ uint asize = abortLocalSequenceNumbers->size();
+ for(uint i=0; i<asize; i++) {
+ int64_t localSequenceNumber = abortLocalSequenceNumbers->get(i);
if (localSequenceNumber <= lastArbitratedSequenceNumberSeen) {
continue;
}
-
+
Abort *abort = liveAbortsGeneratedByLocal->get(localSequenceNumber);
unseenArbitrations->add(abort);
returnDataSize += abort->getSize();
Vector<int64_t> *commitLocalSequenceNumbers = new Vector<int64_t>(commitForClientTable->keySet());
Collections->sort(commitLocalSequenceNumbers);
- for (int64_t localSequenceNumber : commitLocalSequenceNumbers) {
+ uint clsSize = commitLocalSequenceNumbers->size();
+ for(uint clsi = 0; clsi < clsSize; clsi++) {
+ int64_t localSequenceNumber = commitLocalSequenceNumbers->get(clsi);
Commit *commit = commitForClientTable->get(localSequenceNumber);
if (localSequenceNumber <= lastArbitratedSequenceNumberSeen) {
bbEncode->putInt(unseenArbitrations->size());
uint size = unseenArbitrations->size();
- for(uint i = 0; i< size; i++) {
- Entry * entry = unseenArbitrations->get(i);
+ for (uint i = 0; i < size; i++) {
+ Entry *entry = unseenArbitrations->get(i);
entry->encode(bbEncode);
}
if (hadPartialSendToServer) {
bool isInserted = false;
- uint size = array->size();
- for(uint i=0; i < size; i++) {
+ uint size = array->length();
+ for (uint i = 0; i < size; i++) {
Slot *s = array->get(i);
if ((s->getSequenceNumber() == slot->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
isInserted = true;
}
}
- for(uint i=0; i < size; i++) {
+ for (uint i = 0; i < size; i++) {
Slot *s = array->get(i);
if (isInserted) {
break;
}
// Process each entry in the slot
- for (Entry *entry : s->getEntries()) {
+ Vector<Entry *> *entries = s->getEntries();
+ uint eSize = entries->size();
+ for(uint ei=0; ei < eSize; ei++) {
+ Entry * entry = entries->get(ei);
if (entry->getType() == TypeLastMessage) {
LastMessage *lastMessage = (LastMessage *)entry;
ThreeTuple<bool, int32_t, bool> Table::fillSlot(Slot *slot, bool resize, NewKey *newKeyEntry) {
int newSize = 0;
if (liveSlotCount > bufferResizeThreshold) {
- resize = true; //Resize is forced
+ resize = true;//Resize is forced
}
if (resize) {
transactionPartsSent->clear();
pendingSendArbitrationEntriesToDelete->clear();
uint size = pendingSendArbitrationRounds->size();
- for (uint i=0; i<size; i++)
- ArbitrartionRound *round = pendingSendArbitrationRounds->get(i);
+ for (uint i = 0; i < size; i++) {
+ ArbitrationRound *round = pendingSendArbitrationRounds->get(i);
bool isFull = false;
round->generateParts();
Vector<Entry *> *parts = round->getParts();
// Insert pending arbitration data
uint vsize = parts->size();
- for (uint vi=0; vi<vsize; vi++) {
+ for (uint vi = 0; vi < vsize; vi++) {
Entry *arbitrationData = parts->get(vi);
-
+
// If it is an abort then we need to set some information
if (arbitrationData->getType() == TypeAbort) {
((Abort *)arbitrationData)->setSequenceNumber(slot->getSequenceNumber());
// Mandatory Rescue
for (; currentSequenceNumber < threshold; currentSequenceNumber++) {
- Slot previousSlot = buffer->getSlot(currentSequenceNumber);
+ Slot * previousSlot = buffer->getSlot(currentSequenceNumber);
// Push slot number forward
if (!seenLiveSlot) {
oldestLiveSlotSequenceNumver = currentSequenceNumber;
else {
skipcount++;
if (skipcount > Table_SKIP_THRESHOLD)
- break search;
+ goto donesearch;
}
}
}
+ donesearch:
+ ;
}
/**
// Iterate through all the machine Ids that we received new parts
// for
for (int64_t machineId : newTransactionParts->keySet()) {
- Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
+ Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *parts = newTransactionParts->get(machineId);
// Iterate through all the parts for that machine Id
for (Pair<int64_t, int32_t> partId : parts->keySet()) {
Collections->sort(transactionSequenceNumbers);
// Collection of key value pairs that are
- Hashtable<IoTString *, KeyValue *> speculativeTableTmp = new Hashtable<IoTString *, KeyValue *>();
+ Hashtable<IoTString *, KeyValue *> * speculativeTableTmp = new Hashtable<IoTString *, KeyValue *>();
// The last transaction arbitrated on
int64_t lastTransactionCommitted = -1;
// Guard evaluated as true
// Update the local changes so we can make the commit
- for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
speculativeTableTmp->put(kv->getKey(), kv);
}
-
+ delete kvit;
+
// Update what the last transaction committed was for use in batch commit
lastTransactionCommitted = transactionSequenceNumber;
} else {
localArbitrationSequenceNumber++;
// Update the local changes so we can make the commit
- for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(transaction->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
newCommit->addKV(kv);
}
-
+ delete kvit;
+
// create the commit parts
newCommit->createCommitParts();
if (transaction->getMachineId() == localMachineId) {
// For locally created messages update the status
// Guard evaluated was false so create abort
- TransactionStatus status = transaction->getTransactionStatus();
+ TransactionStatus * status = transaction->getTransactionStatus();
if (status != NULL) {
status->setStatus(TransactionStatus_StatusAborted);
}
}
ArbitrationRound *lastRound = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - 1);
- if (lastRound->didSendPart()) {
+ if (lastRound->getDidSendPart()) {
return false;
}
while (numberToDelete < pendingSendArbitrationRounds->size()) {
ArbitrationRound *xs round = pendingSendArbitrationRounds->get(pendingSendArbitrationRounds->size() - numberToDelete - 1);
- if (round->isFull() || round->didSendPart()) {
+ if (round->isFull() || round->getDidSendPart()) {
// Stop since there is a part that cannot be compacted and we
// need to compact in order
break;
// Iterate through all the machine Ids that we received new parts for
for (int64_t machineId : newCommitParts->keySet()) {
- Hashtable<Pair<int64_t, int32_t>, CommitPart *> *parts = newCommitParts->get(machineId);
+ Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *parts = newCommitParts->get(machineId);
// Iterate through all the parts for that machine Id
for (Pair<int64_t, int32_t> partId : parts->keySet()) {
}
// Update the last arbitration data that we have seen so far
- if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(commit->getMachineId()) != NULL) {
-
+ if (lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->contains(commit->getMachineId())) {
int64_t lastArbitrationSequenceNumber = lastArbitrationDataLocalSequenceNumberSeenFromArbitrator->get(commit->getMachineId());
if (commit->getSequenceNumber() > lastArbitrationSequenceNumber) {
// Is larger
// Get what commits should be edited, these are the commits that
// have live values for their keys
Hashset<Commit *> *commitsToEdit = new Hashset<Commit *>();
- for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
commitsToEdit->add(liveCommitsByKeyTable->get(kv->getKey()));
}
+ delete kvit;
commitsToEdit->remove(NULL); // remove NULL since it could be in this set
// Update each previous commit that needs to be updated
if (previousCommit->isLive()) {
// Update which keys in the old commits are still live
- for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
previousCommit->invalidateKey(kv->getKey());
}
-
+ delete kvit;
+
// if the commit is now dead then remove it
if (!previousCommit->isLive()) {
commitForClientTable->remove(previousCommit);
didProcessANewCommit = true;
// Update the committed table of keys and which commit is using which key
- for (KeyValue *kv : commit->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
committedKeyValueTable->put(kv->getKey(), kv);
liveCommitsByKeyTable->put(kv->getKey(), commit);
}
+ delete kvit;
}
}
if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, NULL)) {
// Guard evaluated to true so update the speculative table
- for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
speculatedKeyValueTable->put(kv->getKey(), kv);
}
+ delete kvit;
}
}
if (transaction->evaluateGuard(committedKeyValueTable, speculatedKeyValueTable, pendingTransactionSpeculatedKeyValueTable)) {
// Guard evaluated to true so update the speculative table
- for (KeyValue *kv : transaction->getKeyValueUpdateSet()) {
+ SetIterator<KeyValue *> *kvit = getKeyIterator(commit->getKeyValueUpdateSet());
+ while (kvit->hasNext()) {
+ KeyValue *kv = kvit->next();
pendingTransactionSpeculatedKeyValueTable->put(kv->getKey(), kv);
}
+ delete kvit;
}
}
}
updateLastMessage(slot->getMachineID(), slot->getSequenceNumber(), slot, acceptUpdatesToLocal, machineSet);
// Process each entry in the slot
- for (Entry *entry : slot->getEntries()) {
+ Vector<Entry *> *entries = slot->getEntries();
+ uint eSize = entries->size();
+ for(uint ei=0; ei < eSize; ei++) {
+ Entry * entry = entries->get(ei);
switch (entry->getType()) {
case TypeCommitPart:
processEntry((CommitPart *)entry);
// keep track of it
Abort *previouslySeenAbort = liveAbortTable->put(entry->getAbortId(), entry);
if (previouslySeenAbort != NULL) {
- previouslySeenAbort->setDead(); // Delete old version of the abort since we got a rescued newer version
+ previouslySeenAbort->setDead(); // Delete old version of the abort since we got a rescued newer version
}
if (entry->getTransactionArbitrator() == localMachineId) {
}
// This part is still alive
- Hashtable<Pair<int64_t, int32_t>, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *transactionPart = newTransactionParts->get(entry->getMachineId());
+ Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals> *transactionPart = newTransactionParts->get(entry->getMachineId());
if (transactionPart == NULL) {
// Dont have a table for this machine Id yet so make one
- transactionPart = new Hashtable<Pair<int64_t, int32_t>, TransactionPart *>();
+ transactionPart = new Hashtable<Pair<int64_t, int32_t> *, TransactionPart *, uintptr_t, 0, pairHashFunction, pairEquals>();
newTransactionParts->put(entry->getMachineId(), transactionPart);
}
}
}
- Hashtable<Pair<int64_t, int32_t>, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
+ Hashtable<Pair<int64_t, int32_t> *, CommitPart *> *commitPart = newCommitParts->get(entry->getMachineId());
if (commitPart == NULL) {
// Don't have a table for this machine Id yet so make one
- commitPart = new Hashtable<Pair<int64_t, int32_t>, CommitPart *>();
+ commitPart = new Hashtable<Pair<int64_t, int32_t> *, CommitPart *>();
newCommitParts->put(entry->getMachineId(), commitPart);
}
// Update the part and set dead ones we have already seen (got a