Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
titan
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
titan
Commits
10710bb1
Unverified
Commit
10710bb1
authored
Sep 18, 2019
by
Connor
Committed by
GitHub
Sep 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more metrics (#79)
* add more metrics Signed-off-by:
Connor1996
<
zbk602423539@gmail.com
>
parent
8768067e
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
343 additions
and
170 deletions
+343
-170
db.h
include/titan/db.h
+15
-0
blob_file_reader.cc
src/blob_file_reader.cc
+2
-4
blob_file_set.cc
src/blob_file_set.cc
+2
-4
blob_format.cc
src/blob_format.cc
+21
-0
blob_format.h
src/blob_format.h
+1
-0
blob_gc_job.cc
src/blob_gc_job.cc
+45
-40
blob_gc_job.h
src/blob_gc_job.h
+14
-11
blob_gc_job_test.cc
src/blob_gc_job_test.cc
+1
-1
blob_gc_picker.cc
src/blob_gc_picker.cc
+11
-9
blob_gc_picker.h
src/blob_gc_picker.h
+2
-1
blob_gc_picker_test.cc
src/blob_gc_picker_test.cc
+1
-1
blob_storage.h
src/blob_storage.h
+2
-0
db_impl.cc
src/db_impl.cc
+16
-4
db_impl_gc.cc
src/db_impl_gc.cc
+8
-4
db_iter.h
src/db_iter.h
+6
-6
table_builder.cc
src/table_builder.cc
+4
-4
titan_stats.cc
src/titan_stats.cc
+32
-5
titan_stats.h
src/titan_stats.h
+143
-76
util.cc
src/util.cc
+9
-0
util.h
src/util.h
+8
-0
No files found.
include/titan/db.h
View file @
10710bb1
...
@@ -158,6 +158,21 @@ class TitanDB : public StackableDB {
...
@@ -158,6 +158,21 @@ class TitanDB : public StackableDB {
// "rocksdb.titandb.obsolete-blob-file-size" - returns size of obsolete
// "rocksdb.titandb.obsolete-blob-file-size" - returns size of obsolete
// blob files.
// blob files.
static
const
std
::
string
kObsoleteBlobFileSize
;
static
const
std
::
string
kObsoleteBlobFileSize
;
// "rocksdb.titandb.discardable_ratio_le0_file_num" - returns count of
// file whose discardable ratio is less or equal to 0%.
static
const
std
::
string
kNumDiscardableRatioLE0File
;
// "rocksdb.titandb.discardable_ratio_le20_file_num" - returns count of
// file whose discardable ratio is less or equal to 20%.
static
const
std
::
string
kNumDiscardableRatioLE20File
;
// "rocksdb.titandb.discardable_ratio_le50_file_num" - returns count of
// file whose discardable ratio is less or equal to 50%.
static
const
std
::
string
kNumDiscardableRatioLE50File
;
// "rocksdb.titandb.discardable_ratio_le80_file_num" - returns count of
// file whose discardable ratio is less or equal to 80%.
static
const
std
::
string
kNumDiscardableRatioLE80File
;
// "rocksdb.titandb.discardable_ratio_le100_file_num" - returns count of
// file whose discardable ratio is less or equal to 100%.
static
const
std
::
string
kNumDiscardableRatioLE100File
;
};
};
bool
GetProperty
(
ColumnFamilyHandle
*
column_family
,
const
Slice
&
property
,
bool
GetProperty
(
ColumnFamilyHandle
*
column_family
,
const
Slice
&
property
,
...
...
src/blob_file_reader.cc
View file @
10710bb1
...
@@ -106,15 +106,13 @@ Status BlobFileReader::Get(const ReadOptions& /*options*/,
...
@@ -106,15 +106,13 @@ Status BlobFileReader::Get(const ReadOptions& /*options*/,
EncodeBlobCache
(
&
cache_key
,
cache_prefix_
,
handle
.
offset
);
EncodeBlobCache
(
&
cache_key
,
cache_prefix_
,
handle
.
offset
);
cache_handle
=
cache_
->
Lookup
(
cache_key
);
cache_handle
=
cache_
->
Lookup
(
cache_key
);
if
(
cache_handle
)
{
if
(
cache_handle
)
{
RecordTick
(
stats_
,
BLOCK_CACHE_DATA_HIT
);
RecordTick
(
stats_
,
TitanStats
::
BLOB_CACHE_HIT
);
RecordTick
(
stats_
,
BLOCK_CACHE_HIT
);
auto
blob
=
reinterpret_cast
<
OwnedSlice
*>
(
cache_
->
Value
(
cache_handle
));
auto
blob
=
reinterpret_cast
<
OwnedSlice
*>
(
cache_
->
Value
(
cache_handle
));
buffer
->
PinSlice
(
*
blob
,
UnrefCacheHandle
,
cache_
.
get
(),
cache_handle
);
buffer
->
PinSlice
(
*
blob
,
UnrefCacheHandle
,
cache_
.
get
(),
cache_handle
);
return
DecodeInto
(
*
blob
,
record
);
return
DecodeInto
(
*
blob
,
record
);
}
}
}
}
RecordTick
(
stats_
,
BLOCK_CACHE_DATA_MISS
);
RecordTick
(
stats_
,
TitanStats
::
BLOB_CACHE_MISS
);
RecordTick
(
stats_
,
BLOCK_CACHE_MISS
);
OwnedSlice
blob
;
OwnedSlice
blob
;
Status
s
=
ReadRecord
(
handle
,
record
,
&
blob
);
Status
s
=
ReadRecord
(
handle
,
record
,
&
blob
);
...
...
src/blob_file_set.cc
View file @
10710bb1
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
#include <inttypes.h>
#include <inttypes.h>
#include "file/filename.h"
#include "edit_collector.h"
#include "edit_collector.h"
namespace
rocksdb
{
namespace
rocksdb
{
...
@@ -163,7 +161,7 @@ Status BlobFileSet::OpenManifest(uint64_t file_number) {
...
@@ -163,7 +161,7 @@ Status BlobFileSet::OpenManifest(uint64_t file_number) {
s
=
WriteSnapshot
(
manifest_
.
get
());
s
=
WriteSnapshot
(
manifest_
.
get
());
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
ImmutableDBOptions
ioptions
(
db_options_
);
ImmutableDBOptions
ioptions
(
db_options_
);
s
=
Sync
Manifest
(
env
_
,
&
ioptions
,
manifest_
->
file
());
s
=
Sync
TitanManifest
(
env_
,
stats
_
,
&
ioptions
,
manifest_
->
file
());
}
}
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
// Makes "CURRENT" file that points to the new manifest file.
// Makes "CURRENT" file that points to the new manifest file.
...
@@ -223,7 +221,7 @@ Status BlobFileSet::LogAndApply(VersionEdit& edit) {
...
@@ -223,7 +221,7 @@ Status BlobFileSet::LogAndApply(VersionEdit& edit) {
if
(
!
s
.
ok
())
return
s
;
if
(
!
s
.
ok
())
return
s
;
ImmutableDBOptions
ioptions
(
db_options_
);
ImmutableDBOptions
ioptions
(
db_options_
);
s
=
Sync
Manifest
(
env
_
,
&
ioptions
,
manifest_
->
file
());
s
=
Sync
TitanManifest
(
env_
,
stats
_
,
&
ioptions
,
manifest_
->
file
());
if
(
!
s
.
ok
())
return
s
;
if
(
!
s
.
ok
())
return
s
;
return
collector
.
Apply
(
*
this
);
return
collector
.
Apply
(
*
this
);
}
}
...
...
src/blob_format.cc
View file @
10710bb1
...
@@ -229,6 +229,27 @@ void BlobFileMeta::AddDiscardableSize(uint64_t _discardable_size) {
...
@@ -229,6 +229,27 @@ void BlobFileMeta::AddDiscardableSize(uint64_t _discardable_size) {
assert
(
discardable_size_
<
file_size_
);
assert
(
discardable_size_
<
file_size_
);
}
}
TitanInternalStats
::
StatsType
BlobFileMeta
::
GetDiscardableRatioLevel
()
const
{
auto
ratio
=
GetDiscardableRatio
();
TitanInternalStats
::
StatsType
type
;
if
(
ratio
==
0
)
{
type
=
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE0
;
}
else
if
(
ratio
<=
0.2
)
{
type
=
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE20
;
}
else
if
(
ratio
<=
0.5
)
{
type
=
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE50
;
}
else
if
(
ratio
<=
0.8
)
{
type
=
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE80
;
}
else
if
(
ratio
<=
1.0
||
(
ratio
-
1.0
)
<
std
::
numeric_limits
<
double
>::
epsilon
())
{
type
=
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE100
;
}
else
{
fprintf
(
stderr
,
"invalid discarable ratio"
);
abort
();
}
return
type
;
}
double
BlobFileMeta
::
GetDiscardableRatio
()
const
{
double
BlobFileMeta
::
GetDiscardableRatio
()
const
{
return
static_cast
<
double
>
(
discardable_size_
)
/
return
static_cast
<
double
>
(
discardable_size_
)
/
static_cast
<
double
>
(
file_size_
);
static_cast
<
double
>
(
file_size_
);
...
...
src/blob_format.h
View file @
10710bb1
...
@@ -217,6 +217,7 @@ class BlobFileMeta {
...
@@ -217,6 +217,7 @@ class BlobFileMeta {
void
AddDiscardableSize
(
uint64_t
_discardable_size
);
void
AddDiscardableSize
(
uint64_t
_discardable_size
);
double
GetDiscardableRatio
()
const
;
double
GetDiscardableRatio
()
const
;
TitanInternalStats
::
StatsType
GetDiscardableRatioLevel
()
const
;
private
:
private
:
// Persistent field
// Persistent field
...
...
src/blob_gc_job.cc
View file @
10710bb1
...
@@ -97,19 +97,20 @@ BlobGCJob::~BlobGCJob() {
...
@@ -97,19 +97,20 @@ BlobGCJob::~BlobGCJob() {
LogFlush
(
db_options_
.
info_log
.
get
());
LogFlush
(
db_options_
.
info_log
.
get
());
}
}
// flush metrics
// flush metrics
RecordTick
(
stats_
,
BLOB_DB_BYTES_READ
,
metrics_
.
b
lob_db_b
ytes_read
);
RecordTick
(
stats_
,
BLOB_DB_BYTES_READ
,
metrics_
.
bytes_read
);
RecordTick
(
stats_
,
BLOB_DB_BYTES_WRITTEN
,
metrics_
.
b
lob_db_b
ytes_written
);
RecordTick
(
stats_
,
BLOB_DB_BYTES_WRITTEN
,
metrics_
.
bytes_written
);
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_KEYS_OVERWRITTEN
,
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_KEYS_OVERWRITTEN
,
metrics_
.
blob_db_
gc_num_keys_overwritten
);
metrics_
.
gc_num_keys_overwritten
);
RecordTick
(
stats_
,
BLOB_DB_GC_BYTES_OVERWRITTEN
,
RecordTick
(
stats_
,
BLOB_DB_GC_BYTES_OVERWRITTEN
,
metrics_
.
blob_db_
gc_bytes_overwritten
);
metrics_
.
gc_bytes_overwritten
);
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_KEYS_RELOCATED
,
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_KEYS_RELOCATED
,
metrics_
.
blob_db_gc_num_keys_relocated
);
metrics_
.
gc_num_keys_relocated
);
RecordTick
(
stats_
,
BLOB_DB_GC_BYTES_RELOCATED
,
RecordTick
(
stats_
,
BLOB_DB_GC_BYTES_RELOCATED
,
metrics_
.
gc_bytes_relocated
);
metrics_
.
blob_db_gc_bytes_relocated
);
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_NEW_FILES
,
metrics_
.
gc_num_new_files
);
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_NEW_FILES
,
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_FILES
,
metrics_
.
gc_num_files
);
metrics_
.
blob_db_gc_num_new_files
);
RecordTick
(
stats_
,
TitanStats
::
GC_DISCARDABLE
,
metrics_
.
gc_discardable
);
RecordTick
(
stats_
,
BLOB_DB_GC_NUM_FILES
,
metrics_
.
blob_db_gc_num_files
);
RecordTick
(
stats_
,
TitanStats
::
GC_SMALL_FILE
,
metrics_
.
gc_small_file
);
RecordTick
(
stats_
,
TitanStats
::
GC_SAMPLE
,
metrics_
.
gc_sample
);
}
}
Status
BlobGCJob
::
Prepare
()
{
Status
BlobGCJob
::
Prepare
()
{
...
@@ -151,7 +152,7 @@ Status BlobGCJob::Run() {
...
@@ -151,7 +152,7 @@ Status BlobGCJob::Run() {
}
}
Status
BlobGCJob
::
SampleCandidateFiles
()
{
Status
BlobGCJob
::
SampleCandidateFiles
()
{
TitanStopWatch
sw
(
env_
,
metrics_
.
blob_db_
gc_sampling_micros
);
TitanStopWatch
sw
(
env_
,
metrics_
.
gc_sampling_micros
);
std
::
vector
<
BlobFileMeta
*>
result
;
std
::
vector
<
BlobFileMeta
*>
result
;
for
(
const
auto
&
file
:
blob_gc_
->
inputs
())
{
for
(
const
auto
&
file
:
blob_gc_
->
inputs
())
{
bool
selected
=
false
;
bool
selected
=
false
;
...
@@ -172,12 +173,15 @@ Status BlobGCJob::SampleCandidateFiles() {
...
@@ -172,12 +173,15 @@ Status BlobGCJob::SampleCandidateFiles() {
Status
BlobGCJob
::
DoSample
(
const
BlobFileMeta
*
file
,
bool
*
selected
)
{
Status
BlobGCJob
::
DoSample
(
const
BlobFileMeta
*
file
,
bool
*
selected
)
{
assert
(
selected
!=
nullptr
);
assert
(
selected
!=
nullptr
);
if
(
file
->
file_size
()
<=
if
(
file
->
file_size
()
<=
blob_gc_
->
titan_cf_options
().
merge_small_file_threshold
||
blob_gc_
->
titan_cf_options
().
merge_small_file_threshold
)
{
file
->
GetDiscardableRatio
()
>=
metrics_
.
gc_small_file
+=
1
;
*
selected
=
true
;
}
else
if
(
file
->
GetDiscardableRatio
()
>=
blob_gc_
->
titan_cf_options
().
blob_file_discardable_ratio
)
{
blob_gc_
->
titan_cf_options
().
blob_file_discardable_ratio
)
{
metrics_
.
gc_discardable
+=
1
;
*
selected
=
true
;
*
selected
=
true
;
return
Status
::
OK
();
}
}
if
(
*
selected
)
return
Status
::
OK
();
// TODO: add do sample count metrics
// TODO: add do sample count metrics
auto
records_size
=
file
->
file_size
()
-
BlobFileHeader
::
kEncodedLength
-
auto
records_size
=
file
->
file_size
()
-
BlobFileHeader
::
kEncodedLength
-
...
@@ -232,7 +236,7 @@ Status BlobGCJob::DoSample(const BlobFileMeta* file, bool* selected) {
...
@@ -232,7 +236,7 @@ Status BlobGCJob::DoSample(const BlobFileMeta* file, bool* selected) {
discardable_size
+=
total_length
;
discardable_size
+=
total_length
;
}
}
}
}
metrics_
.
b
lob_db_b
ytes_read
+=
iterated_size
;
metrics_
.
bytes_read
+=
iterated_size
;
assert
(
iter
.
status
().
ok
());
assert
(
iter
.
status
().
ok
());
*
selected
=
*
selected
=
...
@@ -281,7 +285,7 @@ Status BlobGCJob::DoRunGC() {
...
@@ -281,7 +285,7 @@ Status BlobGCJob::DoRunGC() {
}
}
BlobIndex
blob_index
=
gc_iter
->
GetBlobIndex
();
BlobIndex
blob_index
=
gc_iter
->
GetBlobIndex
();
// count read bytes for blob record of gc candidate files
// count read bytes for blob record of gc candidate files
metrics_
.
b
lob_db_b
ytes_read
+=
blob_index
.
blob_handle
.
size
;
metrics_
.
bytes_read
+=
blob_index
.
blob_handle
.
size
;
if
(
!
last_key
.
empty
()
&&
!
gc_iter
->
key
().
compare
(
last_key
))
{
if
(
!
last_key
.
empty
()
&&
!
gc_iter
->
key
().
compare
(
last_key
))
{
if
(
last_key_valid
)
{
if
(
last_key_valid
)
{
...
@@ -298,8 +302,8 @@ Status BlobGCJob::DoRunGC() {
...
@@ -298,8 +302,8 @@ Status BlobGCJob::DoRunGC() {
break
;
break
;
}
}
if
(
discardable
)
{
if
(
discardable
)
{
metrics_
.
blob_db_
gc_num_keys_overwritten
++
;
metrics_
.
gc_num_keys_overwritten
++
;
metrics_
.
blob_db_
gc_bytes_overwritten
+=
blob_index
.
blob_handle
.
size
;
metrics_
.
gc_bytes_overwritten
+=
blob_index
.
blob_handle
.
size
;
continue
;
continue
;
}
}
...
@@ -335,7 +339,7 @@ Status BlobGCJob::DoRunGC() {
...
@@ -335,7 +339,7 @@ Status BlobGCJob::DoRunGC() {
blob_record
.
value
=
gc_iter
->
value
();
blob_record
.
value
=
gc_iter
->
value
();
// count written bytes for new blob record,
// count written bytes for new blob record,
// blob index's size is counted in `RewriteValidKeyToLSM`
// blob index's size is counted in `RewriteValidKeyToLSM`
metrics_
.
b
lob_db_b
ytes_written
+=
blob_record
.
size
();
metrics_
.
bytes_written
+=
blob_record
.
size
();
BlobIndex
new_blob_index
;
BlobIndex
new_blob_index
;
new_blob_index
.
file_number
=
blob_file_handle
->
GetNumber
();
new_blob_index
.
file_number
=
blob_file_handle
->
GetNumber
();
...
@@ -401,7 +405,7 @@ Status BlobGCJob::BuildIterator(
...
@@ -401,7 +405,7 @@ Status BlobGCJob::BuildIterator(
Status
BlobGCJob
::
DiscardEntry
(
const
Slice
&
key
,
const
BlobIndex
&
blob_index
,
Status
BlobGCJob
::
DiscardEntry
(
const
Slice
&
key
,
const
BlobIndex
&
blob_index
,
bool
*
discardable
)
{
bool
*
discardable
)
{
TitanStopWatch
sw
(
env_
,
metrics_
.
blob_db_
gc_read_lsm_micros
);
TitanStopWatch
sw
(
env_
,
metrics_
.
gc_read_lsm_micros
);
assert
(
discardable
!=
nullptr
);
assert
(
discardable
!=
nullptr
);
PinnableSlice
index_entry
;
PinnableSlice
index_entry
;
bool
is_blob_index
=
false
;
bool
is_blob_index
=
false
;
...
@@ -412,7 +416,7 @@ Status BlobGCJob::DiscardEntry(const Slice& key, const BlobIndex& blob_index,
...
@@ -412,7 +416,7 @@ Status BlobGCJob::DiscardEntry(const Slice& key, const BlobIndex& blob_index,
return
s
;
return
s
;
}
}
// count read bytes for checking LSM entry
// count read bytes for checking LSM entry
metrics_
.
b
lob_db_b
ytes_read
+=
key
.
size
()
+
index_entry
.
size
();
metrics_
.
bytes_read
+=
key
.
size
()
+
index_entry
.
size
();
if
(
s
.
IsNotFound
()
||
!
is_blob_index
)
{
if
(
s
.
IsNotFound
()
||
!
is_blob_index
)
{
// Either the key is deleted or updated with a newer version which is
// Either the key is deleted or updated with a newer version which is
// inlined in LSM.
// inlined in LSM.
...
@@ -475,7 +479,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
...
@@ -475,7 +479,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
if
(
!
s
.
ok
())
{
if
(
!
s
.
ok
())
{
break
;
break
;
}
}
metrics_
.
blob_db_
gc_num_new_files
++
;
metrics_
.
gc_num_new_files
++
;
}
}
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
BlobFileMeta
>
,
std
::
vector
<
std
::
pair
<
std
::
shared_ptr
<
BlobFileMeta
>
,
...
@@ -487,7 +491,8 @@ Status BlobGCJob::InstallOutputBlobFiles() {
...
@@ -487,7 +491,8 @@ Status BlobGCJob::InstallOutputBlobFiles() {
builder
.
first
->
GetNumber
(),
builder
.
first
->
GetFile
()
->
GetFileSize
(),
builder
.
first
->
GetNumber
(),
builder
.
first
->
GetFile
()
->
GetFileSize
(),
0
,
0
,
builder
.
second
->
GetSmallestKey
(),
0
,
0
,
builder
.
second
->
GetSmallestKey
(),
builder
.
second
->
GetLargestKey
());
builder
.
second
->
GetLargestKey
());
RecordInHistogram
(
stats_
,
TitanStats
::
GC_OUTPUT_FILE_SIZE
,
file
->
file_size
());
if
(
!
tmp
.
empty
())
{
if
(
!
tmp
.
empty
())
{
tmp
.
append
(
" "
);
tmp
.
append
(
" "
);
}
}
...
@@ -525,7 +530,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
...
@@ -525,7 +530,7 @@ Status BlobGCJob::InstallOutputBlobFiles() {
}
}
Status
BlobGCJob
::
RewriteValidKeyToLSM
()
{
Status
BlobGCJob
::
RewriteValidKeyToLSM
()
{
TitanStopWatch
sw
(
env_
,
metrics_
.
blob_db_
gc_update_lsm_micros
);
TitanStopWatch
sw
(
env_
,
metrics_
.
gc_update_lsm_micros
);
Status
s
;
Status
s
;
auto
*
db_impl
=
reinterpret_cast
<
DBImpl
*>
(
this
->
base_db_
);
auto
*
db_impl
=
reinterpret_cast
<
DBImpl
*>
(
this
->
base_db_
);
...
@@ -544,22 +549,20 @@ Status BlobGCJob::RewriteValidKeyToLSM() {
...
@@ -544,22 +549,20 @@ Status BlobGCJob::RewriteValidKeyToLSM() {
s
=
db_impl
->
WriteWithCallback
(
wo
,
&
write_batch
.
first
,
&
write_batch
.
second
);
s
=
db_impl
->
WriteWithCallback
(
wo
,
&
write_batch
.
first
,
&
write_batch
.
second
);
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
// count written bytes for new blob index.
// count written bytes for new blob index.
metrics_
.
blob_db_bytes_written
+=
write_batch
.
first
.
GetDataSize
();
metrics_
.
bytes_written
+=
write_batch
.
first
.
GetDataSize
();
metrics_
.
blob_db_gc_num_keys_relocated
++
;
metrics_
.
gc_num_keys_relocated
++
;
metrics_
.
blob_db_gc_bytes_relocated
+=
metrics_
.
gc_bytes_relocated
+=
write_batch
.
second
.
blob_record_size
();
write_batch
.
second
.
blob_record_size
();
// Key is successfully written to LSM.
// Key is successfully written to LSM.
}
else
if
(
s
.
IsBusy
())
{
}
else
if
(
s
.
IsBusy
())
{
metrics_
.
blob_db_gc_num_keys_overwritten
++
;
metrics_
.
gc_num_keys_overwritten
++
;
metrics_
.
blob_db_gc_bytes_overwritten
+=
metrics_
.
gc_bytes_overwritten
+=
write_batch
.
second
.
blob_record_size
();
write_batch
.
second
.
blob_record_size
();
// The key is overwritten in the meanwhile. Drop the blob record.
// The key is overwritten in the meanwhile. Drop the blob record.
}
else
{
}
else
{
// We hit an error.
// We hit an error.
break
;
break
;
}
}
// count read bytes in write callback
// count read bytes in write callback
metrics_
.
b
lob_db_b
ytes_read
+=
write_batch
.
second
.
read_bytes
();
metrics_
.
bytes_read
+=
write_batch
.
second
.
read_bytes
();
}
}
if
(
s
.
IsBusy
())
{
if
(
s
.
IsBusy
())
{
s
=
Status
::
OK
();
s
=
Status
::
OK
();
...
@@ -583,7 +586,9 @@ Status BlobGCJob::DeleteInputBlobFiles() {
...
@@ -583,7 +586,9 @@ Status BlobGCJob::DeleteInputBlobFiles() {
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"Titan add obsolete file [%"
PRIu64
"]"
,
"Titan add obsolete file [%"
PRIu64
"]"
,
file
->
file_number
());
file
->
file_number
());
metrics_
.
blob_db_gc_num_files
++
;
metrics_
.
gc_num_files
++
;
RecordInHistogram
(
stats_
,
TitanStats
::
GC_INPUT_FILE_SIZE
,
file
->
file_size
());
edit
.
DeleteBlobFile
(
file
->
file_number
(),
obsolete_sequence
);
edit
.
DeleteBlobFile
(
file
->
file_number
(),
obsolete_sequence
);
}
}
s
=
blob_file_set_
->
LogAndApply
(
edit
);
s
=
blob_file_set_
->
LogAndApply
(
edit
);
...
@@ -612,23 +617,23 @@ void BlobGCJob::UpdateInternalOpStats() {
...
@@ -612,23 +617,23 @@ void BlobGCJob::UpdateInternalOpStats() {
assert
(
internal_op_stats
!=
nullptr
);
assert
(
internal_op_stats
!=
nullptr
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
COUNT
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
COUNT
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
BYTES_READ
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
BYTES_READ
,
metrics_
.
b
lob_db_b
ytes_read
);
metrics_
.
bytes_read
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
BYTES_WRITTEN
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
BYTES_WRITTEN
,
metrics_
.
b
lob_db_b
ytes_written
);
metrics_
.
bytes_written
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
IO_BYTES_READ
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
IO_BYTES_READ
,
io_bytes_read_
);
io_bytes_read_
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
IO_BYTES_WRITTEN
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
IO_BYTES_WRITTEN
,
io_bytes_written_
);
io_bytes_written_
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
INPUT_FILE_NUM
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
INPUT_FILE_NUM
,
metrics_
.
blob_db_
gc_num_files
);
metrics_
.
gc_num_files
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
OUTPUT_FILE_NUM
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
OUTPUT_FILE_NUM
,
metrics_
.
blob_db_
gc_num_new_files
);
metrics_
.
gc_num_new_files
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_SAMPLING_MICROS
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_SAMPLING_MICROS
,
metrics_
.
blob_db_
gc_sampling_micros
);
metrics_
.
gc_sampling_micros
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_READ_LSM_MICROS
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_READ_LSM_MICROS
,
metrics_
.
blob_db_
gc_read_lsm_micros
);
metrics_
.
gc_read_lsm_micros
);
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_UPDATE_LSM_MICROS
,
AddStats
(
internal_op_stats
,
InternalOpStatsType
::
GC_UPDATE_LSM_MICROS
,
metrics_
.
blob_db_
gc_update_lsm_micros
);
metrics_
.
gc_update_lsm_micros
);
}
}
}
// namespace titandb
}
// namespace titandb
...
...
src/blob_gc_job.h
View file @
10710bb1
...
@@ -64,17 +64,20 @@ class BlobGCJob {
...
@@ -64,17 +64,20 @@ class BlobGCJob {
TitanStats
*
stats_
;
TitanStats
*
stats_
;
struct
{
struct
{
uint64_t
blob_db_bytes_read
=
0
;
uint64_t
bytes_read
=
0
;
uint64_t
blob_db_bytes_written
=
0
;
uint64_t
bytes_written
=
0
;
uint64_t
blob_db_gc_num_keys_overwritten
=
0
;
uint64_t
gc_num_keys_overwritten
=
0
;
uint64_t
blob_db_gc_bytes_overwritten
=
0
;
uint64_t
gc_bytes_overwritten
=
0
;
uint64_t
blob_db_gc_num_keys_relocated
=
0
;
uint64_t
gc_num_keys_relocated
=
0
;
uint64_t
blob_db_gc_bytes_relocated
=
0
;
uint64_t
gc_bytes_relocated
=
0
;
uint64_t
blob_db_gc_num_new_files
=
0
;
uint64_t
gc_num_new_files
=
0
;
uint64_t
blob_db_gc_num_files
=
0
;
uint64_t
gc_num_files
=
0
;
uint64_t
blob_db_gc_sampling_micros
=
0
;
uint64_t
gc_small_file
=
0
;
uint64_t
blob_db_gc_read_lsm_micros
=
0
;
uint64_t
gc_discardable
=
0
;
uint64_t
blob_db_gc_update_lsm_micros
=
0
;
uint64_t
gc_sample
=
0
;
uint64_t
gc_sampling_micros
=
0
;
uint64_t
gc_read_lsm_micros
=
0
;
uint64_t
gc_update_lsm_micros
=
0
;
}
metrics_
;
}
metrics_
;
uint64_t
prev_bytes_read_
=
0
;
uint64_t
prev_bytes_read_
=
0
;
...
...
src/blob_gc_job_test.cc
View file @
10710bb1
...
@@ -118,7 +118,7 @@ class BlobGCJobTest : public testing::Test {
...
@@ -118,7 +118,7 @@ class BlobGCJobTest : public testing::Test {
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
{
{
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options
,
cf_options
);
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options
,
cf_options
,
nullptr
);
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
blob_file_set_
->
GetBlobStorage
(
cfh
->
GetID
()).
lock
().
get
());
blob_file_set_
->
GetBlobStorage
(
cfh
->
GetID
()).
lock
().
get
());
}
}
...
...
src/blob_gc_picker.cc
View file @
10710bb1
...
@@ -10,8 +10,9 @@ namespace rocksdb {
...
@@ -10,8 +10,9 @@ namespace rocksdb {
namespace
titandb
{
namespace
titandb
{
BasicBlobGCPicker
::
BasicBlobGCPicker
(
TitanDBOptions
db_options
,
BasicBlobGCPicker
::
BasicBlobGCPicker
(
TitanDBOptions
db_options
,
TitanCFOptions
cf_options
)
TitanCFOptions
cf_options
,
:
db_options_
(
db_options
),
cf_options_
(
cf_options
)
{}
TitanStats
*
stats
)
:
db_options_
(
db_options
),
cf_options_
(
cf_options
),
stats_
(
stats
)
{}
BasicBlobGCPicker
::~
BasicBlobGCPicker
()
{}
BasicBlobGCPicker
::~
BasicBlobGCPicker
()
{}
...
@@ -27,13 +28,10 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
...
@@ -27,13 +28,10 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
uint64_t
next_gc_size
=
0
;
uint64_t
next_gc_size
=
0
;
for
(
auto
&
gc_score
:
blob_storage
->
gc_score
())
{
for
(
auto
&
gc_score
:
blob_storage
->
gc_score
())
{
auto
blob_file
=
blob_storage
->
FindFile
(
gc_score
.
file_number
).
lock
();
auto
blob_file
=
blob_storage
->
FindFile
(
gc_score
.
file_number
).
lock
();
if
(
!
blob_file
||
if
(
!
CheckBlobFile
(
blob_file
.
get
()))
{
blob_file
->
file_state
()
==
BlobFileMeta
::
FileState
::
kBeingGC
)
{
RecordTick
(
stats_
,
TitanStats
::
GC_NO_NEED
,
1
);
// Skip this file id this file is being GCed
// Skip this file id this file is being GCed
// or this file had been GCed
// or this file had been GCed
continue
;
}
if
(
!
CheckBlobFile
(
blob_file
.
get
()))
{
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"Blob file %"
PRIu64
" no need gc"
,
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"Blob file %"
PRIu64
" no need gc"
,
blob_file
->
file_number
());
blob_file
->
file_number
());
continue
;
continue
;
...
@@ -57,6 +55,7 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
...
@@ -57,6 +55,7 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
next_gc_size
+=
blob_file
->
file_size
();
next_gc_size
+=
blob_file
->
file_size
();
if
(
next_gc_size
>
cf_options_
.
min_gc_batch_size
)
{
if
(
next_gc_size
>
cf_options_
.
min_gc_batch_size
)
{
maybe_continue_next_time
=
true
;
maybe_continue_next_time
=
true
;
RecordTick
(
stats_
,
TitanStats
::
GC_REMAIN
,
1
);
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"remain more than %"
PRIu64
"remain more than %"
PRIu64
" bytes to be gc and trigger after this gc"
,
" bytes to be gc and trigger after this gc"
,
...
@@ -80,8 +79,11 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
...
@@ -80,8 +79,11 @@ std::unique_ptr<BlobGC> BasicBlobGCPicker::PickBlobGC(
}
}
bool
BasicBlobGCPicker
::
CheckBlobFile
(
BlobFileMeta
*
blob_file
)
const
{
bool
BasicBlobGCPicker
::
CheckBlobFile
(
BlobFileMeta
*
blob_file
)
const
{
assert
(
blob_file
->
file_state
()
!=
BlobFileMeta
::
FileState
::
kInit
);
assert
(
blob_file
!=
nullptr
&&
if
(
blob_file
->
file_state
()
!=
BlobFileMeta
::
FileState
::
kNormal
)
return
false
;
blob_file
->
file_state
()
!=
BlobFileMeta
::
FileState
::
kInit
);
if
(
blob_file
!=
nullptr
&&
blob_file
->
file_state
()
!=
BlobFileMeta
::
FileState
::
kNormal
)
return
false
;
return
true
;
return
true
;
}
}
...
...
src/blob_gc_picker.h
View file @
10710bb1
...
@@ -29,7 +29,7 @@ class BlobGCPicker {
...
@@ -29,7 +29,7 @@ class BlobGCPicker {
class
BasicBlobGCPicker
final
:
public
BlobGCPicker
{
class
BasicBlobGCPicker
final
:
public
BlobGCPicker
{
public
:
public
:
BasicBlobGCPicker
(
TitanDBOptions
,
TitanCFOptions
);
BasicBlobGCPicker
(
TitanDBOptions
,
TitanCFOptions
,
TitanStats
*
);
~
BasicBlobGCPicker
();
~
BasicBlobGCPicker
();
std
::
unique_ptr
<
BlobGC
>
PickBlobGC
(
BlobStorage
*
blob_storage
)
override
;
std
::
unique_ptr
<
BlobGC
>
PickBlobGC
(
BlobStorage
*
blob_storage
)
override
;
...
@@ -37,6 +37,7 @@ class BasicBlobGCPicker final : public BlobGCPicker {
...
@@ -37,6 +37,7 @@ class BasicBlobGCPicker final : public BlobGCPicker {
private
:
private
:
TitanDBOptions
db_options_
;
TitanDBOptions
db_options_
;
TitanCFOptions
cf_options_
;
TitanCFOptions
cf_options_
;
TitanStats
*
stats_
;
// Check if blob_file needs to gc, return true means we need pick this
// Check if blob_file needs to gc, return true means we need pick this
// file for gc
// file for gc
...
...
src/blob_gc_picker_test.cc
View file @
10710bb1
...
@@ -26,7 +26,7 @@ class BlobGCPickerTest : public testing::Test {
...
@@ -26,7 +26,7 @@ class BlobGCPickerTest : public testing::Test {
blob_storage_
.
reset
(
new
BlobStorage
(
titan_db_options
,
titan_cf_options
,
0
,
blob_storage_
.
reset
(
new
BlobStorage
(
titan_db_options
,
titan_cf_options
,
0
,
blob_file_cache
,
nullptr
));
blob_file_cache
,
nullptr
));
basic_blob_gc_picker_
.
reset
(
basic_blob_gc_picker_
.
reset
(
new
BasicBlobGCPicker
(
titan_db_options
,
titan_cf_options
));
new
BasicBlobGCPicker
(
titan_db_options
,
titan_cf_options
,
nullptr
));
}
}
void
AddBlobFile
(
uint64_t
file_number
,
uint64_t
file_size
,
void
AddBlobFile
(
uint64_t
file_number
,
uint64_t
file_size
,
...
...
src/blob_storage.h
View file @
10710bb1
...
@@ -68,6 +68,8 @@ class BlobStorage {
...
@@ -68,6 +68,8 @@ class BlobStorage {
for
(
auto
&
file
:
files_
)
{
for
(
auto
&
file
:
files_
)
{
file
.
second
->
set_gc_mark
(
true
);
file
.
second
->
set_gc_mark
(
true
);
file
.
second
->
FileStateTransit
(
BlobFileMeta
::
FileEvent
::
kDbRestart
);
file
.
second
->
FileStateTransit
(
BlobFileMeta
::
FileEvent
::
kDbRestart
);
auto
level
=
file
.
second
->
GetDiscardableRatioLevel
();
AddStats
(
stats_
,
cf_id_
,
level
,
1
);
}
}
}
}
...
...
src/db_impl.cc
View file @
10710bb1
...
@@ -58,7 +58,7 @@ class TitanDBImpl::FileManager : public BlobFileManager {
...
@@ -58,7 +58,7 @@ class TitanDBImpl::FileManager : public BlobFileManager {
for
(
auto
&
file
:
files
)
{
for
(
auto
&
file
:
files
)
{
RecordTick
(
db_
->
stats_
.
get
(),
BLOB_DB_BLOB_FILE_SYNCED
);
RecordTick
(
db_
->
stats_
.
get
(),
BLOB_DB_BLOB_FILE_SYNCED
);
{
{
StopWatch
sync_sw
(
db_
->
env_
,
statistics
(
db_
->
stats_
.
get
()
),
StopWatch
sync_sw
(
db_
->
env_
,
db_
->
stats_
.
get
(
),
BLOB_DB_BLOB_FILE_SYNC_MICROS
);
BLOB_DB_BLOB_FILE_SYNC_MICROS
);
s
=
file
.
second
->
GetFile
()
->
Sync
(
false
);
s
=
file
.
second
->
GetFile
()
->
Sync
(
false
);
}
}
...
@@ -546,7 +546,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
...
@@ -546,7 +546,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
nullptr
/*read_callback*/
,
&
is_blob_index
);
nullptr
/*read_callback*/
,
&
is_blob_index
);
if
(
!
s
.
ok
()
||
!
is_blob_index
)
return
s
;
if
(
!
s
.
ok
()
||
!
is_blob_index
)
return
s
;
StopWatch
get_sw
(
env_
,
statistics
(
stats_
.
get
()),
BLOB_DB_GET_MICROS
);
StopWatch
get_sw
(
env_
,
stats_
.
get
(),
BLOB_DB_GET_MICROS
);
RecordTick
(
stats_
.
get
(),
BLOB_DB_NUM_GET
);
BlobIndex
index
;
BlobIndex
index
;
s
=
index
.
DecodeFrom
(
value
);
s
=
index
.
DecodeFrom
(
value
);
...
@@ -561,8 +562,7 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
...
@@ -561,8 +562,7 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
mutex_
.
Unlock
();
mutex_
.
Unlock
();
{
{
StopWatch
read_sw
(
env_
,
statistics
(
stats_
.
get
()),
StopWatch
read_sw
(
env_
,
stats_
.
get
(),
BLOB_DB_BLOB_FILE_READ_MICROS
);
BLOB_DB_BLOB_FILE_READ_MICROS
);
s
=
storage
->
Get
(
options
,
index
,
&
record
,
&
buffer
);
s
=
storage
->
Get
(
options
,
index
,
&
record
,
&
buffer
);
RecordTick
(
stats_
.
get
(),
BLOB_DB_NUM_KEYS_READ
);
RecordTick
(
stats_
.
get
(),
BLOB_DB_NUM_KEYS_READ
);
RecordTick
(
stats_
.
get
(),
BLOB_DB_BLOB_FILE_BYTES_READ
,
RecordTick
(
stats_
.
get
(),
BLOB_DB_BLOB_FILE_BYTES_READ
,
...
@@ -805,7 +805,13 @@ Status TitanDBImpl::DeleteFilesInRanges(ColumnFamilyHandle* column_family,
...
@@ -805,7 +805,13 @@ Status TitanDBImpl::DeleteFilesInRanges(ColumnFamilyHandle* column_family,
if
(
!
file
->
is_obsolete
())
{
if
(
!
file
->
is_obsolete
())
{
delta
+=
bfs
.
second
;
delta
+=
bfs
.
second
;
}
}
auto
before
=
file
->
GetDiscardableRatioLevel
();
file
->
AddDiscardableSize
(
static_cast
<
uint64_t
>
(
bfs
.
second
));
file
->
AddDiscardableSize
(
static_cast
<
uint64_t
>
(
bfs
.
second
));
auto
after
=
file
->
GetDiscardableRatioLevel
();
if
(
before
!=
after
)
{
AddStats
(
stats_
.
get
(),
cf_id
,
after
,
1
);
SubStats
(
stats_
.
get
(),
cf_id
,
before
,
1
);
}
}
}
SubStats
(
stats_
.
get
(),
cf_id
,
TitanInternalStats
::
LIVE_BLOB_SIZE
,
delta
);
SubStats
(
stats_
.
get
(),
cf_id
,
TitanInternalStats
::
LIVE_BLOB_SIZE
,
delta
);
bs
->
ComputeGCScore
();
bs
->
ComputeGCScore
();
...
@@ -1093,7 +1099,13 @@ void TitanDBImpl::OnCompactionCompleted(
...
@@ -1093,7 +1099,13 @@ void TitanDBImpl::OnCompactionCompleted(
if
(
!
file
->
is_obsolete
())
{
if
(
!
file
->
is_obsolete
())
{
delta
+=
-
bfs
.
second
;
delta
+=
-
bfs
.
second
;
}
}
auto
before
=
file
->
GetDiscardableRatioLevel
();
file
->
AddDiscardableSize
(
static_cast
<
uint64_t
>
(
-
bfs
.
second
));
file
->
AddDiscardableSize
(
static_cast
<
uint64_t
>
(
-
bfs
.
second
));
auto
after
=
file
->
GetDiscardableRatioLevel
();
if
(
before
!=
after
)
{
AddStats
(
stats_
.
get
(),
compaction_job_info
.
cf_id
,
after
,
1
);
SubStats
(
stats_
.
get
(),
compaction_job_info
.
cf_id
,
before
,
1
);
}
}
}
SubStats
(
stats_
.
get
(),
compaction_job_info
.
cf_id
,
SubStats
(
stats_
.
get
(),
compaction_job_info
.
cf_id
,
TitanInternalStats
::
LIVE_BLOB_SIZE
,
delta
);
TitanInternalStats
::
LIVE_BLOB_SIZE
,
delta
);
...
...
src/db_impl_gc.cc
View file @
10710bb1
...
@@ -69,7 +69,7 @@ void TitanDBImpl::BackgroundCallGC() {
...
@@ -69,7 +69,7 @@ void TitanDBImpl::BackgroundCallGC() {
Status
TitanDBImpl
::
BackgroundGC
(
LogBuffer
*
log_buffer
)
{
Status
TitanDBImpl
::
BackgroundGC
(
LogBuffer
*
log_buffer
)
{
mutex_
.
AssertHeld
();
mutex_
.
AssertHeld
();
StopWatch
gc_sw
(
env_
,
stat
istics
(
stats_
.
get
()
),
BLOB_DB_GC_MICROS
);
StopWatch
gc_sw
(
env_
,
stat
s_
.
get
(
),
BLOB_DB_GC_MICROS
);
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
std
::
unique_ptr
<
ColumnFamilyHandle
>
cfh
;
std
::
unique_ptr
<
ColumnFamilyHandle
>
cfh
;
...
@@ -88,7 +88,8 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
...
@@ -88,7 +88,8 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
if
(
blob_storage
!=
nullptr
)
{
if
(
blob_storage
!=
nullptr
)
{
const
auto
&
cf_options
=
blob_storage
->
cf_options
();
const
auto
&
cf_options
=
blob_storage
->
cf_options
();
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options_
,
cf_options
);
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options_
,
cf_options
,
stats_
.
get
());
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
blob_storage
.
get
());
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
blob_storage
.
get
());
if
(
blob_gc
)
{
if
(
blob_gc
)
{
...
@@ -123,6 +124,7 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
...
@@ -123,6 +124,7 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
if
(
blob_gc
->
trigger_next
()
&&
if
(
blob_gc
->
trigger_next
()
&&
(
bg_gc_scheduled_
-
1
+
gc_queue_
.
size
()
<
(
bg_gc_scheduled_
-
1
+
gc_queue_
.
size
()
<
2
*
static_cast
<
uint32_t
>
(
db_options_
.
max_background_gc
)))
{
2
*
static_cast
<
uint32_t
>
(
db_options_
.
max_background_gc
)))
{
RecordTick
(
stats_
.
get
(),
TitanStats
::
GC_TRIGGER_NEXT
,
1
);
// There is still data remained to be GCed
// There is still data remained to be GCed
// and the queue is not overwhelmed
// and the queue is not overwhelmed
// then put this cf to GC queue for next GC
// then put this cf to GC queue for next GC
...
@@ -131,9 +133,11 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
...
@@ -131,9 +133,11 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
}
}
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
RecordTick
(
stats_
.
get
(),
TitanStats
::
GC_SUCCESS
,
1
);
// Done
// Done
}
else
{
}
else
{
SetBGError
(
s
);
SetBGError
(
s
);
RecordTick
(
stats_
.
get
(),
TitanStats
::
GC_FAIL
,
1
);
ROCKS_LOG_WARN
(
db_options_
.
info_log
,
"Titan GC error: %s"
,
ROCKS_LOG_WARN
(
db_options_
.
info_log
,
"Titan GC error: %s"
,
s
.
ToString
().
c_str
());
s
.
ToString
().
c_str
());
}
}
...
@@ -157,7 +161,7 @@ Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) {
...
@@ -157,7 +161,7 @@ Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) {
bg_gc_scheduled_
++
;
bg_gc_scheduled_
++
;
// BackgroudGC
// BackgroudGC
StopWatch
gc_sw
(
env_
,
stat
istics
(
stats_
.
get
()
),
BLOB_DB_GC_MICROS
);
StopWatch
gc_sw
(
env_
,
stat
s_
.
get
(
),
BLOB_DB_GC_MICROS
);
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
std
::
unique_ptr
<
BlobGC
>
blob_gc
;
std
::
unique_ptr
<
ColumnFamilyHandle
>
cfh
;
std
::
unique_ptr
<
ColumnFamilyHandle
>
cfh
;
...
@@ -169,7 +173,7 @@ Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) {
...
@@ -169,7 +173,7 @@ Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) {
auto
bs
=
blob_file_set_
->
GetBlobStorage
(
column_family_id
).
lock
().
get
();
auto
bs
=
blob_file_set_
->
GetBlobStorage
(
column_family_id
).
lock
().
get
();
const
auto
&
cf_options
=
bs
->
cf_options
();
const
auto
&
cf_options
=
bs
->
cf_options
();
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
shared_ptr
<
BlobGCPicker
>
blob_gc_picker
=
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options_
,
cf_options
);
std
::
make_shared
<
BasicBlobGCPicker
>
(
db_options_
,
cf_options
,
nullptr
);
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
bs
);
blob_gc
=
blob_gc_picker
->
PickBlobGC
(
bs
);
if
(
blob_gc
)
{
if
(
blob_gc
)
{
...
...
src/db_iter.h
View file @
10710bb1
...
@@ -46,7 +46,7 @@ class TitanDBIterator : public Iterator {
...
@@ -46,7 +46,7 @@ class TitanDBIterator : public Iterator {
void
SeekToFirst
()
override
{
void
SeekToFirst
()
override
{
iter_
->
SeekToFirst
();
iter_
->
SeekToFirst
();
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
seek_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_SEEK_MICROS
);
StopWatch
seek_sw
(
env_
,
stat
s_
,
BLOB_DB_SEEK_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
}
}
...
@@ -55,7 +55,7 @@ class TitanDBIterator : public Iterator {
...
@@ -55,7 +55,7 @@ class TitanDBIterator : public Iterator {
void
SeekToLast
()
override
{
void
SeekToLast
()
override
{
iter_
->
SeekToLast
();
iter_
->
SeekToLast
();
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
seek_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_SEEK_MICROS
);
StopWatch
seek_sw
(
env_
,
stat
s_
,
BLOB_DB_SEEK_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
}
}
...
@@ -64,7 +64,7 @@ class TitanDBIterator : public Iterator {
...
@@ -64,7 +64,7 @@ class TitanDBIterator : public Iterator {
void
Seek
(
const
Slice
&
target
)
override
{
void
Seek
(
const
Slice
&
target
)
override
{
iter_
->
Seek
(
target
);
iter_
->
Seek
(
target
);
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
seek_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_SEEK_MICROS
);
StopWatch
seek_sw
(
env_
,
stat
s_
,
BLOB_DB_SEEK_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
}
}
...
@@ -73,7 +73,7 @@ class TitanDBIterator : public Iterator {
...
@@ -73,7 +73,7 @@ class TitanDBIterator : public Iterator {
void
SeekForPrev
(
const
Slice
&
target
)
override
{
void
SeekForPrev
(
const
Slice
&
target
)
override
{
iter_
->
SeekForPrev
(
target
);
iter_
->
SeekForPrev
(
target
);
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
seek_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_SEEK_MICROS
);
StopWatch
seek_sw
(
env_
,
stat
s_
,
BLOB_DB_SEEK_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
RecordTick
(
stats_
,
BLOB_DB_NUM_SEEK
);
}
}
...
@@ -83,7 +83,7 @@ class TitanDBIterator : public Iterator {
...
@@ -83,7 +83,7 @@ class TitanDBIterator : public Iterator {
assert
(
Valid
());
assert
(
Valid
());
iter_
->
Next
();
iter_
->
Next
();
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
next_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_NEXT_MICROS
);
StopWatch
next_sw
(
env_
,
stat
s_
,
BLOB_DB_NEXT_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_NEXT
);
RecordTick
(
stats_
,
BLOB_DB_NUM_NEXT
);
}
}
...
@@ -93,7 +93,7 @@ class TitanDBIterator : public Iterator {
...
@@ -93,7 +93,7 @@ class TitanDBIterator : public Iterator {
assert
(
Valid
());
assert
(
Valid
());
iter_
->
Prev
();
iter_
->
Prev
();
if
(
ShouldGetBlobValue
())
{
if
(
ShouldGetBlobValue
())
{
StopWatch
prev_sw
(
env_
,
stat
istics
(
stats_
)
,
BLOB_DB_PREV_MICROS
);
StopWatch
prev_sw
(
env_
,
stat
s_
,
BLOB_DB_PREV_MICROS
);
GetBlobValue
();
GetBlobValue
();
RecordTick
(
stats_
,
BLOB_DB_NUM_PREV
);
RecordTick
(
stats_
,
BLOB_DB_NUM_PREV
);
}
}
...
...
src/table_builder.cc
View file @
10710bb1
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#endif
#endif
#include <inttypes.h>
#include <inttypes.h>
#include "monitoring/statistics.h"
namespace
rocksdb
{
namespace
rocksdb
{
namespace
titandb
{
namespace
titandb
{
...
@@ -106,8 +107,7 @@ void TitanTableBuilder::Add(const Slice& key, const Slice& value) {
...
@@ -106,8 +107,7 @@ void TitanTableBuilder::Add(const Slice& key, const Slice& value) {
void
TitanTableBuilder
::
AddBlob
(
const
Slice
&
key
,
const
Slice
&
value
,
void
TitanTableBuilder
::
AddBlob
(
const
Slice
&
key
,
const
Slice
&
value
,
std
::
string
*
index_value
)
{
std
::
string
*
index_value
)
{
if
(
!
ok
())
return
;
if
(
!
ok
())
return
;
StopWatch
write_sw
(
db_options_
.
env
,
statistics
(
stats_
),
StopWatch
write_sw
(
db_options_
.
env
,
stats_
,
BLOB_DB_BLOB_FILE_WRITE_MICROS
);
BLOB_DB_BLOB_FILE_WRITE_MICROS
);
if
(
!
blob_builder_
)
{
if
(
!
blob_builder_
)
{
status_
=
blob_manager_
->
NewFile
(
&
blob_handle_
);
status_
=
blob_manager_
->
NewFile
(
&
blob_handle_
);
...
@@ -120,8 +120,8 @@ void TitanTableBuilder::AddBlob(const Slice& key, const Slice& value,
...
@@ -120,8 +120,8 @@ void TitanTableBuilder::AddBlob(const Slice& key, const Slice& value,
}
}
RecordTick
(
stats_
,
BLOB_DB_NUM_KEYS_WRITTEN
);
RecordTick
(
stats_
,
BLOB_DB_NUM_KEYS_WRITTEN
);
MeasureTime
(
stats_
,
BLOB_DB_KEY_SIZE
,
key
.
size
());
RecordInHistogram
(
stats_
,
BLOB_DB_KEY_SIZE
,
key
.
size
());
MeasureTime
(
stats_
,
BLOB_DB_VALUE_SIZE
,
value
.
size
());
RecordInHistogram
(
stats_
,
BLOB_DB_VALUE_SIZE
,
value
.
size
());
AddStats
(
stats_
,
cf_id_
,
TitanInternalStats
::
LIVE_BLOB_SIZE
,
value
.
size
());
AddStats
(
stats_
,
cf_id_
,
TitanInternalStats
::
LIVE_BLOB_SIZE
,
value
.
size
());
bytes_written_
+=
key
.
size
()
+
value
.
size
();
bytes_written_
+=
key
.
size
()
+
value
.
size
();
...
...
src/titan_stats.cc
View file @
10710bb1
...
@@ -14,6 +14,16 @@ static const std::string num_live_blob_file = "num-live-blob-file";
...
@@ -14,6 +14,16 @@ static const std::string num_live_blob_file = "num-live-blob-file";
static
const
std
::
string
num_obsolete_blob_file
=
"num-obsolete-blob-file"
;
static
const
std
::
string
num_obsolete_blob_file
=
"num-obsolete-blob-file"
;
static
const
std
::
string
live_blob_file_size
=
"live-blob-file-size"
;
static
const
std
::
string
live_blob_file_size
=
"live-blob-file-size"
;
static
const
std
::
string
obsolete_blob_file_size
=
"obsolete-blob-file-size"
;
static
const
std
::
string
obsolete_blob_file_size
=
"obsolete-blob-file-size"
;
static
const
std
::
string
num_discardable_ratio_le0_file
=
"num-discardable-ratio-le0-file"
;
static
const
std
::
string
num_discardable_ratio_le20_file
=
"num-discardable-ratio-le20-file"
;
static
const
std
::
string
num_discardable_ratio_le50_file
=
"num-discardable-ratio-le50-file"
;
static
const
std
::
string
num_discardable_ratio_le80_file
=
"num-discardable-ratio-le80-file"
;
static
const
std
::
string
num_discardable_ratio_le100_file
=
"num-discardable-ratio-le100-file"
;
const
std
::
string
TitanDB
::
Properties
::
kLiveBlobSize
=
const
std
::
string
TitanDB
::
Properties
::
kLiveBlobSize
=
titandb_prefix
+
live_blob_size
;
titandb_prefix
+
live_blob_size
;
...
@@ -25,9 +35,19 @@ const std::string TitanDB::Properties::kLiveBlobFileSize =
...
@@ -25,9 +35,19 @@ const std::string TitanDB::Properties::kLiveBlobFileSize =
titandb_prefix
+
live_blob_file_size
;
titandb_prefix
+
live_blob_file_size
;
const
std
::
string
TitanDB
::
Properties
::
kObsoleteBlobFileSize
=
const
std
::
string
TitanDB
::
Properties
::
kObsoleteBlobFileSize
=
titandb_prefix
+
obsolete_blob_file_size
;
titandb_prefix
+
obsolete_blob_file_size
;
const
std
::
string
TitanDB
::
Properties
::
kNumDiscardableRatioLE0File
=
titandb_prefix
+
num_discardable_ratio_le0_file
;
const
std
::
string
TitanDB
::
Properties
::
kNumDiscardableRatioLE20File
=
titandb_prefix
+
num_discardable_ratio_le20_file
;
const
std
::
string
TitanDB
::
Properties
::
kNumDiscardableRatioLE50File
=
titandb_prefix
+
num_discardable_ratio_le50_file
;
const
std
::
string
TitanDB
::
Properties
::
kNumDiscardableRatioLE80File
=
titandb_prefix
+
num_discardable_ratio_le80_file
;
const
std
::
string
TitanDB
::
Properties
::
kNumDiscardableRatioLE100File
=
titandb_prefix
+
num_discardable_ratio_le100_file
;
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
Ticker
Type
>
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
Stats
Type
>
TitanInternalStats
::
ticker
_type_string_map
=
{
TitanInternalStats
::
stats
_type_string_map
=
{
{
TitanDB
::
Properties
::
kLiveBlobSize
,
{
TitanDB
::
Properties
::
kLiveBlobSize
,
TitanInternalStats
::
LIVE_BLOB_SIZE
},
TitanInternalStats
::
LIVE_BLOB_SIZE
},
{
TitanDB
::
Properties
::
kNumLiveBlobFile
,
{
TitanDB
::
Properties
::
kNumLiveBlobFile
,
...
@@ -38,11 +58,18 @@ const std::unordered_map<std::string, TitanInternalStats::TickerType>
...
@@ -38,11 +58,18 @@ const std::unordered_map<std::string, TitanInternalStats::TickerType>
TitanInternalStats
::
LIVE_BLOB_FILE_SIZE
},
TitanInternalStats
::
LIVE_BLOB_FILE_SIZE
},
{
TitanDB
::
Properties
::
kObsoleteBlobFileSize
,
{
TitanDB
::
Properties
::
kObsoleteBlobFileSize
,
TitanInternalStats
::
OBSOLETE_BLOB_FILE_SIZE
},
TitanInternalStats
::
OBSOLETE_BLOB_FILE_SIZE
},
{
TitanDB
::
Properties
::
kNumDiscardableRatioLE0File
,
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE0
},
{
TitanDB
::
Properties
::
kNumDiscardableRatioLE20File
,
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE20
},
{
TitanDB
::
Properties
::
kNumDiscardableRatioLE50File
,
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE50
},
{
TitanDB
::
Properties
::
kNumDiscardableRatioLE80File
,
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE80
},
{
TitanDB
::
Properties
::
kNumDiscardableRatioLE100File
,
TitanInternalStats
::
NUM_DISCARDABLE_RATIO_LE100
},
};
};
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
HistogramType
>
TitanInternalStats
::
histogram_type_string_map
=
{};
const
std
::
array
<
std
::
string
,
const
std
::
array
<
std
::
string
,
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
TitanInternalStats
::
internal_op_names
=
{
TitanInternalStats
::
internal_op_names
=
{
...
...
src/titan_stats.h
View file @
10710bb1
...
@@ -48,29 +48,28 @@ using InternalOpStats =
...
@@ -48,29 +48,28 @@ using InternalOpStats =
// data.
// data.
class
TitanInternalStats
{
class
TitanInternalStats
{
public
:
public
:
enum
Ticker
Type
{
enum
Stats
Type
{
LIVE_BLOB_SIZE
=
0
,
LIVE_BLOB_SIZE
=
0
,
NUM_LIVE_BLOB_FILE
,
NUM_LIVE_BLOB_FILE
,
NUM_OBSOLETE_BLOB_FILE
,
NUM_OBSOLETE_BLOB_FILE
,
LIVE_BLOB_FILE_SIZE
,
LIVE_BLOB_FILE_SIZE
,
OBSOLETE_BLOB_FILE_SIZE
,
OBSOLETE_BLOB_FILE_SIZE
,
INTERNAL_TICKER_ENUM_MAX
,
};
enum
HistogramType
{
NUM_DISCARDABLE_RATIO_LE0
,
INTERNAL_HISTOGRAM_ENUM_MAX
,
NUM_DISCARDABLE_RATIO_LE20
,
NUM_DISCARDABLE_RATIO_LE50
,
NUM_DISCARDABLE_RATIO_LE80
,
NUM_DISCARDABLE_RATIO_LE100
,
INTERNAL_STATS_ENUM_MAX
,
};
};
TitanInternalStats
()
{
Clear
();
}
TitanInternalStats
()
{
Clear
();
}
void
Clear
()
{
void
Clear
()
{
for
(
int
type
=
0
;
type
<
INTERNAL_TICKER_ENUM_MAX
;
type
++
)
{
for
(
int
stat
=
0
;
stat
<
INTERNAL_STATS_ENUM_MAX
;
stat
++
)
{
tickers_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
stats_
[
stat
].
store
(
0
,
std
::
memory_order_relaxed
);
}
}
for
(
int
type
=
0
;
type
<
INTERNAL_HISTOGRAM_ENUM_MAX
;
type
++
)
{
histograms_
[
type
].
Clear
();
}
for
(
int
op
=
0
;
for
(
int
op
=
0
;
op
<
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
);
op
++
)
{
op
<
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
);
op
++
)
{
assert
(
assert
(
...
@@ -85,28 +84,24 @@ class TitanInternalStats {
...
@@ -85,28 +84,24 @@ class TitanInternalStats {
}
}
}
}
void
ResetStats
(
Ticker
Type
type
)
{
void
ResetStats
(
Stats
Type
type
)
{
ticker
s_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
stat
s_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
}
}
void
AddStats
(
Ticker
Type
type
,
uint64_t
value
)
{
void
AddStats
(
Stats
Type
type
,
uint64_t
value
)
{
auto
&
v
=
ticker
s_
[
type
];
auto
&
v
=
stat
s_
[
type
];
v
.
fetch_add
(
value
,
std
::
memory_order_relaxed
);
v
.
fetch_add
(
value
,
std
::
memory_order_relaxed
);
}
}
void
SubStats
(
Ticker
Type
type
,
uint64_t
value
)
{
void
SubStats
(
Stats
Type
type
,
uint64_t
value
)
{
auto
&
v
=
ticker
s_
[
type
];
auto
&
v
=
stat
s_
[
type
];
v
.
fetch_sub
(
value
,
std
::
memory_order_relaxed
);
v
.
fetch_sub
(
value
,
std
::
memory_order_relaxed
);
}
}
void
MeasureTime
(
HistogramType
type
,
uint64_t
value
)
{
histograms_
[
type
].
Add
(
value
);
}
bool
GetIntProperty
(
const
Slice
&
property
,
uint64_t
*
value
)
const
{
bool
GetIntProperty
(
const
Slice
&
property
,
uint64_t
*
value
)
const
{
auto
p
=
ticker
_type_string_map
.
find
(
property
.
ToString
());
auto
p
=
stats
_type_string_map
.
find
(
property
.
ToString
());
if
(
p
!=
ticker
_type_string_map
.
end
())
{
if
(
p
!=
stats
_type_string_map
.
end
())
{
*
value
=
ticker
s_
[
p
->
second
].
load
(
std
::
memory_order_relaxed
);
*
value
=
stat
s_
[
p
->
second
].
load
(
std
::
memory_order_relaxed
);
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -128,25 +123,45 @@ class TitanInternalStats {
...
@@ -128,25 +123,45 @@ class TitanInternalStats {
void
DumpAndResetInternalOpStats
(
LogBuffer
*
log_buffer
);
void
DumpAndResetInternalOpStats
(
LogBuffer
*
log_buffer
);
private
:
private
:
static
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
StatsType
>
stats_type_string_map
;
static
const
std
::
array
<
static
const
std
::
array
<
std
::
string
,
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
std
::
string
,
static_cast
<
int
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
internal_op_names
;
internal_op_names
;
std
::
array
<
std
::
atomic
<
uint64_t
>
,
INTERNAL_STATS_ENUM_MAX
>
stats_
;
std
::
array
<
InternalOpStats
,
std
::
array
<
InternalOpStats
,
static_cast
<
size_t
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
static_cast
<
size_t
>
(
InternalOpType
::
INTERNAL_OP_ENUM_MAX
)
>
internal_op_stats_
;
internal_op_stats_
;
static
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
TickerType
>
ticker_type_string_map
;
std
::
array
<
std
::
atomic
<
uint64_t
>
,
INTERNAL_TICKER_ENUM_MAX
>
tickers_
;
static
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
HistogramType
>
histogram_type_string_map
;
std
::
array
<
HistogramImpl
,
INTERNAL_HISTOGRAM_ENUM_MAX
>
histograms_
;
};
};
class
TitanStats
{
class
TitanStats
:
public
Statistics
{
public
:
public
:
enum
TickerType
:
uint32_t
{
BLOB_CACHE_HIT
=
TICKER_ENUM_MAX
+
1
,
BLOB_CACHE_MISS
,
GC_NO_NEED
,
GC_REMAIN
,
GC_DISCARDABLE
,
GC_SAMPLE
,
GC_SMALL_FILE
,
GC_FAIL
,
GC_SUCCESS
,
GC_TRIGGER_NEXT
,
INTERNAL_TICKER_ENUM_MAX
,
};
enum
HistogramType
:
uint32_t
{
TITAN_MANIFEST_FILE_SYNC_MICROS
=
HISTOGRAM_ENUM_MAX
+
1
,
GC_INPUT_FILE_SIZE
,
GC_OUTPUT_FILE_SIZE
,
INTERNAL_HISTOGRAM_ENUM_MAX
,
};
TitanStats
(
Statistics
*
stats
)
:
stats_
(
stats
)
{}
TitanStats
(
Statistics
*
stats
)
:
stats_
(
stats
)
{}
// TODO: Initialize corresponding internal stats struct for Column families
// TODO: Initialize corresponding internal stats struct for Column families
...
@@ -158,8 +173,6 @@ class TitanStats {
...
@@ -158,8 +173,6 @@ class TitanStats {
return
Status
::
OK
();
return
Status
::
OK
();
}
}
Statistics
*
statistics
()
{
return
stats_
;
}
TitanInternalStats
*
internal_stats
(
uint32_t
cf_id
)
{
TitanInternalStats
*
internal_stats
(
uint32_t
cf_id
)
{
auto
p
=
internal_stats_
.
find
(
cf_id
);
auto
p
=
internal_stats_
.
find
(
cf_id
);
if
(
p
==
internal_stats_
.
end
())
{
if
(
p
==
internal_stats_
.
end
())
{
...
@@ -171,46 +184,111 @@ class TitanStats {
...
@@ -171,46 +184,111 @@ class TitanStats {
void
DumpInternalOpStats
(
uint32_t
cf_id
,
const
std
::
string
&
cf_name
);
void
DumpInternalOpStats
(
uint32_t
cf_id
,
const
std
::
string
&
cf_name
);
uint64_t
getTickerCount
(
uint32_t
tickerType
)
const
{
if
(
stats_
==
nullptr
)
return
0
;
if
(
tickerType
>
TICKER_ENUM_MAX
)
{
return
tickers_
[
tickerType
-
(
TICKER_ENUM_MAX
+
1
)].
load
(
std
::
memory_order_relaxed
);
}
return
stats_
->
getTickerCount
(
tickerType
);
}
void
histogramData
(
uint32_t
type
,
HistogramData
*
const
data
)
const
{
if
(
stats_
==
nullptr
)
return
;
if
(
type
>
HISTOGRAM_ENUM_MAX
)
{
return
histograms_
[
type
-
(
HISTOGRAM_ENUM_MAX
+
1
)].
Data
(
data
);
}
return
stats_
->
histogramData
(
type
,
data
);
}
std
::
string
getHistogramString
(
uint32_t
type
)
const
{
return
stats_
->
getHistogramString
(
type
);
}
void
recordTick
(
uint32_t
tickerType
,
uint64_t
count
=
0
)
{
if
(
stats_
==
nullptr
)
return
;
if
(
tickerType
>
TICKER_ENUM_MAX
)
{
tickers_
[
tickerType
-
(
TICKER_ENUM_MAX
+
1
)].
fetch_add
(
count
,
std
::
memory_order_relaxed
);
}
else
{
stats_
->
recordTick
(
tickerType
,
count
);
}
}
void
setTickerCount
(
uint32_t
tickerType
,
uint64_t
count
)
{
if
(
stats_
==
nullptr
)
return
;
if
(
tickerType
>
TICKER_ENUM_MAX
)
{
tickers_
[
tickerType
-
(
TICKER_ENUM_MAX
+
1
)].
store
(
count
,
std
::
memory_order_relaxed
);
}
else
{
stats_
->
setTickerCount
(
tickerType
,
count
);
}
}
uint64_t
getAndResetTickerCount
(
uint32_t
tickerType
)
{
if
(
stats_
==
nullptr
)
return
0
;
if
(
tickerType
>
TICKER_ENUM_MAX
)
{
return
tickers_
[
tickerType
-
(
TICKER_ENUM_MAX
+
1
)].
exchange
(
0
,
std
::
memory_order_relaxed
);
}
return
stats_
->
getAndResetTickerCount
(
tickerType
);
}
void
measureTime
(
uint32_t
histogramType
,
uint64_t
time
)
{
if
(
stats_
==
nullptr
)
return
;
if
(
histogramType
>
HISTOGRAM_ENUM_MAX
)
{
histograms_
[
histogramType
-
(
HISTOGRAM_ENUM_MAX
+
1
)].
Add
(
time
);
}
else
{
stats_
->
measureTime
(
histogramType
,
time
);
}
}
// Resets all ticker and histogram stats
virtual
Status
Reset
()
{
for
(
auto
&
p
:
internal_stats_
)
{
p
.
second
->
Clear
();
}
for
(
uint32_t
type
=
TICKER_ENUM_MAX
;
type
<
INTERNAL_TICKER_ENUM_MAX
;
type
++
)
{
tickers_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
}
for
(
uint32_t
type
=
HISTOGRAM_ENUM_MAX
;
type
<
INTERNAL_HISTOGRAM_ENUM_MAX
;
type
++
)
{
histograms_
[
type
].
Clear
();
}
return
stats_
->
Reset
();
}
// String representation of the statistic object.
virtual
std
::
string
ToString
()
const
{
return
stats_
->
ToString
();
}
// Override this function to disable particular histogram collection
virtual
bool
HistEnabledForType
(
uint32_t
type
)
const
{
return
type
<
INTERNAL_HISTOGRAM_ENUM_MAX
;
}
private
:
private
:
// RocksDB statistics
// RocksDB statistics
Statistics
*
stats_
=
nullptr
;
Statistics
*
stats_
=
nullptr
;
std
::
unordered_map
<
uint32_t
,
std
::
shared_ptr
<
TitanInternalStats
>>
std
::
unordered_map
<
uint32_t
,
std
::
shared_ptr
<
TitanInternalStats
>>
internal_stats_
;
internal_stats_
;
std
::
array
<
std
::
atomic
<
uint64_t
>
,
TickerType
::
INTERNAL_TICKER_ENUM_MAX
-
TICKER_ENUM_MAX
>
tickers_
;
std
::
array
<
HistogramImpl
,
INTERNAL_HISTOGRAM_ENUM_MAX
-
HISTOGRAM_ENUM_MAX
>
histograms_
;
std
::
shared_ptr
<
TitanInternalStats
>
NewTitanInternalStats
(
std
::
shared_ptr
<
TitanInternalStats
>
NewTitanInternalStats
(
TitanCFOptions
&
opts
)
{
TitanCFOptions
&
opts
)
{
return
std
::
make_shared
<
TitanInternalStats
>
();
return
std
::
make_shared
<
TitanInternalStats
>
();
}
}
};
};
// Utility functions for RocksDB stats types
inline
Statistics
*
statistics
(
TitanStats
*
stats
)
{
return
(
stats
)
?
stats
->
statistics
()
:
nullptr
;
}
inline
void
RecordTick
(
TitanStats
*
stats
,
uint32_t
ticker_type
,
uint64_t
count
=
1
)
{
if
(
stats
&&
stats
->
statistics
())
{
stats
->
statistics
()
->
recordTick
(
ticker_type
,
count
);
}
}
inline
void
MeasureTime
(
TitanStats
*
stats
,
uint32_t
histogram_type
,
uint64_t
time
)
{
if
(
stats
&&
stats
->
statistics
())
{
stats
->
statistics
()
->
measureTime
(
histogram_type
,
time
);
}
}
inline
void
SetTickerCount
(
TitanStats
*
stats
,
uint32_t
ticker_type
,
uint64_t
count
)
{
if
(
stats
&&
stats
->
statistics
())
{
stats
->
statistics
()
->
setTickerCount
(
ticker_type
,
count
);
}
}
// Utility functions for Titan ticker and histogram stats types
// Utility functions for Titan ticker and histogram stats types
inline
void
ResetStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
inline
void
ResetStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
TitanInternalStats
::
Ticker
Type
type
)
{
TitanInternalStats
::
Stats
Type
type
)
{
if
(
stats
)
{
if
(
stats
)
{
auto
p
=
stats
->
internal_stats
(
cf_id
);
auto
p
=
stats
->
internal_stats
(
cf_id
);
if
(
p
)
{
if
(
p
)
{
...
@@ -220,7 +298,7 @@ inline void ResetStats(TitanStats* stats, uint32_t cf_id,
...
@@ -220,7 +298,7 @@ inline void ResetStats(TitanStats* stats, uint32_t cf_id,
}
}
inline
void
AddStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
inline
void
AddStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
TitanInternalStats
::
Ticker
Type
type
,
uint64_t
value
)
{
TitanInternalStats
::
Stats
Type
type
,
uint64_t
value
)
{
if
(
stats
)
{
if
(
stats
)
{
auto
p
=
stats
->
internal_stats
(
cf_id
);
auto
p
=
stats
->
internal_stats
(
cf_id
);
if
(
p
)
{
if
(
p
)
{
...
@@ -230,7 +308,7 @@ inline void AddStats(TitanStats* stats, uint32_t cf_id,
...
@@ -230,7 +308,7 @@ inline void AddStats(TitanStats* stats, uint32_t cf_id,
}
}
inline
void
SubStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
inline
void
SubStats
(
TitanStats
*
stats
,
uint32_t
cf_id
,
TitanInternalStats
::
Ticker
Type
type
,
uint64_t
value
)
{
TitanInternalStats
::
Stats
Type
type
,
uint64_t
value
)
{
if
(
stats
)
{
if
(
stats
)
{
auto
p
=
stats
->
internal_stats
(
cf_id
);
auto
p
=
stats
->
internal_stats
(
cf_id
);
if
(
p
)
{
if
(
p
)
{
...
@@ -239,17 +317,6 @@ inline void SubStats(TitanStats* stats, uint32_t cf_id,
...
@@ -239,17 +317,6 @@ inline void SubStats(TitanStats* stats, uint32_t cf_id,
}
}
}
}
inline
void
MeasureTime
(
TitanStats
*
stats
,
uint32_t
cf_id
,
TitanInternalStats
::
HistogramType
histogram_type
,
uint64_t
time
)
{
if
(
stats
)
{
auto
p
=
stats
->
internal_stats
(
cf_id
);
if
(
p
)
{
p
->
MeasureTime
(
histogram_type
,
time
);
}
}
}
// Utility functions for Titan internal operation stats type
// Utility functions for Titan internal operation stats type
inline
uint64_t
GetAndResetStats
(
InternalOpStats
*
stats
,
inline
uint64_t
GetAndResetStats
(
InternalOpStats
*
stats
,
InternalOpStatsType
type
)
{
InternalOpStatsType
type
)
{
...
...
src/util.cc
View file @
10710bb1
#include "util.h"
#include "util.h"
#include "util/stop_watch.h"
namespace
rocksdb
{
namespace
rocksdb
{
namespace
titandb
{
namespace
titandb
{
...
@@ -157,5 +159,12 @@ void UnrefCacheHandle(void* arg1, void* arg2) {
...
@@ -157,5 +159,12 @@ void UnrefCacheHandle(void* arg1, void* arg2) {
cache
->
Release
(
h
);
cache
->
Release
(
h
);
}
}
Status
SyncTitanManifest
(
Env
*
env
,
TitanStats
*
stats
,
const
ImmutableDBOptions
*
db_options
,
WritableFileWriter
*
file
)
{
StopWatch
sw
(
env
,
stats
,
TitanStats
::
TITAN_MANIFEST_FILE_SYNC_MICROS
);
return
file
->
Sync
(
db_options
->
use_fsync
);
}
}
// namespace titandb
}
// namespace titandb
}
// namespace rocksdb
}
// namespace rocksdb
src/util.h
View file @
10710bb1
#pragma once
#pragma once
#include "options/db_options.h"
#include "rocksdb/cache.h"
#include "rocksdb/cache.h"
#include "util/compression.h"
#include "util/compression.h"
#include "util/file_reader_writer.h"
#include "titan_stats.h"
namespace
rocksdb
{
namespace
rocksdb
{
namespace
titandb
{
namespace
titandb
{
...
@@ -71,5 +75,9 @@ void DeleteCacheValue(const Slice&, void* value) {
...
@@ -71,5 +75,9 @@ void DeleteCacheValue(const Slice&, void* value) {
delete
reinterpret_cast
<
T
*>
(
value
);
delete
reinterpret_cast
<
T
*>
(
value
);
}
}
Status
SyncTitanManifest
(
Env
*
env
,
TitanStats
*
stats
,
const
ImmutableDBOptions
*
db_options
,
WritableFileWriter
*
file
);
}
// namespace titandb
}
// namespace titandb
}
// namespace rocksdb
}
// namespace rocksdb
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