Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions include/rocksdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct rocksdb_compact_range_s rocksdb_compact_range_t;
typedef struct rocksdb_approximate_size_s rocksdb_approximate_size_t;
typedef struct rocksdb_wal_file_s rocksdb_wal_file_t;
typedef struct rocksdb_current_wal_file_s rocksdb_current_wal_file_t;
typedef struct rocksdb_flush_wal_s rocksdb_flush_wal_t;
typedef struct rocksdb_s rocksdb_t;

typedef void (*rocksdb_idle_cb)(rocksdb_t *db);
Expand All @@ -56,6 +57,7 @@ typedef void (*rocksdb_compact_cb)(rocksdb_compact_t *req, int status);
typedef void (*rocksdb_compact_range_cb)(rocksdb_compact_range_t *req, int status);
typedef void (*rocksdb_approximate_size_cb)(rocksdb_approximate_size_t *req, int status);
typedef void (*rocksdb_current_wal_file_cb)(rocksdb_current_wal_file_t *req, int status);
typedef void (*rocksdb_flush_wal_cb)(rocksdb_flush_wal_t *req, int status);

typedef enum {
rocksdb_tolerate_corrupted_tail_records_recovery_mode = 0,
Expand Down Expand Up @@ -629,6 +631,19 @@ struct rocksdb_current_wal_file_s {
void *data;
};

struct rocksdb_flush_wal_s {
rocksdb_req_t req;

bool sync;

char *error;
int status;

rocksdb_flush_wal_cb cb;

void *data;
};

struct rocksdb_snapshot_s {
rocksdb_t *db;

Expand Down Expand Up @@ -796,6 +811,12 @@ rocksdb_current_wal_file(rocksdb_t *db, rocksdb_current_wal_file_t *req, rocksdb
void
rocksdb_current_wal_file_cleanup(rocksdb_current_wal_file_t *req);

int
rocksdb_flush_wal(rocksdb_t *db, rocksdb_flush_wal_t *req, bool sync, rocksdb_flush_wal_cb cb);

void
rocksdb_flush_wal_cleanup(rocksdb_flush_wal_t *req);

int
rocksdb_snapshot_create(rocksdb_t *db, rocksdb_snapshot_t *snapshot);

Expand Down
59 changes: 59 additions & 0 deletions src/rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,65 @@ rocksdb_current_wal_file_cleanup(rocksdb_current_wal_file_t *req) {
}
}

namespace {

static void
rocksdb__on_after_flush_wal(uv_work_t *handle, int status) {
int err;

auto req = reinterpret_cast<rocksdb_flush_wal_t *>(handle->data);

err = rocksdb__remove_req(req);
assert(err == 0);

if (req->cb) req->cb(req, status);
}

static void
rocksdb__on_flush_wal(uv_work_t *handle) {
auto req = reinterpret_cast<rocksdb_flush_wal_t *>(handle->data);

auto db = reinterpret_cast<DB *>(req->req.db->handle);

auto status = db->FlushWAL(req->sync);

if (status.ok()) {
req->error = nullptr;
req->status = 0;
} else {
req->error = strdup(status.getState());
req->status = rocksdb__status(status);
}
}

} // namespace

extern "C" int
rocksdb_flush_wal(rocksdb_t *db, rocksdb_flush_wal_t *req, bool sync, rocksdb_flush_wal_cb cb) {
if (db->state != rocksdb_active) {
return UV_EINVAL;
}

req->req.db = db;
req->sync = sync;
req->error = nullptr;
req->cb = cb;

req->req.worker.data = static_cast<void *>(req);

rocksdb__add_req(req);

return rocksdb__queue_work(cb ? rocksdb_async : rocksdb_sync, req->req.db->loop, req, rocksdb__on_flush_wal, rocksdb__on_after_flush_wal);
}

extern "C" void
rocksdb_flush_wal_cleanup(rocksdb_flush_wal_t *req) {
if (req->error) {
free(req->error);
req->error = nullptr;
}
}

extern "C" int
rocksdb_snapshot_create(rocksdb_t *db, rocksdb_snapshot_t *snapshot) {
auto handle = reinterpret_cast<DB *>(db->handle)->GetSnapshot();
Expand Down
Loading