diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 077339f3eeaf8ffd5c19b04eb9a52e301e64da0a..3abbe346ace2f536c407dcfe9ab9349fac7c1249 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4784,6 +4784,7 @@ static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { pMsg->rowsInFileBlock = htonl(pCreateDb->rowPerFileBlock); pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); pMsg->replications = pCreateDb->replica; + pMsg->ignoreExist = pCreateDb->ignoreExists; } int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f2570fb22994e80e542ef3a6d2350a4aea30c6fd..bab66bcc184dae3ff33f268a27f0ee8a9b7e8571 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -380,7 +380,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { int doProcessSql(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - + int32_t code = TSDB_CODE_SUCCESS; + if (pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_RETRIEVE || @@ -389,10 +390,15 @@ int doProcessSql(SSqlObj *pSql) { pCmd->command == TSDB_SQL_HB || pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_STABLEVGROUP) { - tscBuildMsg[pCmd->command](pSql, NULL); + pRes->code = tscBuildMsg[pCmd->command](pSql, NULL); + } + + if (pRes->code != TSDB_CODE_SUCCESS) { + tscQueueAsyncRes(pSql); + return pRes->code; } - int32_t code = tscSendMsgToServer(pSql); + code = tscSendMsgToServer(pSql); if (code != TSDB_CODE_SUCCESS) { pRes->code = code; tscQueueAsyncRes(pSql); @@ -701,18 +707,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); char *pMsg = (char *)(pQueryMsg->colList) + numOfCols * sizeof(SColumnInfo); SSchema *pSchema = tscGetTableSchema(pTableMeta); - + + int32_t total = tscGetNumOfColumns(pTableMeta) + tscGetNumOfTags(pTableMeta); for (int32_t i = 0; i < numOfCols; ++i) { SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i); SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex]; - if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL || + if (pCol->colIndex.columnIndex >= total || pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR) { tscError("%p sid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s", pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, pColSchema->name); - return -1; // 0 means build msg failed + return TSDB_CODE_INVALID_SQL; } pQueryMsg->colList[i].colId = htons(pColSchema->colId); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 7d9c343a85d33e0f93d6b3071329bdaf967d44d9..636d5b863ba05af546776825e53a6a4c6421e43d 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -515,8 +515,8 @@ typedef struct { } SVnodeLoad; typedef struct { - char acct[TSDB_USER_LEN + 1]; - char db[TSDB_DB_NAME_LEN + 1]; + char acct[TSDB_USER_LEN]; + char db[TSDB_DB_NAME_LEN]; uint32_t vgId; int32_t maxSessions; int32_t cacheBlockSize; @@ -537,8 +537,8 @@ typedef struct { int8_t repStrategy; int8_t loadLatest; // load into mem or not uint8_t precision; // time resolution - int8_t reserved[16]; -} SDbCfg, SCMCreateDbMsg, SCMAlterDbMsg; + int8_t ignoreExist; +} SCMCreateDbMsg, SCMAlterDbMsg; typedef struct { char db[TSDB_TABLE_ID_LEN + 1]; diff --git a/src/mnode/inc/mgmtDef.h b/src/mnode/inc/mgmtDef.h index 7ed4507ee2e4d0c16b118235e93f23bcddb9bf59..5599ad2e4f19538d345107354a4dc09eb15793e7 100644 --- a/src/mnode/inc/mgmtDef.h +++ b/src/mnode/inc/mgmtDef.h @@ -29,6 +29,32 @@ struct SAcctObj; struct SUserObj; struct SMnodeObj; +typedef struct { + char acct[TSDB_USER_LEN]; + char db[TSDB_DB_NAME_LEN]; + uint32_t vgId; + int32_t maxSessions; + int32_t cacheBlockSize; + union { + int32_t totalBlocks; + float fraction; + } cacheNumOfBlocks; + int32_t daysPerFile; + int32_t daysToKeep1; + int32_t daysToKeep2; + int32_t daysToKeep; + int32_t commitTime; + int32_t rowsInFileBlock; + int16_t blocksPerTable; + int8_t compression; + int8_t commitLog; + int8_t replications; + int8_t repStrategy; + int8_t loadLatest; // load into mem or not + uint8_t precision; // time resolution + int8_t reserved[16]; +} SDbCfg; + typedef struct SDnodeObj { int32_t dnodeId; uint32_t privateIp; @@ -53,7 +79,7 @@ typedef struct SDnodeObj { int32_t refCount; uint32_t moduleStatus; uint32_t lastReboot; // time stamp for last reboot - float score; // calc in balance function + float score; // calc in balance function float diskAvailable; // from dnode status msg int16_t diskAvgUsage; // calc from sys.disk int16_t cpuAvgUsage; // calc from sys.cpu diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index d57b75501ade303133fd594008c5869659a7b7b5..61b5c985c6acb3cf15b0b2deef3476edf6a96697 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" + #include "taoserror.h" #include "tutil.h" #include "tgrant.h" @@ -300,7 +301,12 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { SDbObj *pDb = mgmtGetDb(pCreate->db); if (pDb != NULL) { mgmtDecDbRef(pDb); - return TSDB_CODE_DB_ALREADY_EXIST; + + if (pCreate->ignoreExist) { + return TSDB_CODE_SUCCESS; + } else { + return TSDB_CODE_DB_ALREADY_EXIST; + } } code = mgmtCheckDbParams(pCreate); @@ -313,18 +319,41 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { return code; } - pDb = malloc(sizeof(SDbObj)); - memset(pDb, 0, sizeof(SDbObj)); - strcpy(pDb->name, pCreate->db); - strcpy(pCreate->acct, pAcct->user); + pDb = calloc(1, sizeof(SDbObj)); + + strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN); + strncpy(pCreate->acct, pAcct->user, TSDB_USER_LEN); + pDb->createdTime = taosGetTimestampMs(); - pDb->cfg = *pCreate; + + pDb->cfg = (SDbCfg) { + .vgId = pCreate->vgId, + .precision = pCreate->precision, + .maxSessions = pCreate->maxSessions, + .cacheNumOfBlocks.totalBlocks = pCreate->cacheNumOfBlocks.totalBlocks, + .rowsInFileBlock = pCreate->rowsInFileBlock, + .commitLog = pCreate->commitLog, + .replications = pCreate->replications, + .daysPerFile = pCreate->daysPerFile, + .cacheBlockSize = pCreate->cacheBlockSize, + .commitTime = pCreate->commitTime, + .blocksPerTable = pCreate->blocksPerTable, + .compression = pCreate->compression, + .daysToKeep = pCreate->daysToKeep, + .daysToKeep1 = pCreate->daysToKeep1, + .daysToKeep2 = pCreate->daysToKeep2, + .loadLatest = pCreate->loadLatest, + .repStrategy = pCreate->repStrategy, + }; + + strncpy(pDb->cfg.db, pCreate->db, TSDB_DB_NAME_LEN); + strncpy(pDb->cfg.acct, pCreate->acct, TSDB_USER_LEN); SSdbOper oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb, - .rowSize = sizeof(SDbObj) + .type = SDB_OPER_GLOBAL, + .table = tsDbSdb, + .pObj = pDb, + .rowSize = sizeof(SDbObj), }; code = sdbInsertRow(&oper); diff --git a/src/query/inc/qsqlparser.h b/src/query/inc/qsqlparser.h index b1799b6902d5d66df7dac792e15461337d71936c..42dda2308fe0d487e7d1417df8eb5853f73868a9 100644 --- a/src/query/inc/qsqlparser.h +++ b/src/query/inc/qsqlparser.h @@ -114,14 +114,13 @@ typedef struct SCreateDBInfo { int32_t tablesPerVnode; int32_t daysPerFile; int32_t rowPerFileBlock; - - float numOfAvgCacheBlocks; - int32_t numOfBlocksPerTable; - + float numOfAvgCacheBlocks; + int32_t numOfBlocksPerTable; int64_t commitTime; int32_t commitLog; int32_t compressionLevel; SSQLToken precision; + bool ignoreExists; tVariantList *keep; } SCreateDBInfo; diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index 28b30f6549a952856a520b169fa11a31f4f6c358..075dbc9d14b2fda785e3730275b5e1803f1ea570 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -815,8 +815,7 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI pInfo->pDCLInfo->dbOpt = *pDB; pInfo->pDCLInfo->dbOpt.dbname = *pToken; - - tTokenListAppend(pInfo->pDCLInfo, pIgExists); + pInfo->pDCLInfo->dbOpt.ignoreExists = (pIgExists != NULL); } void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) { diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 1f4ab0941993ba9f67f352f531c79e1cbd7e7aeb..b2c814d101e8eee0f6176fccd4c9f152c49fa6d0 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -3555,7 +3555,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult * int32_t setAdditionalInfo(SQInfo *pQInfo, STable *pTable, STableQueryInfo *pTableQueryInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; - assert(pTableQueryInfo->lastKey > 0); + assert(pTableQueryInfo->lastKey >= 0); setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb);