未验证 提交 0cea3ab9 编写于 作者: H haojun Liao 提交者: GitHub

Merge pull request #6422 from taosdata/feature/TD-2942

[TD-2942]keep improvement
......@@ -2331,8 +2331,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
if (info.precision == TSDB_TIME_PRECISION_MILLI) {
tickPerSec /= 1000000;
} else if (info.precision == TSDB_TIME_PRECISION_MICRO) {
tickPerSec /= 1000;
}
}
if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10);
......@@ -5937,48 +5939,40 @@ int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlN
}
static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDbInfo* pCreateDb) {
const char* msg = "invalid number of options";
const char* msg1 = "invalid number of keep options";
const char* msg2 = "invalid keep value";
const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2";
pMsg->daysToKeep = htonl(-1);
pMsg->daysToKeep0 = htonl(-1);
pMsg->daysToKeep1 = htonl(-1);
pMsg->daysToKeep2 = htonl(-1);
SArray* pKeep = pCreateDb->keep;
if (pKeep != NULL) {
size_t s = taosArrayGetSize(pKeep);
#ifdef _STORAGE
if (s >= 4 ||s <= 0) {
#else
if (s != 1) {
#endif
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
tVariantListItem* p0 = taosArrayGet(pKeep, 0);
switch (s) {
case 1: {
if ((int32_t)p0->pVar.i64 <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
}
break;
case 2: {
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
break;
}
case 3: {
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
tVariantListItem* p2 = taosArrayGet(pKeep, 2);
tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0;
tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1;
if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64);
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
break;
}
default: { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); }
}
}
return TSDB_CODE_SUCCESS;
......
......@@ -548,7 +548,7 @@ typedef struct {
int32_t totalBlocks;
int32_t maxTables;
int32_t daysPerFile;
int32_t daysToKeep;
int32_t daysToKeep0;
int32_t daysToKeep1;
int32_t daysToKeep2;
int32_t minRowsPerFileBlock;
......
......@@ -104,28 +104,28 @@
#define TK_QTIME 85
#define TK_CONNS 86
#define TK_STATE 87
#define TK_KEEP 88
#define TK_CACHE 89
#define TK_REPLICA 90
#define TK_QUORUM 91
#define TK_DAYS 92
#define TK_MINROWS 93
#define TK_MAXROWS 94
#define TK_BLOCKS 95
#define TK_CTIME 96
#define TK_WAL 97
#define TK_FSYNC 98
#define TK_COMP 99
#define TK_PRECISION 100
#define TK_UPDATE 101
#define TK_CACHELAST 102
#define TK_PARTITIONS 103
#define TK_LP 104
#define TK_RP 105
#define TK_UNSIGNED 106
#define TK_TAGS 107
#define TK_USING 108
#define TK_COMMA 109
#define TK_COMMA 88
#define TK_KEEP 89
#define TK_CACHE 90
#define TK_REPLICA 91
#define TK_QUORUM 92
#define TK_DAYS 93
#define TK_MINROWS 94
#define TK_MAXROWS 95
#define TK_BLOCKS 96
#define TK_CTIME 97
#define TK_WAL 98
#define TK_FSYNC 99
#define TK_COMP 100
#define TK_PRECISION 101
#define TK_UPDATE 102
#define TK_CACHELAST 103
#define TK_PARTITIONS 104
#define TK_LP 105
#define TK_RP 106
#define TK_UNSIGNED 107
#define TK_TAGS 108
#define TK_USING 109
#define TK_AS 110
#define TK_NULL 111
#define TK_SELECT 112
......@@ -212,7 +212,6 @@
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_ILLEGAL 302
......
......@@ -161,7 +161,7 @@ typedef struct {
int32_t totalBlocks;
int32_t maxTables;
int32_t daysPerFile;
int32_t daysToKeep;
int32_t daysToKeep0;
int32_t daysToKeep1;
int32_t daysToKeep2;
int32_t minRowsPerFileBlock;
......
......@@ -261,26 +261,27 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
return TSDB_CODE_MND_INVALID_DB_OPTION_DAYS;
}
if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) {
mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) {
mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep0, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP;
}
if (pCfg->daysToKeep < pCfg->daysPerFile) {
mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile);
if (pCfg->daysToKeep0 < pCfg->daysPerFile) {
mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep0, pCfg->daysPerFile);
return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP;
}
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) {
mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep2, TSDB_MIN_KEEP, pCfg->daysToKeep);
if (pCfg->daysToKeep1 < pCfg->daysToKeep0 || pCfg->daysToKeep1 > TSDB_MAX_KEEP) {
mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, pCfg->daysToKeep0, TSDB_MAX_KEEP);
return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP;
}
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) {
mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2);
if (pCfg->daysToKeep2 < pCfg->daysToKeep1 || pCfg->daysToKeep2 > TSDB_MAX_KEEP) {
mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep2, pCfg->daysToKeep1, TSDB_MAX_KEEP);
return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP;
}
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) {
mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock,
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
......@@ -378,9 +379,9 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = tsBlocksPerVnode;
if (pCfg->maxTables < 0) pCfg->maxTables = tsMaxTablePerVnode;
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = tsDaysPerFile;
if (pCfg->daysToKeep < 0) pCfg->daysToKeep = tsDaysToKeep;
if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep;
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep;
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = tsDaysToKeep;
if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep2;
if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = pCfg->daysToKeep1;
if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock;
if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock;
if (pCfg->fsyncPeriod <0) pCfg->fsyncPeriod = tsFsyncPeriod;
......@@ -435,7 +436,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
.totalBlocks = pCreate->totalBlocks,
.maxTables = pCreate->maxTables,
.daysPerFile = pCreate->daysPerFile,
.daysToKeep = pCreate->daysToKeep,
.daysToKeep0 = pCreate->daysToKeep0,
.daysToKeep1 = pCreate->daysToKeep1,
.daysToKeep2 = pCreate->daysToKeep2,
.minRowsPerFileBlock = pCreate->minRowsPerFileBlock,
......@@ -611,7 +612,12 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "keep0,keep1,keep(D)");
#ifdef _STORAGE
strcpy(pSchema[cols].name, "keep0,keep1,keep2");
#else
strcpy(pSchema[cols].name, "keep");
#endif
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
......@@ -777,7 +783,15 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char tmp[128] = {0};
sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep);
#ifdef _STORAGE
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0);
} else {
sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2);
}
#else
sprintf(tmp, "%d", pDb->cfg.daysToKeep2);
#endif
STR_WITH_SIZE_TO_VARSTR(pWrite, tmp, strlen(tmp));
cols++;
......@@ -895,7 +909,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
pCreate->daysToKeep = htonl(pCreate->daysToKeep);
pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0);
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
pCreate->commitTime = htonl(pCreate->commitTime);
......@@ -922,7 +936,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize);
int32_t totalBlocks = htonl(pAlter->totalBlocks);
int32_t daysPerFile = htonl(pAlter->daysPerFile);
int32_t daysToKeep = htonl(pAlter->daysToKeep);
int32_t daysToKeep0 = htonl(pAlter->daysToKeep0);
int32_t daysToKeep1 = htonl(pAlter->daysToKeep1);
int32_t daysToKeep2 = htonl(pAlter->daysToKeep2);
int32_t minRows = htonl(pAlter->minRowsPerFileBlock);
......@@ -941,6 +955,14 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
terrno = TSDB_CODE_SUCCESS;
//UPGRATE FROM LOW VERSION, reorder it
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
int32_t t = pDb->cfg.daysToKeep0;
newCfg.daysToKeep0 = pDb->cfg.daysToKeep1;
newCfg.daysToKeep1 = pDb->cfg.daysToKeep2;
newCfg.daysToKeep2 = t;
}
if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) {
mError("db:%s, can't alter cache option", pDb->name);
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
......@@ -965,17 +987,17 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
}
if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) {
mDebug("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep, daysToKeep);
newCfg.daysToKeep = daysToKeep;
if (daysToKeep0 > 0 && (daysToKeep0 != pDb->cfg.daysToKeep0 || newCfg.daysToKeep0 != pDb->cfg.daysToKeep0)) {
mDebug("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep0, daysToKeep0);
newCfg.daysToKeep0 = daysToKeep0;
}
if (daysToKeep1 > 0 && daysToKeep1 != pDb->cfg.daysToKeep1) {
if (daysToKeep1 > 0 && (daysToKeep1 != pDb->cfg.daysToKeep1 || newCfg.daysToKeep1 != pDb->cfg.daysToKeep1)) {
mDebug("db:%s, daysToKeep1:%d change to %d", pDb->name, pDb->cfg.daysToKeep1, daysToKeep1);
newCfg.daysToKeep1 = daysToKeep1;
}
if (daysToKeep2 > 0 && daysToKeep2 != pDb->cfg.daysToKeep2) {
if (daysToKeep2 > 0 && (daysToKeep2 != pDb->cfg.daysToKeep2 || newCfg.daysToKeep2 != pDb->cfg.daysToKeep2)) {
mDebug("db:%s, daysToKeep2:%d change to %d", pDb->name, pDb->cfg.daysToKeep2, daysToKeep2);
newCfg.daysToKeep2 = daysToKeep2;
}
......@@ -1068,8 +1090,8 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
// community version can only change daysToKeep
// but enterprise version can change all daysToKeep options
#ifndef _STORAGE
newCfg.daysToKeep1 = newCfg.daysToKeep;
newCfg.daysToKeep2 = newCfg.daysToKeep;
newCfg.daysToKeep1 = newCfg.daysToKeep0;
newCfg.daysToKeep2 = newCfg.daysToKeep0;
#endif
return newCfg;
......@@ -1309,4 +1331,4 @@ int32_t mnodeCompactDbs() {
mInfo("end to compact dbs table...");
return 0;
}
\ No newline at end of file
}
......@@ -894,9 +894,9 @@ static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
pCfg->totalBlocks = htonl(pDb->cfg.totalBlocks);
pCfg->maxTables = htonl(maxTables + 1);
pCfg->daysPerFile = htonl(pDb->cfg.daysPerFile);
pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep);
pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1);
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep2); //FROM DB TO VNODE MAP:
pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep0); //keep0,keep1,keep2 in SQL is mapped to keep1,keep2,keep in vnode
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep1); //user,client,mnode use keep0,keep1,keep2; vnode use keep1,keep2,keep
pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock);
pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock);
pCfg->fsyncPeriod = htonl(pDb->cfg.fsyncPeriod);
......
......@@ -184,11 +184,17 @@ static void *monThreadFunc(void *param) {
static void monBuildMonitorSql(char *sql, int32_t cmd) {
memset(sql, 0, SQL_LENGTH);
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
if (cmd == MON_CMD_CREATE_DB) {
snprintf(sql, SQL_LENGTH,
"create database if not exists %s replica 1 days 10 keep 30 cache %d "
"create database if not exists %s replica 1 days 10 keep %s cache %d "
"blocks %d precision 'us'",
tsMonitorDbName, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS);
tsMonitorDbName, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS);
} else if (cmd == MON_CMD_CREATE_MT_DN) {
snprintf(sql, SQL_LENGTH,
"create table if not exists %s.dn(ts timestamp"
......
......@@ -238,9 +238,18 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K
Y.stat = M;
}
%type intitemlist {SArray*}
%destructor intitemlist {taosArrayDestroy($$);}
%type intitem {tVariant}
intitemlist(A) ::= intitemlist(X) COMMA intitem(Y). { A = tVariantListAppend(X, &Y, -1); }
intitemlist(A) ::= intitem(X). { A = tVariantListAppend(NULL, &X, -1); }
intitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
%type keep {SArray*}
%destructor keep {taosArrayDestroy($$);}
keep(Y) ::= KEEP tagitemlist(X). { Y = X; }
keep(Y) ::= KEEP intitemlist(X). { Y = X; }
cache(Y) ::= CACHE INTEGER(X). { Y = X; }
replica(Y) ::= REPLICA INTEGER(X). { Y = X; }
......
此差异已折叠。
......@@ -193,7 +193,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_DROPPING, "Database not availabl
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_READY, "Database unsynced")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_DAYS, "Invalid database option: days out of range")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_KEEP, "Invalid database option: keep >= keep1 >= keep0 >= days")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_KEEP, "Invalid database option: keep2 >= keep1 >= keep0 >= days")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC, "Invalid topic name")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC_OPTION, "Invalid topic option")
......
......@@ -72,9 +72,9 @@ class TDTestCase:
tdSql.query('show databases')
tdSql.checkData(0,7,'3650,3650,3650')
tdSql.error('alter database db keep 10')
tdSql.execute('alter database db keep 10')
tdSql.query('show databases')
tdSql.checkData(0,7,'3650,3650,3650')
tdSql.checkData(0,7,'10,10,10')
## the order for altering keep is keep(D), keep0, keep1.
## if the order is changed, please modify the following test
......@@ -84,17 +84,17 @@ class TDTestCase:
tdSql.query('show databases')
tdSql.checkData(0,7,'10,10,10')
tdSql.execute('alter database db keep 100, 98 ,99')
tdSql.error('alter database db keep 100, 98 ,99')
tdSql.query('show databases')
tdSql.checkData(0,7,'98,99,100')
tdSql.checkData(0,7,'10,10,10')
tdSql.execute('alter database db keep 200, 200 ,200')
tdSql.query('show databases')
tdSql.checkData(0,7,'200,200,200')
tdSql.error('alter database db keep 198, 199 ,200')
tdSql.execute('alter database db keep 198, 199 ,200')
tdSql.query('show databases')
tdSql.checkData(0,7,'200,200,200')
tdSql.checkData(0,7,'198,199,200')
# tdSql.execute('alter database db keep 3650,3650,3650')
# tdSql.error('alter database db keep 4000,3640')
......
......@@ -112,21 +112,21 @@ endi
sql alter database db keep 30
sql show databases
print keep $data7_db
if $data7_db != 20,20,30 then
if $data7_db != 30,30,30 then
return -1
endi
sql alter database db keep 40
sql show databases
print keep $data7_db
if $data7_db != 20,20,40 then
if $data7_db != 40,40,40 then
return -1
endi
sql alter database db keep 40
sql alter database db keep 30
sql alter database db keep 40,50
sql alter database db keep 30,31
sql alter database db keep 20
sql_error alter database db keep 10
sql_error alter database db keep 10.0
sql_error alter database db keep 9
sql_error alter database db keep 1
sql_error alter database db keep 0
......
......@@ -367,7 +367,7 @@ sql_error topic db keep 30
sql alter database db keep 30
sql show databases
print keep $data7_db
if $data7_db != 20,20,30 then
if $data7_db != 30,30,30 then
return -1
endi
......@@ -375,14 +375,14 @@ sql_error alter topic db keep 40
sql alter database db keep 40
sql show databases
print keep $data7_db
if $data7_db != 20,20,40 then
if $data7_db != 40,40,40 then
return -1
endi
sql alter database db keep 40
sql alter database db keep 30
sql alter database db keep 20
sql_error alter database db keep 10
sql_error alter database db keep 10.0
sql_error alter database db keep 9
sql_error alter database db keep 1
sql_error alter database db keep 0
......
......@@ -88,7 +88,7 @@ print =============== step2 - no db
#11
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql
print 11-> $system_content
if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep(D)","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep(D)",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then
if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep2","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep2",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then
return -1
endi
......
......@@ -20,8 +20,82 @@ $db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database if exists $db
sql create database $db
sql create database $db days 10 keep 20,20,20
sql use $db
sql_error alter database $db keep "20"
sql_error alter database $db keep "20","20","20"
sql_error alter database $db keep 20,19
sql_error alter database $db keep 20.0
sql_error alter database $db keep 20.0,20.0,20.0
sql_error alter database $db keep 0,0,0
sql_error alter database $db keep -1,-1,-1
sql_error alter database $db keep 9,20
sql_error alter database $db keep 9,9,9
sql_error alter database $db keep 20,20,19
sql_error alter database $db keep 20,19,20
sql_error alter database $db keep 20,19,19
sql_error alter database $db keep 20,19,18
sql_error alter database $db keep 20,20,20,20
sql_error alter database $db keep 365001,365001,365001
sql alter database $db keep 21
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 21,21,21 then
return -1
endi
sql alter database $db keep 11,12
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,12,12 then
return -1
endi
sql alter database $db keep 20,20,20
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 20,20,20 then
return -1
endi
sql alter database $db keep 10,10,10
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 10,10,10 then
return -1
endi
sql alter database $db keep 10,10,11
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 10,10,11 then
return -1
endi
sql alter database $db keep 11,12,13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,12,13 then
return -1
endi
sql alter database $db keep 365000,365000,365000
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 365000,365000,365000 then
return -1
endi
##### alter table test, simeplest case
sql create table tb (ts timestamp, c1 int, c2 int, c3 int)
sql insert into tb values (now, 1, 1, 1)
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
$dbPrefix = m_alt_db
$tbPrefix = m_alt_tb
$mtPrefix = m_alt_mt
$tbNum = 10
$rowNum = 5
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== alter.sim
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database if exists $db
sql create database $db days 10 keep 20
sql use $db
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 20 then
return -1
endi
sql_error alter database $db keep "20"
sql_error alter database $db keep "20","20","20"
sql_error alter database $db keep 0
sql_error alter database $db keep 20.0
sql_error alter database $db keep 20.0,20.0,20.0
sql_error alter database $db keep 0,0,0
sql_error alter database $db keep 3
sql_error alter database $db keep -1,-1,-1
sql_error alter database $db keep 20,20
sql_error alter database $db keep 9,9,9
sql_error alter database $db keep 20,20,19
sql_error alter database $db keep 20,19,20
sql_error alter database $db keep 20,19,19
sql_error alter database $db keep 20,19,18
sql_error alter database $db keep 20,20,20,20
sql_error alter database $db keep 365001,365001,365001
sql_error alter database $db keep 365001
sql alter database $db keep 20
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 20 then
return -1
endi
sql alter database $db keep 10
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 10 then
return -1
endi
sql alter database $db keep 11
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11 then
return -1
endi
sql alter database $db keep 13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 13 then
return -1
endi
sql alter database $db keep 365000
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 365000 then
return -1
endi
##### alter table test, simeplest case
sql create table tb (ts timestamp, c1 int, c2 int, c3 int)
sql insert into tb values (now, 1, 1, 1)
sql select * from tb order by ts desc
if $rows != 1 then
return -1
endi
sql alter table tb drop column c3
sql select * from tb order by ts desc
if $data01 != 1 then
return -1
endi
if $data02 != 1 then
return -1
endi
if $data03 != null then
return -1
endi
sql alter table tb add column c3 nchar(4)
sql select * from tb order by ts desc
if $rows != 1 then
return -1
endi
if $data03 != NULL then
return -1
endi
sql insert into tb values (now, 2, 2, 'taos')
sql select * from tb order by ts desc
if $rows != 2 then
return -1
endi
print data03 = $data03
if $data03 != taos then
print expect taos, actual: $data03
return -1
endi
sql drop table tb
##### alter metric test, simplest case
sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int)
sql create table tb using mt tags(1)
sql insert into tb values (now, 1, 1, 1)
sql alter table mt drop column c3
sql select * from tb order by ts desc
if $data01 != 1 then
return -1
endi
if $data02 != 1 then
return -1
endi
if $data03 != null then
return -1
endi
sql alter table mt add column c3 nchar(4)
sql select * from tb order by ts desc
if $data03 != NULL then
return -1
endi
sql insert into tb values (now, 2, 2, 'taos')
sql select * from tb order by ts desc
if $rows != 2 then
return -1
endi
if $data03 != taos then
return -1
endi
if $data13 != NULL then
return -1
endi
sql drop table tb
sql drop table mt
## [TBASE272]
sql create table tb (ts timestamp, c1 int, c2 int, c3 int)
sql insert into tb values (now, 1, 1, 1)
sql alter table tb drop column c3
sql alter table tb add column c3 nchar(5)
sql insert into tb values(now, 2, 2, 'taos')
sql drop table tb
sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int)
sql create table tb using mt tags(1)
sql insert into tb values (now, 1, 1, 1)
sql alter table mt drop column c3
sql select * from tb order by ts desc
if $rows != 1 then
return -1
endi
sql drop table tb
sql drop table mt
sleep 100
### ALTER TABLE WHILE STREAMING [TBASE271]
#sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int)
#sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s)
#sql select * from strm
#if $rows != 0 then
# return -1
#endi
##sleep 12000
#sql insert into tb1 values (now, 1, 'taos', 1)
#sleep 20000
#sql select * from strm
#print rows = $rows
#if $rows != 1 then
# return -1
#endi
#if $data04 != 1 then
# return -1
#endi
#sql alter table tb1 drop column c3
#sleep 500
#sql insert into tb1 values (now, 2, 'taos')
#sleep 30000
#sql select * from strm
#if $rows != 2 then
# return -1
#endi
#if $data04 != 1 then
# return -1
#endi
#sql alter table tb1 add column c3 int
#sleep 500
#sql insert into tb1 values (now, 3, 'taos', 3);
#sleep 100
#sql select * from strm
#if $rows != 3 then
# return -1
#endi
#if $data04 != 1 then
# return -1
#endi
## ALTER TABLE AND INSERT BY COLUMNS
sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int)
sql create table tb using mt tags(0)
sql insert into tb values (now-1m, 1, 1)
sql alter table mt drop column c2
sql_error insert into tb (ts, c1, c2) values (now, 2, 2)
sql insert into tb (ts, c1) values (now, 2)
sql select * from tb order by ts desc
if $rows != 2 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != null then
return -1
endi
sql alter table mt add column c2 int
sql insert into tb (ts, c2) values (now, 3)
sql select * from tb order by ts desc
if $data02 != 3 then
return -1
endi
## ALTER TABLE AND IMPORT
sql drop database $db
sql create database $db
sql use $db
sql create table mt (ts timestamp, c1 int, c2 nchar(7), c3 int) tags (t1 int)
sql create table tb using mt tags(1)
sleep 100
sql insert into tb values ('2018-11-01 16:30:00.000', 1, 'insert', 1)
sql alter table mt drop column c3
sql insert into tb values ('2018-11-01 16:29:59.000', 1, 'insert')
sql import into tb values ('2018-11-01 16:29:59.000', 1, 'import')
sql select * from tb order by ts desc
if $data01 != 1 then
return -1
endi
if $data02 != insert then
return -1
endi
sql alter table mt add column c3 nchar(4)
sql select * from tb order by ts desc
if $data03 != NULL then
return -1
endi
print ============================>TD-3366 TD-3486
sql insert into td_3366(ts, c3, c1) using mt(t1) tags(911) values('2018-1-1 11:11:11', 'new1', 12);
sql insert into td_3486(ts, c3, c1) using mt(t1) tags(-12) values('2018-1-1 11:11:11', 'new1', 12);
sql insert into ttxu(ts, c3, c1) using mt(t1) tags('-121') values('2018-1-1 11:11:11', 'new1', 12);
sql insert into tb(ts, c1, c3) using mt(t1) tags(123) values('2018-11-01 16:29:58.000', 2, 'port')
sql insert into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3)
sql import into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3)
sql import into tb values ('2018-11-01 16:39:58.000', 2, 'import', 3)
sql select * from tb order by ts desc
if $rows != 4 then
return -1
endi
if $data03 != 3 then
return -1
endi
##### ILLEGAL OPERATIONS
# try dropping columns that are defined in metric
sql_error alter table tb drop column c1;
# try dropping primary key
sql_error alter table mt drop column ts;
# try modifying two columns in a single statement
sql_error alter table mt add column c5 nchar(3) c6 nchar(4)
# duplicate columns
sql_error alter table mt add column c1 int
# drop non-existing columns
sql_error alter table mt drop column c9
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -102,7 +102,7 @@ print create_db.sim case5: db_meta_data test
# cfg params
$replica = 1 # max=3
$days = 10
$keep = 365
$keep = 365,365,365
$rows_db = 1000
$cache = 16 # 16MB
$ablocks = 100
......@@ -150,6 +150,73 @@ sql_error create database $db day 3651
# keep [1, infinity]
sql_error create database $db keep 0
sql_error create database $db keep 0,0,0
sql_error create database $db keep 3,3,3
sql_error create database $db keep 11.0
sql_error create database $db keep 11.0,11.0,11.0
sql_error create database $db keep "11","11","11"
sql_error create database $db keep "11"
sql_error create database $db keep 13,12,11
sql_error create database $db keep 11,12,11
sql_error create database $db keep 12,11,12
sql_error create database $db keep 8
sql_error create database $db keep 12,11
sql_error create database $db keep 365001,365001,365001
sql create database dbk0 keep 19
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 19,19,19 then
return -1
endi
sql drop database dbk0
sql create database dbka keep 19,20
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 19,20,20 then
return -1
endi
sql drop database dbka
sql create database dbk1 keep 11,11,11
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,11,11 then
return -1
endi
sql drop database dbk1
sql create database dbk2 keep 11,12,13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,12,13 then
return -1
endi
sql drop database dbk2
sql create database dbk3 keep 11,11,13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,11,13 then
return -1
endi
sql drop database dbk3
sql create database dbk4 keep 11,13,13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11,13,13 then
return -1
endi
sql drop database dbk4
#sql_error create database $db keep 3651
# rows [200, 10000]
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
print ======================== dnode1 start
$dbPrefix = fi_in_db
$tbPrefix = fi_in_tb
$mtPrefix = fi_in_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print excuting test script create_db.sim
print =============== set up
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql_error createdatabase $db
sql create database $db
sql use $db
sql show databases
if $rows != 1 then
return -1
endi
if $data00 != $db then
return -1
endi
sql drop database $db
# case1: case_insensitivity test
print =========== create_db.sim case1: case insensitivity test
sql_error CREATEDATABASE $db
sql CREATE DATABASE $db
sql use $db
sql show databases
if $rows != 1 then
return -1
endi
if $data00 != $db then
return -1
endi
sql drop database $db
print case_insensitivity test passed
# case2: illegal_db_name test
print =========== create_db.sim case2: illegal_db_name test
$illegal_db1 = 1db
$illegal_db2 = d@b
sql_error create database $illegal_db1
sql_error create database $illegal_db2
print illegal_db_name test passed
# case3: chinese_char_in_db_name test
print ========== create_db.sim case3: chinese_char_in_db_name test
$CN_db1 = 数据库
$CN_db2 = 数据库1
$CN_db3 = db数据库1
sql_error create database $CN_db1
sql_error create database $CN_db2
sql_error create database $CN_db3
#sql show databases
#if $rows != 3 then
# return -1
#endi
#if $data00 != $CN_db1 then
# return -1
#endi
#if $data10 != $CN_db2 then
# return -1
#endi
#if $data20 != $CN_db3 then
# return -1
#endi
#sql drop database $CN_db1
#sql drop database $CN_db2
#sql drop database $CN_db3
print case_chinese_char_in_db_name test passed
# case4: db_already_exists
print create_db.sim case4: db_already_exists
sql create database db0
sql create database db0
sql show databases
if $rows != 1 then
return -1
endi
sql drop database db0
print db_already_exists test passed
# case5: db_meta_data
print create_db.sim case5: db_meta_data test
# cfg params
$replica = 1 # max=3
$days = 10
$keep = 365
$rows_db = 1000
$cache = 16 # 16MB
$ablocks = 100
$tblocks = 32 # max=512, automatically trimmed when exceeding
$ctime = 36000 # 10 hours
$wal = 1 # valid value is 1, 2
$comp = 1 # max=32, automatically trimmed when exceeding
sql create database $db replica $replica days $days keep $keep maxrows $rows_db cache $cache blocks 4 ctime $ctime wal $wal comp $comp
sql show databases
if $rows != 1 then
return -1
endi
if $data00 != $db then
return -1
endi
if $data04 != $replica then
return -1
endi
if $data06 != $days then
return -1
endi
if $data07 != 365 then
return -1
endi
print data08 = $data07
if $data08 != $cache then
print expect $cache, actual:$data08
return -1
endi
if $data09 != 4 then
return -1
endi
sql drop database $db
## param range tests
# replica [1,3]
#sql_error create database $db replica 0
sql_error create database $db replica 4
# day [1, 3650]
sql_error create database $db day 0
sql_error create database $db day 3651
# keep [1, infinity]
sql_error create database $db keep 0
sql_error create database $db keep 0,0,0
sql_error create database $db keep 3,3,3
sql_error create database $db keep 3
sql_error create database $db keep 11.0
sql_error create database $db keep 11.0,11.0,11.0
sql_error create database $db keep "11","11","11"
sql_error create database $db keep "11"
sql_error create database $db keep 13,12,11
sql_error create database $db keep 11,12,11
sql_error create database $db keep 12,11,12
sql_error create database $db keep 11,12,13
sql_error create database $db keep 11,12,13,14
sql_error create database $db keep 11,11
sql_error create database $db keep 365001,365001,365001
sql_error create database $db keep 365001
sql create database dbk1 keep 11
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11 then
return -1
endi
sql drop database dbk1
sql create database dbk2 keep 12
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 12 then
return -1
endi
sql drop database dbk2
sql create database dbk3 keep 11
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 11 then
return -1
endi
sql drop database dbk3
sql create database dbk4 keep 13
sql show databases
if $rows != 1 then
return -1
endi
if $data07 != 13 then
return -1
endi
sql drop database dbk4
#sql_error create database $db keep 3651
# rows [200, 10000]
sql_error create database $db maxrows 199
#sql_error create database $db maxrows 10001
# cache [100, 10485760]
sql_error create database $db cache 0
#sql_error create database $db cache 10485761
# blocks [32, 4096 overwriten by 4096 if exceeds, Note added:2018-10-24]
#sql_error create database $db tblocks 31
#sql_error create database $db tblocks 4097
# ctime [30, 40960]
sql_error create database $db ctime 29
sql_error create database $db ctime 40961
# wal {0, 2}
#sql_error create database $db wal 0
sql_error create database $db wal -1
sql_error create database $db wal 3
# comp {0, 1, 2}
sql_error create database $db comp -1
sql_error create database $db comp 3
sql_error drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -124,4 +124,4 @@ if $rows != 10000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -367,4 +367,4 @@ if $data35 != 5 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -902,4 +902,4 @@ sql_error select first(c1), count(*), t2, t1, tbname from select_tags_mt0 group
#sql select count(c1) from select_tags_mt0 where c1=99 group by tbname;
#sql select count(*),tbname from select_tags_mt0 group by tbname
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -175,7 +175,7 @@ if $data21 != 2.10000 then
endi
print =====================td-1302 case
sql create database t1 keep 36500;
sql create database t1 keep 36500
sql use t1;
sql create table test(ts timestamp, k int);
sql insert into test values(29999, 1)(70000, 2)(80000, 3)
......@@ -194,7 +194,7 @@ if $rows != 3 then
endi
print ==============>td-1308
sql create database db keep 36500;
sql create database db keep 36500
sql use db;
sql create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10));
......@@ -377,4 +377,4 @@ sql_error select * from ttm2 where k<>null
sql_error select * from ttm2 where k like null
sql_error select * from ttm2 where k<null
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -424,6 +424,10 @@ cd ../../../debug; make
./test.sh -f general/parser/stableOp.sim
./test.sh -f general/parser/timestamp.sim
./test.sh -f general/parser/sliding.sim
./test.sh -f general/parser/having.sim
./test.sh -f general/parser/having_child.sim
./test.sh -f general/parser/between_and.sim
./test.sh -f general/parser/last_cache.sim
./test.sh -f unique/big/balance.sim
#======================b7-end===============
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册