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.
This commit is contained in:
Markus Makela
2014-09-09 10:44:20 +03:00
parent 2097b54c35
commit aa83b6b21a
2 changed files with 19 additions and 17 deletions

View File

@ -874,12 +874,13 @@ static char* blockbuf_get_writepos(
size_t str_len, size_t str_len,
bool flush) bool flush)
{ {
logfile_t* lf; int depth = 0;
mlist_t* bb_list; logfile_t* lf;
char* pos = NULL; mlist_t* bb_list;
mlist_node_t* node; char* pos = NULL;
blockbuf_t* bb; mlist_node_t* node;
ss_debug(bool succp;) blockbuf_t* bb;
ss_debug(bool succp;)
CHK_LOGMANAGER(lm); CHK_LOGMANAGER(lm);
@ -897,6 +898,7 @@ static char* blockbuf_get_writepos(
*/ */
node = bb_list->mlist_first; node = bb_list->mlist_first;
/** Loop over blockbuf list to find write position */ /** Loop over blockbuf list to find write position */
while (true) { while (true) {
CHK_MLIST_NODE(node); CHK_MLIST_NODE(node);
@ -918,19 +920,9 @@ static char* blockbuf_get_writepos(
*/ */
blockbuf_register(bb); 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; bb->bb_isfull = true;
blockbuf_unregister(bb); blockbuf_unregister(bb);
@ -940,6 +932,16 @@ static char* blockbuf_get_writepos(
/** Lock list */ /** Lock list */
simple_mutex_lock(&bb_list->mlist_mutex, true); 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 * If next node exists move forward. Else check if there is
* space for a new block buffer on the list. * space for a new block buffer on the list.

View File

@ -45,7 +45,7 @@ error=0
for i in $MESSAGES for i in $MESSAGES
do do
if [[ $i -le $prev ]] if [[ $i -ne $(( prev + 1 )) ]]
then then
error=1 error=1
echo "message mismatch: $i was after $prev." echo "message mismatch: $i was after $prev."