Skip to content

Commit fe37fae

Browse files
committed
prepare for future auto-generated Native.Raw.cs
1 parent 1d13913 commit fe37fae

File tree

5 files changed

+173
-10
lines changed

5 files changed

+173
-10
lines changed

RocksDbSharp/ColumnFamilyOptions.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,40 @@ public ColumnFamilyOptions SetUint64addMergeOperator()
285285
/// and L4 using compression_per_level[3]. Compaction for each level can
286286
/// change when data grows.
287287
/// </summary>
288+
public ColumnFamilyOptions SetCompressionPerLevel(Compression[] levelValues, ulong numLevels)
289+
{
290+
var values = levelValues.Select(x => (int)x).ToArray();
291+
Native.Instance.rocksdb_options_set_compression_per_level(Handle, values, numLevels);
292+
return this;
293+
}
294+
295+
/// <summary>
296+
/// Different levels can have different compression policies. There
297+
/// are cases where most lower levels would like to use quick compression
298+
/// algorithms while the higher levels (which have more data) use
299+
/// compression algorithms that have better compression but could
300+
/// be slower. This array, if non-empty, should have an entry for
301+
/// each level of the database; these override the value specified in
302+
/// the previous field 'compression'.
303+
///
304+
/// NOTICE if level_compaction_dynamic_level_bytes=true,
305+
/// compression_per_level[0] still determines L0, but other elements
306+
/// of the array are based on base level (the level L0 files are merged
307+
/// to), and may not match the level users see from info log for metadata.
308+
/// If L0 files are merged to level-n, then, for i>0, compression_per_level[i]
309+
/// determines compaction type for level n+i-1.
310+
/// For example, if we have three 5 levels, and we determine to merge L0
311+
/// data to L4 (which means L1..L3 will be empty), then the new files go to
312+
/// L4 uses compression type compression_per_level[1].
313+
/// If now L0 is merged to L2. Data goes to L2 will be compressed
314+
/// according to compression_per_level[1], L3 using compression_per_level[2]
315+
/// and L4 using compression_per_level[3]. Compaction for each level can
316+
/// change when data grows.
317+
/// </summary>
318+
[Obsolete("Use Compression enum")]
288319
public ColumnFamilyOptions SetCompressionPerLevel(CompressionTypeEnum[] levelValues, ulong numLevels)
289320
{
290-
var values = levelValues.Select(x => (int) x).ToArray();
321+
var values = levelValues.Select(x => (int)x).ToArray();
291322
Native.Instance.rocksdb_options_set_compression_per_level(Handle, values, numLevels);
292323
return this;
293324
}
@@ -942,6 +973,29 @@ public ColumnFamilyOptions SetReportBgIoStats(bool value)
942973
/// incompressible, the kSnappyCompression implementation will
943974
/// efficiently detect that and will switch to uncompressed mode.
944975
/// </summary>
976+
public ColumnFamilyOptions SetCompression(Compression value)
977+
{
978+
Native.Instance.rocksdb_options_set_compression(Handle, value);
979+
return this;
980+
}
981+
982+
/// <summary>
983+
/// Compress blocks using the specified compression algorithm. This
984+
/// parameter can be changed dynamically.
985+
///
986+
/// Default: kSnappyCompression, if it's supported. If snappy is not linked
987+
/// with the library, the default is kNoCompression.
988+
///
989+
/// Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz:
990+
/// ~200-500MB/s compression
991+
/// ~400-800MB/s decompression
992+
/// Note that these speeds are significantly faster than most
993+
/// persistent storage speeds, and therefore it is typically never
994+
/// worth switching to kNoCompression. Even if the input data is
995+
/// incompressible, the kSnappyCompression implementation will
996+
/// efficiently detect that and will switch to uncompressed mode.
997+
/// </summary>
998+
[Obsolete("Use Compression enum")]
945999
public ColumnFamilyOptions SetCompression(CompressionTypeEnum value)
9461000
{
9471001
Native.Instance.rocksdb_options_set_compression(Handle, value);
@@ -951,6 +1005,16 @@ public ColumnFamilyOptions SetCompression(CompressionTypeEnum value)
9511005
/// <summary>
9521006
/// The compaction style. Default: kCompactionStyleLevel
9531007
/// </summary>
1008+
public ColumnFamilyOptions SetCompactionStyle(Compaction value)
1009+
{
1010+
Native.Instance.rocksdb_options_set_compaction_style(Handle, value);
1011+
return this;
1012+
}
1013+
1014+
/// <summary>
1015+
/// The compaction style. Default: kCompactionStyleLevel
1016+
/// </summary>
1017+
[Obsolete("Use Compaction enum")]
9541018
public ColumnFamilyOptions SetCompactionStyle(CompactionStyleEnum value)
9551019
{
9561020
Native.Instance.rocksdb_options_set_compaction_style(Handle, value);

RocksDbSharp/DbOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,25 @@ public DbOptions SetMaxTotalWalSize(ulong n)
148148
/// </summary>
149149
/// <param name="mode"></param>
150150
/// <returns></returns>
151+
[Obsolete("Use Recovery enum")]
151152
public DbOptions SetWalRecoveryMode(WalRecoveryMode mode)
152153
{
153154
Native.Instance.rocksdb_options_set_wal_recovery_mode(Handle, mode);
154155
return this;
155156
}
156157

158+
/// <summary>
159+
/// Recovery mode to control the consistency while replaying WAL
160+
/// Default: kPointInTimeRecovery
161+
/// </summary>
162+
/// <param name="mode"></param>
163+
/// <returns></returns>
164+
public DbOptions SetWalRecoveryMode(Recovery mode)
165+
{
166+
Native.Instance.rocksdb_options_set_wal_recovery_mode(Handle, mode);
167+
return this;
168+
}
169+
157170
/// <summary>
158171
/// Enables statistics so that you can call GetStatisticsString() later
159172
/// </summary>

RocksDbSharp/Native.Raw.cs

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ namespace RocksDbSharp
4040
{
4141
using size_t = System.UIntPtr;
4242

43+
public delegate void PutDelegate(IntPtr p0, IntPtr k, size_t klen, IntPtr v, size_t vlen);
44+
public delegate void DeletedDelegate(IntPtr p0, IntPtr k, size_t klen);
45+
public delegate void DestructorDelegate(IntPtr p0);
46+
public delegate IntPtr NameDelegate(IntPtr p0);
47+
public delegate int CompareDelegate(IntPtr p0, IntPtr a, size_t alen, IntPtr b, size_t blen);
48+
4349
//void (*put)(IntPtr s, /*(const char*)*/ IntPtr k, /*(size_t)*/ UIntPtr klen, /*(const char*)*/ IntPtr v, /*(size_t)*/ UIntPtr vlen),
50+
[Obsolete("Use PutDelegate")]
4451
public delegate void WriteBatchIteratePutCallback(IntPtr s, /*(const char*)*/ IntPtr k, /*(size_t)*/ size_t klen, /*(const char*)*/ IntPtr v, /*(size_t)*/ size_t vlen);
4552
//void (*deleted)(void*, const char* k, /*(size_t)*/ UIntPtr klen)
53+
[Obsolete("Use DeletedDelegate")]
4654
public delegate void WriteBatchIterateDeleteCallback(IntPtr s, /*(const char*)*/ IntPtr k, /*(size_t)*/ size_t klen);
55+
4756
public abstract partial class Native
4857
{
4958
/* BEGIN c.h */
@@ -567,12 +576,19 @@ public unsafe abstract void rocksdb_writebatch_delete_rangev_cf(
567576
/*(const size_t)*/ IntPtr end_keys_list_sizes);
568577
public abstract void rocksdb_writebatch_put_log_data(
569578
/*(rocksdb_writebatch_t*)*/ IntPtr writeBatch, byte[] blob, UIntPtr len);
579+
[Obsolete("Use PutDelegate and DeletedDelegate overload")]
570580
public abstract void rocksdb_writebatch_iterate(
571581
/*(rocksdb_writebatch_t*)*/ IntPtr writeBatch, /*(void*)*/ IntPtr state,
572582
//void (*put)(IntPtr s, /*(const char*)*/ IntPtr k, /*(size_t)*/ ulong klen, /*(const char*)*/ IntPtr v, /*(size_t)*/ ulong vlen),
573583
WriteBatchIteratePutCallback put,
574584
//void (*deleted)(void*, const char* k, /*(size_t)*/ ulong klen)
575585
WriteBatchIterateDeleteCallback deleted);
586+
public abstract void rocksdb_writebatch_iterate(
587+
/*(rocksdb_writebatch_t*)*/ IntPtr writeBatch, /*(void*)*/ IntPtr state,
588+
//void (*put)(IntPtr s, /*(const char*)*/ IntPtr k, /*(size_t)*/ ulong klen, /*(const char*)*/ IntPtr v, /*(size_t)*/ ulong vlen),
589+
PutDelegate put,
590+
//void (*deleted)(void*, const char* k, /*(size_t)*/ ulong klen)
591+
DeletedDelegate deleted);
576592
public abstract /* const char* */ IntPtr rocksdb_writebatch_data(
577593
/*(rocksdb_writebatch_t*)*/ IntPtr writeBatch, /*(size_t*)*/ out size_t size);
578594
public abstract void rocksdb_writebatch_set_save_point(
@@ -691,11 +707,17 @@ public abstract void rocksdb_writebatch_wi_put_log_data(
691707
/*(rocksdb_writebatch_wi_t*)*/ IntPtr b, /*(const char*)*/ byte[] blob, /*(size_t)*/ size_t len);
692708
public abstract void rocksdb_writebatch_wi_put_log_data(
693709
/*(rocksdb_writebatch_wi_t*)*/ IntPtr b, /*(const char*)*/ IntPtr blob, /*(size_t)*/ size_t len);
710+
[Obsolete("Use PutDelegate and DeletedDelegate overload")]
694711
public abstract void rocksdb_writebatch_wi_iterate(
695712
/*(rocksdb_writebatch_wi_t*)*/ IntPtr b,
696713
/*(void*)*/ IntPtr state,
697714
/*(void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen))*/ WriteBatchIteratePutCallback put,
698715
/*(void (*deleted)(void*, const char* k, size_t klen))*/ WriteBatchIterateDeleteCallback deleted);
716+
public abstract void rocksdb_writebatch_wi_iterate(
717+
/*(rocksdb_writebatch_wi_t*)*/ IntPtr b,
718+
/*(void*)*/ IntPtr state,
719+
/*(void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen))*/ PutDelegate put,
720+
/*(void (*deleted)(void*, const char* k, size_t klen))*/ DeletedDelegate deleted);
699721
public abstract /*(const char*)*/ IntPtr rocksdb_writebatch_wi_data(
700722
/*(rocksdb_writebatch_wi_t*)*/ IntPtr b,
701723
/*(size_t*)*/ out size_t size);
@@ -809,9 +831,15 @@ public abstract void rocksdb_block_based_options_set_format_version(
809831
/*(rocksdb_block_based_table_options_t*)*/ IntPtr bbto, int format_version);
810832
}
811833
public enum BlockBasedTableIndexType {
834+
[Obsolete("Use Binary")]
812835
BinarySearch = 0,
836+
Binary = 0,
837+
[Obsolete("Use Hash")]
813838
HashSearch = 1,
839+
Hash = 1,
840+
[Obsolete("Use TwoLevelIndex")]
814841
TwoLevelIndexSearch = 2,
842+
TwoLevelIndex = 2,
815843
};
816844
public abstract partial class Native {
817845
public abstract void rocksdb_block_based_options_set_index_type(
@@ -936,8 +964,6 @@ public abstract void rocksdb_options_set_max_bytes_for_level_multiplier_addition
936964
/* rocksdb_options_t* */ IntPtr options, /*(int*)*/ int[] level_values, UIntPtr num_levels);
937965
public abstract void rocksdb_options_enable_statistics(
938966
/* rocksdb_options_t* */ IntPtr options);
939-
public abstract void rocksdb_options_set_skip_stats_update_on_db_open(
940-
/* rocksdb_options_t* */ IntPtr opt, /* unsigned char */ bool val);
941967

942968
/* returns a pointer to a malloc()-ed, null terminated string */
943969
public abstract /* char* */ IntPtr rocksdb_options_statistics_get_string(
@@ -1073,17 +1099,39 @@ public abstract void rocksdb_options_set_report_bg_io_stats(
10731099
/* rocksdb_options_t* */ IntPtr options, int value);
10741100

10751101
}
1102+
public enum Recovery
1103+
{
1104+
TolerateCorruptedTailRecords = 0,
1105+
AbsoluteConsistency = 1,
1106+
PointInTime = 2,
1107+
SkipAnyCorruptedRecords = 3,
1108+
}
1109+
[Obsolete("Use Recovery")]
10761110
public enum WalRecoveryMode {
10771111
rocksdb_tolerate_corrupted_tail_records_recovery = 0,
10781112
rocksdb_absolute_consistency_recovery = 1,
10791113
rocksdb_point_in_time_recovery = 2,
10801114
rocksdb_skip_any_corrupted_records_recovery = 3
10811115
}
10821116
public abstract partial class Native {
1117+
[Obsolete("Use Recovery enum")]
10831118
public abstract void rocksdb_options_set_wal_recovery_mode(
10841119
/* rocksdb_options_t* */ IntPtr options, WalRecoveryMode mode);
1120+
public abstract void rocksdb_options_set_wal_recovery_mode(
1121+
/* rocksdb_options_t* */ IntPtr options, Recovery mode);
10851122
}
1086-
1123+
public enum Compression
1124+
{
1125+
No = 0,
1126+
Snappy = 1,
1127+
Zlib = 2,
1128+
Bz2 = 3,
1129+
Lz4 = 4,
1130+
Lz4hc = 5,
1131+
Xpress = 6,
1132+
Zstd = 7,
1133+
}
1134+
[Obsolete("Use Compression")]
10871135
public enum CompressionTypeEnum {
10881136
rocksdb_no_compression = 0,
10891137
rocksdb_snappy_compression = 1,
@@ -1095,17 +1143,30 @@ public enum CompressionTypeEnum {
10951143
rocksdb_zstd_compression = 7
10961144
}
10971145
public abstract partial class Native {
1146+
[Obsolete("Use Compression enum")]
10981147
public abstract void rocksdb_options_set_compression(
10991148
/* rocksdb_options_t* */ IntPtr options, CompressionTypeEnum value);
1149+
public abstract void rocksdb_options_set_compression(
1150+
/* rocksdb_options_t* */ IntPtr options, Compression value);
11001151
}
1152+
public enum Compaction
1153+
{
1154+
Level = 0,
1155+
Universal = 1,
1156+
Fifo = 2,
1157+
}
1158+
[Obsolete("Use Compaction")]
11011159
public enum CompactionStyleEnum {
11021160
rocksdb_level_compaction = 0,
11031161
rocksdb_universal_compaction = 1,
11041162
rocksdb_fifo_compaction = 2,
11051163
}
11061164
public abstract partial class Native {
1165+
[Obsolete("Use Compaction enum")]
11071166
public abstract void rocksdb_options_set_compaction_style(
11081167
/* rocksdb_options_t* */ IntPtr options, CompactionStyleEnum value);
1168+
public abstract void rocksdb_options_set_compaction_style(
1169+
/* rocksdb_options_t* */ IntPtr options, Compaction value);
11091170
public abstract void rocksdb_options_set_universal_compaction_options(
11101171
/* rocksdb_options_t* */ IntPtr options, /*(rocksdb_universal_compaction_options_t*)*/ IntPtr universal_compaction_options);
11111172
public abstract void rocksdb_options_set_fifo_compaction_options(
@@ -1275,6 +1336,11 @@ public abstract void rocksdb_compactionfilterfactory_destroy(
12751336
/*(int (*compare)(void*, const char* a, size_t alen, const char* b,
12761337
size_t blen))*/ IntPtr compare,
12771338
/*(const char* (*name)(void*))*/ IntPtr getName);
1339+
public abstract /* rocksdb_comparator_t* */ IntPtr rocksdb_comparator_create(
1340+
/*(void*)*/ IntPtr state, /*(void (*destructor)(void*))*/ DestructorDelegate destructor,
1341+
/*(int (*compare)(void*, const char* a, size_t alen, const char* b,
1342+
size_t blen))*/ CompareDelegate compare,
1343+
/*(const char* (*name)(void*))*/ NameDelegate name);
12781344
public abstract void rocksdb_comparator_destroy(
12791345
/*(rocksdb_comparator_t*)*/IntPtr comparator);
12801346

@@ -1416,19 +1482,17 @@ public abstract void rocksdb_flushoptions_set_wait(
14161482
#endregion
14171483

14181484
#region Cache
1419-
#if ROCKSDB_CACHE
14201485

14211486
public abstract /* rocksdb_cache_t* */ IntPtr rocksdb_cache_create_lru(
14221487
size_t capacity);
1423-
public abstract void rocksdb_cache_destroy(rocksdb_cache_t* cache);
1488+
public abstract void rocksdb_cache_destroy(/* rocksdb_cache_t* */ IntPtr cache);
14241489
public abstract void rocksdb_cache_set_capacity(
1425-
rocksdb_cache_t* cache, size_t capacity);
1426-
public abstract /*(size_t)*/ ulong
1490+
/* rocksdb_cache_t* */ IntPtr cache, size_t capacity);
1491+
public abstract /*(size_t)*/ UIntPtr
14271492
rocksdb_cache_get_usage(/*(rocksdb_cache_t*)*/ IntPtr cache);
1428-
public abstract /*(size_t)*/ ulong
1493+
public abstract /*(size_t)*/ UIntPtr
14291494
rocksdb_cache_get_pinned_usage(/*(rocksdb_cache_t*)*/ IntPtr cache);
14301495

1431-
#endif
14321496
#endregion
14331497

14341498
#region DBPath

RocksDbSharp/WriteBatch.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public interface IWriteBatch : IDisposable
2828
unsafe void DeleteRange(byte* startKey, ulong sklen, byte* endKey, ulong eklen, ColumnFamilyHandle cf = null);
2929
unsafe void DeleteRangev(int numKeys, IntPtr startKeysList, IntPtr startKeysListSizes, IntPtr endKeysList, IntPtr endKeysListSizes, ColumnFamilyHandle cf = null);
3030
IWriteBatch PutLogData(byte[] blob, ulong len);
31+
[Obsolete("Use PutDelegate and DeletedDelegate")]
3132
IWriteBatch Iterate(IntPtr state, WriteBatchIteratePutCallback put, WriteBatchIterateDeleteCallback deleted);
33+
IWriteBatch Iterate(IntPtr state, PutDelegate put, DeletedDelegate deleted);
3234
byte[] ToBytes();
3335
byte[] ToBytes(byte[] buffer, int offset = 0, int size = -1);
3436
void SetSavePoint();
@@ -222,12 +224,19 @@ public WriteBatch PutLogData(byte[] blob, ulong len)
222224
return this;
223225
}
224226

227+
[Obsolete("Use PutDelegate and DeletedDelegate")]
225228
public WriteBatch Iterate(IntPtr state, WriteBatchIteratePutCallback put, WriteBatchIterateDeleteCallback deleted)
226229
{
227230
Native.Instance.rocksdb_writebatch_iterate(handle, state, put, deleted);
228231
return this;
229232
}
230233

234+
public WriteBatch Iterate(IntPtr state, PutDelegate put, DeletedDelegate deleted)
235+
{
236+
Native.Instance.rocksdb_writebatch_iterate(handle, state, put, deleted);
237+
return this;
238+
}
239+
231240
/// <summary>
232241
/// Get the write batch as bytes
233242
/// </summary>
@@ -296,7 +305,10 @@ IWriteBatch IWriteBatch.DeleteRange(byte[] startKey, ulong sklen, byte[] endKey,
296305
=> DeleteRange(startKey, sklen, endKey, eklen, cf);
297306
IWriteBatch IWriteBatch.PutLogData(byte[] blob, ulong len)
298307
=> PutLogData(blob, len);
308+
[Obsolete("Use PutDelegate and DeletedDelegate")]
299309
IWriteBatch IWriteBatch.Iterate(IntPtr state, WriteBatchIteratePutCallback put, WriteBatchIterateDeleteCallback deleted)
300310
=> Iterate(state, put, deleted);
311+
IWriteBatch IWriteBatch.Iterate(IntPtr state, PutDelegate put, DeletedDelegate deleted)
312+
=> Iterate(state, put, deleted);
301313
}
302314
}

RocksDbSharp/WriteBatchWithIndex.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,19 @@ public WriteBatchWithIndex PutLogData(byte[] blob, ulong len)
270270
return this;
271271
}
272272

273+
[Obsolete("Use PutDelegate and DeletedDelegate")]
273274
public WriteBatchWithIndex Iterate(IntPtr state, WriteBatchIteratePutCallback put, WriteBatchIterateDeleteCallback deleted)
274275
{
275276
Native.Instance.rocksdb_writebatch_wi_iterate(handle, state, put, deleted);
276277
return this;
277278
}
278279

280+
public WriteBatchWithIndex Iterate(IntPtr state, PutDelegate put, DeletedDelegate deleted)
281+
{
282+
Native.Instance.rocksdb_writebatch_wi_iterate(handle, state, put, deleted);
283+
return this;
284+
}
285+
279286
/// <summary>
280287
/// Get the write batch as bytes
281288
/// </summary>
@@ -340,7 +347,10 @@ IWriteBatch IWriteBatch.DeleteRange(byte[] startKey, ulong sklen, byte[] endKey,
340347
=> DeleteRange(startKey, sklen, endKey, eklen, cf);
341348
IWriteBatch IWriteBatch.PutLogData(byte[] blob, ulong len)
342349
=> PutLogData(blob, len);
350+
[Obsolete("Use PutDelegate and DeletedDelegate")]
343351
IWriteBatch IWriteBatch.Iterate(IntPtr state, WriteBatchIteratePutCallback put, WriteBatchIterateDeleteCallback deleted)
344352
=> Iterate(state, put, deleted);
353+
IWriteBatch IWriteBatch.Iterate(IntPtr state, PutDelegate put, DeletedDelegate deleted)
354+
=> Iterate(state, put, deleted);
345355
}
346356
}

0 commit comments

Comments
 (0)