Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e00f7936
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e00f7936
编写于
5月 29, 2023
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge 3.0
上级
7977490b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
31 deletion
+41
-31
source/libs/stream/src/streamBackendRocksdb.c
source/libs/stream/src/streamBackendRocksdb.c
+41
-31
未找到文件。
source/libs/stream/src/streamBackendRocksdb.c
浏览文件 @
e00f7936
...
...
@@ -142,16 +142,17 @@ void streamBackendCleanup(void* arg) {
}
taosHashCleanup
(
pHandle
->
cfInst
);
rocksdb_flushoptions_t
*
flushOpt
=
rocksdb_flushoptions_create
();
char
*
err
=
NULL
;
rocksdb_flush
(
pHandle
->
db
,
flushOpt
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to flush db before streamBackend clean up, reason:%s"
,
err
);
taosMemoryFree
(
err
);
if
(
pHandle
->
db
)
{
char
*
err
=
NULL
;
rocksdb_flushoptions_t
*
flushOpt
=
rocksdb_flushoptions_create
();
rocksdb_flush
(
pHandle
->
db
,
flushOpt
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to flush db before streamBackend clean up, reason:%s"
,
err
);
taosMemoryFree
(
err
);
}
rocksdb_flushoptions_destroy
(
flushOpt
);
rocksdb_close
(
pHandle
->
db
);
}
rocksdb_flushoptions_destroy
(
flushOpt
);
rocksdb_close
(
pHandle
->
db
);
rocksdb_options_destroy
(
pHandle
->
dbOpt
);
rocksdb_env_destroy
(
pHandle
->
env
);
rocksdb_cache_destroy
(
pHandle
->
cache
);
...
...
@@ -650,7 +651,7 @@ rocksdb_compactionfilter_t* compactFilteFactoryCreateFilter(void* arg, rocksdb_c
void
destroyRocksdbCfInst
(
RocksdbCfInst
*
inst
)
{
int
cfLen
=
sizeof
(
ginitDict
)
/
sizeof
(
ginitDict
[
0
]);
for
(
int
i
=
0
;
i
<
cfLen
;
i
++
)
{
rocksdb_column_family_handle_destroy
(
inst
->
pHandle
[
i
]);
if
(
inst
->
pHandle
[
i
])
rocksdb_column_family_handle_destroy
((
inst
->
pHandle
)
[
i
]);
}
rocksdb_writeoptions_destroy
(
inst
->
wOpt
);
...
...
@@ -668,7 +669,6 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
int64_t
streamId
;
int32_t
taskId
,
dummy
=
0
;
char
suffix
[
64
]
=
{
0
};
SHashObj
*
instTbl
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
rocksdb_options_t
**
cfOpts
=
taosMemoryCalloc
(
nCf
,
sizeof
(
rocksdb_options_t
*
));
RocksdbCfParam
*
params
=
taosMemoryCalloc
(
nCf
,
sizeof
(
RocksdbCfParam
*
));
...
...
@@ -705,8 +705,12 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
qError
(
"failed to open rocksdb cf, reason:%s"
,
err
);
taosMemoryFree
(
err
);
}
else
{
qDebug
(
"succ to open rocksdb cf
, reason
"
);
qDebug
(
"succ to open rocksdb cf"
);
}
// close default cf
rocksdb_column_family_handle_destroy
(
cfHandle
[
0
]);
rocksdb_options_destroy
(
cfOpts
[
0
]);
handle
->
db
=
db
;
static
int32_t
cfLen
=
sizeof
(
ginitDict
)
/
sizeof
(
ginitDict
[
0
]);
for
(
int
i
=
0
;
i
<
nCf
;
i
++
)
{
...
...
@@ -720,7 +724,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
int
idx
=
streamGetInit
(
NULL
,
funcname
);
RocksdbCfInst
*
inst
=
NULL
;
RocksdbCfInst
**
pInst
=
taosHashGet
(
instTbl
,
idstr
,
strlen
(
idstr
)
+
1
);
RocksdbCfInst
**
pInst
=
taosHashGet
(
handle
->
cfInst
,
idstr
,
strlen
(
idstr
)
+
1
);
if
(
pInst
==
NULL
||
*
pInst
==
NULL
)
{
inst
=
taosMemoryCalloc
(
1
,
sizeof
(
RocksdbCfInst
));
inst
->
pHandle
=
taosMemoryCalloc
(
cfLen
,
sizeof
(
rocksdb_column_family_handle_t
*
));
...
...
@@ -745,7 +749,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
}
}
void
**
pIter
=
taosHashIterate
(
handle
->
cfInst
,
NULL
);
while
(
*
pIter
)
{
while
(
pIter
)
{
RocksdbCfInst
*
inst
=
*
pIter
;
for
(
int
i
=
0
;
i
<
cfLen
;
i
++
)
{
...
...
@@ -831,7 +835,7 @@ int streamStateOpenBackend(void* backend, SStreamState* pState) {
rocksdb_options_set_comparator
((
rocksdb_options_t
*
)
cfOpt
[
i
],
compare
);
pCompare
[
i
]
=
compare
;
}
rocksdb_column_family_handle_t
**
cfHandle
=
taosMemoryCalloc
(
1
,
cfLen
*
sizeof
(
rocksdb_column_family_handle_t
*
));
rocksdb_column_family_handle_t
**
cfHandle
=
taosMemoryCalloc
(
cfLen
,
sizeof
(
rocksdb_column_family_handle_t
*
));
pState
->
pTdbState
->
rocksdb
=
handle
->
db
;
pState
->
pTdbState
->
pHandle
=
(
void
**
)
cfHandle
;
pState
->
pTdbState
->
writeOpts
=
rocksdb_writeoptions_create
();
...
...
@@ -873,7 +877,8 @@ void streamStateCloseBackend(SStreamState* pState, bool remove) {
if
(
remove
)
{
for
(
int
i
=
0
;
i
<
cfLen
;
i
++
)
{
if
(
pState
->
pTdbState
->
pHandle
[
i
]
!=
NULL
)
rocksdb_drop_column_family
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
pHandle
[
i
],
&
err
);
rocksdb_drop_column_family
(
pState
->
pTdbState
->
rocksdb
,
((
rocksdb_column_family_handle_t
**
)
pState
->
pTdbState
->
pHandle
)[
i
],
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to create cf:%s_%s, reason:%s"
,
pState
->
pTdbState
->
idstr
,
ginitDict
[
i
].
key
,
err
);
taosMemoryFreeClear
(
err
);
...
...
@@ -951,8 +956,9 @@ int streamGetInit(SStreamState* pState, const char* funcName) {
qError
(
"failed to to open cf, %p 0x%"
PRIx64
"-%d_%s, reason:%s"
,
pState
,
pState
->
streamId
,
pState
->
taskId
,
funcName
,
err
);
taosMemoryFree
(
err
);
}
else
{
pState
->
pTdbState
->
pHandle
[
idx
]
=
cf
;
}
pState
->
pTdbState
->
pHandle
[
idx
]
=
cf
;
taosThreadRwlockUnlock
(
&
pState
->
pTdbState
->
rwLock
);
}
}
...
...
@@ -982,7 +988,8 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
rocksdb_readoptions_set_snapshot
(
rOpt
,
*
snapshot
);
rocksdb_readoptions_set_fill_cache
(
rOpt
,
0
);
return
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
rOpt
,
pState
->
pTdbState
->
pHandle
[
idx
]);
return
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
rOpt
,
((
rocksdb_column_family_handle_t
**
)
pState
->
pTdbState
->
pHandle
)[
idx
]);
}
#define STREAM_STATE_PUT_ROCKSDB(pState, funcname, key, value, vLen) \
...
...
@@ -999,11 +1006,12 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
char toString[128] = {0}; \
if (qDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \
int32_t klen = ginitDict[i].enFunc((void*)key, buf); \
rocksdb_column_family_handle_t* pHandle = pState->pTdbState->pHandle[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_writeoptions_t* opts = pState->pTdbState->writeOpts; \
char* ttlV = NULL; \
int32_t ttlVLen = ginitDict[i].enValueFunc((char*)value, vLen, 0, &ttlV); \
rocksdb_column_family_handle_t* pHandle = \
((rocksdb_column_family_handle_t**)pState->pTdbState->pHandle)[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_writeoptions_t* opts = pState->pTdbState->writeOpts; \
char* ttlV = NULL; \
int32_t ttlVLen = ginitDict[i].enValueFunc((char*)value, vLen, 0, &ttlV); \
rocksdb_put_cf(db, opts, pHandle, (const char*)buf, klen, (const char*)ttlV, (size_t)ttlVLen, &err); \
if (err != NULL) { \
taosMemoryFree(err); \
...
...
@@ -1029,11 +1037,12 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
char toString[128] = {0}; \
if (qDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \
int32_t klen = ginitDict[i].enFunc((void*)key, buf); \
rocksdb_column_family_handle_t* pHandle = pState->pTdbState->pHandle[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_readoptions_t* opts = pState->pTdbState->readOpts; \
size_t len = 0; \
char* val = rocksdb_get_cf(db, opts, pHandle, (const char*)buf, klen, (size_t*)&len, &err); \
rocksdb_column_family_handle_t* pHandle = \
((rocksdb_column_family_handle_t**)pState->pTdbState->pHandle)[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_readoptions_t* opts = pState->pTdbState->readOpts; \
size_t len = 0; \
char* val = rocksdb_get_cf(db, opts, pHandle, (const char*)buf, klen, (size_t*)&len, &err); \
if (val == NULL) { \
if (err == NULL) { \
qDebug("streamState str: %s failed to read from %s_%s, err: not exist", toString, pState->pTdbState->idstr, \
...
...
@@ -1076,9 +1085,10 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
char toString[128] = {0}; \
if (qDebugFlag & DEBUG_TRACE) ginitDict[i].toStrFunc((void*)key, toString); \
int32_t klen = ginitDict[i].enFunc((void*)key, buf); \
rocksdb_column_family_handle_t* pHandle = pState->pTdbState->pHandle[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_writeoptions_t* opts = pState->pTdbState->writeOpts; \
rocksdb_column_family_handle_t* pHandle = \
((rocksdb_column_family_handle_t**)pState->pTdbState->pHandle)[ginitDict[i].idx]; \
rocksdb_t* db = pState->pTdbState->rocksdb; \
rocksdb_writeoptions_t* opts = pState->pTdbState->writeOpts; \
rocksdb_delete_cf(db, opts, pHandle, (const char*)buf, klen, &err); \
if (err != NULL) { \
qError("streamState str: %s failed to del from %s_%s, err: %s", toString, pState->pTdbState->idstr, funcname, \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录