Permalink
Browse files

Don't commit unless we've got pending data to write

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...
1 parent 56ce0a2 commit b77d1e2564662ea0e243cf3e1601da08640b245f @trondn trondn committed May 14, 2012
Showing with 17 additions and 1 deletion.
  1. +16 −1 src/instance.c
  2. +1 −0 src/internal.h
View
@@ -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;
}
@@ -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 {
View
@@ -30,6 +30,7 @@
struct libcbio_st {
Db *couchstore_handle;
+ int dirty;
libcbio_open_mode_t mode;
};

0 comments on commit b77d1e2

Please sign in to comment.