Skip to content

Commit

Permalink
Don't commit unless we've got pending data to write
Browse files Browse the repository at this point in the history
Change-Id: I4bc9685e7cd180891b0146065bfefcfea9756fa0
Reviewed-on: http://review.couchbase.org/15963
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information
trondn committed May 15, 2012
1 parent 56ce0a2 commit b77d1e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ static cbio_error_t cbio_store_local_documents(libcbio_t handle,
return cbio_remap_error(err);
}
}
handle->dirty = 1;
return CBIO_SUCCESS;
}

Expand Down Expand Up @@ -250,16 +251,30 @@ cbio_error_t cbio_store_documents(libcbio_t handle,
free(docs);
free(info);

if (err == COUCHSTORE_SUCCESS) {
handle->dirty = 1;
}

return cbio_remap_error(err);
}

LIBCBIO_API
cbio_error_t cbio_commit(libcbio_t handle)
{
couchstore_error_t err = COUCHSTORE_SUCCESS;

if (handle->mode == CBIO_OPEN_RDONLY) {
return CBIO_ERROR_EINVAL;
}
return cbio_remap_error(couchstore_commit(handle->couchstore_handle));

if (handle->dirty) {
err = couchstore_commit(handle->couchstore_handle);
if (err == COUCHSTORE_SUCCESS) {
handle->dirty = 0;
}
}

return cbio_remap_error(err);
}

struct cbio_wrap_ctx {
Expand Down
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

struct libcbio_st {
Db *couchstore_handle;
int dirty;
libcbio_open_mode_t mode;
};

Expand Down

0 comments on commit b77d1e2

Please sign in to comment.