Skip to content

Commit

Permalink
Made Database::compact not fail when there's an auto-compact in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Apr 1, 2016
1 parent f0f070a commit 5d18bbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CBForest/Database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Document.hh"
#include "LogInternal.hh"
#include "atomic.h" // forestdb internal
#include "time_utils.h" // forestdb internal
#include <errno.h>
#include <stdarg.h> // va_start, va_end
#include <stdio.h>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5d18bbc

Please sign in to comment.