Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
478425e0
T
Terarkdb
项目概览
indiff7643
/
Terarkdb
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Terarkdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
478425e0
编写于
6月 15, 2020
作者:
Z
Zitan Chen
提交者:
奏之章
2月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] GetSessionID
上级
68fb04d3
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
510 addition
and
13 deletion
+510
-13
HISTORY.md
HISTORY.md
+386
-0
db/db_basic_test.cc
db/db_basic_test.cc
+50
-0
db/db_impl.cc
db/db_impl.cc
+17
-1
db/db_impl.h
db/db_impl.h
+34
-8
db/db_info_dumper.cc
db/db_info_dumper.cc
+4
-1
db/db_info_dumper.h
db/db_info_dumper.h
+3
-2
db/db_test.cc
db/db_test.cc
+5
-1
include/rocksdb/db.h
include/rocksdb/db.h
+7
-0
include/rocksdb/utilities/stackable_db.h
include/rocksdb/utilities/stackable_db.h
+4
-0
未找到文件。
HISTORY.md
浏览文件 @
478425e0
此差异已折叠。
点击以展开。
db/db_basic_test.cc
浏览文件 @
478425e0
...
...
@@ -35,6 +35,56 @@ TEST_F(DBBasicTest, OpenWhenOpen) {
delete
db2
;
}
TEST_F
(
DBBasicTest
,
UniqueSession
)
{
Options
options
=
CurrentOptions
();
std
::
string
sid1
,
sid2
,
sid3
,
sid4
;
db_
->
GetDbSessionId
(
sid1
);
Reopen
(
options
);
db_
->
GetDbSessionId
(
sid2
);
ASSERT_OK
(
Put
(
"foo"
,
"v1"
));
db_
->
GetDbSessionId
(
sid4
);
Reopen
(
options
);
db_
->
GetDbSessionId
(
sid3
);
ASSERT_NE
(
sid1
,
sid2
);
ASSERT_NE
(
sid1
,
sid3
);
ASSERT_NE
(
sid2
,
sid3
);
ASSERT_EQ
(
sid2
,
sid4
);
#ifndef ROCKSDB_LITE
Close
();
ASSERT_OK
(
ReadOnlyReopen
(
options
));
db_
->
GetDbSessionId
(
sid1
);
// Test uniqueness between readonly open (sid1) and regular open (sid3)
ASSERT_NE
(
sid1
,
sid3
);
Close
();
ASSERT_OK
(
ReadOnlyReopen
(
options
));
db_
->
GetDbSessionId
(
sid2
);
ASSERT_EQ
(
"v1"
,
Get
(
"foo"
));
db_
->
GetDbSessionId
(
sid3
);
ASSERT_NE
(
sid1
,
sid2
);
ASSERT_EQ
(
sid2
,
sid3
);
#endif // ROCKSDB_LITE
CreateAndReopenWithCF
({
"goku"
},
options
);
db_
->
GetDbSessionId
(
sid1
);
ASSERT_OK
(
Put
(
"bar"
,
"e1"
));
db_
->
GetDbSessionId
(
sid2
);
ASSERT_EQ
(
"e1"
,
Get
(
"bar"
));
db_
->
GetDbSessionId
(
sid3
);
ReopenWithColumnFamilies
({
"default"
,
"goku"
},
options
);
db_
->
GetDbSessionId
(
sid4
);
ASSERT_EQ
(
sid1
,
sid2
);
ASSERT_EQ
(
sid2
,
sid3
);
ASSERT_NE
(
sid1
,
sid4
);
}
#ifndef ROCKSDB_LITE
TEST_F
(
DBBasicTest
,
ReadOnlyDB
)
{
ASSERT_OK
(
Put
(
"foo"
,
"v1"
));
...
...
db/db_impl.cc
浏览文件 @
478425e0
...
...
@@ -365,7 +365,8 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname,
new
ColumnFamilyMemTablesImpl
(
versions_
->
GetColumnFamilySet
()));
DumpRocksDBBuildVersion
(
immutable_db_options_
.
info_log
.
get
());
DumpDBFileSummary
(
immutable_db_options_
,
dbname_
);
SetDbSessionId
();
DumpDBFileSummary
(
immutable_db_options_
,
dbname_
,
db_session_id_
);
immutable_db_options_
.
Dump
(
immutable_db_options_
.
info_log
.
get
());
mutable_db_options_
.
Dump
(
immutable_db_options_
.
info_log
.
get
());
DumpSupportInfo
(
immutable_db_options_
.
info_log
.
get
());
...
...
@@ -3390,6 +3391,21 @@ Status DBImpl::GetDbIdentity(std::string& identity) const {
return
s
;
}
Status
DBImpl
::
GetDbSessionId
(
std
::
string
&
session_id
)
const
{
session_id
.
assign
(
db_session_id_
);
return
Status
::
OK
();
}
void
DBImpl
::
SetDbSessionId
()
{
// GenerateUniqueId() generates an identifier
// that has a negligible probability of being duplicated
db_session_id_
=
env_
->
GenerateUniqueId
();
// Remove the extra '\n' at the end if there is one
if
(
!
db_session_id_
.
empty
()
&&
db_session_id_
.
back
()
==
'\n'
)
{
db_session_id_
.
pop_back
();
}
}
// Default implementation -- returns not supported status
Status
DB
::
CreateColumnFamily
(
const
ColumnFamilyOptions
&
/*cf_options*/
,
const
std
::
string
&
/*column_family_name*/
,
...
...
db/db_impl.h
浏览文件 @
478425e0
...
...
@@ -255,6 +255,11 @@ class DBImpl : public DB {
virtual
bool
SetPreserveDeletesSequenceNumber
(
SequenceNumber
seqnum
)
override
;
virtual
Status
GetDbIdentity
(
std
::
string
&
identity
)
const
override
;
virtual
Status
GetDbIdentityFromIdentityFile
(
std
::
string
*
identity
)
const
;
virtual
Status
GetDbSessionId
(
std
::
string
&
session_id
)
const
override
;
ColumnFamilyHandle
*
DefaultColumnFamily
()
const
override
;
ColumnFamilyHandle
*
PersistentStatsColumnFamily
()
const
;
...
...
@@ -788,6 +793,10 @@ class DBImpl : public DB {
protected:
Env
*
const
env_
;
const
std
::
string
dbname_
;
std
::
string
db_id_
;
// db_session_id_ is an identifier that gets reset
// every time the DB is opened
std
::
string
db_session_id_
;
std
::
unique_ptr
<
VersionSet
>
versions_
;
// Flag to check whether we allocated and own the info log file
bool
own_info_log_
;
...
...
@@ -887,7 +896,31 @@ class DBImpl : public DB {
// Actual implementation of Close()
Status
CloseImpl
();
// Recover the descriptor from persistent storage. May do a significant
// amount of work to recover recently logged updates. Any changes to
// be made to the descriptor are added to *edit.
// recovered_seq is set to less than kMaxSequenceNumber if the log's tail is
// skipped.
virtual
Status
Recover
(
const
std
::
vector
<
ColumnFamilyDescriptor
>&
column_families
,
bool
read_only
=
false
,
bool
error_if_log_file_exist
=
false
,
bool
error_if_data_exists_in_logs
=
false
,
uint64_t
*
recovered_seq
=
nullptr
);
virtual
bool
OwnTablesAndLogs
()
const
{
return
true
;
}
// REQUIRES: db mutex held when calling this function, but the db mutex can
// be released and re-acquired. Db mutex will be held when the function
// returns.
// After best-efforts recovery, there may be SST files in db/cf paths that are
// not referenced in the MANIFEST. We delete these SST files. In the
// meantime, we find out the largest file number present in the paths, and
// bump up the version set's next_file_number_ to be 1 + largest_file_number.
Status
FinishBestEffortsRecovery
();
// SetDbSessionId() should be called in the constuctor DBImpl()
// to ensure that db_session_id_ gets updated every time the DB is opened
void
SetDbSessionId
();
private:
friend
class
DB
;
friend
class
ErrorHandler
;
...
...
@@ -937,13 +970,6 @@ class DBImpl : public DB {
struct
PrepickedCompaction
;
struct
PurgeFileInfo
;
// Recover the descriptor from persistent storage. May do a significant
// amount of work to recover recently logged updates. Any changes to
// be made to the descriptor are added to *edit.
Status
Recover
(
const
std
::
vector
<
ColumnFamilyDescriptor
>&
column_families
,
bool
read_only
=
false
,
bool
error_if_log_file_exist
=
false
,
bool
error_if_data_exists_in_logs
=
false
);
// Initialize the built-in column family for persistent stats. Depending on
// whether on-disk persistent stats have been enabled before, it may either
// create a new column family and column family handle or just a column family
...
...
db/db_info_dumper.cc
浏览文件 @
478425e0
...
...
@@ -22,7 +22,8 @@
namespace
TERARKDB_NAMESPACE
{
void
DumpDBFileSummary
(
const
ImmutableDBOptions
&
options
,
const
std
::
string
&
dbname
)
{
const
std
::
string
&
dbname
,
const
std
::
string
&
session_id
)
{
if
(
options
.
info_log
==
nullptr
)
{
return
;
}
...
...
@@ -37,6 +38,8 @@ void DumpDBFileSummary(const ImmutableDBOptions& options,
std
::
string
file_info
,
wal_info
;
Header
(
options
.
info_log
,
"DB SUMMARY
\n
"
);
Header
(
options
.
info_log
,
"DB Session ID: %s
\n
"
,
session_id
.
c_str
());
// Get files in dbname dir
if
(
!
env
->
GetChildren
(
dbname
,
&
files
).
ok
())
{
Error
(
options
.
info_log
,
...
...
db/db_info_dumper.h
浏览文件 @
478425e0
...
...
@@ -7,9 +7,10 @@
#include <string>
#include "options/db_options.h"
#include "rocksdb/terark_namespace.h"
namespace
TERARKDB_NAMESPACE
{
void
DumpDBFileSummary
(
const
ImmutableDBOptions
&
options
,
const
std
::
string
&
dbname
);
const
std
::
string
&
dbname
,
const
std
::
string
&
session_id
=
""
);
}
// namespace TERARKDB_NAMESPACE
db/db_test.cc
浏览文件 @
478425e0
...
...
@@ -2722,7 +2722,11 @@ class ModelDB : public DB {
return
Status
::
OK
();
}
virtual
SequenceNumber
GetLatestSequenceNumber
()
const
override
{
return
0
;
}
Status
GetDbSessionId
(
std
::
string
&
/*session_id*/
)
const
override
{
return
Status
::
OK
();
}
SequenceNumber
GetLatestSequenceNumber
()
const
override
{
return
0
;
}
virtual
bool
SetPreserveDeletesSequenceNumber
(
SequenceNumber
/*seqnum*/
)
override
{
...
...
include/rocksdb/db.h
浏览文件 @
478425e0
...
...
@@ -1237,6 +1237,13 @@ class DB {
// be set properly
virtual
Status
GetDbIdentity
(
std
::
string
&
identity
)
const
=
0
;
// Return a unique identifier for each DB object that is opened
// This DB session ID should be unique among all open DB instances on all
// hosts, and should be unique among re-openings of the same or other DBs.
// (Two open DBs have the same identity from other function GetDbIdentity when
// one is physically copied from the other.)
virtual
Status
GetDbSessionId
(
std
::
string
&
session_id
)
const
=
0
;
// Returns default column family handle
virtual
ColumnFamilyHandle
*
DefaultColumnFamily
()
const
=
0
;
...
...
include/rocksdb/utilities/stackable_db.h
浏览文件 @
478425e0
...
...
@@ -339,6 +339,10 @@ class StackableDB : public DB {
return
db_
->
GetDbIdentity
(
identity
);
}
virtual
Status
GetDbSessionId
(
std
::
string
&
session_id
)
const
override
{
return
db_
->
GetDbSessionId
(
session_id
);
}
using
DB
::
SetOptions
;
virtual
Status
SetOptions
(
ColumnFamilyHandle
*
column_family_handle
,
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录