Cleans up RocksDB wrapper code and implements backup from read-only and secondary instances

pull/417/head
Tpt 2 years ago committed by Thomas Tanon
parent 1ffb559ee2
commit 5f68cb3746
  1. 786
      lib/src/storage/backend/rocksdb.rs
  2. 29
      lib/tests/store.rs
  3. 14
      oxrocksdb-sys/api/c.cc
  4. 3
      oxrocksdb-sys/api/c.h
  5. 5
      server/src/main.rs

File diff suppressed because it is too large Load Diff

@ -312,17 +312,34 @@ fn test_backup() -> Result<(), Box<dyn Error>> {
GraphNameRef::DefaultGraph,
);
let store_dir = TempDir::default();
let backup_dir = TempDir::default();
let secondary_store_dir = TempDir::default();
let backup_from_rw_dir = TempDir::default();
let backup_from_ro_dir = TempDir::default();
let backup_from_secondary_dir = TempDir::default();
let store = Store::open(&store_dir)?;
store.insert(quad)?;
store.backup(&backup_dir)?;
store.remove(quad)?;
let secondary_store = Store::open_secondary(&store_dir, secondary_store_dir)?;
store.flush()?;
store.backup(&backup_from_rw_dir)?;
secondary_store.backup(&backup_from_secondary_dir)?;
store.remove(quad)?;
assert!(!store.contains(quad)?);
let backup = Store::open(&backup_dir.0)?;
backup.validate()?;
assert!(backup.contains(quad)?);
let backup_from_rw = Store::open_read_only(&backup_from_rw_dir.0)?;
backup_from_rw.validate()?;
assert!(backup_from_rw.contains(quad)?);
backup_from_rw.backup(&backup_from_ro_dir)?;
let backup_from_ro = Store::open_read_only(&backup_from_ro_dir.0)?;
backup_from_ro.validate()?;
assert!(backup_from_ro.contains(quad)?);
let backup_from_secondary = Store::open_read_only(&backup_from_secondary_dir.0)?;
backup_from_secondary.validate()?;
assert!(backup_from_secondary.contains(quad)?);
Ok(())
}

@ -106,6 +106,20 @@ rocksdb_t* rocksdb_open_as_secondary_column_families_with_status(
return result;
}
void rocksdb_create_checkpoint_with_status(rocksdb_t* db,
const char* checkpoint_dir,
rocksdb_status_t* statusptr) {
Checkpoint* checkpoint;
Status s = Checkpoint::Create(db->rep, &checkpoint);
if (!s.ok()) {
SaveStatus(statusptr, s);
return;
}
SaveStatus(statusptr,
checkpoint->CreateCheckpoint(std::string(checkpoint_dir)));
delete checkpoint;
}
rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families_with_status(
const rocksdb_options_t* options,
const rocksdb_transactiondb_options_t* txn_db_options, const char* name,

@ -90,6 +90,9 @@ rocksdb_open_as_secondary_column_families_with_status(
rocksdb_column_family_handle_t** column_family_handles,
rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API void rocksdb_create_checkpoint_with_status(
rocksdb_t* db, const char* checkpoint_dir, rocksdb_status_t* statusptr);
extern ROCKSDB_LIBRARY_API rocksdb_transactiondb_t*
rocksdb_transactiondb_open_column_families_with_status(
const rocksdb_options_t* options,

@ -56,8 +56,9 @@ enum Command {
},
/// Start Oxigraph HTTP server in read-only mode.
///
/// It allows to read the database while other processes are accessing it.
/// Changes done after this process has been launched will not be seen.
/// It allows to read the database while other processes are also reading it.
/// Opening as read-only while having an other process writing the database is undefined behavior.
/// Please use the serve-secondary command in this case.
ServeReadOnly {
/// Directory in which the data stored by Oxigraph are persisted.
#[arg(short, long)]

Loading…
Cancel
Save