Code polishing.

This commit is contained in:
vraatikka
2013-07-26 21:46:23 +03:00
parent ff8b432943
commit 3989615197

View File

@ -1444,18 +1444,22 @@ static void filewriter_done(
* with spinlock. Another protected section is when block buffer's metadata is * with spinlock. Another protected section is when block buffer's metadata is
* read, and optionally the write operation. * read, and optionally the write operation.
* *
* When block buffer is marked full or flush flag is set, they don't try to * When block buffer is marked full, logfile's flushflag is set, other
* access buffer. There may, however, be active writes, on the block in parallel * log clients don't try to access buffer(s). There may, however, be
* with file writer operations. Each active write corresponds to bb_refcounter * active writes, on the block in parallel with file writer operations.
* values. File writer doesn't write block buffer before its refcount is zero. * Each active write corresponds to bb_refcounter values.
* On the other hand, file writer doesn't process the block buffer before
* its refcount is zero.
* *
* Block buffers are located in a linked list. List is accessed by log clients, * Every log file obj. has its own block buffer (linked) list.
* which add nodes if necessary, and by file writer which traverses the list * List is accessed by log clients, which add nodes if necessary, and
* and accesses block buffers included in list nodes. List modifications are * by file writer which traverses the list and accesses block buffers
* protected with version numbers. Before modification, version is increased * included in list nodes.
* by one to be odd. After the completion, it is increased again to even. List * List modifications are protected with version numbers.
* can be read only when version is even and read is consistent only if version * Before modification, version is increased by one to be odd. After the
* hasn't changed during the read. * completion, it is increased again to even. List can be read only when
* version is even and read is consistent only if version hasn't changed
* during the read.
*/ */
static void* thr_filewriter_fun( static void* thr_filewriter_fun(
void* data) void* data)
@ -1469,8 +1473,9 @@ static void* thr_filewriter_fun(
blockbuf_t* bb; blockbuf_t* bb;
mlist_node_t* node; mlist_node_t* node;
int i; int i;
bool flush; /**< flush logfile */ bool flush_blockbuf; /**< flush single block buffer. */
bool flushall;/**< flush all logfiles */ bool flush_logfile; /**< flush logfile */
bool flushall_logfiles;/**< flush all logfiles */
size_t vn1; size_t vn1;
size_t vn2; size_t vn2;
@ -1489,7 +1494,7 @@ static void* thr_filewriter_fun(
*/ */
skygw_message_wait(fwr->fwr_logmes); skygw_message_wait(fwr->fwr_logmes);
flushall = skygw_thread_must_exit(thr); flushall_logfiles = skygw_thread_must_exit(thr);
/** Process all logfiles which have buffered writes. */ /** Process all logfiles which have buffered writes. */
for (i=LOGFILE_FIRST; i<=LOGFILE_LAST; i++) { for (i=LOGFILE_FIRST; i<=LOGFILE_LAST; i++) {
@ -1503,7 +1508,7 @@ static void* thr_filewriter_fun(
* read and reset logfile's flushflag * read and reset logfile's flushflag
*/ */
acquire_lock(&lf->lf_spinlock); acquire_lock(&lf->lf_spinlock);
flush = lf->lf_flushflag; flush_logfile = lf->lf_flushflag;
lf->lf_flushflag = FALSE; lf->lf_flushflag = FALSE;
release_lock(&lf->lf_spinlock); release_lock(&lf->lf_spinlock);
@ -1523,8 +1528,10 @@ static void* thr_filewriter_fun(
/** Lock block buffer */ /** Lock block buffer */
simple_mutex_lock(&bb->bb_mutex, TRUE); simple_mutex_lock(&bb->bb_mutex, TRUE);
flush_blockbuf = bb->bb_isfull;
if (bb->bb_buf_used != 0 && if (bb->bb_buf_used != 0 &&
(bb->bb_isfull || flush || flushall)) (flush_blockbuf || flush_logfile || flushall_logfiles))
{ {
/** /**
* buffer is at least half-full -> write to disk * buffer is at least half-full -> write to disk
@ -1537,12 +1544,9 @@ static void* thr_filewriter_fun(
skygw_file_write(file, skygw_file_write(file,
(void *)bb->bb_buf, (void *)bb->bb_buf,
bb->bb_buf_used, bb->bb_buf_used,
(flush || flushall)); /**< call fsync */ (flush_logfile || flushall_logfiles));
/** /**
* Reset buffer * Reset buffer's counters and mark not full.
* NOTE: it may be probably faster to free and calloc
* new buffer every time full one is locked for
* file write.
*/ */
bb->bb_buf_left = bb->bb_buf_size; bb->bb_buf_left = bb->bb_buf_size;
bb->bb_buf_used = 0; bb->bb_buf_used = 0;