|
|
|
@ -29,6 +29,7 @@ |
|
|
|
|
#include "rocksdb/statistics.h" |
|
|
|
|
#include "rocksdb/slice_transform.h" |
|
|
|
|
#include "rocksdb/table.h" |
|
|
|
|
#include "rocksdb/utilities/backupable_db.h" |
|
|
|
|
|
|
|
|
|
using rocksdb::Cache; |
|
|
|
|
using rocksdb::ColumnFamilyDescriptor; |
|
|
|
@ -69,12 +70,19 @@ using rocksdb::WritableFile; |
|
|
|
|
using rocksdb::WriteBatch; |
|
|
|
|
using rocksdb::WriteOptions; |
|
|
|
|
using rocksdb::LiveFileMetaData; |
|
|
|
|
using rocksdb::BackupEngine; |
|
|
|
|
using rocksdb::BackupableDBOptions; |
|
|
|
|
using rocksdb::BackupInfo; |
|
|
|
|
using rocksdb::RestoreOptions; |
|
|
|
|
|
|
|
|
|
using std::shared_ptr; |
|
|
|
|
|
|
|
|
|
extern "C" { |
|
|
|
|
|
|
|
|
|
struct rocksdb_t { DB* rep; }; |
|
|
|
|
struct rocksdb_backup_engine_t { BackupEngine* rep; }; |
|
|
|
|
struct rocksdb_backup_engine_info_t { std::vector<BackupInfo> rep; }; |
|
|
|
|
struct rocksdb_restore_options_t { RestoreOptions rep; }; |
|
|
|
|
struct rocksdb_iterator_t { Iterator* rep; }; |
|
|
|
|
struct rocksdb_writebatch_t { WriteBatch rep; }; |
|
|
|
|
struct rocksdb_snapshot_t { const Snapshot* rep; }; |
|
|
|
@ -527,6 +535,96 @@ rocksdb_t* rocksdb_open_for_read_only( |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rocksdb_backup_engine_t* rocksdb_backup_engine_open( |
|
|
|
|
const rocksdb_options_t* options, |
|
|
|
|
const char* path, |
|
|
|
|
char** errptr) { |
|
|
|
|
BackupEngine* be; |
|
|
|
|
if (SaveError(errptr, BackupEngine::Open(options->rep.env, BackupableDBOptions(path), &be))) { |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
rocksdb_backup_engine_t* result = new rocksdb_backup_engine_t; |
|
|
|
|
result->rep = be; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_backup_engine_create_new_backup( |
|
|
|
|
rocksdb_backup_engine_t *be, |
|
|
|
|
rocksdb_t *db, |
|
|
|
|
char** errptr) { |
|
|
|
|
SaveError(errptr, be->rep->CreateNewBackup(db->rep)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rocksdb_restore_options_t* rocksdb_restore_options_create() { |
|
|
|
|
return new rocksdb_restore_options_t; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_restore_options_destroy(rocksdb_restore_options_t* opt) { |
|
|
|
|
delete opt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_restore_options_set_keep_log_files( |
|
|
|
|
rocksdb_restore_options_t* opt, int v) { |
|
|
|
|
opt->rep.keep_log_files = v; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_backup_engine_restore_db_from_latest_backup( |
|
|
|
|
rocksdb_backup_engine_t *be, |
|
|
|
|
const char* db_dir, |
|
|
|
|
const char* wal_dir, |
|
|
|
|
const rocksdb_restore_options_t *restore_options, |
|
|
|
|
char** errptr) { |
|
|
|
|
SaveError(errptr, be->rep->RestoreDBFromLatestBackup(std::string(db_dir), std::string(wal_dir), restore_options->rep)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const rocksdb_backup_engine_info_t* rocksdb_backup_engine_get_backup_info( |
|
|
|
|
rocksdb_backup_engine_t* be) { |
|
|
|
|
rocksdb_backup_engine_info_t* result = new rocksdb_backup_engine_info_t; |
|
|
|
|
be->rep->GetBackupInfo(&result->rep); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int rocksdb_backup_engine_info_count( |
|
|
|
|
const rocksdb_backup_engine_info_t* info) { |
|
|
|
|
return static_cast<int>(info->rep.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const int64_t rocksdb_backup_engine_info_timestamp( |
|
|
|
|
const rocksdb_backup_engine_info_t* info, |
|
|
|
|
int index) { |
|
|
|
|
return info->rep[index].timestamp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const uint32_t rocksdb_backup_engine_info_backup_id( |
|
|
|
|
const rocksdb_backup_engine_info_t* info, |
|
|
|
|
int index) { |
|
|
|
|
return info->rep[index].backup_id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const uint64_t rocksdb_backup_engine_info_size( |
|
|
|
|
const rocksdb_backup_engine_info_t* info, |
|
|
|
|
int index) { |
|
|
|
|
return info->rep[index].size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const uint32_t rocksdb_backup_engine_info_number_files( |
|
|
|
|
const rocksdb_backup_engine_info_t* info, |
|
|
|
|
int index) { |
|
|
|
|
return info->rep[index].number_files; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_backup_engine_info_destroy( |
|
|
|
|
const rocksdb_backup_engine_info_t* info) { |
|
|
|
|
delete info; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void rocksdb_backup_engine_close( |
|
|
|
|
rocksdb_backup_engine_t *be) { |
|
|
|
|
delete be->rep; |
|
|
|
|
delete be; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rocksdb_close(rocksdb_t* db) { |
|
|
|
|
delete db->rep; |
|
|
|
|
delete db; |
|
|
|
|