-bool Table::sendToServer(NewKey *newKey) {
- bool fromRetry = false;
- try {
- if (hadPartialSendToServer) {
- Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
- if (newSlots->length() == 0) {
- fromRetry = true;
- ThreeTuple<bool, bool, Array<Slot *> *> sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey);
-
- if (sendSlotsReturn.getFirst()) {
- if (newKey != NULL) {
- if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
- newKey = NULL;
- }
- }
-
- SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
- while (trit->hasNext()) {
- Transaction *transaction = trit->next();
- transaction->resetServerFailure();
- // Update which transactions parts still need to be sent
- transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
- // Add the transaction status to the outstanding list
- outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
-
- // Update the transaction status
- transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
-
- // Check if all the transaction parts were successfully
- // sent and if so then remove it from pending
- if (transaction->didSendAllParts()) {
- transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
- pendingTransactionQueue->remove(transaction);
- }
- }
- delete trit;
- } else {
- newSlots = sendSlotsReturn.getThird();
- bool isInserted = false;
- for (uint si = 0; si < newSlots->length(); si++) {
- Slot *s = newSlots->get(si);
- if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+NewKey * Table::handlePartialSend(NewKey * newKey) {
+ //Didn't receive acknowledgement for last send
+ //See if the server has received a newer slot
+
+ Array<Slot *> *newSlots = cloud->getSlots(sequenceNumber + 1);
+ if (newSlots->length() == 0) {
+ //Retry sending old slot
+ bool wasInserted = false;
+ bool sendSlotsReturn = sendSlotsToServer(lastSlotAttemptedToSend, lastNewSize, lastIsNewKey, &wasInserted, &newSlots);
+
+ if (sendSlotsReturn) {
+ if (newKey != NULL) {
+ if (lastInsertedNewKey && (lastNewKey->getKey() == newKey->getKey()) && (lastNewKey->getMachineID() == newKey->getMachineID())) {
+ newKey = NULL;
+ }
+ }
+
+ SetIterator<Transaction *, Vector<int> *> *trit = getKeyIterator(lastTransactionPartsSent);
+ while (trit->hasNext()) {
+ Transaction *transaction = trit->next();
+ transaction->resetServerFailure();
+ // Update which transactions parts still need to be sent
+ transaction->removeSentParts(lastTransactionPartsSent->get(transaction));
+ // Add the transaction status to the outstanding list
+ outstandingTransactionStatus->put(transaction->getSequenceNumber(), transaction->getTransactionStatus());
+
+ // Update the transaction status
+ transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentPartial);
+
+ // Check if all the transaction parts were successfully
+ // sent and if so then remove it from pending
+ if (transaction->didSendAllParts()) {
+ transaction->getTransactionStatus()->setStatus(TransactionStatus_StatusSentFully);
+ pendingTransactionQueue->remove(transaction);
+ }
+ }
+ delete trit;
+ } else {
+ bool isInserted = false;
+ for (uint si = 0; si < newSlots->length(); si++) {
+ Slot *s = newSlots->get(si);
+ if ((s->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber()) && (s->getMachineID() == localMachineId)) {
+ isInserted = true;
+ break;
+ }
+ }
+
+ for (uint si = 0; si < newSlots->length(); si++) {
+ Slot *s = newSlots->get(si);
+ if (isInserted) {
+ break;
+ }
+
+ // Process each entry in the slot
+ Vector<Entry *> *ventries = s->getEntries();
+ uint vesize = ventries->size();
+ for (uint vei = 0; vei < vesize; vei++) {
+ Entry *entry = ventries->get(vei);
+ if (entry->getType() == TypeLastMessage) {
+ LastMessage *lastMessage = (LastMessage *)entry;
+ if ((lastMessage->getMachineID() == localMachineId) && (lastMessage->getSequenceNumber() == lastSlotAttemptedToSend->getSequenceNumber())) {