Skip to content

Commit 51ce04d

Browse files
committed
fix SstFileWriter crash
1 parent 5861127 commit 51ce04d

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

RocksDbSharp/SstFileWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public SstFileWriter(EnvOptions envOptions = null, ColumnFamilyOptions ioOptions
1515
{
1616
if (envOptions == null)
1717
envOptions = new EnvOptions();
18-
var ioOptionsHandle = ioOptions?.Handle ?? IntPtr.Zero;
18+
var opts = ioOptions ?? new ColumnFamilyOptions();
1919
References.EnvOptions = envOptions;
2020
References.IoOptions = ioOptions;
21-
Handle = Native.Instance.rocksdb_sstfilewriter_create(envOptions.Handle, ioOptionsHandle);
21+
Handle = Native.Instance.rocksdb_sstfilewriter_create(envOptions.Handle, opts.Handle);
2222
}
2323

2424
public void Dispose()

tests/RocksDbSharpTest/FunctionalTests.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,31 @@ public void FunctionalTest()
247247

248248
// Test SstFileWriter
249249
{
250+
using (var writer = new SstFileWriter())
251+
{
252+
}
253+
250254
var envOpts = new EnvOptions();
251255
var ioOpts = new ColumnFamilyOptions();
252-
var sst = new SstFileWriter(envOpts, ioOpts);
253-
var filename = Path.Combine(temp, "test.sst");
254-
if (File.Exists(filename))
255-
File.Delete(filename);
256-
sst.Open(filename);
257-
sst.Add("four", "quatro");
258-
sst.Add("one", "uno");
259-
sst.Add("two", "dos");
260-
sst.Finish();
261-
262-
using (var db = RocksDb.Open(options, path, columnFamilies))
256+
using (var sst = new SstFileWriter(envOpts, ioOpts))
263257
{
264-
Assert.NotEqual("four", db.Get("four"));
265-
var ingestOptions = new IngestExternalFileOptions()
266-
.SetMoveFiles(true);
267-
db.IngestExternalFiles(new string[] { filename }, ingestOptions);
268-
Assert.Equal("quatro", db.Get("four"));
258+
var filename = Path.Combine(temp, "test.sst");
259+
if (File.Exists(filename))
260+
File.Delete(filename);
261+
sst.Open(filename);
262+
sst.Add("four", "quatro");
263+
sst.Add("one", "uno");
264+
sst.Add("two", "dos");
265+
sst.Finish();
266+
267+
using (var db = RocksDb.Open(options, path, columnFamilies))
268+
{
269+
Assert.NotEqual("four", db.Get("four"));
270+
var ingestOptions = new IngestExternalFileOptions()
271+
.SetMoveFiles(true);
272+
db.IngestExternalFiles(new string[] { filename }, ingestOptions);
273+
Assert.Equal("quatro", db.Get("four"));
274+
}
269275
}
270276
}
271277

0 commit comments

Comments
 (0)