Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
888d62e8
Commit
888d62e8
authored
Apr 11, 2019
by
siddontang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*: support getting sequence number
parent
f1e3ae36
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
5 deletions
+47
-5
c.cc
librocksdb_sys/crocksdb/c.cc
+10
-3
c.h
librocksdb_sys/crocksdb/crocksdb/c.h
+5
-0
lib.rs
librocksdb_sys/src/lib.rs
+3
-0
rocksdb.rs
src/rocksdb.rs
+28
-0
titan.rs
src/titan.rs
+1
-2
No files found.
librocksdb_sys/crocksdb/c.cc
View file @
888d62e8
...
@@ -1101,6 +1101,11 @@ void crocksdb_release_snapshot(
...
@@ -1101,6 +1101,11 @@ void crocksdb_release_snapshot(
delete
snapshot
;
delete
snapshot
;
}
}
uint64_t
crocksdb_get_snapshot_sequence_number
(
const
crocksdb_snapshot_t
*
snapshot
)
{
return
snapshot
->
rep
->
GetSequenceNumber
();
}
char
*
crocksdb_property_value
(
char
*
crocksdb_property_value
(
crocksdb_t
*
db
,
crocksdb_t
*
db
,
const
char
*
propname
)
{
const
char
*
propname
)
{
...
@@ -1269,9 +1274,11 @@ void crocksdb_sync_wal(
...
@@ -1269,9 +1274,11 @@ void crocksdb_sync_wal(
SaveError
(
errptr
,
db
->
rep
->
SyncWAL
());
SaveError
(
errptr
,
db
->
rep
->
SyncWAL
());
}
}
void
crocksdb_disable_file_deletions
(
uint64_t
crocksdb_get_latest_sequence_number
(
crocksdb_t
*
db
)
{
crocksdb_t
*
db
,
return
db
->
rep
->
GetLatestSequenceNumber
();
char
**
errptr
)
{
}
void
crocksdb_disable_file_deletions
(
crocksdb_t
*
db
,
char
**
errptr
)
{
SaveError
(
errptr
,
db
->
rep
->
DisableFileDeletions
());
SaveError
(
errptr
,
db
->
rep
->
DisableFileDeletions
());
}
}
...
...
librocksdb_sys/crocksdb/crocksdb/c.h
View file @
888d62e8
...
@@ -378,6 +378,8 @@ extern C_ROCKSDB_LIBRARY_API const crocksdb_snapshot_t* crocksdb_create_snapshot
...
@@ -378,6 +378,8 @@ extern C_ROCKSDB_LIBRARY_API const crocksdb_snapshot_t* crocksdb_create_snapshot
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_release_snapshot
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_release_snapshot
(
crocksdb_t
*
db
,
const
crocksdb_snapshot_t
*
snapshot
);
crocksdb_t
*
db
,
const
crocksdb_snapshot_t
*
snapshot
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_get_snapshot_sequence_number
(
const
crocksdb_snapshot_t
*
snapshot
);
/* Returns NULL if property name is unknown.
/* Returns NULL if property name is unknown.
Else returns a pointer to a malloc()-ed null-terminated value. */
Else returns a pointer to a malloc()-ed null-terminated value. */
...
@@ -450,6 +452,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_flush_wal(
...
@@ -450,6 +452,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_flush_wal(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sync_wal
(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_sync_wal
(
crocksdb_t
*
db
,
char
**
errptr
);
crocksdb_t
*
db
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
uint64_t
crocksdb_get_latest_sequence_number
(
crocksdb_t
*
db
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_disable_file_deletions
(
crocksdb_t
*
db
,
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_disable_file_deletions
(
crocksdb_t
*
db
,
char
**
errptr
);
char
**
errptr
);
...
...
librocksdb_sys/src/lib.rs
View file @
888d62e8
...
@@ -709,6 +709,7 @@ extern "C" {
...
@@ -709,6 +709,7 @@ extern "C" {
)
->
*
mut
DBIterator
;
)
->
*
mut
DBIterator
;
pub
fn
crocksdb_create_snapshot
(
db
:
*
mut
DBInstance
)
->
*
const
DBSnapshot
;
pub
fn
crocksdb_create_snapshot
(
db
:
*
mut
DBInstance
)
->
*
const
DBSnapshot
;
pub
fn
crocksdb_release_snapshot
(
db
:
*
mut
DBInstance
,
snapshot
:
*
const
DBSnapshot
);
pub
fn
crocksdb_release_snapshot
(
db
:
*
mut
DBInstance
,
snapshot
:
*
const
DBSnapshot
);
pub
fn
crocksdb_get_snapshot_sequence_number
(
snapshot
:
*
const
DBSnapshot
)
->
u64
;
pub
fn
crocksdb_delete
(
pub
fn
crocksdb_delete
(
db
:
*
mut
DBInstance
,
db
:
*
mut
DBInstance
,
...
@@ -1003,6 +1004,8 @@ extern "C" {
...
@@ -1003,6 +1004,8 @@ extern "C" {
pub
fn
crocksdb_flush_wal
(
db
:
*
mut
DBInstance
,
sync
:
bool
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_flush_wal
(
db
:
*
mut
DBInstance
,
sync
:
bool
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_sync_wal
(
db
:
*
mut
DBInstance
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_sync_wal
(
db
:
*
mut
DBInstance
,
err
:
*
mut
*
mut
c_char
);
pub
fn
crocksdb_get_latest_sequence_number
(
db
:
*
mut
DBInstance
)
->
u64
;
pub
fn
crocksdb_approximate_sizes
(
pub
fn
crocksdb_approximate_sizes
(
db
:
*
mut
DBInstance
,
db
:
*
mut
DBInstance
,
num_ranges
:
c_int
,
num_ranges
:
c_int
,
...
...
src/rocksdb.rs
View file @
888d62e8
...
@@ -326,6 +326,11 @@ impl<D: Deref<Target = DB>> Snapshot<D> {
...
@@ -326,6 +326,11 @@ impl<D: Deref<Target = DB>> Snapshot<D> {
}
}
self
.db
.get_cf_opt
(
cf
,
key
,
&
readopts
)
self
.db
.get_cf_opt
(
cf
,
key
,
&
readopts
)
}
}
/// Get the snapshot's sequence number.
pub
fn
get_sequence_number
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_get_snapshot_sequence_number
(
self
.snap
.get_inner
())
}
}
}
}
impl
<
D
:
Deref
<
Target
=
DB
>>
Drop
for
Snapshot
<
D
>
{
impl
<
D
:
Deref
<
Target
=
DB
>>
Drop
for
Snapshot
<
D
>
{
...
@@ -1011,6 +1016,11 @@ impl DB {
...
@@ -1011,6 +1016,11 @@ impl DB {
}
}
}
}
/// Get the sequence number of the most recent transaction.
pub
fn
get_latest_sequence_number
(
&
self
)
->
u64
{
unsafe
{
crocksdb_ffi
::
crocksdb_get_latest_sequence_number
(
self
.inner
)
}
}
/// Return the approximate file system space used by keys in each ranges.
/// Return the approximate file system space used by keys in each ranges.
///
///
/// Note that the returned sizes measure file system space usage, so
/// Note that the returned sizes measure file system space usage, so
...
@@ -2869,4 +2879,22 @@ mod test {
...
@@ -2869,4 +2879,22 @@ mod test {
}
}
}
}
}
}
#[test]
fn
test_sequence_number
()
{
let
path
=
TempDir
::
new
(
"_rust_rocksdb_sequence_number"
)
.expect
(
""
);
let
mut
opts
=
DBOptions
::
new
();
opts
.create_if_missing
(
true
);
let
db
=
DB
::
open
(
opts
,
path
.path
()
.to_str
()
.unwrap
())
.unwrap
();
let
snap
=
db
.snapshot
();
let
snap_seq
=
snap
.get_sequence_number
();
let
seq1
=
db
.get_latest_sequence_number
();
assert_eq!
(
snap_seq
,
seq1
);
db
.put
(
b
"key"
,
b
"value"
)
.unwrap
();
let
seq2
=
db
.get_latest_sequence_number
();
assert
!
(
seq2
>
seq1
);
}
}
}
src/titan.rs
View file @
888d62e8
...
@@ -3,7 +3,6 @@ use std::ops::Deref;
...
@@ -3,7 +3,6 @@ use std::ops::Deref;
use
crocksdb_ffi
::{
self
,
DBCompressionType
,
DBTitanBlobIndex
,
DBTitanDBOptions
};
use
crocksdb_ffi
::{
self
,
DBCompressionType
,
DBTitanBlobIndex
,
DBTitanDBOptions
};
use
librocksdb_sys
::
ctitandb_encode_blob_index
;
use
librocksdb_sys
::
ctitandb_encode_blob_index
;
use
std
::
ffi
::
c_void
;
use
std
::
ops
::
DerefMut
;
use
std
::
ops
::
DerefMut
;
use
std
::
os
::
raw
::
c_double
;
use
std
::
os
::
raw
::
c_double
;
use
std
::
os
::
raw
::
c_int
;
use
std
::
os
::
raw
::
c_int
;
...
@@ -148,7 +147,7 @@ impl TitanBlobIndex {
...
@@ -148,7 +147,7 @@ impl TitanBlobIndex {
ctitandb_encode_blob_index
(
&
self
.inner
,
&
mut
value
,
&
mut
value_size
);
ctitandb_encode_blob_index
(
&
self
.inner
,
&
mut
value
,
&
mut
value_size
);
let
slice
=
slice
::
from_raw_parts
(
value
,
value_size
as
usize
);
let
slice
=
slice
::
from_raw_parts
(
value
,
value_size
as
usize
);
let
vec
=
slice
.to_vec
();
let
vec
=
slice
.to_vec
();
libc
::
free
(
value
as
*
mut
c_void
);
libc
::
free
(
value
as
*
mut
libc
::
c_void
);
vec
vec
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment