Skip to content

Commit 5b4b0bc

Browse files
committed
allow nulls in CompactRange() fixing #67
1 parent ec64967 commit 5b4b0bc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

RocksDbSharp/RocksDb.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,16 @@ public void IngestExternalFiles(string[] files, IngestExternalFileOptions ingest
295295
public void CompactRange(byte[] start, byte[] limit, ColumnFamilyHandle cf = null)
296296
{
297297
if (cf == null)
298-
Native.Instance.rocksdb_compact_range(Handle, start, (UIntPtr)start.GetLongLength(0), limit, (UIntPtr)limit.GetLongLength(0));
298+
Native.Instance.rocksdb_compact_range(Handle, start, (UIntPtr)(start?.GetLongLength(0) ?? 0L), limit, (UIntPtr)(limit?.GetLongLength(0) ?? 0L));
299299
else
300-
Native.Instance.rocksdb_compact_range_cf(Handle, cf.Handle, start, (UIntPtr)start.GetLongLength(0), limit, (UIntPtr)limit.GetLongLength(0));
300+
Native.Instance.rocksdb_compact_range_cf(Handle, cf.Handle, start, (UIntPtr)(start?.GetLongLength(0) ?? 0L), limit, (UIntPtr)(limit?.GetLongLength(0) ?? 0L));
301301
}
302302

303303
public void CompactRange(string start, string limit, ColumnFamilyHandle cf = null, Encoding encoding = null)
304304
{
305305
if (encoding == null)
306306
encoding = Encoding.UTF8;
307-
CompactRange(encoding.GetBytes(start), encoding.GetBytes(limit), cf);
307+
CompactRange(start == null ? null : encoding.GetBytes(start), limit == null ? null : encoding.GetBytes(limit), cf);
308308
}
309309
}
310310
}

tests/RocksDbSharpTest/FunctionalTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ public void FunctionalTest()
170170
Assert.Null(cpdb.Get("four"));
171171
}
172172

173+
// Test various operations
174+
using (var db = RocksDb.Open(options, path))
175+
{
176+
// Nulls should be allowed here
177+
db.CompactRange((byte[])null, (byte[])null);
178+
db.CompactRange((string)null, (string)null);
179+
}
180+
173181
// Test with column families
174182
var optionsCf = new DbOptions()
175183
.SetCreateIfMissing(true)

0 commit comments

Comments
 (0)