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
9cbbf5f8
Unverified
Commit
9cbbf5f8
authored
Dec 13, 2017
by
Huachao Huang
Committed by
GitHub
Dec 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add delete files in range with delete range test (#128)
parent
f01a1b22
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
Cargo.toml
Cargo.toml
+1
-0
test.rs
tests/test.rs
+1
-0
test_delete_files_in_range.rs
tests/test_delete_files_in_range.rs
+67
-0
No files found.
Cargo.toml
View file @
9cbbf5f8
...
@@ -33,3 +33,4 @@ path = "librocksdb_sys"
...
@@ -33,3 +33,4 @@ path = "librocksdb_sys"
[dev-dependencies]
[dev-dependencies]
byteorder
=
"1.0.0"
byteorder
=
"1.0.0"
rand
=
"0.3"
tests/test.rs
View file @
9cbbf5f8
...
@@ -2,6 +2,7 @@ extern crate byteorder;
...
@@ -2,6 +2,7 @@ extern crate byteorder;
extern
crate
crc
;
extern
crate
crc
;
extern
crate
rocksdb
;
extern
crate
rocksdb
;
extern
crate
tempdir
;
extern
crate
tempdir
;
extern
crate
rand
;
mod
test_iterator
;
mod
test_iterator
;
mod
test_multithreaded
;
mod
test_multithreaded
;
...
...
tests/test_delete_files_in_range.rs
View file @
9cbbf5f8
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
use
rand
::{
self
,
Rng
};
use
rocksdb
::
*
;
use
rocksdb
::
*
;
use
tempdir
::
TempDir
;
use
tempdir
::
TempDir
;
...
@@ -100,3 +101,69 @@ fn test_delete_files_in_range_with_snap() {
...
@@ -100,3 +101,69 @@ fn test_delete_files_in_range_with_snap() {
// sst2 has been dropped.
// sst2 has been dropped.
assert_eq!
(
count
,
6
);
assert_eq!
(
count
,
6
);
}
}
#[test]
fn
test_delete_files_in_range_with_delete_range
()
{
// Regression test for https://github.com/facebook/rocksdb/issues/2833.
let
path
=
TempDir
::
new
(
"_rocksdb_test_delete_files_in_range_with_delete_range"
)
.expect
(
""
);
let
path_str
=
path
.path
()
.to_str
()
.unwrap
();
let
sst_size
=
1
<<
10
;
let
value_size
=
8
<<
10
;
let
mut
opts
=
DBOptions
::
new
();
opts
.create_if_missing
(
true
);
let
mut
cf_opts
=
ColumnFamilyOptions
::
new
();
cf_opts
.set_target_file_size_base
(
sst_size
);
cf_opts
.set_level_zero_file_num_compaction_trigger
(
10
);
let
db
=
DB
::
open_cf
(
opts
,
path_str
,
vec!
[(
"default"
,
cf_opts
)])
.unwrap
();
// Flush 5 files in level 0.
// File i will contain keys i and i+1.
for
i
in
0
..
5
{
let
k1
=
format!
(
"{}"
,
i
);
let
k2
=
format!
(
"{}"
,
i
+
1
);
let
mut
v
=
vec!
[
0
;
value_size
];
rand
::
thread_rng
()
.fill_bytes
(
&
mut
v
);
db
.put
(
k1
.as_bytes
(),
v
.as_slice
())
.unwrap
();
db
.put
(
k2
.as_bytes
(),
v
.as_slice
())
.unwrap
();
db
.flush
(
true
)
.unwrap
();
}
// Hold a snapshot to prevent the following delete range from dropping keys above.
let
snapshot
=
db
.snapshot
();
db
.delete_range
(
b
"0"
,
b
"6"
)
.unwrap
();
db
.flush
(
true
)
.unwrap
();
// After this, we will have 3 files in level 1.
// File i will contain keys i and i+1, and the delete range [0, 6).
db
.compact_range
(
None
,
None
);
drop
(
snapshot
);
// Before the fix, the file in the middle with keys 2 and 3 will be deleted,
// which can be a problem when we compact later. After the fix, no file will
// be deleted since they have an overlapped delete range [0, 6).
db
.delete_file_in_range
(
b
"1"
,
b
"4"
)
.unwrap
();
// Flush a file with keys 4 and 5 to level 0.
for
i
in
4
..
5
{
let
k1
=
format!
(
"{}"
,
i
);
let
k2
=
format!
(
"{}"
,
i
+
1
);
let
mut
v
=
vec!
[
0
;
value_size
];
rand
::
thread_rng
()
.fill_bytes
(
&
mut
v
);
db
.put
(
k1
.as_bytes
(),
v
.as_slice
())
.unwrap
();
db
.put
(
k2
.as_bytes
(),
v
.as_slice
())
.unwrap
();
db
.flush
(
true
)
.unwrap
();
}
// After this, the delete range [0, 6) will drop all entries before it, so
// we should have only keys 4 and 5.
db
.compact_range
(
None
,
None
);
let
mut
it
=
db
.iter
();
it
.seek
(
SeekKey
::
Start
);
assert
!
(
it
.valid
());
assert_eq!
(
it
.key
(),
b
"4"
);
assert
!
(
it
.next
());
assert_eq!
(
it
.key
(),
b
"5"
);
assert
!
(
!
it
.next
());
}
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