Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python Rocksdb
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
Python Rocksdb
Commits
f4c5aed4
Commit
f4c5aed4
authored
11 years ago
by
hofmockel
Browse files
Options
Downloads
Patches
Plain Diff
Make the 'compact_range' call available in python
(cherry picked from commit c6e4014136aa3d81ecd4288150b3eefca9849b0b)
parent
f897bf49
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/api/database.rst
+32
-0
32 additions, 0 deletions
docs/api/database.rst
rocksdb/_rocksdb.pyx
+28
-0
28 additions, 0 deletions
rocksdb/_rocksdb.pyx
rocksdb/db.pxd
+2
-2
2 additions, 2 deletions
rocksdb/db.pxd
rocksdb/tests/test_db.py
+7
-0
7 additions, 0 deletions
rocksdb/tests/test_db.py
with
69 additions
and
2 deletions
docs/api/database.rst
+
32
−
0
View file @
f4c5aed4
...
...
@@ -237,6 +237,38 @@ Database object
``largest_seqno``
largest seqno in file
.. py:method:: compact_range(begin=None, end=None, reduce_level=False, target_level=-1)
Compact the underlying storage for the key range [begin,end].
The actual compaction interval might be superset of [begin, end].
In particular, deleted and overwritten versions are discarded,
and the data is rearranged to reduce the cost of operations
needed to access the data.
This operation should typically only be invoked by users who understand
the underlying implementation.
``begin == None`` is treated as a key before all keys in the database.
``end == None`` is treated as a key after all keys in the database.
Therefore the following call will compact the entire database: ``db.compact_range()``.
Note that after the entire database is compacted, all data are pushed
down to the last level containing any data. If the total data size
after compaction is reduced, that level might not be appropriate for
hosting all the files. In this case, client could set reduce_level
to ``True``, to move the files back to the minimum level capable of holding
the data set or a given level (specified by non-negative target_level).
:param bytes begin: Key where to start compaction.
If ``None`` start at the beginning of the database.
:param bytes end: Key where to end compaction.
If ``None`` end at the last key of the database.
:param bool reduce_level: If ``True`` allow rocksdb to move the data to
another level, if the current is not big enouth.
If ``False`` you may end with a bigger level
than configured.
:param int target_level: Level where to push the the range to compact.
.. py:attribute:: options
...
...
This diff is collapsed.
Click to expand it.
rocksdb/_rocksdb.pyx
+
28
−
0
View file @
f4c5aed4
...
...
@@ -1533,6 +1533,34 @@ cdef class DB(object):
return
ret
def
compact_range
(
self
,
begin
=
None
,
end
=
None
,
reduce_level
=
False
,
target_level
=-
1
):
cdef
Status
st
cdef
Slice
begin_val
cdef
Slice
end_val
cdef
Slice
*
begin_ptr
cdef
Slice
*
end_ptr
begin_ptr
=
NULL
end_ptr
=
NULL
if
begin
is
not
None
:
begin_val
=
bytes_to_slice
(
begin
)
begin_ptr
=
cython
.
address
(
begin_val
)
if
end
is
not
None
:
end_val
=
bytes_to_slice
(
end
)
end_ptr
=
cython
.
address
(
end_val
)
st
=
self
.
db
.
CompactRange
(
begin_ptr
,
end_ptr
,
reduce_level
,
target_level
)
check_status
(
st
)
@staticmethod
def
__parse_read_opts
(
verify_checksums
=
False
,
...
...
This diff is collapsed.
Click to expand it.
rocksdb/db.pxd
+
2
−
2
View file @
f4c5aed4
...
...
@@ -91,10 +91,10 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb":
int
,
uint64_t
*
)
nogil
except
+
void
CompactRange
(
Status
CompactRange
(
const
Slice
*
,
const
Slice
*
,
bool
,
cpp_
bool
,
int
)
nogil
except
+
int
NumberLevels
()
nogil
except
+
...
...
This diff is collapsed.
Click to expand it.
rocksdb/tests/test_db.py
+
7
−
0
View file @
f4c5aed4
...
...
@@ -189,6 +189,13 @@ class TestDB(unittest.TestCase, TestHelper):
self
.
assertIsNotNone
(
self
.
db
.
get_property
(
b
'
rocksdb.num-files-at-level0
'
))
self
.
assertIsNone
(
self
.
db
.
get_property
(
b
'
does not exsits
'
))
def
test_compact_range
(
self
):
for
x
in
range
(
10000
):
x
=
int_to_bytes
(
x
)
self
.
db
.
put
(
x
,
x
)
self
.
db
.
compact_range
()
class
AssocCounter
(
rocksdb
.
interfaces
.
AssociativeMergeOperator
):
def
merge
(
self
,
key
,
existing_value
,
value
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment