Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
689fb267
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
689fb267
编写于
3月 31, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
db or table option keep implement
上级
4afa7acf
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
2000 addition
and
1934 deletion
+2000
-1934
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+6
-2
include/util/tdef.h
include/util/tdef.h
+3
-3
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+2
-2
source/dnode/mnode/impl/src/mndInfoSchema.c
source/dnode/mnode/impl/src/mndInfoSchema.c
+1
-1
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+5
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+13
-8
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+68
-30
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+6
-6
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1892
-1878
tests/script/tsim/db/alter_option.sim
tests/script/tsim/db/alter_option.sim
+4
-4
未找到文件。
include/libs/nodes/cmdnodes.h
浏览文件 @
689fb267
...
...
@@ -38,7 +38,9 @@ typedef struct SDatabaseOptions {
int32_t
fsyncPeriod
;
int32_t
maxRowsPerBlock
;
int32_t
minRowsPerBlock
;
int32_t
keep
;
int32_t
keep0
;
int32_t
keep1
;
int32_t
keep2
;
int32_t
precision
;
int32_t
quorum
;
int32_t
replica
;
...
...
@@ -76,7 +78,9 @@ typedef struct SAlterDatabaseStmt {
typedef
struct
STableOptions
{
ENodeType
type
;
int32_t
keep
;
int32_t
keep0
;
int32_t
keep1
;
int32_t
keep2
;
int32_t
ttl
;
char
comments
[
TSDB_STB_COMMENT_LEN
];
SNodeList
*
pSma
;
...
...
include/util/tdef.h
浏览文件 @
689fb267
...
...
@@ -307,9 +307,9 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_DAYS_PER_FILE (3650 * 1440)
#define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440)
#define TSDB_MIN_KEEP
1 // data in db to be reserved.
#define TSDB_MAX_KEEP
365000
// data in db to be reserved.
#define TSDB_DEFAULT_KEEP
3650
// ten years
#define TSDB_MIN_KEEP
(1 * 1440) // data in db to be reserved. unit minute
#define TSDB_MAX_KEEP
(365000 * 1440)
// data in db to be reserved.
#define TSDB_DEFAULT_KEEP
(3650 * 1440)
// ten years
#define TSDB_MIN_MIN_ROW_FBLOCK 10
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
689fb267
...
...
@@ -1309,7 +1309,7 @@ static int32_t mndGetDbMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMet
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_
SMALL
INT
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"days"
);
pSchema
[
cols
].
bytes
=
pShow
->
bytes
[
cols
];
cols
++
;
...
...
@@ -1444,7 +1444,7 @@ static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_
cols
++
;
pWrite
=
getDataPosition
(
data
,
pShow
,
cols
,
rows
,
rowCapacity
);
*
(
int
16
_t
*
)
pWrite
=
pDb
->
cfg
.
daysPerFile
;
*
(
int
32
_t
*
)
pWrite
=
pDb
->
cfg
.
daysPerFile
;
cols
++
;
pWrite
=
getDataPosition
(
data
,
pShow
,
cols
,
rows
,
rowCapacity
);
...
...
source/dnode/mnode/impl/src/mndInfoSchema.c
浏览文件 @
689fb267
...
...
@@ -53,7 +53,7 @@ static const SInfosTableSchema userDBSchema[] = {
{.
name
=
"ntables"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"replica"
,
.
bytes
=
2
,
.
type
=
TSDB_DATA_TYPE_SMALLINT
},
{.
name
=
"quorum"
,
.
bytes
=
2
,
.
type
=
TSDB_DATA_TYPE_SMALLINT
},
{.
name
=
"days"
,
.
bytes
=
2
,
.
type
=
TSDB_DATA_TYPE_SMALL
INT
},
{.
name
=
"days"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_
INT
},
{.
name
=
"keep"
,
.
bytes
=
24
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"cache"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"blocks"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
689fb267
...
...
@@ -71,6 +71,7 @@ typedef enum ETableOptionType {
typedef
struct
SAlterOption
{
int32_t
type
;
SToken
val
;
SNodeList
*
pKeep
;
}
SAlterOption
;
extern
SToken
nil_token
;
...
...
@@ -121,6 +122,8 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
SNode
*
createDefaultDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultAlterDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setDatabaseOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
EDatabaseOptionType
type
,
const
SToken
*
pVal
);
SNode
*
setDatabaseKeepOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pKeep
);
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pDbName
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SNode
*
pOptions
);
...
...
@@ -129,6 +132,8 @@ SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt);
SNode
*
setTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
ETableOptionType
type
,
const
SToken
*
pVal
);
SNode
*
setTableSmaOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pSma
);
SNode
*
setTableRollupOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pFuncs
);
SNode
*
setTableKeepOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pKeep
);
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
689fb267
...
...
@@ -137,7 +137,7 @@ db_options(A) ::= db_options(B) DAYS NK_INTEGER(C).
db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); }
db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); }
db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); }
db_options(A) ::= db_options(B) KEEP
NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, &
C); }
db_options(A) ::= db_options(B) KEEP
integer_list(C). { A = setDatabaseKeepOption(pCxt, B,
C); }
db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); }
db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_QUORUM, &C); }
db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); }
...
...
@@ -148,19 +148,24 @@ db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C).
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); }
db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); }
alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabase
Option(pCxt, A, B.type, &B.val
); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabase
Option(pCxt, B, C.type, &C.val
); }
alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabase
AlterOption(pCxt, A, &B
); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabase
AlterOption(pCxt, B, &C
); }
%type alter_db_option { SAlterOption }
%destructor alter_db_option { }
alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.val = B; }
alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; }
alter_db_option(A) ::= KEEP
NK_INTEGER(B). { A.type = DB_OPTION_KEEP; A.val
= B; }
alter_db_option(A) ::= KEEP
integer_list(B). { A.type = DB_OPTION_KEEP; A.pKeep
= B; }
alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; }
alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.val = B; }
alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; }
alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; }
%type integer_list { SNodeList* }
%destructor integer_list { nodesDestroyList($$); }
integer_list(A) ::= NK_INTEGER(B). { A = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
integer_list(A) ::= integer_list(B) NK_COMMA NK_INTEGER(C). { A = addNodeToList(pCxt, B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C)); }
/************************************************ create/drop table/stable ********************************************/
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
...
...
@@ -260,20 +265,20 @@ tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP.
table_options(A) ::= . { A = createDefaultTableOptions(pCxt); }
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
table_options(A) ::= table_options(B) KEEP
NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &
C); }
table_options(A) ::= table_options(B) KEEP
integer_list(C). { A = setTableKeepOption(pCxt, B,
C); }
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); }
table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); }
table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); }
alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTable
Option(pCxt, A, B.type, &B.val
); }
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTable
Option(pCxt, B, C.type, &C.val
); }
alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTable
AlterOption(pCxt, A, &B
); }
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTable
AlterOption(pCxt, B, &C
); }
%type alter_table_option { SAlterOption }
%destructor alter_table_option { }
alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; }
alter_table_option(A) ::= KEEP
NK_INTEGER(B). { A.type = TABLE_OPTION_KEEP; A.val
= B; }
alter_table_option(A) ::= KEEP
integer_list(B). { A.type = TABLE_OPTION_KEEP; A.pKeep
= B; }
alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; }
%type col_name_list { SNodeList* }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
689fb267
...
...
@@ -138,18 +138,6 @@ static SDatabaseOptions* setDbMinRows(SAstCreateContext* pCxt, SDatabaseOptions*
return
pOptions
;
}
static
SDatabaseOptions
*
setDbKeep
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
int64_t
val
=
strtol
(
pVal
->
z
,
NULL
,
10
);
if
(
val
<
TSDB_MIN_KEEP
||
val
>
TSDB_MAX_KEEP
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid db option keep: %"
PRId64
" valid range: [%d, %d]"
,
val
,
TSDB_MIN_KEEP
,
TSDB_MAX_KEEP
);
pCxt
->
valid
=
false
;
return
pOptions
;
}
pOptions
->
keep
=
val
;
return
pOptions
;
}
static
SDatabaseOptions
*
setDbPrecision
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
char
val
[
10
]
=
{
0
};
trimString
(
pVal
->
z
,
pVal
->
n
,
val
,
sizeof
(
val
));
...
...
@@ -291,7 +279,6 @@ static void initSetDatabaseOptionFp() {
setDbOptionFuncs
[
DB_OPTION_FSYNC
]
=
setDbFsync
;
setDbOptionFuncs
[
DB_OPTION_MAXROWS
]
=
setDbMaxRows
;
setDbOptionFuncs
[
DB_OPTION_MINROWS
]
=
setDbMinRows
;
setDbOptionFuncs
[
DB_OPTION_KEEP
]
=
setDbKeep
;
setDbOptionFuncs
[
DB_OPTION_PRECISION
]
=
setDbPrecision
;
setDbOptionFuncs
[
DB_OPTION_QUORUM
]
=
setDbQuorum
;
setDbOptionFuncs
[
DB_OPTION_REPLICA
]
=
setDbReplica
;
...
...
@@ -303,18 +290,6 @@ static void initSetDatabaseOptionFp() {
setDbOptionFuncs
[
DB_OPTION_RETENTIONS
]
=
setDbRetentions
;
}
static
STableOptions
*
setTableKeep
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
int64_t
val
=
strtol
(
pVal
->
z
,
NULL
,
10
);
if
(
val
<
TSDB_MIN_KEEP
||
val
>
TSDB_MAX_KEEP
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid table option keep: %"
PRId64
" valid range: [%d, %d]"
,
val
,
TSDB_MIN_KEEP
,
TSDB_MAX_KEEP
);
pCxt
->
valid
=
false
;
return
pOptions
;
}
pOptions
->
keep
=
val
;
return
pOptions
;
}
static
STableOptions
*
setTableTtl
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
int64_t
val
=
strtol
(
pVal
->
z
,
NULL
,
10
);
if
(
val
<
TSDB_MIN_DB_TTL_OPTION
)
{
...
...
@@ -363,7 +338,6 @@ static STableOptions* setTableDelay(SAstCreateContext* pCxt, STableOptions* pOpt
}
static
void
initSetTableOptionFp
()
{
setTableOptionFuncs
[
TABLE_OPTION_KEEP
]
=
setTableKeep
;
setTableOptionFuncs
[
TABLE_OPTION_TTL
]
=
setTableTtl
;
setTableOptionFuncs
[
TABLE_OPTION_COMMENT
]
=
setTableComment
;
setTableOptionFuncs
[
TABLE_OPTION_FILE_FACTOR
]
=
setTableFileFactor
;
...
...
@@ -892,7 +866,9 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
pOptions
->
fsyncPeriod
=
TSDB_DEFAULT_FSYNC_PERIOD
;
pOptions
->
maxRowsPerBlock
=
TSDB_DEFAULT_MAX_ROW_FBLOCK
;
pOptions
->
minRowsPerBlock
=
TSDB_DEFAULT_MIN_ROW_FBLOCK
;
pOptions
->
keep
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep0
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep1
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep2
=
TSDB_DEFAULT_KEEP
;
pOptions
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
pOptions
->
quorum
=
TSDB_DEFAULT_DB_QUORUM_OPTION
;
pOptions
->
replica
=
TSDB_DEFAULT_DB_REPLICA_OPTION
;
...
...
@@ -915,7 +891,9 @@ SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt) {
pOptions
->
fsyncPeriod
=
-
1
;
pOptions
->
maxRowsPerBlock
=
-
1
;
pOptions
->
minRowsPerBlock
=
-
1
;
pOptions
->
keep
=
-
1
;
pOptions
->
keep0
=
-
1
;
pOptions
->
keep1
=
-
1
;
pOptions
->
keep2
=
-
1
;
pOptions
->
precision
=
-
1
;
pOptions
->
quorum
=
-
1
;
pOptions
->
replica
=
-
1
;
...
...
@@ -931,6 +909,48 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti
return
(
SNode
*
)
setDbOptionFuncs
[
type
](
pCxt
,
(
SDatabaseOptions
*
)
pOptions
,
pVal
);
}
static
bool
checkAndSetKeepOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pKeep
,
int32_t
*
pKeep0
,
int32_t
*
pKeep1
,
int32_t
*
pKeep2
)
{
int32_t
numOfKeep
=
LIST_LENGTH
(
pKeep
);
if
(
numOfKeep
>
3
||
numOfKeep
<
1
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid number of keep options"
);
return
false
;
}
int32_t
daysToKeep0
=
strtol
(((
SValueNode
*
)
nodesListGetNode
(
pKeep
,
0
))
->
literal
,
NULL
,
10
);
int32_t
daysToKeep1
=
numOfKeep
>
1
?
strtol
(((
SValueNode
*
)
nodesListGetNode
(
pKeep
,
1
))
->
literal
,
NULL
,
10
)
:
daysToKeep0
;
int32_t
daysToKeep2
=
numOfKeep
>
2
?
strtol
(((
SValueNode
*
)
nodesListGetNode
(
pKeep
,
2
))
->
literal
,
NULL
,
10
)
:
daysToKeep1
;
if
(
daysToKeep0
<
TSDB_MIN_KEEP
||
daysToKeep1
<
TSDB_MIN_KEEP
||
daysToKeep2
<
TSDB_MIN_KEEP
||
daysToKeep0
>
TSDB_MAX_KEEP
||
daysToKeep1
>
TSDB_MAX_KEEP
||
daysToKeep2
>
TSDB_MAX_KEEP
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid option keep: %"
PRId64
", %"
PRId64
", %"
PRId64
" valid range: [%d, %d]"
,
daysToKeep0
,
daysToKeep1
,
daysToKeep2
,
TSDB_MIN_KEEP
,
TSDB_MAX_KEEP
);
return
false
;
}
if
(
!
((
daysToKeep0
<=
daysToKeep1
)
&&
(
daysToKeep1
<=
daysToKeep2
)))
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid keep value, should be keep0 <= keep1 <= keep2"
);
return
false
;
}
*
pKeep0
=
daysToKeep0
;
*
pKeep1
=
daysToKeep1
;
*
pKeep2
=
daysToKeep2
;
return
true
;
}
SNode
*
setDatabaseKeepOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pKeep
)
{
SDatabaseOptions
*
pOp
=
(
SDatabaseOptions
*
)
pOptions
;
pCxt
->
valid
=
checkAndSetKeepOption
(
pCxt
,
pKeep
,
&
pOp
->
keep0
,
&
pOp
->
keep1
,
&
pOp
->
keep2
);
return
pOptions
;
}
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
)
{
if
(
DB_OPTION_KEEP
==
pAlterOption
->
type
)
{
return
setDatabaseKeepOption
(
pCxt
,
pOptions
,
pAlterOption
->
pKeep
);
}
else
{
return
setDatabaseOption
(
pCxt
,
pOptions
,
pAlterOption
->
type
,
&
pAlterOption
->
val
);
}
}
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
)
{
if
(
!
checkDbName
(
pCxt
,
pDbName
,
false
))
{
return
NULL
;
...
...
@@ -968,7 +988,9 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode*
SNode
*
createDefaultTableOptions
(
SAstCreateContext
*
pCxt
)
{
STableOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_TABLE_OPTIONS
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
keep
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep0
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep1
=
TSDB_DEFAULT_KEEP
;
pOptions
->
keep2
=
TSDB_DEFAULT_KEEP
;
pOptions
->
ttl
=
TSDB_DEFAULT_DB_TTL_OPTION
;
pOptions
->
filesFactor
=
TSDB_DEFAULT_DB_FILE_FACTOR
;
pOptions
->
delay
=
TSDB_DEFAULT_DB_DELAY
;
...
...
@@ -978,7 +1000,9 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
SNode
*
createDefaultAlterTableOptions
(
SAstCreateContext
*
pCxt
)
{
STableOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_TABLE_OPTIONS
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
keep
=
-
1
;
pOptions
->
keep0
=
-
1
;
pOptions
->
keep1
=
-
1
;
pOptions
->
keep2
=
-
1
;
pOptions
->
ttl
=
-
1
;
pOptions
->
filesFactor
=
-
1
;
pOptions
->
delay
=
-
1
;
...
...
@@ -1004,6 +1028,20 @@ SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList*
return
pOptions
;
}
SNode
*
setTableKeepOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pKeep
)
{
STableOptions
*
pOp
=
(
STableOptions
*
)
pOptions
;
pCxt
->
valid
=
checkAndSetKeepOption
(
pCxt
,
pKeep
,
&
pOp
->
keep0
,
&
pOp
->
keep1
,
&
pOp
->
keep2
);
return
pOptions
;
}
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
)
{
if
(
TABLE_OPTION_KEEP
==
pAlterOption
->
type
)
{
return
setTableKeepOption
(
pCxt
,
pOptions
,
pAlterOption
->
pKeep
);
}
else
{
return
setTableOption
(
pCxt
,
pOptions
,
pAlterOption
->
type
,
&
pAlterOption
->
val
);
}
}
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
)
{
SColumnDefNode
*
pCol
=
(
SColumnDefNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN_DEF
);
CHECK_OUT_OF_MEM
(
pCol
);
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
689fb267
...
...
@@ -956,9 +956,9 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
pReq
->
cacheBlockSize
=
pStmt
->
pOptions
->
cacheBlockSize
;
pReq
->
totalBlocks
=
pStmt
->
pOptions
->
numOfBlocks
;
pReq
->
daysPerFile
=
pStmt
->
pOptions
->
daysPerFile
;
pReq
->
daysToKeep0
=
pStmt
->
pOptions
->
keep
;
pReq
->
daysToKeep1
=
-
1
;
pReq
->
daysToKeep2
=
-
1
;
pReq
->
daysToKeep0
=
pStmt
->
pOptions
->
keep
0
;
pReq
->
daysToKeep1
=
pStmt
->
pOptions
->
keep
1
;
pReq
->
daysToKeep2
=
pStmt
->
pOptions
->
keep2
;
pReq
->
minRows
=
pStmt
->
pOptions
->
minRowsPerBlock
;
pReq
->
maxRows
=
pStmt
->
pOptions
->
maxRowsPerBlock
;
pReq
->
commitTime
=
-
1
;
...
...
@@ -1041,9 +1041,9 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt,
tNameSetDbName
(
&
name
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
strlen
(
pStmt
->
dbName
));
tNameGetFullDbName
(
&
name
,
pReq
->
db
);
pReq
->
totalBlocks
=
pStmt
->
pOptions
->
numOfBlocks
;
pReq
->
daysToKeep0
=
pStmt
->
pOptions
->
keep
;
pReq
->
daysToKeep1
=
-
1
;
pReq
->
daysToKeep2
=
-
1
;
pReq
->
daysToKeep0
=
pStmt
->
pOptions
->
keep
0
;
pReq
->
daysToKeep1
=
pStmt
->
pOptions
->
keep
1
;
pReq
->
daysToKeep2
=
pStmt
->
pOptions
->
keep2
;
pReq
->
fsyncPeriod
=
pStmt
->
pOptions
->
fsyncPeriod
;
pReq
->
walLevel
=
pStmt
->
pOptions
->
walLevel
;
pReq
->
quorum
=
pStmt
->
pOptions
->
quorum
;
...
...
source/libs/parser/src/sql.c
浏览文件 @
689fb267
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
tests/script/tsim/db/alter_option.sim
浏览文件 @
689fb267
...
...
@@ -66,7 +66,7 @@ print ============= create database
# | REPLICA value [1 | 3]
# | WAL value [1 | 2]
sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS
240 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1
000 PRECISION 'ns' QUORUM 1 REPLICA 3 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1
sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS
345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440
000 PRECISION 'ns' QUORUM 1 REPLICA 3 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1
sql show databases
print rows: $rows
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
...
...
@@ -92,10 +92,10 @@ endi
if $data5_db != 1 then # quorum
return -1
endi
if $data6_db !=
24
0 then # days
if $data6_db !=
34560
0 then # days
return -1
endi
if $data7_db != 1
000,1000,1
000 then # keep
if $data7_db != 1
440000,1440000,1440
000 then # keep
return -1
endi
if $data8_db != 3 then # cache
...
...
@@ -186,7 +186,7 @@ print ============== modify keep
sql alter database db keep 2000
sql show databases
print keep $data7_db
if $data7_db !=
1000,1
000,2000 then
if $data7_db !=
2000,2
000,2000 then
return -1
endi
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录