提交 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) { ...@@ -4784,6 +4784,7 @@ static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
pMsg->rowsInFileBlock = htonl(pCreateDb->rowPerFileBlock); pMsg->rowsInFileBlock = htonl(pCreateDb->rowPerFileBlock);
pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); pMsg->daysPerFile = htonl(pCreateDb->daysPerFile);
pMsg->replications = pCreateDb->replica; pMsg->replications = pCreateDb->replica;
pMsg->ignoreExist = pCreateDb->ignoreExists;
} }
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
......
...@@ -380,7 +380,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { ...@@ -380,7 +380,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
int doProcessSql(SSqlObj *pSql) { int doProcessSql(SSqlObj *pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
int32_t code = TSDB_CODE_SUCCESS;
if (pCmd->command == TSDB_SQL_SELECT || if (pCmd->command == TSDB_SQL_SELECT ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE ||
...@@ -389,10 +390,15 @@ int doProcessSql(SSqlObj *pSql) { ...@@ -389,10 +390,15 @@ int doProcessSql(SSqlObj *pSql) {
pCmd->command == TSDB_SQL_HB || pCmd->command == TSDB_SQL_HB ||
pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_META ||
pCmd->command == TSDB_SQL_STABLEVGROUP) { 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) { if (code != TSDB_CODE_SUCCESS) {
pRes->code = code; pRes->code = code;
tscQueueAsyncRes(pSql); tscQueueAsyncRes(pSql);
...@@ -701,18 +707,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -701,18 +707,19 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
char *pMsg = (char *)(pQueryMsg->colList) + numOfCols * sizeof(SColumnInfo); char *pMsg = (char *)(pQueryMsg->colList) + numOfCols * sizeof(SColumnInfo);
SSchema *pSchema = tscGetTableSchema(pTableMeta); SSchema *pSchema = tscGetTableSchema(pTableMeta);
int32_t total = tscGetNumOfColumns(pTableMeta) + tscGetNumOfTags(pTableMeta);
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i); SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex]; 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) { 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", 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, pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex,
pColSchema->name); pColSchema->name);
return -1; // 0 means build msg failed return TSDB_CODE_INVALID_SQL;
} }
pQueryMsg->colList[i].colId = htons(pColSchema->colId); pQueryMsg->colList[i].colId = htons(pColSchema->colId);
......
...@@ -515,8 +515,8 @@ typedef struct { ...@@ -515,8 +515,8 @@ typedef struct {
} SVnodeLoad; } SVnodeLoad;
typedef struct { typedef struct {
char acct[TSDB_USER_LEN + 1]; char acct[TSDB_USER_LEN];
char db[TSDB_DB_NAME_LEN + 1]; char db[TSDB_DB_NAME_LEN];
uint32_t vgId; uint32_t vgId;
int32_t maxSessions; int32_t maxSessions;
int32_t cacheBlockSize; int32_t cacheBlockSize;
...@@ -537,8 +537,8 @@ typedef struct { ...@@ -537,8 +537,8 @@ typedef struct {
int8_t repStrategy; int8_t repStrategy;
int8_t loadLatest; // load into mem or not int8_t loadLatest; // load into mem or not
uint8_t precision; // time resolution uint8_t precision; // time resolution
int8_t reserved[16]; int8_t ignoreExist;
} SDbCfg, SCMCreateDbMsg, SCMAlterDbMsg; } SCMCreateDbMsg, SCMAlterDbMsg;
typedef struct { typedef struct {
char db[TSDB_TABLE_ID_LEN + 1]; char db[TSDB_TABLE_ID_LEN + 1];
......
...@@ -29,6 +29,32 @@ struct SAcctObj; ...@@ -29,6 +29,32 @@ struct SAcctObj;
struct SUserObj; struct SUserObj;
struct SMnodeObj; 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 { typedef struct SDnodeObj {
int32_t dnodeId; int32_t dnodeId;
uint32_t privateIp; uint32_t privateIp;
...@@ -53,7 +79,7 @@ typedef struct SDnodeObj { ...@@ -53,7 +79,7 @@ typedef struct SDnodeObj {
int32_t refCount; int32_t refCount;
uint32_t moduleStatus; uint32_t moduleStatus;
uint32_t lastReboot; // time stamp for last reboot 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 float diskAvailable; // from dnode status msg
int16_t diskAvgUsage; // calc from sys.disk int16_t diskAvgUsage; // calc from sys.disk
int16_t cpuAvgUsage; // calc from sys.cpu int16_t cpuAvgUsage; // calc from sys.cpu
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tutil.h" #include "tutil.h"
#include "tgrant.h" #include "tgrant.h"
...@@ -300,7 +301,12 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { ...@@ -300,7 +301,12 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
SDbObj *pDb = mgmtGetDb(pCreate->db); SDbObj *pDb = mgmtGetDb(pCreate->db);
if (pDb != NULL) { if (pDb != NULL) {
mgmtDecDbRef(pDb); 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); code = mgmtCheckDbParams(pCreate);
...@@ -313,18 +319,41 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { ...@@ -313,18 +319,41 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) {
return code; return code;
} }
pDb = malloc(sizeof(SDbObj)); pDb = calloc(1, sizeof(SDbObj));
memset(pDb, 0, sizeof(SDbObj));
strcpy(pDb->name, pCreate->db); strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN);
strcpy(pCreate->acct, pAcct->user); strncpy(pCreate->acct, pAcct->user, TSDB_USER_LEN);
pDb->createdTime = taosGetTimestampMs(); 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 = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDbSdb, .table = tsDbSdb,
.pObj = pDb, .pObj = pDb,
.rowSize = sizeof(SDbObj) .rowSize = sizeof(SDbObj),
}; };
code = sdbInsertRow(&oper); code = sdbInsertRow(&oper);
......
...@@ -114,14 +114,13 @@ typedef struct SCreateDBInfo { ...@@ -114,14 +114,13 @@ typedef struct SCreateDBInfo {
int32_t tablesPerVnode; int32_t tablesPerVnode;
int32_t daysPerFile; int32_t daysPerFile;
int32_t rowPerFileBlock; int32_t rowPerFileBlock;
float numOfAvgCacheBlocks;
float numOfAvgCacheBlocks; int32_t numOfBlocksPerTable;
int32_t numOfBlocksPerTable;
int64_t commitTime; int64_t commitTime;
int32_t commitLog; int32_t commitLog;
int32_t compressionLevel; int32_t compressionLevel;
SSQLToken precision; SSQLToken precision;
bool ignoreExists;
tVariantList *keep; tVariantList *keep;
} SCreateDBInfo; } SCreateDBInfo;
......
...@@ -815,8 +815,7 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI ...@@ -815,8 +815,7 @@ void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBI
pInfo->pDCLInfo->dbOpt = *pDB; pInfo->pDCLInfo->dbOpt = *pDB;
pInfo->pDCLInfo->dbOpt.dbname = *pToken; pInfo->pDCLInfo->dbOpt.dbname = *pToken;
pInfo->pDCLInfo->dbOpt.ignoreExists = (pIgExists != NULL);
tTokenListAppend(pInfo->pDCLInfo, pIgExists);
} }
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) { void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo) {
......
...@@ -3555,7 +3555,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult * ...@@ -3555,7 +3555,7 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *
int32_t setAdditionalInfo(SQInfo *pQInfo, STable *pTable, STableQueryInfo *pTableQueryInfo) { int32_t setAdditionalInfo(SQInfo *pQInfo, STable *pTable, STableQueryInfo *pTableQueryInfo) {
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
assert(pTableQueryInfo->lastKey > 0); assert(pTableQueryInfo->lastKey >= 0);
setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb); setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册