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
f963b880
Unverified
Commit
f963b880
authored
Sep 16, 2019
by
Connor
Committed by
GitHub
Sep 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support histogram for titan stats (#74)
Signed-off-by:
Connor1996
<
zbk602423539@gmail.com
>
parent
73ed3a9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
30 deletions
+63
-30
db_impl.cc
src/db_impl.cc
+4
-4
titan_stats.cc
src/titan_stats.cc
+5
-2
titan_stats.h
src/titan_stats.h
+54
-24
No files found.
src/db_impl.cc
View file @
f963b880
...
@@ -56,7 +56,7 @@ class TitanDBImpl::FileManager : public BlobFileManager {
...
@@ -56,7 +56,7 @@ class TitanDBImpl::FileManager : public BlobFileManager {
VersionEdit
edit
;
VersionEdit
edit
;
edit
.
SetColumnFamilyID
(
cf_id
);
edit
.
SetColumnFamilyID
(
cf_id
);
for
(
auto
&
file
:
files
)
{
for
(
auto
&
file
:
files
)
{
RecordTick
(
statistics
(
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_
,
statistics
(
db_
->
stats_
.
get
()),
BLOB_DB_BLOB_FILE_SYNC_MICROS
);
BLOB_DB_BLOB_FILE_SYNC_MICROS
);
...
@@ -278,7 +278,7 @@ Status TitanDBImpl::Open(const std::vector<TitanCFDescriptor>& descs,
...
@@ -278,7 +278,7 @@ Status TitanDBImpl::Open(const std::vector<TitanCFDescriptor>& descs,
if
(
s
.
ok
())
{
if
(
s
.
ok
())
{
db_impl_
=
reinterpret_cast
<
DBImpl
*>
(
db_
->
GetRootDB
());
db_impl_
=
reinterpret_cast
<
DBImpl
*>
(
db_
->
GetRootDB
());
if
(
stats_
.
get
())
{
if
(
stats_
.
get
())
{
stats_
->
Initialize
(
column_families
,
db_
->
DefaultColumnFamily
()
->
GetID
()
);
stats_
->
Initialize
(
column_families
);
}
}
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"Titan DB open."
);
ROCKS_LOG_INFO
(
db_options_
.
info_log
,
"Titan DB open."
);
ROCKS_LOG_HEADER
(
db_options_
.
info_log
,
"Titan git sha: %s"
,
ROCKS_LOG_HEADER
(
db_options_
.
info_log
,
"Titan git sha: %s"
,
...
@@ -555,8 +555,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
...
@@ -555,8 +555,8 @@ Status TitanDBImpl::GetImpl(const ReadOptions& options,
StopWatch
read_sw
(
env_
,
statistics
(
stats_
.
get
()),
StopWatch
read_sw
(
env_
,
statistics
(
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
(
stat
istics
(
stats_
.
get
()
),
BLOB_DB_NUM_KEYS_READ
);
RecordTick
(
stat
s_
.
get
(
),
BLOB_DB_NUM_KEYS_READ
);
RecordTick
(
stat
istics
(
stats_
.
get
()
),
BLOB_DB_BLOB_FILE_BYTES_READ
,
RecordTick
(
stat
s_
.
get
(
),
BLOB_DB_BLOB_FILE_BYTES_READ
,
index
.
blob_handle
.
size
);
index
.
blob_handle
.
size
);
}
}
if
(
s
.
IsCorruption
())
{
if
(
s
.
IsCorruption
())
{
...
...
src/titan_stats.cc
View file @
f963b880
...
@@ -26,8 +26,8 @@ const std::string TitanDB::Properties::kLiveBlobFileSize =
...
@@ -26,8 +26,8 @@ const std::string TitanDB::Properties::kLiveBlobFileSize =
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
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
Stats
Type
>
const
std
::
unordered_map
<
std
::
string
,
TitanInternalStats
::
Ticker
Type
>
TitanInternalStats
::
stats
_type_string_map
=
{
TitanInternalStats
::
ticker
_type_string_map
=
{
{
TitanDB
::
Properties
::
kLiveBlobSize
,
{
TitanDB
::
Properties
::
kLiveBlobSize
,
TitanInternalStats
::
LIVE_BLOB_SIZE
},
TitanInternalStats
::
LIVE_BLOB_SIZE
},
{
TitanDB
::
Properties
::
kNumLiveBlobFile
,
{
TitanDB
::
Properties
::
kNumLiveBlobFile
,
...
@@ -40,6 +40,9 @@ const std::unordered_map<std::string, TitanInternalStats::StatsType>
...
@@ -40,6 +40,9 @@ const std::unordered_map<std::string, TitanInternalStats::StatsType>
TitanInternalStats
::
OBSOLETE_BLOB_FILE_SIZE
},
TitanInternalStats
::
OBSOLETE_BLOB_FILE_SIZE
},
};
};
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 @
f963b880
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include <unordered_map>
#include <unordered_map>
#include "logging/log_buffer.h"
#include "logging/log_buffer.h"
#include "monitoring/histogram.h"
#include "rocksdb/iostats_context.h"
#include "rocksdb/iostats_context.h"
#include "rocksdb/statistics.h"
#include "rocksdb/statistics.h"
...
@@ -47,21 +48,29 @@ using InternalOpStats =
...
@@ -47,21 +48,29 @@ using InternalOpStats =
// data.
// data.
class
TitanInternalStats
{
class
TitanInternalStats
{
public
:
public
:
enum
Stats
Type
{
enum
Ticker
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_STATS_ENUM_MAX
,
INTERNAL_TICKER_ENUM_MAX
,
};
enum
HistogramType
{
INTERNAL_HISTOGRAM_ENUM_MAX
,
};
};
TitanInternalStats
()
{
Clear
();
}
TitanInternalStats
()
{
Clear
();
}
void
Clear
()
{
void
Clear
()
{
for
(
int
stat
=
0
;
stat
<
INTERNAL_STATS_ENUM_MAX
;
stat
++
)
{
for
(
int
type
=
0
;
type
<
INTERNAL_TICKER_ENUM_MAX
;
type
++
)
{
stats_
[
stat
].
store
(
0
,
std
::
memory_order_relaxed
);
tickers_
[
type
].
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
(
...
@@ -76,24 +85,28 @@ class TitanInternalStats {
...
@@ -76,24 +85,28 @@ class TitanInternalStats {
}
}
}
}
void
ResetStats
(
Stats
Type
type
)
{
void
ResetStats
(
Ticker
Type
type
)
{
stat
s_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
ticker
s_
[
type
].
store
(
0
,
std
::
memory_order_relaxed
);
}
}
void
AddStats
(
Stats
Type
type
,
uint64_t
value
)
{
void
AddStats
(
Ticker
Type
type
,
uint64_t
value
)
{
auto
&
v
=
stat
s_
[
type
];
auto
&
v
=
ticker
s_
[
type
];
v
.
fetch_add
(
value
,
std
::
memory_order_relaxed
);
v
.
fetch_add
(
value
,
std
::
memory_order_relaxed
);
}
}
void
SubStats
(
Stats
Type
type
,
uint64_t
value
)
{
void
SubStats
(
Ticker
Type
type
,
uint64_t
value
)
{
auto
&
v
=
stat
s_
[
type
];
auto
&
v
=
ticker
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
=
stats
_type_string_map
.
find
(
property
.
ToString
());
auto
p
=
ticker
_type_string_map
.
find
(
property
.
ToString
());
if
(
p
!=
stats
_type_string_map
.
end
())
{
if
(
p
!=
ticker
_type_string_map
.
end
())
{
*
value
=
stat
s_
[
p
->
second
].
load
(
std
::
memory_order_relaxed
);
*
value
=
ticker
s_
[
p
->
second
].
load
(
std
::
memory_order_relaxed
);
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -115,15 +128,21 @@ class TitanInternalStats {
...
@@ -115,15 +128,21 @@ 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
{
...
@@ -132,12 +151,10 @@ class TitanStats {
...
@@ -132,12 +151,10 @@ class TitanStats {
// TODO: Initialize corresponding internal stats struct for Column families
// TODO: Initialize corresponding internal stats struct for Column families
// created after DB open.
// created after DB open.
Status
Initialize
(
std
::
map
<
uint32_t
,
TitanCFOptions
>
cf_options
,
Status
Initialize
(
std
::
map
<
uint32_t
,
TitanCFOptions
>
cf_options
)
{
uint32_t
default_cf
)
{
for
(
auto
&
opts
:
cf_options
)
{
for
(
auto
&
opts
:
cf_options
)
{
internal_stats_
[
opts
.
first
]
=
NewTitanInternalStats
(
opts
.
second
);
internal_stats_
[
opts
.
first
]
=
NewTitanInternalStats
(
opts
.
second
);
}
}
default_cf_
=
default_cf
;
return
Status
::
OK
();
return
Status
::
OK
();
}
}
...
@@ -155,8 +172,8 @@ class TitanStats {
...
@@ -155,8 +172,8 @@ class TitanStats {
void
DumpInternalOpStats
(
uint32_t
cf_id
,
const
std
::
string
&
cf_name
);
void
DumpInternalOpStats
(
uint32_t
cf_id
,
const
std
::
string
&
cf_name
);
private
:
private
:
// RocksDB statistics
Statistics
*
stats_
=
nullptr
;
Statistics
*
stats_
=
nullptr
;
uint32_t
default_cf_
=
0
;
std
::
unordered_map
<
uint32_t
,
std
::
shared_ptr
<
TitanInternalStats
>>
std
::
unordered_map
<
uint32_t
,
std
::
shared_ptr
<
TitanInternalStats
>>
internal_stats_
;
internal_stats_
;
std
::
shared_ptr
<
TitanInternalStats
>
NewTitanInternalStats
(
std
::
shared_ptr
<
TitanInternalStats
>
NewTitanInternalStats
(
...
@@ -165,7 +182,7 @@ class TitanStats {
...
@@ -165,7 +182,7 @@ class TitanStats {
}
}
};
};
// Utility functions
// Utility functions
for RocksDB stats types
inline
Statistics
*
statistics
(
TitanStats
*
stats
)
{
inline
Statistics
*
statistics
(
TitanStats
*
stats
)
{
return
(
stats
)
?
stats
->
statistics
()
:
nullptr
;
return
(
stats
)
?
stats
->
statistics
()
:
nullptr
;
}
}
...
@@ -191,8 +208,9 @@ inline void SetTickerCount(TitanStats* stats, uint32_t ticker_type,
...
@@ -191,8 +208,9 @@ inline void SetTickerCount(TitanStats* stats, uint32_t ticker_type,
}
}
}
}
// 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
::
Stats
Type
type
)
{
TitanInternalStats
::
Ticker
Type
type
)
{
if
(
stats
)
{
if
(
stats
)
{
auto
p
=
stats
->
internal_stats
(
cf_id
);
auto
p
=
stats
->
internal_stats
(
cf_id
);
if
(
p
)
{
if
(
p
)
{
...
@@ -202,7 +220,7 @@ inline void ResetStats(TitanStats* stats, uint32_t cf_id,
...
@@ -202,7 +220,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
::
Stats
Type
type
,
uint64_t
value
)
{
TitanInternalStats
::
Ticker
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
)
{
...
@@ -212,7 +230,7 @@ inline void AddStats(TitanStats* stats, uint32_t cf_id,
...
@@ -212,7 +230,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
::
Stats
Type
type
,
uint64_t
value
)
{
TitanInternalStats
::
Ticker
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
)
{
...
@@ -221,6 +239,18 @@ inline void SubStats(TitanStats* stats, uint32_t cf_id,
...
@@ -221,6 +239,18 @@ 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
inline
uint64_t
GetAndResetStats
(
InternalOpStats
*
stats
,
inline
uint64_t
GetAndResetStats
(
InternalOpStats
*
stats
,
InternalOpStatsType
type
)
{
InternalOpStatsType
type
)
{
if
(
stats
!=
nullptr
)
{
if
(
stats
!=
nullptr
)
{
...
...
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