Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b4c53d83
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
未验证
提交
b4c53d83
编写于
10月 09, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17237 from taosdata/feat/alter_pages_buffer
feat: alter pages buffer
上级
181a7d60
bacfabfc
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
2125 addition
and
1964 deletion
+2125
-1964
include/util/tdef.h
include/util/tdef.h
+2
-2
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+3
-3
source/dnode/mnode/impl/test/db/db.cpp
source/dnode/mnode/impl/test/db/db.cpp
+2
-0
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+1
-1
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/meta/metaOpen.c
source/dnode/vnode/src/meta/metaOpen.c
+12
-0
source/dnode/vnode/src/vnd/vnodeBufPool.c
source/dnode/vnode/src/vnd/vnodeBufPool.c
+54
-48
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+2
-2
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+1
-1
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+17
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+2
-2
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1909
-1899
source/libs/parser/test/parAlterToBalanceTest.cpp
source/libs/parser/test/parAlterToBalanceTest.cpp
+27
-3
source/libs/tdb/inc/tdb.h
source/libs/tdb/inc/tdb.h
+1
-0
source/libs/tdb/src/db/tdbDb.c
source/libs/tdb/src/db/tdbDb.c
+2
-0
source/libs/tdb/src/db/tdbPCache.c
source/libs/tdb/src/db/tdbPCache.c
+88
-3
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+1
-0
未找到文件。
include/util/tdef.h
浏览文件 @
b4c53d83
...
...
@@ -297,7 +297,7 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_BUFFER_PER_VNODE 16384 // unit MB
#define TSDB_DEFAULT_BUFFER_PER_VNODE 96
#define TSDB_MIN_PAGES_PER_VNODE 64
#define TSDB_MAX_PAGES_PER_VNODE
16384
#define TSDB_MAX_PAGES_PER_VNODE
INT32_MAX
#define TSDB_DEFAULT_PAGES_PER_VNODE 256
#define TSDB_MIN_PAGESIZE_PER_VNODE 1 // unit KB
#define TSDB_MAX_PAGESIZE_PER_VNODE 16384
...
...
@@ -483,7 +483,7 @@ enum {
#define SNODE_HANDLE -2
#define VNODE_HANDLE -3
#define BNODE_HANDLE -4
#define CLIENT_HANDLE
-5
#define CLIENT_HANDLE -5
#define TSDB_CONFIG_OPTION_LEN 32
#define TSDB_CONFIG_VALUE_LEN 64
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
b4c53d83
...
...
@@ -631,7 +631,7 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
terrno
=
TSDB_CODE_MND_DB_OPTION_UNCHANGED
;
if
(
pAlter
->
buffer
>
0
&&
pAlter
->
buffer
!=
pDb
->
cfg
.
buffer
)
{
#if
1
#if
0
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
return terrno;
#else
...
...
@@ -641,7 +641,7 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
}
if
(
pAlter
->
pages
>
0
&&
pAlter
->
pages
!=
pDb
->
cfg
.
pages
)
{
#if
1
#if
0
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
return terrno;
#else
...
...
@@ -1311,7 +1311,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
continue
;
}
else
{
mInfo
(
"db:%s, vgroup version changed from %d to %d"
,
pDbVgVersion
->
dbFName
,
pDbVgVersion
->
vgVersion
,
pDb
->
vgVersion
);
pDb
->
vgVersion
);
}
usedbRsp
.
pVgroupInfos
=
taosArrayInit
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgroupInfo
));
...
...
source/dnode/mnode/impl/test/db/db.cpp
浏览文件 @
b4c53d83
...
...
@@ -30,6 +30,7 @@ TEST_F(MndTestDb, 01_ShowDb) {
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
#if 0
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
{
SCreateDbReq createReq = {0};
...
...
@@ -125,6 +126,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
EXPECT_EQ(test.GetShowRows(), 2);
}
#endif
TEST_F
(
MndTestDb
,
03
_Create_Use_Restart_Use_Db
)
{
{
...
...
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
b4c53d83
...
...
@@ -72,7 +72,7 @@ struct SVBufPool {
SVBufPoolNode
node
;
};
int32_t
vnodeOpenBufPool
(
SVnode
*
pVnode
,
int64_t
size
);
int32_t
vnodeOpenBufPool
(
SVnode
*
pVnode
);
int32_t
vnodeCloseBufPool
(
SVnode
*
pVnode
);
void
vnodeBufPoolReset
(
SVBufPool
*
pPool
);
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
b4c53d83
...
...
@@ -111,6 +111,7 @@ SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, boo
STSchema
*
metaGetTbTSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
);
int32_t
metaGetTbTSchemaEx
(
SMeta
*
pMeta
,
tb_uid_t
suid
,
tb_uid_t
uid
,
int32_t
sver
,
STSchema
**
ppTSchema
);
int
metaGetTableEntryByName
(
SMetaReader
*
pReader
,
const
char
*
name
);
int
metaAlterCache
(
SMeta
*
pMeta
,
int32_t
nPage
);
tb_uid_t
metaGetTableEntryUidByName
(
SMeta
*
pMeta
,
const
char
*
name
);
int64_t
metaGetTbNum
(
SMeta
*
pMeta
);
...
...
source/dnode/vnode/src/meta/metaOpen.c
浏览文件 @
b4c53d83
...
...
@@ -197,6 +197,18 @@ int metaClose(SMeta *pMeta) {
return
0
;
}
int
metaAlterCache
(
SMeta
*
pMeta
,
int32_t
nPage
)
{
metaWLock
(
pMeta
);
if
(
tdbAlter
(
pMeta
->
pEnv
,
nPage
)
<
0
)
{
metaULock
(
pMeta
);
return
-
1
;
}
metaULock
(
pMeta
);
return
0
;
}
int32_t
metaRLock
(
SMeta
*
pMeta
)
{
int32_t
ret
=
0
;
...
...
source/dnode/vnode/src/vnd/vnodeBufPool.c
浏览文件 @
b4c53d83
...
...
@@ -16,20 +16,53 @@
#include "vnd.h"
/* ------------------------ STRUCTURES ------------------------ */
#define VNODE_BUFPOOL_SEGMENTS 3
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
);
static
int
vnodeBufPoolDestroy
(
SVBufPool
*
pPool
);
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
)
{
SVBufPool
*
pPool
;
pPool
=
taosMemoryMalloc
(
sizeof
(
SVBufPool
)
+
size
);
if
(
pPool
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
taosThreadSpinInit
(
&
pPool
->
lock
,
0
)
!=
0
)
{
taosMemoryFree
(
pPool
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
pPool
->
next
=
NULL
;
pPool
->
pVnode
=
pVnode
;
pPool
->
nRef
=
0
;
pPool
->
size
=
0
;
pPool
->
ptr
=
pPool
->
node
.
data
;
pPool
->
pTail
=
&
pPool
->
node
;
pPool
->
node
.
prev
=
NULL
;
pPool
->
node
.
pnext
=
&
pPool
->
pTail
;
pPool
->
node
.
size
=
size
;
int
vnodeOpenBufPool
(
SVnode
*
pVnode
,
int64_t
size
)
{
*
ppPool
=
pPool
;
return
0
;
}
static
int
vnodeBufPoolDestroy
(
SVBufPool
*
pPool
)
{
vnodeBufPoolReset
(
pPool
);
taosThreadSpinDestroy
(
&
pPool
->
lock
);
taosMemoryFree
(
pPool
);
return
0
;
}
int
vnodeOpenBufPool
(
SVnode
*
pVnode
)
{
SVBufPool
*
pPool
=
NULL
;
int
ret
;
int
64_t
size
=
pVnode
->
config
.
szBuf
/
VNODE_BUFPOOL_SEGMENTS
;
ASSERT
(
pVnode
->
pPool
==
NULL
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// create pool
ret
=
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pPool
);
if
(
ret
<
0
)
{
if
(
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pPool
))
{
vError
(
"vgId:%d, failed to open vnode buffer pool since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
vnodeCloseBufPool
(
pVnode
);
return
-
1
;
...
...
@@ -41,7 +74,6 @@ int vnodeOpenBufPool(SVnode *pVnode, int64_t size) {
}
vDebug
(
"vgId:%d, vnode buffer pool is opened, size:%"
PRId64
,
TD_VID
(
pVnode
),
size
);
return
0
;
}
...
...
@@ -63,9 +95,7 @@ int vnodeCloseBufPool(SVnode *pVnode) {
}
void
vnodeBufPoolReset
(
SVBufPool
*
pPool
)
{
SVBufPoolNode
*
pNode
;
for
(
pNode
=
pPool
->
pTail
;
pNode
->
prev
;
pNode
=
pPool
->
pTail
)
{
for
(
SVBufPoolNode
*
pNode
=
pPool
->
pTail
;
pNode
->
prev
;
pNode
=
pPool
->
pTail
)
{
ASSERT
(
pNode
->
pnext
==
&
pPool
->
pTail
);
pNode
->
prev
->
pnext
=
&
pPool
->
pTail
;
pPool
->
pTail
=
pNode
->
prev
;
...
...
@@ -81,7 +111,7 @@ void vnodeBufPoolReset(SVBufPool *pPool) {
void
*
vnodeBufPoolMalloc
(
SVBufPool
*
pPool
,
int
size
)
{
SVBufPoolNode
*
pNode
;
void
*
p
;
void
*
p
=
NULL
;
taosThreadSpinLock
(
&
pPool
->
lock
);
if
(
pPool
->
node
.
size
>=
pPool
->
ptr
-
pPool
->
node
.
data
+
size
)
{
// allocate from the anchor node
...
...
@@ -124,43 +154,6 @@ void vnodeBufPoolFree(SVBufPool *pPool, void *p) {
}
}
// STATIC METHODS -------------------
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
)
{
SVBufPool
*
pPool
;
pPool
=
taosMemoryMalloc
(
sizeof
(
SVBufPool
)
+
size
);
if
(
pPool
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
taosThreadSpinInit
(
&
pPool
->
lock
,
0
)
!=
0
)
{
taosMemoryFree
(
pPool
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
pPool
->
next
=
NULL
;
pPool
->
pVnode
=
pVnode
;
pPool
->
nRef
=
0
;
pPool
->
size
=
0
;
pPool
->
ptr
=
pPool
->
node
.
data
;
pPool
->
pTail
=
&
pPool
->
node
;
pPool
->
node
.
prev
=
NULL
;
pPool
->
node
.
pnext
=
&
pPool
->
pTail
;
pPool
->
node
.
size
=
size
;
*
ppPool
=
pPool
;
return
0
;
}
static
int
vnodeBufPoolDestroy
(
SVBufPool
*
pPool
)
{
vnodeBufPoolReset
(
pPool
);
taosThreadSpinDestroy
(
&
pPool
->
lock
);
taosMemoryFree
(
pPool
);
return
0
;
}
void
vnodeBufPoolRef
(
SVBufPool
*
pPool
)
{
int32_t
nRef
=
atomic_fetch_add_32
(
&
pPool
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
...
...
@@ -175,6 +168,19 @@ void vnodeBufPoolUnRef(SVBufPool *pPool) {
taosThreadMutexLock
(
&
pVnode
->
mutex
);
int64_t
size
=
pVnode
->
config
.
szBuf
/
VNODE_BUFPOOL_SEGMENTS
;
if
(
pPool
->
node
.
size
!=
size
)
{
SVBufPool
*
pPoolT
=
NULL
;
if
(
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pPoolT
)
<
0
)
{
vWarn
(
"vgId:%d try to change buf pools size from %"
PRId64
" to %"
PRId64
" since %s"
,
TD_VID
(
pVnode
),
pPool
->
node
.
size
,
size
,
tstrerror
(
errno
));
}
else
{
vnodeBufPoolDestroy
(
pPool
);
pPool
=
pPoolT
;
vDebug
(
"vgId:%d change buf pools size from %"
PRId64
" to %"
PRId64
,
TD_VID
(
pVnode
),
pPool
->
node
.
size
,
size
);
}
}
pPool
->
next
=
pVnode
->
pPool
;
pVnode
->
pPool
=
pPool
;
taosThreadCondSignal
(
&
pVnode
->
poolNotEmpty
);
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
b4c53d83
...
...
@@ -73,7 +73,7 @@ int vnodeBegin(SVnode *pVnode) {
int
vnodeShouldCommit
(
SVnode
*
pVnode
)
{
if
(
pVnode
->
inUse
)
{
return
pVnode
->
inUse
->
size
>
pVnode
->
config
.
szBuf
/
3
;
return
pVnode
->
inUse
->
size
>
pVnode
->
inUse
->
node
.
size
;
}
return
false
;
}
...
...
@@ -236,7 +236,7 @@ int vnodeCommit(SVnode *pVnode) {
// preCommit
// smaSyncPreCommit(pVnode->pSma);
if
(
smaAsyncPreCommit
(
pVnode
->
pSma
)
<
0
)
{
if
(
smaAsyncPreCommit
(
pVnode
->
pSma
)
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
b4c53d83
...
...
@@ -96,7 +96,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
taosThreadCondInit
(
&
pVnode
->
poolNotEmpty
,
NULL
);
// open buffer pool
if
(
vnodeOpenBufPool
(
pVnode
,
pVnode
->
config
.
isHeap
?
0
:
pVnode
->
config
.
szBuf
/
3
)
<
0
)
{
if
(
vnodeOpenBufPool
(
pVnode
)
<
0
)
{
vError
(
"vgId:%d, failed to open vnode buffer pool since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
b4c53d83
...
...
@@ -1040,6 +1040,23 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void
tsdbCacheSetCapacity
(
pVnode
,
(
size_t
)
pVnode
->
config
.
cacheLastSize
*
1024
*
1024
);
}
if
(
pVnode
->
config
.
szBuf
!=
alterReq
.
buffer
*
1024LL
*
1024LL
)
{
vInfo
(
"vgId:%d vnode buffer is changed from %"
PRId64
" to %"
PRId64
,
TD_VID
(
pVnode
),
pVnode
->
config
.
szBuf
,
alterReq
.
buffer
*
1024LL
*
1024LL
);
pVnode
->
config
.
szBuf
=
alterReq
.
buffer
*
1024LL
*
1024LL
;
}
if
(
pVnode
->
config
.
szCache
!=
alterReq
.
pages
)
{
if
(
metaAlterCache
(
pVnode
->
pMeta
,
alterReq
.
pages
)
<
0
)
{
vError
(
"vgId:%d failed to change vnode pages from %d to %d failed since %s"
,
TD_VID
(
pVnode
),
pVnode
->
config
.
szCache
,
alterReq
.
pages
,
tstrerror
(
errno
));
return
errno
;
}
else
{
vInfo
(
"vgId:%d vnode pages is changed from %d to %d"
,
TD_VID
(
pVnode
),
pVnode
->
config
.
szCache
,
alterReq
.
pages
);
pVnode
->
config
.
szCache
=
alterReq
.
pages
;
}
}
if
(
pVnode
->
config
.
cacheLast
!=
alterReq
.
cacheLast
)
{
pVnode
->
config
.
cacheLast
=
alterReq
.
cacheLast
;
}
...
...
source/libs/parser/inc/sql.y
浏览文件 @
b4c53d83
...
...
@@ -217,13 +217,13 @@ alter_db_options(A) ::= alter_db_options(B) alter_db_option(C).
%type alter_db_option { SAlterOption }
%destructor alter_db_option { }
//
alter_db_option(A) ::= BUFFER NK_INTEGER(B). { A.type = DB_OPTION_BUFFER; A.val = B; }
alter_db_option(A) ::= BUFFER NK_INTEGER(B). { A.type = DB_OPTION_BUFFER; A.val = B; }
alter_db_option(A) ::= CACHEMODEL NK_STRING(B). { A.type = DB_OPTION_CACHEMODEL; A.val = B; }
alter_db_option(A) ::= CACHESIZE NK_INTEGER(B). { A.type = DB_OPTION_CACHESIZE; A.val = B; }
alter_db_option(A) ::= WAL_FSYNC_PERIOD NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; }
alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; }
alter_db_option(A) ::= KEEP variable_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; }
//
alter_db_option(A) ::= PAGES NK_INTEGER(B). { A.type = DB_OPTION_PAGES; A.val = B; }
alter_db_option(A) ::= PAGES NK_INTEGER(B). { A.type = DB_OPTION_PAGES; A.val = B; }
//alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; }
//alter_db_option(A) ::= STRICT NK_STRING(B). { A.type = DB_OPTION_STRICT; A.val = B; }
alter_db_option(A) ::= WAL_LEVEL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; }
...
...
source/libs/parser/src/sql.c
浏览文件 @
b4c53d83
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
source/libs/parser/test/parAlterToBalanceTest.cpp
浏览文件 @
b4c53d83
...
...
@@ -79,12 +79,12 @@ TEST_F(ParserInitialATest, alterDnode) {
* alter_database_option ...
*
* alter_database_option: {
* BUFFER int_value --
todo:
range [3, 16384], default 96, unit MB
* BUFFER int_value -- range [3, 16384], default 96, unit MB
* | CACHEMODEL {'none' | 'last_row' | 'last_value' | 'both'} -- default 'none'
* | CACHESIZE int_value -- range [1, 65536], default 1, unit MB
* | WAL_FSYNC_PERIOD int_value -- rang [0, 180000], default 3000, unit ms
* | KEEP {int_value | duration_value} -- rang [1, 365000], default 3650, unit day
* | PAGES int_value --
todo: rang [64, +oo)
, default 256, unit page
* | PAGES int_value --
rang [64, INT32_MAX]
, default 256, unit page
* | REPLICA int_value -- todo: enum 1, 3, default 1, unit replica
* | STRICT {'off' | 'on'} -- todo: default 'off'
* | WAL_LEVEL int_value -- enum 1, 2, default 1
...
...
@@ -162,7 +162,19 @@ TEST_F(ParserInitialATest, alterDatabase) {
setAlterDbWal
(
1
);
setAlterDbCacheModel
(
TSDB_CACHE_MODEL_LAST_ROW
);
setAlterDbSstTrigger
(
16
);
run
(
"ALTER DATABASE test CACHEMODEL 'last_row' CACHESIZE 32 WAL_FSYNC_PERIOD 200 KEEP 10 WAL_LEVEL 1 STT_TRIGGER 16"
);
setAlterDbBuffer
(
16
);
setAlterDbPages
(
128
);
run
(
"ALTER DATABASE test BUFFER 16 CACHEMODEL 'last_row' CACHESIZE 32 WAL_FSYNC_PERIOD 200 KEEP 10 PAGES 128 "
"WAL_LEVEL 1 STT_TRIGGER 16"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
setAlterDbBuffer
(
3
);
run
(
"ALTER DATABASE test BUFFER 3"
);
setAlterDbBuffer
(
64
);
run
(
"ALTER DATABASE test BUFFER 64"
);
setAlterDbBuffer
(
16384
);
run
(
"ALTER DATABASE test BUFFER 16384"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
...
...
@@ -213,6 +225,15 @@ TEST_F(ParserInitialATest, alterDatabase) {
run
(
"ALTER DATABASE test KEEP 14400m,2400h,1500d"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
setAlterDbPages
(
64
);
run
(
"ALTER DATABASE test PAGES 64"
);
setAlterDbPages
(
1024
);
run
(
"ALTER DATABASE test PAGES 1024"
);
setAlterDbPages
(
16384
);
run
(
"ALTER DATABASE test PAGES 16384"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
setAlterDbWal
(
1
);
run
(
"ALTER DATABASE test WAL_LEVEL 1"
);
...
...
@@ -224,6 +245,8 @@ TEST_F(ParserInitialATest, alterDatabase) {
TEST_F
(
ParserInitialATest
,
alterDatabaseSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"ALTER DATABASE test BUFFER 2"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test BUFFER 16385"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test CACHEMODEL 'other'"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test CACHESIZE 0"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test CACHESIZE 65537"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
...
...
@@ -234,6 +257,7 @@ TEST_F(ParserInitialATest, alterDatabaseSemanticCheck) {
run
(
"ALTER DATABASE test KEEP 365001"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test KEEP 1000000000s"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test KEEP 1w"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test PAGES 63"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test WAL_LEVEL 0"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test WAL_LEVEL 3"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test STT_TRIGGER 0"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
...
...
source/libs/tdb/inc/tdb.h
浏览文件 @
b4c53d83
...
...
@@ -36,6 +36,7 @@ int32_t tdbClose(TDB *pDb);
int32_t
tdbBegin
(
TDB
*
pDb
,
TXN
*
pTxn
);
int32_t
tdbCommit
(
TDB
*
pDb
,
TXN
*
pTxn
);
int32_t
tdbAbort
(
TDB
*
pDb
,
TXN
*
pTxn
);
int32_t
tdbAlter
(
TDB
*
pDb
,
int
pages
);
// TTB
int32_t
tdbTbOpen
(
const
char
*
tbname
,
int
keyLen
,
int
valLen
,
tdb_cmpr_fn_t
keyCmprFn
,
TDB
*
pEnv
,
TTB
**
ppTb
);
...
...
source/libs/tdb/src/db/tdbDb.c
浏览文件 @
b4c53d83
...
...
@@ -97,6 +97,8 @@ int tdbClose(TDB *pDb) {
return
0
;
}
int32_t
tdbAlter
(
TDB
*
pDb
,
int
pages
)
{
return
tdbPCacheAlter
(
pDb
->
pCache
,
pages
);
}
int32_t
tdbBegin
(
TDB
*
pDb
,
TXN
*
pTxn
)
{
SPager
*
pPager
;
int
ret
;
...
...
source/libs/tdb/src/db/tdbPCache.c
浏览文件 @
b4c53d83
...
...
@@ -61,7 +61,11 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
pCache
->
szPage
=
pageSize
;
pCache
->
nPages
=
cacheSize
;
pCache
->
aPage
=
(
SPage
**
)
&
pCache
[
1
];
pCache
->
aPage
=
(
SPage
**
)
tdbOsCalloc
(
cacheSize
,
sizeof
(
SPage
*
));
if
(
pCache
->
aPage
==
NULL
)
{
tdbOsFree
(
pCache
);
return
-
1
;
}
if
(
tdbPCacheOpenImpl
(
pCache
)
<
0
)
{
tdbOsFree
(
pCache
);
...
...
@@ -75,11 +79,93 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
int
tdbPCacheClose
(
SPCache
*
pCache
)
{
if
(
pCache
)
{
tdbPCacheCloseImpl
(
pCache
);
tdbOsFree
(
pCache
->
aPage
);
tdbOsFree
(
pCache
);
}
return
0
;
}
// TODO:
// if (pPage->id >= pCache->nPages) {
// free(pPage);
// pCache->aPage[pPage->id] = NULL;
// } else {
// add to free list
// }
static
int
tdbPCacheAlterImpl
(
SPCache
*
pCache
,
int32_t
nPage
)
{
if
(
pCache
->
nPages
==
nPage
)
{
return
0
;
}
else
if
(
pCache
->
nPages
<
nPage
)
{
SPage
**
aPage
=
tdbOsCalloc
(
nPage
,
sizeof
(
SPage
*
));
if
(
aPage
==
NULL
)
{
return
-
1
;
}
for
(
int32_t
iPage
=
pCache
->
nPages
;
iPage
<
nPage
;
iPage
++
)
{
if
(
tdbPageCreate
(
pCache
->
szPage
,
&
aPage
[
iPage
],
tdbDefaultMalloc
,
NULL
)
<
0
)
{
// TODO: handle error
return
-
1
;
}
// pPage->pgid = 0;
aPage
[
iPage
]
->
isAnchor
=
0
;
aPage
[
iPage
]
->
isLocal
=
1
;
aPage
[
iPage
]
->
nRef
=
0
;
aPage
[
iPage
]
->
pHashNext
=
NULL
;
aPage
[
iPage
]
->
pLruNext
=
NULL
;
aPage
[
iPage
]
->
pLruPrev
=
NULL
;
aPage
[
iPage
]
->
pDirtyNext
=
NULL
;
// add to local list
aPage
[
iPage
]
->
id
=
iPage
;
}
// add page to free list
for
(
int32_t
iPage
=
pCache
->
nPages
;
iPage
<
nPage
;
iPage
++
)
{
aPage
[
iPage
]
->
pFreeNext
=
pCache
->
pFree
;
pCache
->
pFree
=
aPage
[
iPage
];
pCache
->
nFree
++
;
}
for
(
int32_t
iPage
=
0
;
iPage
<
pCache
->
nPage
;
iPage
++
)
{
aPage
[
iPage
]
=
pCache
->
aPage
[
iPage
];
}
tdbOsFree
(
pCache
->
aPage
);
pCache
->
aPage
=
aPage
;
}
else
{
for
(
SPage
**
ppPage
=
&
pCache
->
pFree
;
*
ppPage
;)
{
int32_t
iPage
=
(
*
ppPage
)
->
id
;
if
(
iPage
>=
nPage
)
{
SPage
*
pPage
=
*
ppPage
;
*
ppPage
=
pPage
->
pFreeNext
;
pCache
->
aPage
[
pPage
->
id
]
=
NULL
;
tdbPageDestroy
(
pPage
,
tdbDefaultFree
,
NULL
);
pCache
->
nFree
--
;
}
else
{
ppPage
=
&
(
*
ppPage
)
->
pFreeNext
;
}
}
}
pCache
->
nPages
=
nPage
;
return
0
;
}
int
tdbPCacheAlter
(
SPCache
*
pCache
,
int32_t
nPage
)
{
int
ret
=
0
;
tdbPCacheLock
(
pCache
);
ret
=
tdbPCacheAlterImpl
(
pCache
,
nPage
);
tdbPCacheUnlock
(
pCache
);
return
ret
;
}
SPage
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
TXN
*
pTxn
)
{
SPage
*
pPage
;
i32
nRef
;
...
...
@@ -310,8 +396,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
pCache
->
nFree
=
0
;
pCache
->
pFree
=
NULL
;
for
(
int
i
=
0
;
i
<
pCache
->
nPages
;
i
++
)
{
ret
=
tdbPageCreate
(
pCache
->
szPage
,
&
pPage
,
tdbDefaultMalloc
,
NULL
);
if
(
ret
<
0
)
{
if
(
tdbPageCreate
(
pCache
->
szPage
,
&
pPage
,
tdbDefaultMalloc
,
NULL
)
<
0
)
{
// TODO: handle error
return
-
1
;
}
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
b4c53d83
...
...
@@ -216,6 +216,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt);
int
tdbPCacheOpen
(
int
pageSize
,
int
cacheSize
,
SPCache
**
ppCache
);
int
tdbPCacheClose
(
SPCache
*
pCache
);
int
tdbPCacheAlter
(
SPCache
*
pCache
,
int32_t
nPage
);
SPage
*
tdbPCacheFetch
(
SPCache
*
pCache
,
const
SPgid
*
pPgid
,
TXN
*
pTxn
);
void
tdbPCacheRelease
(
SPCache
*
pCache
,
SPage
*
pPage
,
TXN
*
pTxn
);
int
tdbPCacheGetPageSize
(
SPCache
*
pCache
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录