int timeout = recv_data((int)acceptfd, &control, sizeof(char));
#ifdef RECOVERY
- tlist_node_t* tNode;
- tNode = tlistSearch(transList,fixed->transid);
-
if(timeout < 0) { // timeout. failed to receiving data from coordinator
- tNode->decision = DECISION_LOST;
- printf("%s -> DECISON_LOST! control = %d\n",__func__,control);
+ control = -1;
}
- else
- tNode->decision = control;
-
// check if it is allowed to commit
- if(!((tNode->decision != DECISION_LOST) && (okCommit == TRANS_OK)))
- {
- pthread_mutex_lock(&liveHosts_mutex);
- tNode->status = TRANS_WAIT;
- pthread_mutex_unlock(&liveHosts_mutex);
-
- while(!((tNode->decision != DECISION_LOST) && (okCommit == TRANS_OK))) {
- printf("%s -> transID : %u decision : %d is waiting\n",__func__,tNode->transid,tNode->decision);
- sleep(1);
- }
- }
-
- control = tNode->decision;
-
+ control = inspectTransaction(control,fixed->transid);
thashInsert(fixed->transid, control);
+
#endif
switch(control) {
#ifdef RECOVERY
// printf("%s -> transID : %u has been committed\n",__func__,transID);
+
+ tlist_node_t* tNode = tlistSearch(transList,fixed->transid);
tNode->status = TRANS_OK;
pthread_mutex_lock(&clearNotifyList_mutex);
return flag;
}
+char inspectTransaction(char finalResponse,unsigned int transid)
+{
+ tlist_node_t* tNode;
+
+ tNode = tlistSearch(transList,transid);
+
+ if(finalResponse < 0) {
+ tNode->decision = DECISION_LOST;
+ }
+ else {
+ tNode->decision = finalResponse;
+ }
+
+ if(!((tNode->decision != DECISION_LOST) && (okCommit == TRANS_OK)))
+ {
+ pthread_mutex_lock(&liveHosts_mutex);
+ tNode->status = TRANS_WAIT;
+ pthread_mutex_unlock(&liveHosts_mutex);
+
+ while(!((tNode->decision != DECISION_LOST) && (okCommit == TRANS_OK))) {
+ printf("%s -> transID : %u decision : %d is waiting\n",__func__,tNode->transid,tNode->decision);
+ sleep(3);
+ }
+
+ finalResponse = tNode->decision;
+ }
+
+ return finalResponse;
+}
+
#endif
} else {
/* Complete local processing */
-#ifdef RECOVERY
- thashInsert(transID,finalResponse);
-#endif
doLocalProcess(finalResponse, &(tosend[i]), &transinfo);
#ifdef ABORTREADERS
void doLocalProcess(char finalResponse, trans_req_data_t *tdata, trans_commit_data_t *transinfo) {
+#ifdef RECOVERY
+ finalResponse = inspectTransaction(finalResponse,tdata->f.transid);
+ thashInsert(tdata->f.transid,finalResponse);
+#endif
+
if(finalResponse == TRANS_ABORT) {
if(transAbortProcess(transinfo) != 0) {
printf("Error in transAbortProcess() %s,%d\n", __FILE__, __LINE__);