rdbpython 0.2.1__cp39-cp39-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. rdbpy/.dylibs/libbz2.1.0.8.dylib +0 -0
  2. rdbpy/.dylibs/liblz4.1.9.4.dylib +0 -0
  3. rdbpy/.dylibs/libsnappy.1.2.1.dylib +0 -0
  4. rdbpy/.dylibs/libz.1.3.1.dylib +0 -0
  5. rdbpy/.dylibs/libzstd.1.5.6.dylib +0 -0
  6. rdbpy/__init__.py +1 -0
  7. rdbpy/backup.pxd +35 -0
  8. rdbpy/cache.pxd +8 -0
  9. rdbpy/comparator.pxd +23 -0
  10. rdbpy/db.pxd +230 -0
  11. rdbpy/env.pxd +5 -0
  12. rdbpy/errors.py +26 -0
  13. rdbpy/filter_policy.pxd +39 -0
  14. rdbpy/include/rdb_include/comparator_wrapper.hpp +63 -0
  15. rdbpy/include/rdb_include/filter_policy_wrapper.hpp +89 -0
  16. rdbpy/include/rdb_include/memtable_factories.hpp +15 -0
  17. rdbpy/include/rdb_include/merge_operator_wrapper.hpp +132 -0
  18. rdbpy/include/rdb_include/slice_transform_wrapper.hpp +109 -0
  19. rdbpy/include/rdb_include/utils.hpp +8 -0
  20. rdbpy/include/rdb_include/write_batch_iter_helper.hpp +65 -0
  21. rdbpy/interfaces.py +77 -0
  22. rdbpy/iterator.pxd +16 -0
  23. rdbpy/lib_rocksdb.cpython-39-darwin.so +0 -0
  24. rdbpy/lib_rocksdb.pxd +768 -0
  25. rdbpy/lib_rocksdb.pyi +1465 -0
  26. rdbpy/lib_rocksdb.pyx +3221 -0
  27. rdbpy/lib_utils.py +52 -0
  28. rdbpy/logger.pxd +5 -0
  29. rdbpy/memtablerep.pxd +12 -0
  30. rdbpy/merge_operator.pxd +46 -0
  31. rdbpy/merge_operators.py +25 -0
  32. rdbpy/options.pxd +179 -0
  33. rdbpy/slice_.pxd +20 -0
  34. rdbpy/slice_transform.pxd +37 -0
  35. rdbpy/snapshot.pxd +3 -0
  36. rdbpy/status.pxd +15 -0
  37. rdbpy/std_memory.pxd +7 -0
  38. rdbpy/table_factory.pxd +50 -0
  39. rdbpy/transaction.pxd +154 -0
  40. rdbpy/universal_compaction.pxd +15 -0
  41. rdbpython-0.2.1.dist-info/METADATA +104 -0
  42. rdbpython-0.2.1.dist-info/RECORD +45 -0
  43. rdbpython-0.2.1.dist-info/WHEEL +5 -0
  44. rdbpython-0.2.1.dist-info/licenses/LICENSE.md +21 -0
  45. rdbpython-0.2.1.dist-info/top_level.txt +1 -0
