提交 96c4e414 编写于 作者: H hjxilinx

[td-171] suppress create if not exists dbname return error msg

上级 d78d7886
......@@ -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) {
......
......@@ -380,6 +380,7 @@ 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 ||
......@@ -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);
}
int32_t code = tscSendMsgToServer(pSql);
if (pRes->code != TSDB_CODE_SUCCESS) {
tscQueueAsyncRes(pSql);
return pRes->code;
}
code = tscSendMsgToServer(pSql);
if (code != TSDB_CODE_SUCCESS) {
pRes->code = code;
tscQueueAsyncRes(pSql);
......@@ -702,17 +708,18 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
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);
......
......@@ -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];
......
......@@ -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;
......
......@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "tutil.h"
#include "tgrant.h"
......@@ -300,8 +301,13 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
SDbObj *pDb = mgmtGetDb(pCreate->db);
if (pDb != NULL) {
mgmtDecDbRef(pDb);
if (pCreate->ignoreExist) {
return TSDB_CODE_SUCCESS;
} else {
return TSDB_CODE_DB_ALREADY_EXIST;
}
}
code = mgmtCheckDbParams(pCreate);
if (code != TSDB_CODE_SUCCESS) return code;
......@@ -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)
.rowSize = sizeof(SDbObj),
};
code = sdbInsertRow(&oper);
......
......@@ -114,14 +114,13 @@ typedef struct SCreateDBInfo {
int32_t tablesPerVnode;
int32_t daysPerFile;
int32_t rowPerFileBlock;
float numOfAvgCacheBlocks;
int32_t numOfBlocksPerTable;
int64_t commitTime;
int32_t commitLog;
int32_t compressionLevel;
SSQLToken precision;
bool ignoreExists;
tVariantList *keep;
} SCreateDBInfo;
......
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册