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
e7a7ab9c
Unverified
Commit
e7a7ab9c
authored
Jan 31, 2018
by
Huachao Huang
Committed by
GitHub
Jan 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update rocksdb to commit '169406c1592b7e15f570345ff78ee4d895ca0373'
parent
76587cac
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
191 additions
and
39 deletions
+191
-39
convenience.cc
librocksdb_sys/rocksdb/db/convenience.cc
+10
-2
db_compaction_test.cc
librocksdb_sys/rocksdb/db/db_compaction_test.cc
+116
-0
db_impl.cc
librocksdb_sys/rocksdb/db/db_impl.cc
+45
-34
db_impl.h
librocksdb_sys/rocksdb/db/db_impl.h
+3
-2
convenience.h
librocksdb_sys/rocksdb/include/rocksdb/convenience.h
+9
-1
db.h
librocksdb_sys/rocksdb/include/rocksdb/db.h
+8
-0
No files found.
librocksdb_sys/rocksdb/db/convenience.cc
View file @
e7a7ab9c
...
...
@@ -19,9 +19,17 @@ void CancelAllBackgroundWork(DB* db, bool wait) {
}
Status
DeleteFilesInRange
(
DB
*
db
,
ColumnFamilyHandle
*
column_family
,
const
Slice
*
begin
,
const
Slice
*
end
)
{
const
Slice
*
begin
,
const
Slice
*
end
,
bool
include_end
)
{
RangePtr
range
(
begin
,
end
);
return
DeleteFilesInRanges
(
db
,
column_family
,
&
range
,
1
,
include_end
);
}
Status
DeleteFilesInRanges
(
DB
*
db
,
ColumnFamilyHandle
*
column_family
,
const
RangePtr
*
ranges
,
size_t
n
,
bool
include_end
)
{
return
(
static_cast_with_check
<
DBImpl
,
DB
>
(
db
->
GetRootDB
()))
->
DeleteFilesInRange
(
column_family
,
begin
,
end
);
->
DeleteFilesInRange
s
(
column_family
,
ranges
,
n
,
include_
end
);
}
Status
VerifySstFileChecksum
(
const
Options
&
options
,
...
...
librocksdb_sys/rocksdb/db/db_compaction_test.cc
View file @
e7a7ab9c
...
...
@@ -1439,6 +1439,122 @@ TEST_F(DBCompactionTest, DeleteFileRange) {
ASSERT_GT
(
old_num_files
,
new_num_files
);
}
TEST_F
(
DBCompactionTest
,
DeleteFilesInRanges
)
{
Options
options
=
CurrentOptions
();
options
.
write_buffer_size
=
10
*
1024
*
1024
;
options
.
max_bytes_for_level_multiplier
=
2
;
options
.
num_levels
=
4
;
options
.
max_background_compactions
=
3
;
options
.
disable_auto_compactions
=
true
;
DestroyAndReopen
(
options
);
int32_t
value_size
=
10
*
1024
;
// 10 KB
Random
rnd
(
301
);
std
::
map
<
int32_t
,
std
::
string
>
values
;
// file [0 => 100), [100 => 200), ... [900, 1000)
for
(
auto
i
=
0
;
i
<
10
;
i
++
)
{
for
(
auto
j
=
0
;
j
<
100
;
j
++
)
{
auto
k
=
i
*
100
+
j
;
values
[
k
]
=
RandomString
(
&
rnd
,
value_size
);
ASSERT_OK
(
Put
(
Key
(
k
),
values
[
k
]));
}
ASSERT_OK
(
Flush
());
}
ASSERT_EQ
(
"10"
,
FilesPerLevel
(
0
));
CompactRangeOptions
compact_options
;
compact_options
.
change_level
=
true
;
compact_options
.
target_level
=
2
;
ASSERT_OK
(
db_
->
CompactRange
(
compact_options
,
nullptr
,
nullptr
));
ASSERT_EQ
(
"0,0,10"
,
FilesPerLevel
(
0
));
// file [0 => 100), [200 => 300), ... [800, 900)
for
(
auto
i
=
0
;
i
<
10
;
i
+=
2
)
{
for
(
auto
j
=
0
;
j
<
100
;
j
++
)
{
auto
k
=
i
*
100
+
j
;
ASSERT_OK
(
Put
(
Key
(
k
),
values
[
k
]));
}
ASSERT_OK
(
Flush
());
}
ASSERT_EQ
(
"5,0,10"
,
FilesPerLevel
(
0
));
ASSERT_OK
(
dbfull
()
->
TEST_CompactRange
(
0
,
nullptr
,
nullptr
));
ASSERT_EQ
(
"0,5,10"
,
FilesPerLevel
(
0
));
// Delete files in range [0, 299] (inclusive)
{
auto
begin_str1
=
Key
(
0
),
end_str1
=
Key
(
100
);
auto
begin_str2
=
Key
(
100
),
end_str2
=
Key
(
200
);
auto
begin_str3
=
Key
(
200
),
end_str3
=
Key
(
299
);
Slice
begin1
(
begin_str1
),
end1
(
end_str1
);
Slice
begin2
(
begin_str2
),
end2
(
end_str2
);
Slice
begin3
(
begin_str3
),
end3
(
end_str3
);
std
::
vector
<
RangePtr
>
ranges
;
ranges
.
push_back
(
RangePtr
(
&
begin1
,
&
end1
));
ranges
.
push_back
(
RangePtr
(
&
begin2
,
&
end2
));
ranges
.
push_back
(
RangePtr
(
&
begin3
,
&
end3
));
ASSERT_OK
(
DeleteFilesInRanges
(
db_
,
db_
->
DefaultColumnFamily
(),
ranges
.
data
(),
ranges
.
size
()));
ASSERT_EQ
(
"0,3,7"
,
FilesPerLevel
(
0
));
// Keys [0, 300) should not exist.
for
(
auto
i
=
0
;
i
<
300
;
i
++
)
{
ReadOptions
ropts
;
std
::
string
result
;
auto
s
=
db_
->
Get
(
ropts
,
Key
(
i
),
&
result
);
ASSERT_TRUE
(
s
.
IsNotFound
());
}
for
(
auto
i
=
300
;
i
<
1000
;
i
++
)
{
ASSERT_EQ
(
Get
(
Key
(
i
)),
values
[
i
]);
}
}
// Delete files in range [600, 999) (exclusive)
{
auto
begin_str1
=
Key
(
600
),
end_str1
=
Key
(
800
);
auto
begin_str2
=
Key
(
700
),
end_str2
=
Key
(
900
);
auto
begin_str3
=
Key
(
800
),
end_str3
=
Key
(
999
);
Slice
begin1
(
begin_str1
),
end1
(
end_str1
);
Slice
begin2
(
begin_str2
),
end2
(
end_str2
);
Slice
begin3
(
begin_str3
),
end3
(
end_str3
);
std
::
vector
<
RangePtr
>
ranges
;
ranges
.
push_back
(
RangePtr
(
&
begin1
,
&
end1
));
ranges
.
push_back
(
RangePtr
(
&
begin2
,
&
end2
));
ranges
.
push_back
(
RangePtr
(
&
begin3
,
&
end3
));
ASSERT_OK
(
DeleteFilesInRanges
(
db_
,
db_
->
DefaultColumnFamily
(),
ranges
.
data
(),
ranges
.
size
(),
false
));
ASSERT_EQ
(
"0,1,4"
,
FilesPerLevel
(
0
));
// Keys [600, 900) should not exist.
for
(
auto
i
=
600
;
i
<
900
;
i
++
)
{
ReadOptions
ropts
;
std
::
string
result
;
auto
s
=
db_
->
Get
(
ropts
,
Key
(
i
),
&
result
);
ASSERT_TRUE
(
s
.
IsNotFound
());
}
for
(
auto
i
=
300
;
i
<
600
;
i
++
)
{
ASSERT_EQ
(
Get
(
Key
(
i
)),
values
[
i
]);
}
for
(
auto
i
=
900
;
i
<
1000
;
i
++
)
{
ASSERT_EQ
(
Get
(
Key
(
i
)),
values
[
i
]);
}
}
// Delete all files.
{
RangePtr
range
;
ASSERT_OK
(
DeleteFilesInRanges
(
db_
,
db_
->
DefaultColumnFamily
(),
&
range
,
1
));
ASSERT_EQ
(
""
,
FilesPerLevel
(
0
));
for
(
auto
i
=
0
;
i
<
1000
;
i
++
)
{
ReadOptions
ropts
;
std
::
string
result
;
auto
s
=
db_
->
Get
(
ropts
,
Key
(
i
),
&
result
);
ASSERT_TRUE
(
s
.
IsNotFound
());
}
}
}
TEST_F
(
DBCompactionTest
,
DeleteFileRangeFileEndpointsOverlapBug
)
{
// regression test for #2833: groups of files whose user-keys overlap at the
// endpoints could be split by `DeleteFilesInRange`. This caused old data to
...
...
librocksdb_sys/rocksdb/db/db_impl.cc
View file @
e7a7ab9c
...
...
@@ -2029,52 +2029,63 @@ Status DBImpl::DeleteFile(std::string name) {
return
status
;
}
Status
DBImpl
::
DeleteFilesInRange
(
ColumnFamilyHandle
*
column_family
,
const
Slice
*
begin
,
const
Slice
*
end
)
{
Status
DBImpl
::
DeleteFilesInRanges
(
ColumnFamilyHandle
*
column_family
,
const
RangePtr
*
ranges
,
size_t
n
,
bool
include_end
)
{
Status
status
;
auto
cfh
=
reinterpret_cast
<
ColumnFamilyHandleImpl
*>
(
column_family
);
ColumnFamilyData
*
cfd
=
cfh
->
cfd
();
VersionEdit
edit
;
std
::
vector
<
FileMetaData
*>
deleted_files
;
std
::
set
<
FileMetaData
*>
deleted_files
;
JobContext
job_context
(
next_job_id_
.
fetch_add
(
1
),
true
);
{
InstrumentedMutexLock
l
(
&
mutex_
);
Version
*
input_version
=
cfd
->
current
();
auto
*
vstorage
=
input_version
->
storage_info
();
for
(
int
i
=
1
;
i
<
cfd
->
NumberLevels
();
i
++
)
{
if
(
vstorage
->
LevelFiles
(
i
).
empty
()
||
!
vstorage
->
OverlapInLevel
(
i
,
begin
,
end
))
{
continue
;
}
std
::
vector
<
FileMetaData
*>
level_files
;
InternalKey
begin_storage
,
end_storage
,
*
begin_key
,
*
end_key
;
if
(
begin
==
nullptr
)
{
begin_key
=
nullptr
;
}
else
{
begin_storage
.
SetMaxPossibleForUserKey
(
*
begin
);
begin_key
=
&
begin_storage
;
}
if
(
end
==
nullptr
)
{
end_key
=
nullptr
;
}
else
{
end_storage
.
SetMinPossibleForUserKey
(
*
end
);
end_key
=
&
end_storage
;
}
vstorage
->
GetCleanInputsWithinInterval
(
i
,
begin_key
,
end_key
,
&
level_files
,
-
1
/* hint_index */
,
nullptr
/* file_index */
);
FileMetaData
*
level_file
;
for
(
uint32_t
j
=
0
;
j
<
level_files
.
size
();
j
++
)
{
level_file
=
level_files
[
j
];
if
(
level_file
->
being_compacted
)
{
for
(
size_t
r
=
0
;
r
<
n
;
r
++
)
{
auto
begin
=
ranges
[
r
].
start
,
end
=
ranges
[
r
].
limit
;
for
(
int
i
=
1
;
i
<
cfd
->
NumberLevels
();
i
++
)
{
if
(
vstorage
->
LevelFiles
(
i
).
empty
()
||
!
vstorage
->
OverlapInLevel
(
i
,
begin
,
end
))
{
continue
;
}
edit
.
SetColumnFamily
(
cfd
->
GetID
());
edit
.
DeleteFile
(
i
,
level_file
->
fd
.
GetNumber
());
deleted_files
.
push_back
(
level_file
);
level_file
->
being_compacted
=
true
;
std
::
vector
<
FileMetaData
*>
level_files
;
InternalKey
begin_storage
,
end_storage
,
*
begin_key
,
*
end_key
;
if
(
begin
==
nullptr
)
{
begin_key
=
nullptr
;
}
else
{
begin_storage
.
SetMinPossibleForUserKey
(
*
begin
);
begin_key
=
&
begin_storage
;
}
if
(
end
==
nullptr
)
{
end_key
=
nullptr
;
}
else
{
end_storage
.
SetMaxPossibleForUserKey
(
*
end
);
end_key
=
&
end_storage
;
}
vstorage
->
GetCleanInputsWithinInterval
(
i
,
begin_key
,
end_key
,
&
level_files
,
-
1
/* hint_index */
,
nullptr
/* file_index */
);
FileMetaData
*
level_file
;
for
(
uint32_t
j
=
0
;
j
<
level_files
.
size
();
j
++
)
{
level_file
=
level_files
[
j
];
if
(
level_file
->
being_compacted
)
{
continue
;
}
if
(
deleted_files
.
find
(
level_file
)
!=
deleted_files
.
end
())
{
continue
;
}
if
(
!
include_end
&&
end
!=
nullptr
&&
cfd
->
user_comparator
()
->
Compare
(
level_file
->
largest
.
user_key
(),
*
end
)
==
0
)
{
continue
;
}
edit
.
SetColumnFamily
(
cfd
->
GetID
());
edit
.
DeleteFile
(
i
,
level_file
->
fd
.
GetNumber
());
deleted_files
.
insert
(
level_file
);
level_file
->
being_compacted
=
true
;
}
}
}
if
(
edit
.
GetDeletedFiles
().
empty
())
{
...
...
librocksdb_sys/rocksdb/db/db_impl.h
View file @
e7a7ab9c
...
...
@@ -237,8 +237,9 @@ class DBImpl : public DB {
const
TransactionLogIterator
::
ReadOptions
&
read_options
=
TransactionLogIterator
::
ReadOptions
())
override
;
virtual
Status
DeleteFile
(
std
::
string
name
)
override
;
Status
DeleteFilesInRange
(
ColumnFamilyHandle
*
column_family
,
const
Slice
*
begin
,
const
Slice
*
end
);
Status
DeleteFilesInRanges
(
ColumnFamilyHandle
*
column_family
,
const
RangePtr
*
ranges
,
size_t
n
,
bool
include_end
=
true
);
virtual
void
GetLiveFilesMetaData
(
std
::
vector
<
LiveFileMetaData
>*
metadata
)
override
;
...
...
librocksdb_sys/rocksdb/include/rocksdb/convenience.h
View file @
e7a7ab9c
...
...
@@ -329,7 +329,15 @@ void CancelAllBackgroundWork(DB* db, bool wait = false);
// in the range.
// Snapshots before the delete might not see the data in the given range.
Status
DeleteFilesInRange
(
DB
*
db
,
ColumnFamilyHandle
*
column_family
,
const
Slice
*
begin
,
const
Slice
*
end
);
const
Slice
*
begin
,
const
Slice
*
end
,
bool
include_end
=
true
);
// Delete files in multiple ranges at once
// Delete files in a lot of ranges one at a time can be slow, use this API for
// better performance in that case.
Status
DeleteFilesInRanges
(
DB
*
db
,
ColumnFamilyHandle
*
column_family
,
const
RangePtr
*
ranges
,
size_t
n
,
bool
include_end
=
true
);
// Verify the checksum of file
Status
VerifySstFileChecksum
(
const
Options
&
options
,
...
...
librocksdb_sys/rocksdb/include/rocksdb/db.h
View file @
e7a7ab9c
...
...
@@ -99,6 +99,14 @@ struct Range {
Range
(
const
Slice
&
s
,
const
Slice
&
l
)
:
start
(
s
),
limit
(
l
)
{
}
};
struct
RangePtr
{
const
Slice
*
start
;
const
Slice
*
limit
;
RangePtr
()
:
start
(
nullptr
),
limit
(
nullptr
)
{
}
RangePtr
(
const
Slice
*
s
,
const
Slice
*
l
)
:
start
(
s
),
limit
(
l
)
{
}
};
// A collections of table properties objects, where
// key: is the table's file name.
// value: the table properties object of the given table.
...
...
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