rdbpy/lib_rocksdb.pyi ADDED
@@ -0,0 +1,1465 @@
1
+ # import cython
2
+ # from libcpp.string cimport string
3
+ # from libcpp.deque cimport deque
4
+ # from libcpp.vector cimport vector
5
+ # from cpython cimport bool as py_bool
6
+ # from libcpp cimport bool as cpp_bool
7
+ # from libc.stdint cimport uint32_t
8
+ # from cython.operator cimport dereference as deref
9
+ # from cpython.bytes cimport PyBytes_AsString
10
+ # from cpython.bytes cimport PyBytes_Size
11
+ # from cpython.bytes cimport PyBytes_FromString
12
+ # from cpython.bytes cimport PyBytes_FromStringAndSize
13
+ # from cpython.unicode cimport PyUnicode_Decode
14
+
15
+ # from std_memory cimport shared_ptr
16
+ # cimport options
17
+ # cimport merge_operator
18
+ # cimport filter_policy
19
+ # cimport comparator
20
+ # cimport slice_transform
21
+ # cimport cache
22
+ # cimport logger
23
+ # cimport snapshot
24
+ # cimport db
25
+ # cimport iterator
26
+ # cimport backup
27
+ # cimport env
28
+ # cimport table_factory
29
+ # cimport memtablerep
30
+ # cimport universal_compaction
31
+
32
+ # # Enums are the only exception for direct imports
33
+ # # Their name als already unique enough
34
+ # from universal_compaction cimport kCompactionStopStyleSimilarSize
35
+ # from universal_compaction cimport kCompactionStopStyleTotalSize
36
+
37
+ # from options cimport kCompactionStyleLevel
38
+ # from options cimport kCompactionStyleUniversal
39
+ # from options cimport kCompactionStyleFIFO
40
+ # from options cimport kCompactionStyleNone
41
+
42
+ # from slice_ cimport Slice
43
+ # from status cimport Status
44
+
45
+ # import sys
46
+ # from interfaces import MergeOperator as IMergeOperator
47
+ # from interfaces import AssociativeMergeOperator as IAssociativeMergeOperator
48
+ # from interfaces import FilterPolicy as IFilterPolicy
49
+ # from interfaces import Comparator as IComparator
50
+ # from interfaces import SliceTransform as ISliceTransform
51
+ # import traceback
52
+ # import errors
53
+ # import weakref
54
+
55
+ # ctypedef const filter_policy.FilterPolicy ConstFilterPolicy
56
+
57
+ # cdef extern from "cpp/utils.hpp" namespace "py_rocks":
58
+ # cdef const Slice* vector_data(vector[Slice]&)
59
+
60
+ # # Prepare python for threaded usage.
61
+ # # Python callbacks (merge, comparator)
62
+ # # could be executed in a rocksdb background thread (eg. compaction).
63
+ # cdef extern from "Python.h":
64
+ # void PyEval_InitThreads()
65
+ # PyEval_InitThreads()
66
+
67
+ # ## Here comes the stuff to wrap the status to exception
68
+ # cdef check_status(const Status& st):
69
+ # if st.ok():
70
+ # return
71
+
72
+ # if st.IsNotFound():
73
+ # raise errors.NotFound(st.ToString())
74
+
75
+ # if st.IsCorruption():
76
+ # raise errors.Corruption(st.ToString())
77
+
78
+ # if st.IsNotSupported():
79
+ # raise errors.NotSupported(st.ToString())
80
+
81
+ # if st.IsInvalidArgument():
82
+ # raise errors.InvalidArgument(st.ToString())
83
+
84
+ # if st.IsIOError():
85
+ # raise errors.RocksIOError(st.ToString())
86
+
87
+ # if st.IsMergeInProgress():
88
+ # raise errors.MergeInProgress(st.ToString())
89
+
90
+ # if st.IsIncomplete():
91
+ # raise errors.Incomplete(st.ToString())
92
+
93
+ # raise Exception("Unknown error: %s" % st.ToString())
94
+ # ######################################################
95
+
96
+ # cdef string bytes_to_string(path) except *:
97
+ # return string(PyBytes_AsString(path), PyBytes_Size(path))
98
+
99
+ # cdef string_to_bytes(string ob):
100
+ # return PyBytes_FromStringAndSize(ob.c_str(), ob.size())
101
+
102
+ # cdef Slice bytes_to_slice(ob) except *:
103
+ # return Slice(PyBytes_AsString(ob), PyBytes_Size(ob))
104
+
105
+ # cdef slice_to_bytes(Slice sl):
106
+ # return PyBytes_FromStringAndSize(sl.data(), sl.size())
107
+
108
+ # ## only for filsystem paths
109
+ # cdef string path_to_string(object path) except *:
110
+ # if isinstance(path, bytes):
111
+ # return bytes_to_string(path)
112
+ # if isinstance(path, unicode):
113
+ # path = path.encode(sys.getfilesystemencoding())
114
+ # return bytes_to_string(path)
115
+ # else:
116
+ # raise TypeError("Wrong type for path: %s" % path)
117
+
118
+ # cdef object string_to_path(string path):
119
+ # fs_encoding = sys.getfilesystemencoding().encode('ascii')
120
+ # return PyUnicode_Decode(path.c_str(), path.size(), fs_encoding, "replace")
121
+
122
+ # ## Here comes the stuff for the comparator
123
+ # @cython.internal
124
+ # cdef class PyComparator(object):
125
+ # cdef object get_ob(self):
126
+ # return None
127
+
128
+ # cdef const comparator.Comparator* get_comparator(self):
129
+ # return NULL
130
+
131
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
132
+ # pass
133
+
134
+ # @cython.internal
135
+ # cdef class PyGenericComparator(PyComparator):
136
+ # cdef comparator.ComparatorWrapper* comparator_ptr
137
+ # cdef object ob
138
+
139
+ # def __cinit__(self, object ob):
140
+ # self.comparator_ptr = NULL
141
+ # if not isinstance(ob, IComparator):
142
+ # raise TypeError("%s is not of type %s" % (ob, IComparator))
143
+
144
+ # self.ob = ob
145
+ # self.comparator_ptr = new comparator.ComparatorWrapper(
146
+ # bytes_to_string(ob.name()),
147
+ # <void*>ob,
148
+ # compare_callback)
149
+
150
+ # def __dealloc__(self):
151
+ # if not self.comparator_ptr == NULL:
152
+ # del self.comparator_ptr
153
+
154
+ # cdef object get_ob(self):
155
+ # return self.ob
156
+
157
+ # cdef const comparator.Comparator* get_comparator(self):
158
+ # return <comparator.Comparator*> self.comparator_ptr
159
+
160
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
161
+ # self.comparator_ptr.set_info_log(info_log)
162
+
163
+ # @cython.internal
164
+ # cdef class PyBytewiseComparator(PyComparator):
165
+ # cdef const comparator.Comparator* comparator_ptr
166
+
167
+ # def __cinit__(self):
168
+ # self.comparator_ptr = comparator.BytewiseComparator()
169
+
170
+ # def name(self):
171
+ # return PyBytes_FromString(self.comparator_ptr.Name())
172
+
173
+ # def compare(self, a, b):
174
+ # return self.comparator_ptr.Compare(
175
+ # bytes_to_slice(a),
176
+ # bytes_to_slice(b))
177
+
178
+ # cdef object get_ob(self):
179
+ # return self
180
+
181
+ # cdef const comparator.Comparator* get_comparator(self):
182
+ # return self.comparator_ptr
183
+
184
+ # cdef int compare_callback(
185
+ # void* ctx,
186
+ # logger.Logger* log,
187
+ # string& error_msg,
188
+ # const Slice& a,
189
+ # const Slice& b) with gil:
190
+
191
+ # try:
192
+ # return (<object>ctx).compare(slice_to_bytes(a), slice_to_bytes(b))
193
+ # except BaseException as error:
194
+ # tb = traceback.format_exc()
195
+ # logger.Log(log, "Error in compare callback: %s", <bytes>tb)
196
+ # error_msg.assign(<bytes>str(error))
197
+
198
+ # BytewiseComparator = PyBytewiseComparator
199
+ # #########################################
200
+
201
+ # ## Here comes the stuff for the filter policy
202
+ # @cython.internal
203
+ # cdef class PyFilterPolicy(object):
204
+ # cdef object get_ob(self):
205
+ # return None
206
+
207
+ # cdef shared_ptr[ConstFilterPolicy] get_policy(self):
208
+ # return shared_ptr[ConstFilterPolicy]()
209
+
210
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
211
+ # pass
212
+
213
+ # @cython.internal
214
+ # cdef class PyGenericFilterPolicy(PyFilterPolicy):
215
+ # cdef shared_ptr[filter_policy.FilterPolicyWrapper] policy
216
+ # cdef object ob
217
+
218
+ # def __cinit__(self, object ob):
219
+ # if not isinstance(ob, IFilterPolicy):
220
+ # raise TypeError("%s is not of type %s" % (ob, IFilterPolicy))
221
+
222
+ # self.ob = ob
223
+ # self.policy.reset(new filter_policy.FilterPolicyWrapper(
224
+ # bytes_to_string(ob.name()),
225
+ # <void*>ob,
226
+ # create_filter_callback,
227
+ # key_may_match_callback))
228
+
229
+ # cdef object get_ob(self):
230
+ # return self.ob
231
+
232
+ # cdef shared_ptr[ConstFilterPolicy] get_policy(self):
233
+ # return <shared_ptr[ConstFilterPolicy]>(self.policy)
234
+
235
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
236
+ # self.policy.get().set_info_log(info_log)
237
+
238
+ # cdef void create_filter_callback(
239
+ # void* ctx,
240
+ # logger.Logger* log,
241
+ # string& error_msg,
242
+ # const Slice* keys,
243
+ # int n,
244
+ # string* dst) with gil:
245
+
246
+ # try:
247
+ # ret = (<object>ctx).create_filter(
248
+ # [slice_to_bytes(keys[i]) for i in range(n)])
249
+ # dst.append(bytes_to_string(ret))
250
+ # except BaseException as error:
251
+ # tb = traceback.format_exc()
252
+ # logger.Log(log, "Error in create filter callback: %s", <bytes>tb)
253
+ # error_msg.assign(<bytes>str(error))
254
+
255
+ # cdef cpp_bool key_may_match_callback(
256
+ # void* ctx,
257
+ # logger.Logger* log,
258
+ # string& error_msg,
259
+ # const Slice& key,
260
+ # const Slice& filt) with gil:
261
+
262
+ # try:
263
+ # return (<object>ctx).key_may_match(
264
+ # slice_to_bytes(key),
265
+ # slice_to_bytes(filt))
266
+ # except BaseException as error:
267
+ # tb = traceback.format_exc()
268
+ # logger.Log(log, "Error in key_mach_match callback: %s", <bytes>tb)
269
+ # error_msg.assign(<bytes>str(error))
270
+
271
+ # @cython.internal
272
+ # cdef class PyBloomFilterPolicy(PyFilterPolicy):
273
+ # cdef shared_ptr[ConstFilterPolicy] policy
274
+
275
+ # def __cinit__(self, int bits_per_key):
276
+ # self.policy.reset(filter_policy.NewBloomFilterPolicy(bits_per_key))
277
+
278
+ # def name(self):
279
+ # return PyBytes_FromString(self.policy.get().Name())
280
+
281
+ # def create_filter(self, keys):
282
+ # cdef string dst
283
+ # cdef vector[Slice] c_keys
284
+
285
+ # for key in keys:
286
+ # c_keys.push_back(bytes_to_slice(key))
287
+
288
+ # self.policy.get().CreateFilter(
289
+ # vector_data(c_keys),
290
+ # <int>c_keys.size(),
291
+ # cython.address(dst))
292
+
293
+ # return string_to_bytes(dst)
294
+
295
+ # def key_may_match(self, key, filter_):
296
+ # return self.policy.get().KeyMayMatch(
297
+ # bytes_to_slice(key),
298
+ # bytes_to_slice(filter_))
299
+
300
+ # cdef object get_ob(self):
301
+ # return self
302
+
303
+ # cdef shared_ptr[ConstFilterPolicy] get_policy(self):
304
+ # return self.policy
305
+
306
+ # BloomFilterPolicy = PyBloomFilterPolicy
307
+ # #############################################
308
+
309
+ # ## Here comes the stuff for the merge operator
310
+ # @cython.internal
311
+ # cdef class PyMergeOperator(object):
312
+ # cdef shared_ptr[merge_operator.MergeOperator] merge_op
313
+ # cdef object ob
314
+
315
+ # def __cinit__(self, object ob):
316
+ # self.ob = ob
317
+ # if isinstance(ob, IAssociativeMergeOperator):
318
+ # self.merge_op.reset(
319
+ # <merge_operator.MergeOperator*>
320
+ # new merge_operator.AssociativeMergeOperatorWrapper(
321
+ # bytes_to_string(ob.name()),
322
+ # <void*>(ob),
323
+ # merge_callback))
324
+
325
+ # elif isinstance(ob, IMergeOperator):
326
+ # self.merge_op.reset(
327
+ # <merge_operator.MergeOperator*>
328
+ # new merge_operator.MergeOperatorWrapper(
329
+ # bytes_to_string(ob.name()),
330
+ # <void*>ob,
331
+ # <void*>ob,
332
+ # full_merge_callback,
333
+ # partial_merge_callback))
334
+ # # elif isinstance(ob, str):
335
+ # # if ob == "put":
336
+ # # self.merge_op = merge_operator.MergeOperators.CreatePutOperator()
337
+ # # elif ob == "put_v1":
338
+ # # self.merge_op = merge_operator.MergeOperators.CreateDeprecatedPutOperator()
339
+ # # elif ob == "uint64add":
340
+ # # self.merge_op = merge_operator.MergeOperators.CreateUInt64AddOperator()
341
+ # # elif ob == "stringappend":
342
+ # # self.merge_op = merge_operator.MergeOperators.CreateStringAppendOperator()
343
+ # # #TODO: necessary?
344
+ # # # elif ob == "stringappendtest":
345
+ # # # self.merge_op = merge_operator.MergeOperators.CreateStringAppendTESTOperator()
346
+ # # elif ob == "max":
347
+ # # self.merge_op = merge_operator.MergeOperators.CreateMaxOperator()
348
+ # # else:
349
+ # # msg = "{0} is not the default type".format(ob)
350
+ # # raise TypeError(msg)
351
+ # else:
352
+ # msg = "%s is not of this types %s"
353
+ # msg %= (ob, (IAssociativeMergeOperator, IMergeOperator))
354
+ # raise TypeError(msg)
355
+
356
+ # cdef object get_ob(self):
357
+ # return self.ob
358
+
359
+ # cdef shared_ptr[merge_operator.MergeOperator] get_operator(self):
360
+ # return self.merge_op
361
+
362
+ # cdef cpp_bool merge_callback(
363
+ # void* ctx,
364
+ # const Slice& key,
365
+ # const Slice* existing_value,
366
+ # const Slice& value,
367
+ # string* new_value,
368
+ # logger.Logger* log) with gil:
369
+
370
+ # if existing_value == NULL:
371
+ # py_existing_value = None
372
+ # else:
373
+ # py_existing_value = slice_to_bytes(deref(existing_value))
374
+
375
+ # try:
376
+ # ret = (<object>ctx).merge(
377
+ # slice_to_bytes(key),
378
+ # py_existing_value,
379
+ # slice_to_bytes(value))
380
+
381
+ # if ret[0]:
382
+ # new_value.assign(bytes_to_string(ret[1]))
383
+ # return True
384
+ # return False
385
+
386
+ # except:
387
+ # tb = traceback.format_exc()
388
+ # logger.Log(log, "Error in merge_callback: %s", <bytes>tb)
389
+ # return False
390
+
391
+ # cdef cpp_bool full_merge_callback(
392
+ # void* ctx,
393
+ # const Slice& key,
394
+ # const Slice* existing_value,
395
+ # const deque[string]& op_list,
396
+ # string* new_value,
397
+ # logger.Logger* log) with gil:
398
+
399
+ # if existing_value == NULL:
400
+ # py_existing_value = None
401
+ # else:
402
+ # py_existing_value = slice_to_bytes(deref(existing_value))
403
+
404
+ # try:
405
+ # ret = (<object>ctx).full_merge(
406
+ # slice_to_bytes(key),
407
+ # py_existing_value,
408
+ # [string_to_bytes(op_list[i]) for i in range(op_list.size())])
409
+
410
+ # if ret[0]:
411
+ # new_value.assign(bytes_to_string(ret[1]))
412
+ # return True
413
+ # return False
414
+
415
+ # except:
416
+ # tb = traceback.format_exc()
417
+ # logger.Log(log, "Error in full_merge_callback: %s", <bytes>tb)
418
+ # return False
419
+
420
+ # cdef cpp_bool partial_merge_callback(
421
+ # void* ctx,
422
+ # const Slice& key,
423
+ # const Slice& left_op,
424
+ # const Slice& right_op,
425
+ # string* new_value,
426
+ # logger.Logger* log) with gil:
427
+
428
+ # try:
429
+ # ret = (<object>ctx).partial_merge(
430
+ # slice_to_bytes(key),
431
+ # slice_to_bytes(left_op),
432
+ # slice_to_bytes(right_op))
433
+
434
+ # if ret[0]:
435
+ # new_value.assign(bytes_to_string(ret[1]))
436
+ # return True
437
+ # return False
438
+
439
+ # except:
440
+ # tb = traceback.format_exc()
441
+ # logger.Log(log, "Error in partial_merge_callback: %s", <bytes>tb)
442
+ # return False
443
+ # ##############################################
444
+
445
+ # #### Here comes the Cache stuff
446
+ # @cython.internal
447
+ # cdef class PyCache(object):
448
+ # cdef shared_ptr[cache.Cache] get_cache(self):
449
+ # return shared_ptr[cache.Cache]()
450
+
451
+ # @cython.internal
452
+ # cdef class PyLRUCache(PyCache):
453
+ # cdef shared_ptr[cache.Cache] cache_ob
454
+
455
+ # def __cinit__(self, capacity, shard_bits=None):
456
+ # if shard_bits is not None:
457
+ # self.cache_ob = cache.NewLRUCache(capacity, shard_bits)
458
+ # else:
459
+ # self.cache_ob = cache.NewLRUCache(capacity)
460
+
461
+ # cdef shared_ptr[cache.Cache] get_cache(self):
462
+ # return self.cache_ob
463
+
464
+ # LRUCache = PyLRUCache
465
+ # ###############################
466
+
467
+ # ### Here comes the stuff for SliceTransform
468
+ # @cython.internal
469
+ # cdef class PySliceTransform(object):
470
+ # cdef shared_ptr[slice_transform.SliceTransform] transfomer
471
+ # cdef object ob
472
+
473
+ # def __cinit__(self, object ob):
474
+ # if not isinstance(ob, ISliceTransform):
475
+ # raise TypeError("%s is not of type %s" % (ob, ISliceTransform))
476
+
477
+ # self.ob = ob
478
+ # self.transfomer.reset(
479
+ # <slice_transform.SliceTransform*>
480
+ # new slice_transform.SliceTransformWrapper(
481
+ # bytes_to_string(ob.name()),
482
+ # <void*>ob,
483
+ # slice_transform_callback,
484
+ # slice_in_domain_callback,
485
+ # slice_in_range_callback))
486
+
487
+ # cdef object get_ob(self):
488
+ # return self.ob
489
+
490
+ # cdef shared_ptr[slice_transform.SliceTransform] get_transformer(self):
491
+ # return self.transfomer
492
+
493
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
494
+ # cdef slice_transform.SliceTransformWrapper* ptr
495
+ # ptr = <slice_transform.SliceTransformWrapper*> self.transfomer.get()
496
+ # ptr.set_info_log(info_log)
497
+
498
+ # cdef Slice slice_transform_callback(
499
+ # void* ctx,
500
+ # logger.Logger* log,
501
+ # string& error_msg,
502
+ # const Slice& src) with gil:
503
+
504
+ # cdef size_t offset
505
+ # cdef size_t size
506
+
507
+ # try:
508
+ # ret = (<object>ctx).transform(slice_to_bytes(src))
509
+ # offset = ret[0]
510
+ # size = ret[1]
511
+ # if (offset + size) > src.size():
512
+ # msg = "offset(%i) + size(%i) is bigger than slice(%i)"
513
+ # raise Exception(msg % (offset, size, src.size()))
514
+
515
+ # return Slice(src.data() + offset, size)
516
+ # except BaseException as error:
517
+ # tb = traceback.format_exc()
518
+ # logger.Log(log, "Error in slice transfrom callback: %s", <bytes>tb)
519
+ # error_msg.assign(<bytes>str(error))
520
+
521
+ # cdef cpp_bool slice_in_domain_callback(
522
+ # void* ctx,
523
+ # logger.Logger* log,
524
+ # string& error_msg,
525
+ # const Slice& src) with gil:
526
+
527
+ # try:
528
+ # return (<object>ctx).in_domain(slice_to_bytes(src))
529
+ # except BaseException as error:
530
+ # tb = traceback.format_exc()
531
+ # logger.Log(log, "Error in slice transfrom callback: %s", <bytes>tb)
532
+ # error_msg.assign(<bytes>str(error))
533
+
534
+ # cdef cpp_bool slice_in_range_callback(
535
+ # void* ctx,
536
+ # logger.Logger* log,
537
+ # string& error_msg,
538
+ # const Slice& src) with gil:
539
+
540
+ # try:
541
+ # return (<object>ctx).in_range(slice_to_bytes(src))
542
+ # except BaseException as error:
543
+ # tb = traceback.format_exc()
544
+ # logger.Log(log, "Error in slice transfrom callback: %s", <bytes>tb)
545
+ # error_msg.assign(<bytes>str(error))
546
+ # ###########################################
547
+
548
+ # ## Here are the TableFactories
549
+ # @cython.internal
550
+ # cdef class PyTableFactory(object):
551
+ # cdef shared_ptr[table_factory.TableFactory] factory
552
+
553
+ # cdef shared_ptr[table_factory.TableFactory] get_table_factory(self):
554
+ # return self.factory
555
+
556
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
557
+ # pass
558
+
559
+ # cdef class BlockBasedTableFactory(PyTableFactory):
560
+ # cdef PyFilterPolicy py_filter_policy
561
+
562
+ # def __init__(self,
563
+ # index_type='binary_search',
564
+ # py_bool hash_index_allow_collision=True,
565
+ # checksum='crc32',
566
+ # PyCache block_cache=None,
567
+ # PyCache block_cache_compressed=None,
568
+ # filter_policy=None,
569
+ # no_block_cache=False,
570
+ # block_size=None,
571
+ # block_size_deviation=None,
572
+ # block_restart_interval=None,
573
+ # whole_key_filtering=None):
574
+
575
+ # cdef table_factory.BlockBasedTableOptions table_options
576
+
577
+ # if index_type == 'binary_search':
578
+ # table_options.index_type = table_factory.kBinarySearch
579
+ # elif index_type == 'hash_search':
580
+ # table_options.index_type = table_factory.kHashSearch
581
+ # else:
582
+ # raise ValueError("Unknown index_type: %s" % index_type)
583
+
584
+ # if hash_index_allow_collision:
585
+ # table_options.hash_index_allow_collision = True
586
+ # else:
587
+ # table_options.hash_index_allow_collision = False
588
+
589
+ # if checksum == 'crc32':
590
+ # table_options.checksum = table_factory.kCRC32c
591
+ # elif checksum == 'xxhash':
592
+ # table_options.checksum = table_factory.kxxHash
593
+ # else:
594
+ # raise ValueError("Unknown checksum: %s" % checksum)
595
+
596
+ # if no_block_cache:
597
+ # table_options.no_block_cache = True
598
+ # else:
599
+ # table_options.no_block_cache = False
600
+
601
+ # # If the following options are None use the rocksdb default.
602
+ # if block_size is not None:
603
+ # table_options.block_size = block_size
604
+
605
+ # if block_size_deviation is not None:
606
+ # table_options.block_size_deviation = block_size_deviation
607
+
608
+ # if block_restart_interval is not None:
609
+ # table_options.block_restart_interval = block_restart_interval
610
+
611
+ # if whole_key_filtering is not None:
612
+ # if whole_key_filtering:
613
+ # table_options.whole_key_filtering = True
614
+ # else:
615
+ # table_options.whole_key_filtering = False
616
+
617
+ # if block_cache is not None:
618
+ # table_options.block_cache = block_cache.get_cache()
619
+
620
+ # if block_cache_compressed is not None:
621
+ # table_options.block_cache_compressed = block_cache_compressed.get_cache()
622
+
623
+ # # Set the filter_policy
624
+ # self.py_filter_policy = None
625
+ # if filter_policy is not None:
626
+ # if isinstance(filter_policy, PyFilterPolicy):
627
+ # if (<PyFilterPolicy?>filter_policy).get_policy().get() == NULL:
628
+ # raise Exception("Cannot set filter policy: %s" % filter_policy)
629
+ # self.py_filter_policy = filter_policy
630
+ # else:
631
+ # self.py_filter_policy = PyGenericFilterPolicy(filter_policy)
632
+
633
+ # table_options.filter_policy = self.py_filter_policy.get_policy()
634
+
635
+ # self.factory.reset(table_factory.NewBlockBasedTableFactory(table_options))
636
+
637
+ # cdef set_info_log(self, shared_ptr[logger.Logger] info_log):
638
+ # if self.py_filter_policy is not None:
639
+ # self.py_filter_policy.set_info_log(info_log)
640
+
641
+ # cdef class PlainTableFactory(PyTableFactory):
642
+ # def __init__(
643
+ # self,
644
+ # user_key_len=0,
645
+ # bloom_bits_per_key=10,
646
+ # hash_table_ratio=0.75,
647
+ # index_sparseness=10,
648
+ # huge_page_tlb_size=0,
649
+ # encoding_type='plain',
650
+ # py_bool full_scan_mode=False):
651
+
652
+ # cdef table_factory.PlainTableOptions table_options
653
+
654
+ # table_options.user_key_len = user_key_len
655
+ # table_options.bloom_bits_per_key = bloom_bits_per_key
656
+ # table_options.hash_table_ratio = hash_table_ratio
657
+ # table_options.index_sparseness = index_sparseness
658
+ # table_options.huge_page_tlb_size = huge_page_tlb_size
659
+
660
+ # if encoding_type == 'plain':
661
+ # table_options.encoding_type = table_factory.kPlain
662
+ # elif encoding_type == 'prefix':
663
+ # table_options.encoding_type = table_factory.kPrefix
664
+ # else:
665
+ # raise ValueError("Unknown encoding_type: %s" % encoding_type)
666
+
667
+ # table_options.full_scan_mode = full_scan_mode
668
+
669
+ # self.factory.reset( table_factory.NewPlainTableFactory(table_options))
670
+ # #############################################
671
+
672
+ # ### Here are the MemtableFactories
673
+ # @cython.internal
674
+ # cdef class PyMemtableFactory(object):
675
+ # cdef shared_ptr[memtablerep.MemTableRepFactory] factory
676
+
677
+ # cdef shared_ptr[memtablerep.MemTableRepFactory] get_memtable_factory(self):
678
+ # return self.factory
679
+
680
+ # cdef class SkipListMemtableFactory(PyMemtableFactory):
681
+ # def __init__(self):
682
+ # self.factory.reset(memtablerep.NewSkipListFactory())
683
+
684
+ # cdef class VectorMemtableFactory(PyMemtableFactory):
685
+ # def __init__(self, count=0):
686
+ # self.factory.reset(memtablerep.NewVectorRepFactory(count))
687
+
688
+ # cdef class HashSkipListMemtableFactory(PyMemtableFactory):
689
+ # def __init__(
690
+ # self,
691
+ # bucket_count=1000000,
692
+ # skiplist_height=4,
693
+ # skiplist_branching_factor=4):
694
+
695
+ # self.factory.reset(
696
+ # memtablerep.NewHashSkipListRepFactory(
697
+ # bucket_count,
698
+ # skiplist_height,
699
+ # skiplist_branching_factor))
700
+
701
+ # cdef class HashLinkListMemtableFactory(PyMemtableFactory):
702
+ # def __init__(self, bucket_count=50000):
703
+ # self.factory.reset(memtablerep.NewHashLinkListRepFactory(bucket_count))
704
+ # ##################################
705
+
706
+ # cdef class CompressionType(object):
707
+ # no_compression = u'no_compression'
708
+ # snappy_compression = u'snappy_compression'
709
+ # zlib_compression = u'zlib_compression'
710
+ # bzip2_compression = u'bzip2_compression'
711
+ # lz4_compression = u'lz4_compression'
712
+ # lz4hc_compression = u'lz4hc_compression'
713
+ # xpress_compression = u'xpress_compression'
714
+ # zstd_compression = u'zstd_compression'
715
+ # zstdnotfinal_compression = u'zstdnotfinal_compression'
716
+ # disable_compression = u'disable_compression'
717
+
718
+ # cdef class CompactionPri(object):
719
+ # by_compensated_size = u'by_compensated_size'
720
+ # oldest_largest_seq_first = u'oldest_largest_seq_first'
721
+ # oldest_smallest_seq_first = u'oldest_smallest_seq_first'
722
+ # min_overlapping_ratio = u'min_overlapping_ratio'
723
+
724
+ # @cython.internal
725
+ # cdef class _ColumnFamilyHandle:
726
+ # """ This is an internal class that we will weakref for safety """
727
+ # cdef db.ColumnFamilyHandle* handle
728
+ # cdef object __weakref__
729
+ # cdef object weak_handle
730
+
731
+ # def __cinit__(self):
732
+ # self.handle = NULL
733
+
734
+ # def __dealloc__(self):
735
+ # if not self.handle == NULL:
736
+ # del self.handle
737
+
738
+ # @staticmethod
739
+ # cdef from_handle_ptr(db.ColumnFamilyHandle* handle):
740
+ # inst = <_ColumnFamilyHandle>_ColumnFamilyHandle.__new__(_ColumnFamilyHandle)
741
+ # inst.handle = handle
742
+ # return inst
743
+
744
+ # @property
745
+ # def name(self):
746
+ # return self.handle.GetName()
747
+
748
+ # @property
749
+ # def id(self):
750
+ # return self.handle.GetID()
751
+
752
+ # @property
753
+ # def weakref(self):
754
+ # if self.weak_handle is None:
755
+ # self.weak_handle = ColumnFamilyHandle.from_wrapper(self)
756
+ # return self.weak_handle
757
+
758
+ class ColumnFamilyHandle:
759
+ @property
760
+ def is_valid(self) -> bool: ...
761
+ def __repr__(self) -> str: ...
762
+ def __eq__(self, other) -> bool: ...
763
+ def __lt__(self, other) -> bool: ...
764
+ def __ne__(self, other):
765
+ return not self == other
766
+
767
+ def __gt__(self, other):
768
+ return other < self
769
+
770
+ def __le__(self, other):
771
+ return not other < self
772
+
773
+ def __ge__(self, other):
774
+ return not self < other
775
+
776
+ def __hash__(self) -> int: ...
777
+
778
+ class ColumnFamilyOptions:
779
+ def __init__(self, **kwargs) -> None:
780
+ self.py_comparator = None
781
+ self.py_merge_operator = None
782
+ self.py_prefix_extractor = None
783
+ self.py_table_factory = None
784
+ self.py_memtable_factory = None
785
+ self.write_buffer_size = None
786
+ self.max_write_buffer_number = None
787
+ self.min_write_buffer_number_to_merge = None
788
+ self.compression_opts = None
789
+ self.compaction_pri = None
790
+ self.compression = None
791
+ self.max_compaction_bytes = None
792
+ self.num_levels = None
793
+ self.level0_file_num_compaction_trigger = None
794
+ self.level0_slowdown_writes_trigger = None
795
+ self.level0_stop_writes_trigger = None
796
+ self.max_mem_compaction_level = None
797
+ self.target_file_size_base = None
798
+ self.target_file_size_multiplier = None
799
+ self.max_bytes_for_level_base = None
800
+ self.max_bytes_for_level_multiplier = None
801
+ self.max_bytes_for_level_multiplier_additional = None
802
+ self.arena_block_size = None
803
+ self.disable_auto_compactions = None
804
+ self.compaction_style = None
805
+ self.compaction_options_universal = None
806
+ self.max_sequential_skip_in_iterations = None
807
+ self.inplace_update_support = None
808
+ self.table_factory = None
809
+ self.memtable_factory = None
810
+ self.inplace_update_num_locks = None
811
+ self.comparator = None
812
+ self.merge_operator = None
813
+ self.prefix_extractors = None
814
+
815
+ class Options(ColumnFamilyOptions):
816
+ def __init__(self, **kwargs) -> None:
817
+ super().__init__()
818
+ self.create_if_missing: bool
819
+ self.error_if_exists: bool
820
+ self.paranoid_checks: bool
821
+ self.max_open_files = None
822
+ self.use_fsync: bool
823
+ self.db_log_dir = None
824
+ self.wal_dir = None
825
+ self.delete_obsolete_files_period_micros: bool
826
+ self.max_background_compactions = None
827
+ self.max_background_flushes = None
828
+ self.max_log_file_size = None
829
+ self.log_file_time_to_roll = None
830
+ self.keep_log_file_num = None
831
+ self.max_manifest_file_size = None
832
+ self.table_cache_numshardbits = None
833
+ self.wal_ttl_seconds = None
834
+ self.wal_size_limit_mb = None
835
+ self.manifest_preallocation_size = None
836
+ self.enable_write_thread_adaptive_yield = None
837
+ self.allow_concurrent_memtable_write = None
838
+ self.allow_mmap_reads = None
839
+ self.allow_mmap_writes = None
840
+ self.is_fd_close_on_exec = None
841
+ self.stats_dump_period_sec = None
842
+ self.advise_random_on_open = None
843
+ self.use_adaptive_mutex = None
844
+ self.bytes_per_sync = None
845
+ self.row_cache = None
846
+
847
+ # # Forward declaration
848
+ # cdef class Snapshot
849
+
850
+ # cdef class KeysIterator
851
+ # cdef class ValuesIterator
852
+ # cdef class ItemsIterator
853
+ # cdef class ReversedIterator
854
+
855
+ # # Forward declaration
856
+ # cdef class WriteBatchIterator
857
+
858
+ class WriteBatch:
859
+ def __init__(self, data=None) -> None: ...
860
+ def put(self, key: bytes, value: bytes): ...
861
+ def merge(self, key: bytes, value: bytes): ...
862
+ def delete(self, key: bytes): ...
863
+ def delete_range(self, key: tuple[bytes, bytes]): ...
864
+ def clear(self): ...
865
+ def data(self): ...
866
+ def count(self): ...
867
+ def __iter__(self): ...
868
+
869
+ # @cython.internal
870
+ # cdef class WriteBatchIterator(object):
871
+ # # Need a reference to the WriteBatch.
872
+ # # The BatchItems are only pointers to the memory in WriteBatch.
873
+ # cdef WriteBatch batch
874
+ # cdef vector[db.BatchItem] items
875
+ # cdef size_t pos
876
+
877
+ # def __init__(self, WriteBatch batch):
878
+ # cdef Status st
879
+
880
+ # self.batch = batch
881
+ # self.pos = 0
882
+
883
+ # st = db.get_batch_items(batch.batch, cython.address(self.items))
884
+ # check_status(st)
885
+
886
+ # def __iter__(self):
887
+ # return self
888
+
889
+ # def __next__(self):
890
+ # if self.pos == self.items.size():
891
+ # raise StopIteration()
892
+
893
+ # cdef str op
894
+
895
+ # if self.items[self.pos].op == db.BatchItemOpPut:
896
+ # op = "Put"
897
+ # elif self.items[self.pos].op == db.BatchItemOpMerge:
898
+ # op = "Merge"
899
+ # elif self.items[self.pos].op == db.BatchItemOpDelte:
900
+ # op = "Delete"
901
+
902
+ # if self.items[self.pos].column_family_id != 0: # Column Family is set
903
+ # ret = (
904
+ # op,
905
+ # (
906
+ # self.items[self.pos].column_family_id,
907
+ # slice_to_bytes(self.items[self.pos].key)
908
+ # ),
909
+ # slice_to_bytes(self.items[self.pos].value)
910
+ # )
911
+ # else:
912
+ # ret = (
913
+ # op,
914
+ # slice_to_bytes(self.items[self.pos].key),
915
+ # slice_to_bytes(self.items[self.pos].value)
916
+ # )
917
+ # self.pos += 1
918
+ # return ret
919
+
920
+ from collections.abc import Iterable
921
+ from typing import Any
922
+
923
+ class DB:
924
+ def __init__(
925
+ self,
926
+ db_name: str,
927
+ opts: Options,
928
+ column_families: dict | None = None,
929
+ read_only: bool = False,
930
+ secondary_path: str | None = None,
931
+ ) -> None:
932
+ ...
933
+ self.opts = opts
934
+ self.opts.in_use = True
935
+
936
+ def __dealloc__(self):
937
+ self.close()
938
+
939
+ def close(self): ...
940
+ @property
941
+ def column_families(self) -> list: ...
942
+ def get_column_family(self, name: bytes): ...
943
+ def put(self, key: bytes, value: bytes, sync: bool = False, disable_wal: bool = False): ...
944
+ def delete(self, key: bytes, sync: bool = False, disable_wal: bool = False): ...
945
+ def delete_range(
946
+ self, key: tuple[bytes, bytes], sync: bool = False, disable_wal: bool = False
947
+ ): ...
948
+ def merge(self, key: bytes, value: bytes, sync: bool = False, disable_wal: bool = False): ...
949
+ def write(self, batch: WriteBatch, sync: bool = False, disable_wal: bool = False): ...
950
+ def get(self, key: bytes, *args, **kwargs) -> bytes: ...
951
+ def multi_get(self, keys: Iterable[bytes], *args, **kwargs) -> dict[bytes, bytes]: ...
952
+ def key_may_exist(
953
+ self, key: bytes, fetch: bool = False, *args, **kwargs
954
+ ) -> tuple[bool, Any]: ...
955
+ def iterkeys(
956
+ self, column_family: ColumnFamilyHandle = None, *args, **kwargs
957
+ ) -> KeysIterator: ...
958
+ def itervalues(
959
+ self, column_family: ColumnFamilyHandle = None, *args, **kwargs
960
+ ) -> ValuesIterator: ...
961
+ def iteritems(
962
+ self, column_family: ColumnFamilyHandle = None, *args, **kwargs
963
+ ) -> ItemsIterator: ...
964
+
965
+ # def iterskeys(self, column_families, *args, **kwargs):
966
+ # cdef vector[db.Iterator*] iters
967
+ # iters.resize(len(column_families))
968
+ # cdef options.ReadOptions opts
969
+ # cdef db.Iterator* it_ptr
970
+ # cdef KeysIterator it
971
+ # cdef db.ColumnFamilyHandle* cf_handle
972
+ # cdef vector[db.ColumnFamilyHandle*] cf_handles
973
+
974
+ # for column_family in column_families:
975
+ # cf_handle = (<ColumnFamilyHandle?>column_family).get_handle()
976
+ # cf_handles.push_back(cf_handle)
977
+
978
+ # opts = self.build_read_opts(self.__parse_read_opts(*args, **kwargs))
979
+ # with nogil:
980
+ # self.db.NewIterators(opts, cf_handles, &iters)
981
+
982
+ # cf_iter = iter(column_families)
983
+ # cdef list ret = []
984
+ # for it_ptr in iters:
985
+ # it = KeysIterator(self, next(cf_iter))
986
+ # it.ptr = it_ptr
987
+ # ret.append(it)
988
+ # return ret
989
+
990
+ # def itersvalues(self, column_families, *args, **kwargs):
991
+ # cdef vector[db.Iterator*] iters
992
+ # iters.resize(len(column_families))
993
+ # cdef options.ReadOptions opts
994
+ # cdef db.Iterator* it_ptr
995
+ # cdef ValuesIterator it
996
+ # cdef db.ColumnFamilyHandle* cf_handle
997
+ # cdef vector[db.ColumnFamilyHandle*] cf_handles
998
+
999
+ # for column_family in column_families:
1000
+ # cf_handle = (<ColumnFamilyHandle?>column_family).get_handle()
1001
+ # cf_handles.push_back(cf_handle)
1002
+
1003
+ # opts = self.build_read_opts(self.__parse_read_opts(*args, **kwargs))
1004
+ # with nogil:
1005
+ # self.db.NewIterators(opts, cf_handles, &iters)
1006
+
1007
+ # cdef list ret = []
1008
+ # for it_ptr in iters:
1009
+ # it = ValuesIterator(self)
1010
+ # it.ptr = it_ptr
1011
+ # ret.append(it)
1012
+ # return ret
1013
+
1014
+ # def iterskeys(self, column_families, *args, **kwargs):
1015
+ # cdef vector[db.Iterator*] iters
1016
+ # iters.resize(len(column_families))
1017
+ # cdef options.ReadOptions opts
1018
+ # cdef db.Iterator* it_ptr
1019
+ # cdef ItemsIterator it
1020
+ # cdef db.ColumnFamilyHandle* cf_handle
1021
+ # cdef vector[db.ColumnFamilyHandle*] cf_handles
1022
+
1023
+ # for column_family in column_families:
1024
+ # cf_handle = (<ColumnFamilyHandle?>column_family).get_handle()
1025
+ # cf_handles.push_back(cf_handle)
1026
+
1027
+ # opts = self.build_read_opts(self.__parse_read_opts(*args, **kwargs))
1028
+ # with nogil:
1029
+ # self.db.NewIterators(opts, cf_handles, &iters)
1030
+
1031
+ # cf_iter = iter(column_families)
1032
+ # cdef list ret = []
1033
+ # for it_ptr in iters:
1034
+ # it = ItemsIterator(self, next(cf_iter))
1035
+ # it.ptr = it_ptr
1036
+ # ret.append(it)
1037
+ # return ret
1038
+
1039
+ # def snapshot(self):
1040
+ # return Snapshot(self)
1041
+
1042
+ def get_property(self, prop: bytes, column_family: ColumnFamilyHandle = None): ...
1043
+ def get_live_files_metadata(self) -> list[dict[str, Any]]: ...
1044
+
1045
+ # def compact_range(self, begin=None, end=None, ColumnFamilyHandle column_family=None, **py_options):
1046
+ # cdef options.CompactRangeOptions c_options
1047
+
1048
+ # c_options.change_level = py_options.get('change_level', False)
1049
+ # c_options.target_level = py_options.get('target_level', -1)
1050
+
1051
+ # blc = py_options.get('bottommost_level_compaction', 'if_compaction_filter')
1052
+ # if blc == 'skip':
1053
+ # c_options.bottommost_level_compaction = options.blc_skip
1054
+ # elif blc == 'if_compaction_filter':
1055
+ # c_options.bottommost_level_compaction = options.blc_is_filter
1056
+ # elif blc == 'force':
1057
+ # c_options.bottommost_level_compaction = options.blc_force
1058
+ # else:
1059
+ # raise ValueError("bottommost_level_compaction is not valid")
1060
+
1061
+ # cdef Status st
1062
+ # cdef Slice begin_val
1063
+ # cdef Slice end_val
1064
+
1065
+ # cdef Slice* begin_ptr
1066
+ # cdef Slice* end_ptr
1067
+
1068
+ # begin_ptr = NULL
1069
+ # end_ptr = NULL
1070
+
1071
+ # if begin is not None:
1072
+ # begin_val = bytes_to_slice(begin)
1073
+ # begin_ptr = cython.address(begin_val)
1074
+
1075
+ # if end is not None:
1076
+ # end_val = bytes_to_slice(end)
1077
+ # end_ptr = cython.address(end_val)
1078
+
1079
+ # cdef db.ColumnFamilyHandle* cf_handle = self.db.DefaultColumnFamily()
1080
+ # if column_family:
1081
+ # cf_handle = (<ColumnFamilyHandle?>column_family).get_handle()
1082
+
1083
+ # st = self.db.CompactRange(c_options, cf_handle, begin_ptr, end_ptr)
1084
+ # check_status(st)
1085
+
1086
+ # @staticmethod
1087
+ # def __parse_read_opts(
1088
+ # verify_checksums=False,
1089
+ # fill_cache=True,
1090
+ # snapshot=None,
1091
+ # read_tier="all"):
1092
+
1093
+ # # TODO: Is this really effiencet ?
1094
+ # return locals()
1095
+
1096
+ # cdef options.ReadOptions build_read_opts(self, dict py_opts):
1097
+ # cdef options.ReadOptions opts
1098
+ # opts.verify_checksums = py_opts['verify_checksums']
1099
+ # opts.fill_cache = py_opts['fill_cache']
1100
+ # if py_opts['snapshot'] is not None:
1101
+ # opts.snapshot = (<Snapshot?>(py_opts['snapshot'])).ptr
1102
+
1103
+ # if py_opts['read_tier'] == "all":
1104
+ # opts.read_tier = options.kReadAllTier
1105
+ # elif py_opts['read_tier'] == 'cache':
1106
+ # opts.read_tier = options.kBlockCacheTier
1107
+ # else:
1108
+ # raise ValueError("Invalid read_tier")
1109
+
1110
+ # return opts
1111
+
1112
+ # property options:
1113
+ # def __get__(self):
1114
+ # return self.opts
1115
+
1116
+ # def create_column_family(self, bytes name, ColumnFamilyOptions copts):
1117
+ # cdef db.ColumnFamilyHandle* cf_handle
1118
+ # cdef Status st
1119
+ # cdef string c_name = name
1120
+
1121
+ # for handle in self.cf_handles:
1122
+ # if handle.name == name:
1123
+ # raise ValueError(f"{name} is already an existing column family")
1124
+
1125
+ # if copts.in_use:
1126
+ # raise Exception("ColumnFamilyOptions are in_use by another column family")
1127
+
1128
+ # copts.in_use = True
1129
+ # with nogil:
1130
+ # st = self.db.CreateColumnFamily(deref(copts.copts), c_name, &cf_handle)
1131
+ # check_status(st)
1132
+
1133
+ # handle = _ColumnFamilyHandle.from_handle_ptr(cf_handle)
1134
+
1135
+ # self.cf_handles.append(handle)
1136
+ # self.cf_options.append(copts)
1137
+ # return handle.weakref
1138
+
1139
+ # def drop_column_family(self, ColumnFamilyHandle weak_handle not None):
1140
+ # cdef db.ColumnFamilyHandle* cf_handle
1141
+ # cdef ColumnFamilyOptions copts
1142
+ # cdef Status st
1143
+
1144
+ # cf_handle = weak_handle.get_handle()
1145
+
1146
+ # with nogil:
1147
+ # st = self.db.DropColumnFamily(cf_handle)
1148
+ # check_status(st)
1149
+
1150
+ # py_handle = weak_handle._ref()
1151
+ # index = self.cf_handles.index(py_handle)
1152
+ # copts = self.cf_options.pop(index)
1153
+ # del self.cf_handles[index]
1154
+ # del py_handle
1155
+ # if copts:
1156
+ # copts.in_use = False
1157
+
1158
+ class TxnDBWritePolicy:
1159
+ write_committed: str = "write_committed"
1160
+ write_prepared: str = "write_prepared"
1161
+ write_unprepared: str = "write_unprepared"
1162
+
1163
+ class TransactionDBOptions:
1164
+ max_num_locks: int
1165
+ max_num_deadlocks: int
1166
+ num_stripes: int
1167
+ transaction_lock_timeout: int
1168
+ default_lock_timeout: int
1169
+ write_policy: str
1170
+ rollback_merge_operands: bool
1171
+ skip_concurrency_control: bool
1172
+ default_write_batch_flush_threshold: int
1173
+ in_use: bool
1174
+
1175
+ def __init__(self, **kwargs: Any) -> None: ...
1176
+
1177
+ class TransactionOptions:
1178
+ set_snapshot: bool
1179
+ deadlock_detect: bool
1180
+ use_only_the_last_commit_time_batch_for_recovery: bool
1181
+ lock_timeout: int
1182
+ expiration: int
1183
+ deadlock_detect_depth: int
1184
+ max_write_batch_size: int
1185
+ skip_concurrency_control: bool
1186
+ skip_prepare: bool
1187
+ write_batch_flush_threshold: int
1188
+
1189
+ def __init__(self, **kwargs: Any) -> None: ...
1190
+
1191
+ class TransactionDB(DB):
1192
+ txn_opts: TransactionDBOptions
1193
+
1194
+ def __init__(
1195
+ self,
1196
+ db_name: str,
1197
+ opts: Options,
1198
+ txn_db_opts: TransactionDBOptions | None = None,
1199
+ column_families: dict | None = None,
1200
+ ) -> None: ...
1201
+ def begin_transaction(
1202
+ self,
1203
+ txn_options: TransactionOptions | None = ...,
1204
+ write_options: dict[str, Any] | None = ...,
1205
+ reuse: Transaction | None = ...,
1206
+ ) -> Transaction: ...
1207
+ def close(self) -> None: ...
1208
+
1209
+ class Transaction:
1210
+ closed: bool
1211
+
1212
+ def close(self) -> None: ...
1213
+ def commit(self) -> None: ...
1214
+ def rollback(self) -> None: ...
1215
+ def prepare(self) -> None: ...
1216
+ def set_snapshot(self) -> None: ...
1217
+ def clear_snapshot(self) -> None: ...
1218
+ def snapshot(self) -> TransactionSnapshot | None: ...
1219
+ def save_point(self) -> None: ...
1220
+ def rollback_to_save_point(self) -> None: ...
1221
+ def pop_save_point(self) -> None: ...
1222
+ def set_name(self, name: str | bytes) -> None: ...
1223
+ def get_name(self) -> str: ...
1224
+ def get_id(self) -> int: ...
1225
+ def put(
1226
+ self,
1227
+ key: bytes,
1228
+ value: bytes,
1229
+ column_family: ColumnFamilyHandle | None = None,
1230
+ assume_tracked: bool = False,
1231
+ ) -> None: ...
1232
+ def merge(
1233
+ self,
1234
+ key: bytes,
1235
+ value: bytes,
1236
+ column_family: ColumnFamilyHandle | None = None,
1237
+ assume_tracked: bool = False,
1238
+ ) -> None: ...
1239
+ def delete_single(
1240
+ self,
1241
+ key: bytes,
1242
+ column_family: ColumnFamilyHandle | None = None,
1243
+ assume_tracked: bool = False,
1244
+ ) -> None: ...
1245
+ def get(self, key: bytes, column_family: ColumnFamilyHandle | None = None) -> bytes | None: ...
1246
+ def multi_get(
1247
+ self, keys: Iterable[bytes | tuple[ColumnFamilyHandle, bytes]]
1248
+ ) -> dict[Any, bytes | None]: ...
1249
+ def iterkeys(self, column_family: ColumnFamilyHandle | None = None) -> KeysIterator: ...
1250
+ def itervalues(self, column_family: ColumnFamilyHandle | None = None) -> ValuesIterator: ...
1251
+ def iteritems(self, column_family: ColumnFamilyHandle | None = None) -> ItemsIterator: ...
1252
+ def disable_indexing(self) -> None: ...
1253
+ def enable_indexing(self) -> None: ...
1254
+
1255
+ class TransactionSnapshot:
1256
+ pointer: int
1257
+ transaction: Transaction
1258
+
1259
+ def __bool__(self) -> bool: ...
1260
+
1261
+ # def repair_db(db_name, Options opts):
1262
+ # cdef Status st
1263
+ # cdef string db_path
1264
+
1265
+ # db_path = path_to_string(db_name)
1266
+ # st = db.RepairDB(db_path, deref(opts.opts))
1267
+ # check_status(st)
1268
+
1269
+ # def list_column_families(db_name, Options opts):
1270
+ # cdef Status st
1271
+ # cdef string db_path
1272
+ # cdef vector[string] column_families
1273
+
1274
+ # db_path = path_to_string(db_name)
1275
+ # with nogil:
1276
+ # st = db.ListColumnFamilies(deref(opts.opts), db_path, &column_families)
1277
+ # check_status(st)
1278
+
1279
+ # return column_families
1280
+
1281
+ # @cython.no_gc_clear
1282
+ # @cython.internal
1283
+ # cdef class Snapshot(object):
1284
+ # cdef const snapshot.Snapshot* ptr
1285
+ # cdef DB db
1286
+
1287
+ # def __cinit__(self, DB db):
1288
+ # self.db = db
1289
+ # self.ptr = NULL
1290
+ # with nogil:
1291
+ # self.ptr = db.db.GetSnapshot()
1292
+
1293
+ # def __dealloc__(self):
1294
+ # if not self.ptr == NULL:
1295
+ # with nogil:
1296
+ # self.db.db.ReleaseSnapshot(self.ptr)
1297
+
1298
+ class BaseIterator:
1299
+ def __init__(self, db: DB, handle: ColumnFamilyHandle = None) -> None: ...
1300
+ def __dealloc__(self): ...
1301
+ def __iter__(self):
1302
+ return self
1303
+
1304
+ def __next__(self): ...
1305
+ def get(self): ...
1306
+ def __reversed__(self): ...
1307
+ def seek_to_first(self): ...
1308
+ def seek_to_last(self): ...
1309
+ def seek(self, key: bytes): ...
1310
+ def seek_for_prev(self, key): ...
1311
+ def get_ob(self) -> None:
1312
+ return None
1313
+
1314
+ class KeysIterator(BaseIterator):
1315
+ def get(self) -> bytes: ...
1316
+ def __next__(self) -> bytes: ...
1317
+
1318
+ class ValuesIterator(BaseIterator):
1319
+ def get(self) -> bytes: ...
1320
+ def __next__(self) -> bytes: ...
1321
+
1322
+ class ItemsIterator(BaseIterator):
1323
+ def get(self) -> tuple[bytes, bytes]: ...
1324
+ def __next__(self) -> tuple[bytes, bytes]: ...
1325
+
1326
+ # @cython.internal
1327
+ # cdef class ReversedIterator(object):
1328
+ # cdef BaseIterator it
1329
+
1330
+ # def __cinit__(self, BaseIterator it):
1331
+ # self.it = it
1332
+
1333
+ # def seek_to_first(self):
1334
+ # self.it.seek_to_first()
1335
+
1336
+ # def seek_to_last(self):
1337
+ # self.it.seek_to_last()
1338
+
1339
+ # def seek(self, key):
1340
+ # self.it.seek(key)
1341
+
1342
+ # def seek_for_prev(self, key):
1343
+ # self.it.seek_for_prev(key)
1344
+
1345
+ # def get(self):
1346
+ # return self.it.get()
1347
+
1348
+ # def __iter__(self):
1349
+ # return self
1350
+
1351
+ # def __reversed__(self):
1352
+ # return self.it
1353
+
1354
+ # def __next__(self):
1355
+ # if not self.it.ptr.Valid():
1356
+ # raise StopIteration()
1357
+
1358
+ # cdef object ret = self.it.get_ob()
1359
+ # with nogil:
1360
+ # self.it.ptr.Prev()
1361
+ # check_status(self.it.ptr.status())
1362
+ # return ret
1363
+
1364
+ # cdef class BackupEngine(object):
1365
+ # cdef backup.BackupEngine* engine
1366
+
1367
+ # def __cinit__(self, backup_dir):
1368
+ # cdef Status st
1369
+ # cdef string c_backup_dir
1370
+ # self.engine = NULL
1371
+
1372
+ # c_backup_dir = path_to_string(backup_dir)
1373
+ # st = backup.BackupEngine_Open(
1374
+ # env.Env_Default(),
1375
+ # backup.BackupEngineOptions(c_backup_dir),
1376
+ # cython.address(self.engine))
1377
+
1378
+ # check_status(st)
1379
+
1380
+ # def __dealloc__(self):
1381
+ # if not self.engine == NULL:
1382
+ # with nogil:
1383
+ # del self.engine
1384
+
1385
+ # def create_backup(self, DB db, flush_before_backup=False):
1386
+ # cdef Status st
1387
+ # cdef cpp_bool c_flush_before_backup
1388
+
1389
+ # c_flush_before_backup = flush_before_backup
1390
+
1391
+ # with nogil:
1392
+ # st = self.engine.CreateNewBackup(db.db, c_flush_before_backup)
1393
+ # check_status(st)
1394
+
1395
+ # def restore_backup(self, backup_id, db_dir, wal_dir):
1396
+ # cdef Status st
1397
+ # cdef backup.BackupID c_backup_id
1398
+ # cdef string c_db_dir
1399
+ # cdef string c_wal_dir
1400
+
1401
+ # c_backup_id = backup_id
1402
+ # c_db_dir = path_to_string(db_dir)
1403
+ # c_wal_dir = path_to_string(wal_dir)
1404
+
1405
+ # with nogil:
1406
+ # st = self.engine.RestoreDBFromBackup(
1407
+ # c_backup_id,
1408
+ # c_db_dir,
1409
+ # c_wal_dir)
1410
+
1411
+ # check_status(st)
1412
+
1413
+ # def restore_latest_backup(self, db_dir, wal_dir):
1414
+ # cdef Status st
1415
+ # cdef string c_db_dir
1416
+ # cdef string c_wal_dir
1417
+
1418
+ # c_db_dir = path_to_string(db_dir)
1419
+ # c_wal_dir = path_to_string(wal_dir)
1420
+
1421
+ # with nogil:
1422
+ # st = self.engine.RestoreDBFromLatestBackup(c_db_dir, c_wal_dir)
1423
+
1424
+ # check_status(st)
1425
+
1426
+ # def stop_backup(self):
1427
+ # with nogil:
1428
+ # self.engine.StopBackup()
1429
+
1430
+ # def purge_old_backups(self, num_backups_to_keep):
1431
+ # cdef Status st
1432
+ # cdef uint32_t c_num_backups_to_keep
1433
+
1434
+ # c_num_backups_to_keep = num_backups_to_keep
1435
+
1436
+ # with nogil:
1437
+ # st = self.engine.PurgeOldBackups(c_num_backups_to_keep)
1438
+ # check_status(st)
1439
+
1440
+ # def delete_backup(self, backup_id):
1441
+ # cdef Status st
1442
+ # cdef backup.BackupID c_backup_id
1443
+
1444
+ # c_backup_id = backup_id
1445
+
1446
+ # with nogil:
1447
+ # st = self.engine.DeleteBackup(c_backup_id)
1448
+
1449
+ # check_status(st)
1450
+
1451
+ # def get_backup_info(self):
1452
+ # cdef vector[backup.BackupInfo] backup_info
1453
+
1454
+ # with nogil:
1455
+ # self.engine.GetBackupInfo(cython.address(backup_info))
1456
+
1457
+ # ret = []
1458
+ # for ob in backup_info:
1459
+ # t = {}
1460
+ # t['backup_id'] = ob.backup_id
1461
+ # t['timestamp'] = ob.timestamp
1462
+ # t['size'] = ob.size
1463
+ # ret.append(t)
1464
+
1465
+ # return ret