Skip to content

Commit aad0f20

Browse files
committed
add with-ttl open option to high level interface, fixing #57
1 parent ab6f375 commit aad0f20

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

RocksDbSharp/Native.Wrap.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ public IntPtr rocksdb_open_for_read_only(
3333
return result;
3434
}
3535

36+
public IntPtr rocksdb_open_with_ttl(
37+
/* const rocksdb_options_t* */ IntPtr options,
38+
string name,
39+
int ttlSeconds)
40+
{
41+
var result = rocksdb_open_with_ttl(options, name, ttlSeconds, out IntPtr errptr);
42+
if (errptr != IntPtr.Zero)
43+
throw new RocksDbException(errptr);
44+
return result;
45+
}
46+
3647
public IntPtr rocksdb_open_column_families(
3748
/* const rocksdb_options_t* */ IntPtr options,
3849
string name,

RocksDbSharp/RocksDb.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public static RocksDb OpenReadOnly(OptionsHandle options, string path, bool erro
5151
return new RocksDb(db, optionsReferences: null, cfOptionsRefs: null);
5252
}
5353

54+
public static RocksDb OpenWithTtl(OptionsHandle options, string path, int ttlSeconds)
55+
{
56+
IntPtr db = Native.Instance.rocksdb_open_with_ttl(options.Handle, path, ttlSeconds);
57+
return new RocksDb(db, optionsReferences: null, cfOptionsRefs: null);
58+
}
59+
5460
public static RocksDb Open(DbOptions options, string path, ColumnFamilies columnFamilies)
5561
{
5662
string[] cfnames = columnFamilies.Names.ToArray();

tests/RocksDbSharpTest/FunctionalTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,21 @@ public void FunctionalTest()
375375

376376
}
377377

378+
// Smoke test OpenWithTtl
379+
{
380+
var dbname = "test-with-ttl";
381+
if (Directory.Exists(dbname))
382+
Directory.Delete(dbname, true);
383+
var optsTest = (DbOptions)new RocksDbSharp.DbOptions()
384+
.SetCreateIfMissing(true)
385+
.SetCreateMissingColumnFamilies(true);
386+
using (var db = RocksDbSharp.RocksDb.OpenWithTtl(optsTest, dbname, 1))
387+
{
388+
}
389+
if (Directory.Exists(dbname))
390+
Directory.Delete(dbname, true);
391+
}
392+
378393
// Smoke test MergeOperator
379394
{
380395
var dbname = "test-merge-operator";

0 commit comments

Comments
 (0)