Array<char> *CloudComm::encryptSlotAndPrependIV(Array<char> *rawData, Array<char> *ivBytes) {
try {
Array<char> *encryptedBytes = AESEncrypt(ivBytes, key, rawData);
- Array<char> *origBytes = AESDecrypt(ivBytes, key, encryptedBytes);
- if (!rawData->equals(origBytes))
- throw new Error("BAD");
Array<char> *chars = new Array<char>(encryptedBytes->length() + CloudComm_IV_SIZE);
System_arraycopy(ivBytes, 0, chars, 0, ivBytes->length());
System_arraycopy(encryptedBytes, 0, chars, CloudComm_IV_SIZE, encryptedBytes->length());
-
+ delete encryptedBytes;
return chars;
} catch (Exception *e) {
throw new Error("Failed To Encrypt");
Array<char> *encryptedBytes = new Array<char>(rawData->length() - CloudComm_IV_SIZE);
System_arraycopy(rawData, 0, ivBytes, 0, CloudComm_IV_SIZE);
System_arraycopy(rawData, CloudComm_IV_SIZE, encryptedBytes, 0, encryptedBytes->length());
- return AESDecrypt(ivBytes, key, encryptedBytes);
+ Array<char> * data = AESDecrypt(ivBytes, key, encryptedBytes);
+ delete encryptedBytes;
+ delete ivBytes;
+ return data;
} catch (Exception *e) {
throw new Error("Failed To Decrypt");
}
int64_t sequencenumber = slot->getSequenceNumber();
Array<char> *slotBytes = slot->encode(mac);
Array<char> *chars = encryptSlotAndPrependIV(slotBytes, slot->getSlotCryptIV());
+ delete slotBytes;
IoTString *url = buildRequest(true, sequencenumber, max);
timer->startTime();
wc = openURL(url);
writeURLDataAndClose(&wc, chars);
+ delete chars;
timer->endTime();
} catch (ServerException *e) {
timer->endTime();
Array<char> *rawData = new Array<char>(sizesofslots->get(i));
readURLData(wc, rawData);
Array<char> *data = stripIVAndDecryptSlot(rawData);
+ delete rawData;
slots->set(i, Slot_decode(table, data, mac));
+ delete data;
}
return slots;
}
delete pendingTransactionSpeculatedKeyValueTable;
delete liveNewKeyTable;
delete lastMessageTable;
- delete rejectedMessageWatchVectorTable;
+ {
+ 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 localCommunicationTable;
delete lastTransactionSeenFromMachineFromServer;
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;
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);
}
// 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;
}
lastInsertedNewKey = insertedNewKey;
lastNewSize = newSize;
lastNewKey = newKey;
+ if (lastTransactionPartsSent != NULL)
+ delete lastTransactionPartsSent;
lastTransactionPartsSent = transactionPartsSent->clone();
lastPendingSendArbitrationEntriesToDelete = new Vector<Entry *>(pendingSendArbitrationEntriesToDelete);
// insert into the local block chain
validateAndUpdate(newSlots, true);
}
+ delete newSlots;
}
} catch (ServerException *e) {
if (e->getType() != ServerException_TypeInputTimeout) {
updateExpectedSize();
}
}
-
+ delete indexer;
+
// If there is a gap, check to see if the server sent us
// everything->
if (firstSeqNum != (sequenceNumber + 1)) {
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() {
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);
commit->addPartDecode(part);
}
delete pairit;
+ delete parts;
}
delete partsit;
// Delete it and move on
commit->setDead();
commitForClientTable->remove(commit->getSequenceNumber());
+ delete commit;
continue;
}
}
// if the commit is now dead then remove it
if (!previousCommit->isLive()) {
commitForClientTable->remove(previousCommit->getSequenceNumber());
+ delete previousCommit;
}
}
}
// Remove the transaction from the live table
iter->remove();
liveTransactionByTransactionIdTable->remove(transaction->getId());
+ delete transaction;
}
}
delete iter;
rmit->remove();
// Decrement machines that need to see this notification
rm->removeWatcher(machineId);
+ delete rm;
}
}
delete rmit;
t1->createNewKey(ib, 351);
t2->createNewKey(ic, 321);
t2->createNewKey(id, 351);
+ delete ia;
+ delete ib;
+ delete ic;
+ delete id;
}
// Do Updates for the keys
IoTString * iValueD = new IoTString(buffer);
t1->startTransaction();
- t1->addKV(iKeyA, iValueA);
+ t1->put(iKeyA, iValueA);
transStatusList->add(t1->commitTransaction());
+ delete iKeyA; delete iValueA;
+
t1->startTransaction();
- t1->addKV(iKeyB, iValueB);
+ t1->put(iKeyB, iValueB);
transStatusList->add(t1->commitTransaction());
+ delete iKeyB; delete iValueB;
t2->startTransaction();
- t2->addKV(iKeyC, iValueC);
+ t2->put(iKeyC, iValueC);
transStatusList->add(t2->commitTransaction());
+ delete iKeyC; delete iValueC;
t2->startTransaction();
- t2->addKV(iKeyD, iValueD);
+ t2->put(iKeyD, iValueD);
transStatusList->add(t2->commitTransaction());
+ delete iKeyD; delete iValueD;
}
+
printf("Updating Clients...\n");
t1->update();
t2->update();
printf("Key-Value t2 incorrect: keyD testValD2\n");
foundError = true;
}
+ delete iKeyA; delete iValueA;
+ delete iKeyB; delete iValueB;
+ delete iKeyC; delete iValueC;
+ delete iKeyD; delete iValueD;
+ delete testValA1; delete testValA2;
+ delete testValB1; delete testValB2;
+ delete testValC1; delete testValC2;
+ delete testValD1; delete testValD2;
}
for (uint i = 0; i < transStatusList->size(); i++) {
} else {
printf("No Errors Found...\n");
}
+
+ delete transStatusList;
+ delete t1;
+ delete t2;
}