From 5d18bbcf93e4c6d7fc065f98d5908d7478647209 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Fri, 1 Apr 2016 17:16:08 -0400 Subject: [PATCH] Made Database::compact not fail when there's an auto-compact in progress For couchbase/couchbase-lite-ios#1192 --- CBForest/Database.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CBForest/Database.cc b/CBForest/Database.cc index aff40ef..fd0e1fe 100644 --- a/CBForest/Database.cc +++ b/CBForest/Database.cc @@ -17,6 +17,7 @@ #include "Document.hh" #include "LogInternal.hh" #include "atomic.h" // forestdb internal +#include "time_utils.h" // forestdb internal #include #include // va_start, va_end #include @@ -340,7 +341,14 @@ namespace cbforest { static atomic_uint32_t sCompactCount; void Database::compact() { - check(fdb_compact(_fileHandle, NULL)); + auto status = fdb_compact(_fileHandle, NULL); + if (status == FDB_RESULT_FILE_IS_BUSY) { + // This result means there is already a background auto-compact in progress. + while (isCompacting()) + ::usleep(100 * 1000); + } else { + check(status); + } } // static