diff --git a/src/Plugins/RocksDBStore/Plugins/Storage/Options.cs b/src/Plugins/RocksDBStore/Plugins/Storage/Options.cs
index 5b70fcdbef..46cb66fa8c 100644
--- a/src/Plugins/RocksDBStore/Plugins/Storage/Options.cs
+++ b/src/Plugins/RocksDBStore/Plugins/Storage/Options.cs
@@ -16,13 +16,13 @@ namespace Neo.Plugins.Storage
public static class Options
{
public static readonly DbOptions Default = CreateDbOptions();
- public static readonly ReadOptions ReadDefault = new ReadOptions();
- public static readonly WriteOptions WriteDefault = new WriteOptions();
+ public static readonly ReadOptions ReadDefault = new();
+ public static readonly WriteOptions WriteDefault = new();
public static readonly WriteOptions WriteDefaultSync = new WriteOptions().SetSync(true);
public static DbOptions CreateDbOptions()
{
- DbOptions options = new DbOptions();
+ var options = new DbOptions();
options.SetCreateMissingColumnFamilies(true);
options.SetCreateIfMissing(true);
options.SetErrorIfExists(false);
diff --git a/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs b/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs
index cba1cc2942..95c8c3ccb6 100644
--- a/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs
+++ b/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs
@@ -13,6 +13,7 @@
using RocksDbSharp;
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
namespace Neo.Plugins.Storage
{
@@ -21,43 +22,43 @@ namespace Neo.Plugins.Storage
///
internal class Snapshot : ISnapshot
{
- private readonly RocksDb db;
- private readonly RocksDbSharp.Snapshot snapshot;
- private readonly WriteBatch batch;
- private readonly ReadOptions options;
+ private readonly RocksDb _db;
+ private readonly RocksDbSharp.Snapshot _snapshot;
+ private readonly WriteBatch _batch;
+ private readonly ReadOptions _options;
public Snapshot(RocksDb db)
{
- this.db = db;
- snapshot = db.CreateSnapshot();
- batch = new WriteBatch();
+ _db = db;
+ _snapshot = db.CreateSnapshot();
+ _batch = new WriteBatch();
- options = new ReadOptions();
- options.SetFillCache(false);
- options.SetSnapshot(snapshot);
+ _options = new ReadOptions();
+ _options.SetFillCache(false);
+ _options.SetSnapshot(_snapshot);
}
public void Commit()
{
- db.Write(batch, Options.WriteDefault);
+ _db.Write(_batch, Options.WriteDefault);
}
public void Delete(byte[] key)
{
- batch.Delete(key);
+ _batch.Delete(key);
}
public void Put(byte[] key, byte[] value)
{
- batch.Put(key, value);
+ _batch.Put(key, value);
}
///
- public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction)
+ public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[]? keyOrPrefix, SeekDirection direction)
{
- if (keyOrPrefix == null) keyOrPrefix = Array.Empty();
+ keyOrPrefix ??= [];
- using var it = db.NewIterator(readOptions: options);
+ using var it = _db.NewIterator(readOptions: _options);
if (direction == SeekDirection.Forward)
for (it.Seek(keyOrPrefix); it.Valid(); it.Next())
@@ -69,24 +70,24 @@ public void Put(byte[] key, byte[] value)
public bool Contains(byte[] key)
{
- return db.Get(key, Array.Empty(), 0, 0, readOptions: options) >= 0;
+ return _db.Get(key, Array.Empty(), 0, 0, readOptions: _options) >= 0;
}
- public byte[] TryGet(byte[] key)
+ public byte[]? TryGet(byte[] key)
{
- return db.Get(key, readOptions: options);
+ return _db.Get(key, readOptions: _options);
}
- public bool TryGet(byte[] key, out byte[] value)
+ public bool TryGet(byte[] key, [NotNullWhen(true)] out byte[]? value)
{
- value = db.Get(key, readOptions: options);
+ value = _db.Get(key, readOptions: _options);
return value != null;
}
public void Dispose()
{
- snapshot.Dispose();
- batch.Dispose();
+ _snapshot.Dispose();
+ _batch.Dispose();
}
}
}
diff --git a/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs b/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs
index 09fa63d08a..9891325479 100644
--- a/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs
+++ b/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs
@@ -13,35 +13,36 @@
using RocksDbSharp;
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
namespace Neo.Plugins.Storage
{
internal class Store : IStore
{
- private readonly RocksDb db;
+ private readonly RocksDb _db;
public Store(string path)
{
- db = RocksDb.Open(Options.Default, Path.GetFullPath(path));
+ _db = RocksDb.Open(Options.Default, Path.GetFullPath(path));
}
public void Dispose()
{
- db.Dispose();
+ _db.Dispose();
}
public ISnapshot GetSnapshot()
{
- return new Snapshot(db);
+ return new Snapshot(_db);
}
///
- public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
+ public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[]? keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
- if (keyOrPrefix == null) keyOrPrefix = Array.Empty();
+ keyOrPrefix ??= [];
- using var it = db.NewIterator();
+ using var it = _db.NewIterator();
if (direction == SeekDirection.Forward)
for (it.Seek(keyOrPrefix); it.Valid(); it.Next())
yield return (it.Key(), it.Value());
@@ -52,33 +53,33 @@ public ISnapshot GetSnapshot()
public bool Contains(byte[] key)
{
- return db.Get(key, Array.Empty(), 0, 0) >= 0;
+ return _db.Get(key, Array.Empty(), 0, 0) >= 0;
}
- public byte[] TryGet(byte[] key)
+ public byte[]? TryGet(byte[] key)
{
- return db.Get(key);
+ return _db.Get(key);
}
- public bool TryGet(byte[] key, out byte[] value)
+ public bool TryGet(byte[] key, [NotNullWhen(true)] out byte[]? value)
{
- value = db.Get(key);
+ value = _db.Get(key);
return value != null;
}
public void Delete(byte[] key)
{
- db.Remove(key);
+ _db.Remove(key);
}
public void Put(byte[] key, byte[] value)
{
- db.Put(key, value);
+ _db.Put(key, value);
}
public void PutSync(byte[] key, byte[] value)
{
- db.Put(key, value, writeOptions: Options.WriteDefaultSync);
+ _db.Put(key, value, writeOptions: Options.WriteDefaultSync);
}
}
}
diff --git a/src/Plugins/RocksDBStore/RocksDBStore.csproj b/src/Plugins/RocksDBStore/RocksDBStore.csproj
index 7a827d382e..b8e10b0c23 100644
--- a/src/Plugins/RocksDBStore/RocksDBStore.csproj
+++ b/src/Plugins/RocksDBStore/RocksDBStore.csproj
@@ -5,6 +5,7 @@
Neo.Plugins.Storage.RocksDBStore
Neo.Plugins.Storage
../../../bin/$(PackageId)
+ enable