From aa83b6b21a6caab1a5a805d7acb53e8a7d72fecf Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 9 Sep 2014 10:44:20 +0300 Subject: [PATCH] Changed the way blockbuffers are used after they fill up. The blockbuffers that get full are now moved to the end of the list of blocks. This prevents messages being written to the disk in the wrong order. --- log_manager/log_manager.cc | 34 ++++++++++++++++++---------------- log_manager/test/logorder.sh | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index af9cf5fee..e8f80b0d6 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -874,12 +874,13 @@ static char* blockbuf_get_writepos( size_t str_len, bool flush) { - logfile_t* lf; - mlist_t* bb_list; - char* pos = NULL; - mlist_node_t* node; - blockbuf_t* bb; - ss_debug(bool succp;) + int depth = 0; + logfile_t* lf; + mlist_t* bb_list; + char* pos = NULL; + mlist_node_t* node; + blockbuf_t* bb; + ss_debug(bool succp;) CHK_LOGMANAGER(lm); @@ -896,6 +897,7 @@ static char* blockbuf_get_writepos( * At least block buffer exists on the list. */ node = bb_list->mlist_first; + /** Loop over blockbuf list to find write position */ while (true) { @@ -918,19 +920,9 @@ static char* blockbuf_get_writepos( */ blockbuf_register(bb); -#if defined(SS_DEBUG) - if(!bb->bb_isfull){ - char* tmp = (char*)calloc(128,sizeof(char)); - sprintf(tmp,"[full:%d]",atomic_add(&block_end_index,1)); - memcpy(bb->bb_buf,tmp,strlen(tmp)); - free(tmp); - } -#endif - bb->bb_isfull = true; - blockbuf_unregister(bb); @@ -940,6 +932,16 @@ static char* blockbuf_get_writepos( /** Lock list */ simple_mutex_lock(&bb_list->mlist_mutex, true); + /**Move the full buffer to the end of the list*/ + if(node->mlnode_next){ + bb_list->mlist_first = node->mlnode_next; + bb_list->mlist_last->mlnode_next = node; + node->mlnode_next = NULL; + bb_list->mlist_last = node; + node = bb_list->mlist_first; + continue; + } + /** * If next node exists move forward. Else check if there is * space for a new block buffer on the list. diff --git a/log_manager/test/logorder.sh b/log_manager/test/logorder.sh index 2d45a3d79..940b2327d 100755 --- a/log_manager/test/logorder.sh +++ b/log_manager/test/logorder.sh @@ -45,7 +45,7 @@ error=0 for i in $MESSAGES do - if [[ $i -le $prev ]] + if [[ $i -ne $(( prev + 1 )) ]] then error=1 echo "message mismatch: $i was after $prev."