Skip to content

Commit 18fc4bf

Browse files
committed
expose a read-only open option
1 parent ecfa28e commit 18fc4bf

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/database.zig

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,30 @@ pub const DB = struct {
4747
cf_options[i] = cf.options.convert();
4848
}
4949
var ch = CallHandler.init(err_str);
50-
break :db try ch.handle(rdb.rocksdb_open_column_families(
51-
db_options.convert(),
52-
dir.ptr,
53-
@intCast(cf_names.len),
54-
@ptrCast(cf_names.ptr),
55-
@ptrCast(cf_options.ptr),
56-
@ptrCast(cf_handles.ptr),
57-
@ptrCast(&ch.err_str_in),
58-
), error.RocksDBOpen);
50+
51+
const ret = if (db_options.open_read_only)
52+
rdb.rocksdb_open_for_read_only_column_families(
53+
db_options.convert(),
54+
dir.ptr,
55+
@intCast(cf_names.len),
56+
@ptrCast(cf_names.ptr),
57+
@ptrCast(cf_options.ptr),
58+
@ptrCast(cf_handles.ptr),
59+
0,
60+
@ptrCast(&ch.err_str_in),
61+
)
62+
else
63+
rdb.rocksdb_open_column_families(
64+
db_options.convert(),
65+
dir.ptr,
66+
@intCast(cf_names.len),
67+
@ptrCast(cf_names.ptr),
68+
@ptrCast(cf_options.ptr),
69+
@ptrCast(cf_handles.ptr),
70+
@ptrCast(&ch.err_str_in),
71+
);
72+
73+
break :db try ch.handle(ret, error.RocksDBOpen);
5974
};
6075

6176
// organize column family metadata
@@ -343,6 +358,8 @@ pub const DBOptions = struct {
343358
/// Dynamically changeable through SetDBOptions() API.
344359
max_open_files: i32 = -1,
345360

361+
open_read_only: bool = false,
362+
346363
fn convert(do: DBOptions) *rdb.struct_rocksdb_options_t {
347364
const ro = rdb.rocksdb_options_create().?;
348365
rdb.rocksdb_options_set_create_if_missing(ro, @intFromBool(do.create_if_missing));

0 commit comments

Comments
 (0)