From ee14fa074c5e5bd758edd503be646e61a00a407e Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 14 Jul 2020 01:49:25 +0000 Subject: [PATCH] add fsync option --- src/client/src/tscSQLParser.c | 7 +++++++ src/dnode/src/dnodeMgmt.c | 1 + src/inc/ttokendef.h | 1 - src/mnode/src/mnodeDb.c | 7 +++++++ src/query/inc/sql.y | 2 +- src/query/src/sql.c | 10 +++++++--- src/wal/src/walMain.c | 6 +++++- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 056314460d..0fd9efcd6f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5530,6 +5530,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); } + val = htonl(pCreate->fsyncPeriod); + if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) { + snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, + TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); + } + if (pCreate->compression != -1 && (pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) { snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index d0c42c4412..4577a5c31d 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -401,6 +401,7 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { pCreate->cfg.daysToKeep = htonl(pCreate->cfg.daysToKeep); pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock); pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock); + pCreate->cfg.fsyncPeriod = htonl(pCreate->cfg.fsyncPeriod); pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime); for (int32_t j = 0; j < pCreate->cfg.replications; ++j) { diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index c581fc69e2..0b63e9e71d 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -222,7 +222,6 @@ #define TK_INTO 204 #define TK_VALUES 205 - #define TK_SPACE 300 #define TK_COMMENT 301 #define TK_ILLEGAL 302 diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 6bb6f450a5..e3b1603856 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -561,6 +561,12 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "fsync"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 1; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema[cols].name, "comp"); @@ -764,6 +770,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); pCreate->commitTime = htonl(pCreate->commitTime); + pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod); pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock); pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock); diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index a274b5e450..d709b4f838 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -237,7 +237,7 @@ db_optr(Y) ::= db_optr(Z) maxrows(X). { Y = Z; Y.maxRowsPerBlock = strtod db_optr(Y) ::= db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) ctime(X). { Y = Z; Y.commitTime = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } -db_optr(Y) ::= db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtod(X.z, NULL); } +db_optr(Y) ::= db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; } db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; } diff --git a/src/query/src/sql.c b/src/query/src/sql.c index a7f3dd875b..ac9952bb97 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -30,8 +30,12 @@ #include #include #include +#include "qsqlparser.h" +#include "tcmdtype.h" +#include "tstoken.h" +#include "ttokendef.h" #include "tutil.h" - +#include "tvariant.h" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless @@ -2252,7 +2256,7 @@ static void yy_reduce( yymsp[-1].minor.yy158 = yylhsminor.yy158; break; case 93: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtod(yymsp[0].minor.yy0.z, NULL); } +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy158 = yylhsminor.yy158; break; case 94: /* db_optr ::= db_optr comp */ @@ -2273,7 +2277,7 @@ static void yy_reduce( { setDefaultCreateDbOption(&yymsp[1].minor.yy158);} break; case 104: /* alter_db_optr ::= alter_db_optr fsync */ -{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtod(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy158 = yylhsminor.yy158; break; case 105: /* typename ::= ids */ diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index 45bacc317f..9001d29415 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -68,7 +68,10 @@ static void walRelease(SWal *pWal); static void walModuleInitFunc() { walTmrCtrl = taosTmrInit(1000, 100, 300000, "WAL"); - if (walTmrCtrl == NULL) walModuleInit = PTHREAD_ONCE_INIT; + if (walTmrCtrl == NULL) + walModuleInit = PTHREAD_ONCE_INIT; + else + wDebug("WAL module is initialized"); } void *walOpen(const char *path, const SWalCfg *pCfg) { @@ -343,6 +346,7 @@ static void walRelease(SWal *pWal) { if (walTmrCtrl) taosTmrCleanUp(walTmrCtrl); walTmrCtrl = NULL; walModuleInit = PTHREAD_ONCE_INIT; + wDebug("WAL module is cleaned up"); } } -- GitLab