未验证 提交 5c5fcc0a 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #17768 from taosdata/feat/audit

feat: add audit db for DDL storage
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# local fully qualified domain name (FQDN) # local fully qualified domain name (FQDN)
# fqdn hostname # fqdn hostname
# first port number for the connection (12 continuous UDP/TCP port number are used) # first port number for the connection (12 continuous UDP/TCP port number are used)
# serverPort 6030 # serverPort 6030
# log file's directory # log file's directory
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
# temporary file's directory # temporary file's directory
# tempDir /tmp/ # tempDir /tmp/
# the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only # the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only
# arbitrator arbitrator_hostname:6042 # arbitrator arbitrator_hostname:6042
# number of threads per CPU core # number of threads per CPU core
# numOfThreadsPerCore 1.0 # numOfThreadsPerCore 1.0
...@@ -60,19 +60,19 @@ keepColumnName 1 ...@@ -60,19 +60,19 @@ keepColumnName 1
# max timer control blocks # max timer control blocks
# maxTmrCtrl 512 # maxTmrCtrl 512
# time interval of system monitor, seconds # time interval of system monitor, seconds
# monitorInterval 30 # monitorInterval 30
# number of seconds allowed for a dnode to be offline, for cluster only # number of seconds allowed for a dnode to be offline, for cluster only
# offlineThreshold 864000 # offlineThreshold 864000
# RPC re-try timer, millisecond # RPC re-try timer, millisecond
# rpcTimer 300 # rpcTimer 300
# RPC maximum time for ack, seconds. # RPC maximum time for ack, seconds.
# rpcMaxTime 600 # rpcMaxTime 600
# time interval of dnode status reporting to mnode, seconds, for cluster only # time interval of dnode status reporting to mnode, seconds, for cluster only
# statusInterval 1 # statusInterval 1
# time interval of heart beat from shell to dnode, seconds # time interval of heart beat from shell to dnode, seconds
...@@ -121,7 +121,7 @@ keepColumnName 1 ...@@ -121,7 +121,7 @@ keepColumnName 1
# maxRows 4096 # maxRows 4096
# the number of acknowledgments required for successful data writing # the number of acknowledgments required for successful data writing
# quorum 1 # quorum 1
# enable/disable compression # enable/disable compression
# comp 2 # comp 2
...@@ -132,7 +132,7 @@ keepColumnName 1 ...@@ -132,7 +132,7 @@ keepColumnName 1
# if walLevel is set to 2, the cycle of fsync being executed, if set to 0, fsync is called right away # if walLevel is set to 2, the cycle of fsync being executed, if set to 0, fsync is called right away
# fsync 3000 # fsync 3000
# number of replications, for cluster only # number of replications, for cluster only
# replica 1 # replica 1
# the compressed rpc message, option: # the compressed rpc message, option:
...@@ -188,9 +188,12 @@ keepColumnName 1 ...@@ -188,9 +188,12 @@ keepColumnName 1
# enbale/disable http service # enbale/disable http service
# http 1 # http 1
# enable/disable system monitor # enable/disable system monitor
# monitor 1 # monitor 1
# enable/disable system audit
# audit 0
# enable/disable recording the SQL statements via restful interface # enable/disable recording the SQL statements via restful interface
# httpEnableRecordSql 0 # httpEnableRecordSql 0
...@@ -219,7 +222,7 @@ keepColumnName 1 ...@@ -219,7 +222,7 @@ keepColumnName 1
# The following parameters are used for debug purpose only. # The following parameters are used for debug purpose only.
# debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR # debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR
# 131: output warning and error # 131: output warning and error
# 135: output debug, warning and error # 135: output debug, warning and error
# 143: output trace, debug, warning and error to log # 143: output trace, debug, warning and error to log
# 199: output debug, warning and error to both screen and file # 199: output debug, warning and error to both screen and file
...@@ -243,13 +246,13 @@ keepColumnName 1 ...@@ -243,13 +246,13 @@ keepColumnName 1
# debug flag for SDB # debug flag for SDB
# sdbDebugFlag 135 # sdbDebugFlag 135
# debug flag for RPC # debug flag for RPC
# rpcDebugFlag 131 # rpcDebugFlag 131
# debug flag for TAOS TIMER # debug flag for TAOS TIMER
# tmrDebugFlag 131 # tmrDebugFlag 131
# debug flag for TDengine client # debug flag for TDengine client
# cDebugFlag 131 # cDebugFlag 131
# debug flag for JNI # debug flag for JNI
...@@ -302,7 +305,7 @@ keepColumnName 1 ...@@ -302,7 +305,7 @@ keepColumnName 1
# default string type used for storing JSON String, options can be binary/nchar, default is nchar # default string type used for storing JSON String, options can be binary/nchar, default is nchar
# defaultJSONStrType nchar # defaultJSONStrType nchar
# force TCP transmission # force TCP transmission
# rpcForceTcp 0 # rpcForceTcp 0
# unit MB. Flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks # unit MB. Flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks
...@@ -318,4 +321,4 @@ keepColumnName 1 ...@@ -318,4 +321,4 @@ keepColumnName 1
# writeBatchTimeout 10 # writeBatchTimeout 10
# using thread local write batching. this option is not available when writeBatchSize = 0. # using thread local write batching. this option is not available when writeBatchSize = 0.
# writeBatchThreadLocal 0 # writeBatchThreadLocal 0
\ No newline at end of file
...@@ -154,6 +154,10 @@ extern char tsMonitorDbName[]; ...@@ -154,6 +154,10 @@ extern char tsMonitorDbName[];
extern char tsInternalPass[]; extern char tsInternalPass[];
extern int32_t tsMonitorInterval; extern int32_t tsMonitorInterval;
// audit
extern int8_t tsEnableAudit;
extern char tsAuditDbName[];
// stream // stream
extern int8_t tsEnableStream; extern int8_t tsEnableStream;
......
...@@ -205,6 +205,10 @@ char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; ...@@ -205,6 +205,10 @@ char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log";
char tsInternalPass[] = "secretkey"; char tsInternalPass[] = "secretkey";
int32_t tsMonitorInterval = 30; // seconds int32_t tsMonitorInterval = 30; // seconds
// audit
int8_t tsEnableAudit = 0;
char tsAuditDbName[TSDB_DB_NAME_LEN] = "audit";
// stream // stream
int8_t tsEnableStream = 1; int8_t tsEnableStream = 1;
...@@ -1292,6 +1296,16 @@ static void doInitGlobalConfig(void) { ...@@ -1292,6 +1296,16 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "audit";
cfg.ptr = &tsEnableAudit;
cfg.valType = TAOS_CFG_VTYPE_INT8;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 0;
cfg.maxValue = 1;
cfg.ptrLength = 1;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "stream"; cfg.option = "stream";
cfg.ptr = &tsEnableStream; cfg.ptr = &tsEnableStream;
cfg.valType = TAOS_CFG_VTYPE_INT8; cfg.valType = TAOS_CFG_VTYPE_INT8;
......
...@@ -27,6 +27,27 @@ extern "C" { ...@@ -27,6 +27,27 @@ extern "C" {
monSaveDnodeLog(level, __VA_ARGS__); \ monSaveDnodeLog(level, __VA_ARGS__); \
} }
typedef enum {
// create
MON_DDL_CMD_CREATE_DATABASE,
MON_DDL_CMD_CREATE_TABLE,
MON_DDL_CMD_CREATE_CHILD_TABLE,
MON_DDL_CMD_CREATE_SUPER_TABLE,
// drop
MON_DDL_CMD_DROP_DATABASE,
MON_DDL_CMD_DROP_TABLE,
MON_DDL_CMD_DROP_CHILD_TABLE,
MON_DDL_CMD_DROP_SUPER_TABLE,
// alter
MON_DDL_CMD_ALTER_DATABASE,
MON_DDL_CMD_ADD_COLUMN,
MON_DDL_CMD_DROP_COLUMN,
MON_DDL_CMD_MODIFY_COLUMN,
MON_DDL_CMD_ADD_TAG,
MON_DDL_CMD_DROP_TAG,
MON_DDL_CMD_CHANGE_TAG,
} EMonDDLCmdType;
typedef struct { typedef struct {
const char * name; const char * name;
int32_t code; int32_t code;
...@@ -62,6 +83,7 @@ int32_t monInitSystem(); ...@@ -62,6 +83,7 @@ int32_t monInitSystem();
int32_t monStartSystem(); int32_t monStartSystem();
void monStopSystem(); void monStopSystem();
void monCleanupSystem(); void monCleanupSystem();
void monSaveAuditLog(int8_t type, const char *user, const char *obj, bool result);
void monSaveAcctLog(SAcctMonitorObj *pMonObj); void monSaveAcctLog(SAcctMonitorObj *pMonObj);
void monSaveLog(int32_t level, const char *const format, ...); void monSaveLog(int32_t level, const char *const format, ...);
void monSaveDnodeLog(int32_t level, const char *const format, ...); void monSaveDnodeLog(int32_t level, const char *const format, ...);
......
...@@ -244,12 +244,12 @@ do { \ ...@@ -244,12 +244,12 @@ do { \
#define TSDB_VERSION_LEN 12 #define TSDB_VERSION_LEN 12
#define TSDB_LOCALE_LEN 64 #define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 96 #define TSDB_TIMEZONE_LEN 96
#define TSDB_LABEL_LEN 8 #define TSDB_LABEL_LEN 8
#define TSDB_CLUSTER_ID_LEN 40 #define TSDB_CLUSTER_ID_LEN 40
#define TSDB_FQDN_LEN 128 #define TSDB_FQDN_LEN 128
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6) #define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
#define TSDB_IPv4ADDR_LEN 16 #define TSDB_IPv4ADDR_LEN 16
#define TSDB_FILENAME_LEN 128 #define TSDB_FILENAME_LEN 128
#define TSDB_SHOW_SQL_LEN 512 #define TSDB_SHOW_SQL_LEN 512
#define TSDB_SHOW_SUBQUERY_LEN 1000 #define TSDB_SHOW_SUBQUERY_LEN 1000
...@@ -313,7 +313,7 @@ do { \ ...@@ -313,7 +313,7 @@ do { \
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default #define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
#define TSDB_MIN_DAYS_PER_FILE 1 #define TSDB_MIN_DAYS_PER_FILE 1
#define TSDB_MAX_DAYS_PER_FILE 3650 #define TSDB_MAX_DAYS_PER_FILE 3650
#define TSDB_DEFAULT_DAYS_PER_FILE 10 #define TSDB_DEFAULT_DAYS_PER_FILE 10
#define TSDB_MIN_KEEP 1 // data in db to be reserved. #define TSDB_MIN_KEEP 1 // data in db to be reserved.
...@@ -412,7 +412,7 @@ do { \ ...@@ -412,7 +412,7 @@ do { \
#define TSDB_ORDER_ASC 1 #define TSDB_ORDER_ASC 1
#define TSDB_ORDER_DESC 2 #define TSDB_ORDER_DESC 2
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1 #define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5 #define TSDB_DEFAULT_MNODES_HASH_SIZE 5
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10 #define TSDB_DEFAULT_DNODES_HASH_SIZE 10
......
...@@ -57,7 +57,7 @@ typedef struct SDnodeObj { ...@@ -57,7 +57,7 @@ typedef struct SDnodeObj {
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
int8_t status; // set in balance function int8_t status; // set in balance function
int8_t isMgmt; int8_t isMgmt;
int8_t reserve1[11]; int8_t reserve1[11];
int8_t updateEnd[4]; int8_t updateEnd[4];
int32_t refCount; int32_t refCount;
uint32_t moduleStatus; uint32_t moduleStatus;
...@@ -90,7 +90,7 @@ typedef struct STableObj { ...@@ -90,7 +90,7 @@ typedef struct STableObj {
} STableObj; } STableObj;
typedef struct SSTableObj { typedef struct SSTableObj {
STableObj info; STableObj info;
int8_t reserved0[9]; // for fill struct STableObj to 4byte align int8_t reserved0[9]; // for fill struct STableObj to 4byte align
int16_t nextColId; int16_t nextColId;
int32_t sversion; int32_t sversion;
...@@ -107,10 +107,10 @@ typedef struct SSTableObj { ...@@ -107,10 +107,10 @@ typedef struct SSTableObj {
} SSTableObj; } SSTableObj;
typedef struct { typedef struct {
STableObj info; STableObj info;
int8_t reserved0[9]; // for fill struct STableObj to 4byte align int8_t reserved0[9]; // for fill struct STableObj to 4byte align
int16_t nextColId; //used by normal table int16_t nextColId; //used by normal table
int32_t sversion; //used by normal table int32_t sversion; //used by normal table
uint64_t uid; uint64_t uid;
uint64_t suid; uint64_t suid;
int64_t createdTime; int64_t createdTime;
...@@ -195,7 +195,7 @@ typedef struct SDbObj { ...@@ -195,7 +195,7 @@ typedef struct SDbObj {
int32_t numOfVgroups; int32_t numOfVgroups;
int32_t numOfTables; int32_t numOfTables;
int32_t numOfSuperTables; int32_t numOfSuperTables;
int32_t vgListSize; int32_t vgListSize;
int32_t vgListIndex; int32_t vgListIndex;
SVgObj **vgList; SVgObj **vgList;
struct SAcctObj *pAcct; struct SAcctObj *pAcct;
......
...@@ -160,7 +160,7 @@ static int32_t mnodeDbActionEncode(SSdbRow *pRow) { ...@@ -160,7 +160,7 @@ static int32_t mnodeDbActionEncode(SSdbRow *pRow) {
static int32_t mnodeDbActionDecode(SSdbRow *pRow) { static int32_t mnodeDbActionDecode(SSdbRow *pRow) {
SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj));
if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
memcpy(pDb, pRow->rowData, tsDbUpdateSize); memcpy(pDb, pRow->rowData, tsDbUpdateSize);
pRow->pObj = pDb; pRow->pObj = pDb;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -205,8 +205,8 @@ int32_t mnodeInitDbs() { ...@@ -205,8 +205,8 @@ int32_t mnodeInitDbs() {
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DB, mnodeGetDbMeta); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DB, mnodeGetDbMeta);
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DB, mnodeRetrieveDbs); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DB, mnodeRetrieveDbs);
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_DB, mnodeCancelGetNextDb); mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_DB, mnodeCancelGetNextDb);
mDebug("table:dbs table is created"); mDebug("table:dbs table is created");
return tpInit(); return tpInit();
} }
...@@ -224,11 +224,11 @@ SDbObj *mnodeGetDb(char *db) { ...@@ -224,11 +224,11 @@ SDbObj *mnodeGetDb(char *db) {
} }
void mnodeIncDbRef(SDbObj *pDb) { void mnodeIncDbRef(SDbObj *pDb) {
sdbIncRef(tsDbSdb, pDb); sdbIncRef(tsDbSdb, pDb);
} }
void mnodeDecDbRef(SDbObj *pDb) { void mnodeDecDbRef(SDbObj *pDb) {
sdbDecRef(tsDbSdb, pDb); sdbDecRef(tsDbSdb, pDb);
} }
SDbObj *mnodeGetDbByTableName(char *tableName) { SDbObj *mnodeGetDbByTableName(char *tableName) {
...@@ -409,6 +409,7 @@ static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -409,6 +409,7 @@ static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) {
} else { } else {
mError("db:%s, failed to create by %s, reason:%s", pDb->name, mnodeGetUserFromMsg(pMsg), tstrerror(code)); mError("db:%s, failed to create by %s, reason:%s", pDb->name, mnodeGetUserFromMsg(pMsg), tstrerror(code));
} }
monSaveAuditLog(MON_DDL_CMD_CREATE_DATABASE, mnodeGetUserFromMsg(pMsg), pDb->name, !code);
return code; return code;
} }
...@@ -419,7 +420,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * ...@@ -419,7 +420,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
SDbObj *pDb = mnodeGetDb(pCreate->db); SDbObj *pDb = mnodeGetDb(pCreate->db);
if (pDb != NULL) { if (pDb != NULL) {
mnodeDecDbRef(pDb); mnodeDecDbRef(pDb);
if (pCreate->ignoreExist) { if (pCreate->ignoreExist) {
mDebug("db:%s, already exist, ignore exist is set", pCreate->db); mDebug("db:%s, already exist, ignore exist is set", pCreate->db);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -434,8 +435,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * ...@@ -434,8 +435,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
pDb = calloc(1, sizeof(SDbObj)); pDb = calloc(1, sizeof(SDbObj));
tstrncpy(pDb->name, pCreate->db, sizeof(pDb->name)); tstrncpy(pDb->name, pCreate->db, sizeof(pDb->name));
tstrncpy(pDb->acct, pAcct->user, sizeof(pDb->acct)); tstrncpy(pDb->acct, pAcct->user, sizeof(pDb->acct));
pDb->createdTime = taosGetTimestampMs(); pDb->createdTime = taosGetTimestampMs();
pDb->cfg = (SDbCfg) { pDb->cfg = (SDbCfg) {
.cacheBlockSize = pCreate->cacheBlockSize, .cacheBlockSize = pCreate->cacheBlockSize,
.totalBlocks = pCreate->totalBlocks, .totalBlocks = pCreate->totalBlocks,
...@@ -499,7 +500,7 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { ...@@ -499,7 +500,7 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) {
#if 0 #if 0
void mnodePrintVgroups(SDbObj *pDb, char *row) { void mnodePrintVgroups(SDbObj *pDb, char *row) {
mInfo("db:%s, vgroup link from head, row:%s", pDb->name, row); mInfo("db:%s, vgroup link from head, row:%s", pDb->name, row);
SVgObj *pVgroup = pDb->pHead; SVgObj *pVgroup = pDb->pHead;
while (pVgroup != NULL) { while (pVgroup != NULL) {
mInfo("vgId:%d", pVgroup->vgId); mInfo("vgId:%d", pVgroup->vgId);
...@@ -621,7 +622,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn ...@@ -621,7 +622,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
#ifdef _STORAGE #ifdef _STORAGE
strcpy(pSchema[cols].name, "keep0,keep1,keep2"); strcpy(pSchema[cols].name, "keep0,keep1,keep2");
#else #else
strcpy(pSchema[cols].name, "keep"); strcpy(pSchema[cols].name, "keep");
...@@ -638,13 +639,13 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn ...@@ -638,13 +639,13 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
strcpy(pSchema[cols].name, "cache(MB)"); strcpy(pSchema[cols].name, "cache(MB)");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "blocks"); strcpy(pSchema[cols].name, "blocks");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "minrows"); strcpy(pSchema[cols].name, "minrows");
...@@ -743,7 +744,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void ...@@ -743,7 +744,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
cols = 0; cols = 0;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char* name = mnodeGetDbStr(pDb->name); char* name = mnodeGetDbStr(pDb->name);
if (name != NULL) { if (name != NULL) {
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]);
...@@ -789,10 +790,10 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void ...@@ -789,10 +790,10 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
#endif #endif
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
char tmp[128] = {0}; char tmp[128] = {0};
#ifdef _STORAGE #ifdef _STORAGE
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { 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); sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0);
} else { } else {
sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2); sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2);
...@@ -821,7 +822,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void ...@@ -821,7 +822,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int32_t *)pWrite = pDb->cfg.maxRowsPerFileBlock; *(int32_t *)pWrite = pDb->cfg.maxRowsPerFileBlock;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int8_t *)pWrite = pDb->cfg.walLevel; *(int8_t *)pWrite = pDb->cfg.walLevel;
cols++; cols++;
...@@ -912,7 +913,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { ...@@ -912,7 +913,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) {
} }
static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
SCreateDbMsg *pCreate = pMsg->rpcMsg.pCont; SCreateDbMsg *pCreate = pMsg->rpcMsg.pCont;
pCreate->maxTables = htonl(pCreate->maxTables); pCreate->maxTables = htonl(pCreate->maxTables);
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize); pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
pCreate->totalBlocks = htonl(pCreate->totalBlocks); pCreate->totalBlocks = htonl(pCreate->totalBlocks);
...@@ -925,7 +926,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { ...@@ -925,7 +926,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
pCreate->partitions = htons(pCreate->partitions); pCreate->partitions = htons(pCreate->partitions);
pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock); pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock); pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
int32_t code; int32_t code;
#ifdef GRANT_CHECK_WRITE #ifdef GRANT_CHECK_WRITE
if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) {
...@@ -963,7 +964,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { ...@@ -963,7 +964,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
int8_t cacheLastRow = pAlter->cacheLastRow; int8_t cacheLastRow = pAlter->cacheLastRow;
int8_t dbType = pAlter->dbType; int8_t dbType = pAlter->dbType;
int16_t partitions = htons(pAlter->partitions); int16_t partitions = htons(pAlter->partitions);
terrno = TSDB_CODE_SUCCESS; terrno = TSDB_CODE_SUCCESS;
//UPGRATE FROM LOW VERSION, reorder it //UPGRATE FROM LOW VERSION, reorder it
...@@ -1127,6 +1128,8 @@ static int32_t mnodeAlterDbFp(SMnodeMsg *pMsg) { ...@@ -1127,6 +1128,8 @@ static int32_t mnodeAlterDbFp(SMnodeMsg *pMsg) {
mDebug("db:%s, all vgroups is altered", pDb->name); mDebug("db:%s, all vgroups is altered", pDb->name);
mLInfo("db:%s, is alterd by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); mLInfo("db:%s, is alterd by %s", pDb->name, mnodeGetUserFromMsg(pMsg));
monSaveAuditLog(MON_DDL_CMD_ALTER_DATABASE, mnodeGetUserFromMsg(pMsg), pDb->name, true);
// in case there is no vnode for this db currently(no table in db,etc.) // in case there is no vnode for this db currently(no table in db,etc.)
if (pMsg->expected == 0) { if (pMsg->expected == 0) {
SSdbRow row = { SSdbRow row = {
...@@ -1183,7 +1186,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { ...@@ -1183,7 +1186,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) {
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("db:%s, failed to alter, reason:%s", pDb->name, tstrerror(code)); mError("db:%s, failed to alter, reason:%s", pDb->name, tstrerror(code));
} }
} }
return code; return code;
} }
...@@ -1197,7 +1200,7 @@ int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { ...@@ -1197,7 +1200,7 @@ int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
mError("db:%s, failed to alter, invalid db", pAlter->db); mError("db:%s, failed to alter, invalid db", pAlter->db);
return TSDB_CODE_MND_INVALID_DB; return TSDB_CODE_MND_INVALID_DB;
} }
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("db:%s, status:%d, in dropping", pAlter->db, pMsg->pDb->status); mError("db:%s, status:%d, in dropping", pAlter->db, pMsg->pDb->status);
return TSDB_CODE_MND_DB_IN_DROPPING; return TSDB_CODE_MND_DB_IN_DROPPING;
...@@ -1213,13 +1216,14 @@ static int32_t mnodeDropDbCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1213,13 +1216,14 @@ static int32_t mnodeDropDbCb(SMnodeMsg *pMsg, int32_t code) {
} else { } else {
mLInfo("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); mLInfo("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg));
} }
monSaveAuditLog(MON_DDL_CMD_DROP_DATABASE, mnodeGetUserFromMsg(pMsg), pDb->name, !code);
return code; return code;
} }
static int32_t mnodeDropDb(SMnodeMsg *pMsg) { static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
SDbObj *pDb = pMsg->pDb; SDbObj *pDb = pMsg->pDb;
mInfo("db:%s, drop db from sdb", pDb->name); mInfo("db:%s, drop db from sdb", pDb->name);
...@@ -1259,7 +1263,7 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) { ...@@ -1259,7 +1263,7 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
mError("db:%s, can't drop monitor database", pDrop->db); mError("db:%s, can't drop monitor database", pDrop->db);
return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
} }
#endif #endif
int32_t code = mnodeSetDbDropping(pMsg->pDb); int32_t code = mnodeSetDbDropping(pMsg->pDb);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
...@@ -1292,15 +1296,15 @@ static int32_t mnodeSyncDb(SDbObj *pDb, SMnodeMsg *pMsg) { ...@@ -1292,15 +1296,15 @@ static int32_t mnodeSyncDb(SDbObj *pDb, SMnodeMsg *pMsg) {
static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) { static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) {
int32_t count = ntohs(pCompactMsg->numOfVgroup); int32_t count = ntohs(pCompactMsg->numOfVgroup);
int32_t *buf = malloc(sizeof(int32_t) * count); int32_t *buf = malloc(sizeof(int32_t) * count);
if (buf == NULL) { if (buf == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
for (int32_t i = 0; i < count; i++) { for (int32_t i = 0; i < count; i++) {
buf[i] = ntohs(pCompactMsg->vgid[i]); buf[i] = ntohs(pCompactMsg->vgid[i]);
} }
// copy from mnodeSyncDb, so ugly // copy from mnodeSyncDb, so ugly
for (int32_t i = 0; i < count; i++) { for (int32_t i = 0; i < count; i++) {
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
...@@ -1312,7 +1316,7 @@ static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) { ...@@ -1312,7 +1316,7 @@ static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) {
if (pVgroup->pDb == pDb && pVgroup->vgId == buf[i]) { if (pVgroup->pDb == pDb && pVgroup->vgId == buf[i]) {
mnodeSendCompactVgroupMsg(pVgroup); mnodeSendCompactVgroupMsg(pVgroup);
mnodeDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
valid = true; valid = true;
break; break;
} }
mnodeDecVgroupRef(pVgroup); mnodeDecVgroupRef(pVgroup);
...@@ -1321,7 +1325,7 @@ static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) { ...@@ -1321,7 +1325,7 @@ static int32_t mnodeCompact(SDbObj *pDb, SCompactMsg *pCompactMsg) {
mLError("db:%s, cannot find valid vgId: %d", pDb->name, buf[i]); mLError("db:%s, cannot find valid vgId: %d", pDb->name, buf[i]);
} }
} }
free(buf); free(buf);
mLInfo("db:%s, trigger compact", pDb->name); mLInfo("db:%s, trigger compact", pDb->name);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1352,14 +1356,14 @@ static int32_t mnodeProcessSyncDbMsg(SMnodeMsg *pMsg) { ...@@ -1352,14 +1356,14 @@ static int32_t mnodeProcessSyncDbMsg(SMnodeMsg *pMsg) {
static int32_t mnodeProcessCompactMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCompactMsg(SMnodeMsg *pMsg) {
SCompactMsg *pCompact = pMsg->rpcMsg.pCont; SCompactMsg *pCompact = pMsg->rpcMsg.pCont;
mDebug("db:%s, compact is received from thandle:%p", pCompact->db, pMsg->rpcMsg.handle); mDebug("db:%s, compact is received from thandle:%p", pCompact->db, pMsg->rpcMsg.handle);
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCompact->db); if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCompact->db);
if (pMsg->pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; if (pMsg->pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) { if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
mError("db:%s, status:%d, in dropping, ignore compact request", pCompact->db, pMsg->pDb->status); mError("db:%s, status:%d, in dropping, ignore compact request", pCompact->db, pMsg->pDb->status);
return TSDB_CODE_MND_DB_IN_DROPPING; return TSDB_CODE_MND_DB_IN_DROPPING;
} }
return mnodeCompact(pMsg->pDb, pCompact); return mnodeCompact(pMsg->pDb, pCompact);
} }
...@@ -1382,7 +1386,7 @@ void mnodeDropAllDbs(SAcctObj *pAcct) { ...@@ -1382,7 +1386,7 @@ void mnodeDropAllDbs(SAcctObj *pAcct) {
.pTable = tsDbSdb, .pTable = tsDbSdb,
.pObj = pDb .pObj = pDb
}; };
sdbDeleteRow(&row); sdbDeleteRow(&row);
numOfDbs++; numOfDbs++;
} }
...@@ -1410,11 +1414,11 @@ int32_t mnodeCompactDbs() { ...@@ -1410,11 +1414,11 @@ int32_t mnodeCompactDbs() {
}; };
mInfo("compact dbs %s", pDb->name); mInfo("compact dbs %s", pDb->name);
sdbInsertCompactRow(&row); sdbInsertCompactRow(&row);
} }
mInfo("end to compact dbs table..."); mInfo("end to compact dbs table...");
return 0; return 0;
} }
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "mnodeSdb.h" #include "mnodeSdb.h"
#include "mnodeShow.h" #include "mnodeShow.h"
#include "mnodeTable.h" #include "mnodeTable.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h" #include "mnodeVgroup.h"
#include "mnodeWrite.h" #include "mnodeWrite.h"
#include "mnodeRead.h" #include "mnodeRead.h"
...@@ -1047,7 +1048,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1047,7 +1048,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLInfo("stable:%s, is created in sdb, uid:%" PRIu64, pTable->info.tableId, pTable->uid); mLInfo("stable:%s, is created in sdb, uid:%" PRIu64, pTable->info.tableId, pTable->uid);
if(pMsg->pBatchMasterMsg) if(pMsg->pBatchMasterMsg)
pMsg->pBatchMasterMsg->successed ++; pMsg->pBatchMasterMsg->successed ++;
} else { } else {
mError("msg:%p, app:%p stable:%s, failed to create in sdb, reason:%s", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, mError("msg:%p, app:%p stable:%s, failed to create in sdb, reason:%s", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId,
tstrerror(code)); tstrerror(code));
...@@ -1056,11 +1057,12 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1056,11 +1057,12 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
if(pMsg->pBatchMasterMsg) if(pMsg->pBatchMasterMsg)
pMsg->pBatchMasterMsg->received ++; pMsg->pBatchMasterMsg->received ++;
} }
monSaveAuditLog(MON_DDL_CMD_CREATE_SUPER_TABLE, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, !code);
// if super table create by batch msg, check done and send finished to client // if super table create by batch msg, check done and send finished to client
if(pMsg->pBatchMasterMsg) { if(pMsg->pBatchMasterMsg) {
if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected) if (pMsg->pBatchMasterMsg->successed + pMsg->pBatchMasterMsg->received >= pMsg->pBatchMasterMsg->expected)
dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code); dnodeSendRpcMWriteRsp(pMsg->pBatchMasterMsg, code);
} }
return code; return code;
...@@ -1171,11 +1173,12 @@ static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1171,11 +1173,12 @@ static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pTable = (SSTableObj *)pMsg->pTable; SSTableObj *pTable = (SSTableObj *)pMsg->pTable;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("msg:%p, app:%p stable:%s, failed to drop, sdb error", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId); mError("msg:%p, app:%p stable:%s, failed to drop, sdb error", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId);
monSaveAuditLog(MON_DDL_CMD_DROP_SUPER_TABLE, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return code; return code;
} }
mLInfo("msg:%p, app:%p stable:%s, is dropped from sdb", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId); mLInfo("msg:%p, app:%p stable:%s, is dropped from sdb", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId);
monSaveAuditLog(MON_DDL_CMD_DROP_SUPER_TABLE, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
if (pStable->vgHash != NULL /*pStable->numOfTables != 0*/) { if (pStable->vgHash != NULL /*pStable->numOfTables != 0*/) {
...@@ -1250,6 +1253,8 @@ static int32_t mnodeAddSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1250,6 +1253,8 @@ static int32_t mnodeAddSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_ADD_TAG, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -1308,6 +1313,8 @@ static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1308,6 +1313,8 @@ static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_DROP_TAG, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -1345,6 +1352,8 @@ static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1345,6 +1352,8 @@ static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_CHANGE_TAG, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -1403,6 +1412,8 @@ static int32_t mnodeAddSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1403,6 +1412,8 @@ static int32_t mnodeAddSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_ADD_COLUMN, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -1474,6 +1485,8 @@ static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1474,6 +1485,8 @@ static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_DROP_COLUMN, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -1522,6 +1535,8 @@ static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1522,6 +1535,8 @@ static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg); code = mnodeGetSuperTableMeta(pMsg);
} }
monSaveAuditLog(MON_DDL_CMD_MODIFY_COLUMN, mnodeGetUserFromMsg(pMsg), pStable->info.tableId, !code);
return code; return code;
} }
...@@ -2073,6 +2088,9 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -2073,6 +2088,9 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
SCreateTableMsg *pCreate = (SCreateTableMsg*) ((char*)pMsg->rpcMsg.pCont + sizeof(SCMCreateTableMsg)); SCreateTableMsg *pCreate = (SCreateTableMsg*) ((char*)pMsg->rpcMsg.pCont + sizeof(SCMCreateTableMsg));
assert(pTable); assert(pTable);
monSaveAuditLog((pTable->info.type == TSDB_CHILD_TABLE) ? MON_DDL_CMD_CREATE_CHILD_TABLE : MON_DDL_CMD_CREATE_TABLE,
mnodeGetUserFromMsg(pMsg), pTable->info.tableId, !code);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
if (pCreate->getMeta) { if (pCreate->getMeta) {
mDebug("msg:%p, app:%p table:%s, created in dnode and continue to get meta, thandle:%p", pMsg, mDebug("msg:%p, app:%p table:%s, created in dnode and continue to get meta, thandle:%p", pMsg,
...@@ -2101,6 +2119,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -2101,6 +2119,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
} else { } else {
mError("msg:%p, app:%p table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg, mError("msg:%p, app:%p table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg,
pMsg->rpcMsg.ahandle, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code)); pMsg->rpcMsg.ahandle, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code));
SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsChildTableSdb}; SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsChildTableSdb};
sdbDeleteRow(&desc); sdbDeleteRow(&desc);
...@@ -2294,6 +2313,8 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { ...@@ -2294,6 +2313,8 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) {
if (pDrop == NULL) { if (pDrop == NULL) {
mError("msg:%p, app:%p ctable:%s, failed to drop ctable, no enough memory", pMsg, pMsg->rpcMsg.ahandle, mError("msg:%p, app:%p ctable:%s, failed to drop ctable, no enough memory", pMsg, pMsg->rpcMsg.ahandle,
pTable->info.tableId); pTable->info.tableId);
monSaveAuditLog((pTable->info.type == TSDB_CHILD_TABLE) ? MON_DDL_CMD_DROP_CHILD_TABLE : MON_DDL_CMD_DROP_TABLE,
mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return TSDB_CODE_MND_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
...@@ -2308,6 +2329,9 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { ...@@ -2308,6 +2329,9 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) {
mInfo("msg:%p, app:%p ctable:%s, send drop ctable msg, vgId:%d sid:%d uid:%" PRIu64, pMsg, pMsg->rpcMsg.ahandle, mInfo("msg:%p, app:%p ctable:%s, send drop ctable msg, vgId:%d sid:%d uid:%" PRIu64, pMsg, pMsg->rpcMsg.ahandle,
pDrop->tableFname, pTable->vgId, pTable->tid, pTable->uid); pDrop->tableFname, pTable->vgId, pTable->tid, pTable->uid);
monSaveAuditLog((pTable->info.type == TSDB_CHILD_TABLE) ? MON_DDL_CMD_DROP_CHILD_TABLE : MON_DDL_CMD_DROP_TABLE,
mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.ahandle = pMsg, .ahandle = pMsg,
.pCont = pDrop, .pCont = pDrop,
...@@ -2327,6 +2351,8 @@ static int32_t mnodeDropChildTableCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -2327,6 +2351,8 @@ static int32_t mnodeDropChildTableCb(SMnodeMsg *pMsg, int32_t code) {
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
SCTableObj *pTable = (SCTableObj *)pMsg->pTable; SCTableObj *pTable = (SCTableObj *)pMsg->pTable;
mError("msg:%p, app:%p ctable:%s, failed to drop, sdb error", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId); mError("msg:%p, app:%p ctable:%s, failed to drop, sdb error", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId);
monSaveAuditLog((pTable->info.type == TSDB_CHILD_TABLE) ? MON_DDL_CMD_DROP_CHILD_TABLE : MON_DDL_CMD_DROP_TABLE,
mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return code; return code;
} }
...@@ -2414,6 +2440,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 ...@@ -2414,6 +2440,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
SDbObj *pDb = pMsg->pDb; SDbObj *pDb = pMsg->pDb;
if (ncols <= 0) { if (ncols <= 0) {
mError("msg:%p, app:%p ctable:%s, add column, ncols:%d <= 0", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, ncols); mError("msg:%p, app:%p ctable:%s, add column, ncols:%d <= 0", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, ncols);
monSaveAuditLog(MON_DDL_CMD_ADD_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return TSDB_CODE_MND_APP_ERROR; return TSDB_CODE_MND_APP_ERROR;
} }
...@@ -2421,6 +2448,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 ...@@ -2421,6 +2448,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) { if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) {
mError("msg:%p, app:%p ctable:%s, add column, column:%s already exist", pMsg, pMsg->rpcMsg.ahandle, mError("msg:%p, app:%p ctable:%s, add column, column:%s already exist", pMsg, pMsg->rpcMsg.ahandle,
pTable->info.tableId, schema[i].name); pTable->info.tableId, schema[i].name);
monSaveAuditLog(MON_DDL_CMD_ADD_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return TSDB_CODE_MND_FIELD_ALREAY_EXIST; return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
} }
} }
...@@ -2445,6 +2473,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 ...@@ -2445,6 +2473,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
} }
mInfo("msg:%p, app:%p ctable %s, start to add column", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId); mInfo("msg:%p, app:%p ctable %s, start to add column", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId);
monSaveAuditLog(MON_DDL_CMD_ADD_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);
SSdbRow row = { SSdbRow row = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -2464,6 +2493,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { ...@@ -2464,6 +2493,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
if (col <= 0) { if (col <= 0) {
mError("msg:%p, app:%p ctable:%s, drop column, column:%s not exist", pMsg, pMsg->rpcMsg.ahandle, mError("msg:%p, app:%p ctable:%s, drop column, column:%s not exist", pMsg, pMsg->rpcMsg.ahandle,
pTable->info.tableId, colName); pTable->info.tableId, colName);
monSaveAuditLog(MON_DDL_CMD_DROP_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return TSDB_CODE_MND_FIELD_NOT_EXIST; return TSDB_CODE_MND_FIELD_NOT_EXIST;
} }
...@@ -2478,6 +2508,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { ...@@ -2478,6 +2508,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
} }
mInfo("msg:%p, app:%p ctable %s, start to drop column %s", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, colName); mInfo("msg:%p, app:%p ctable %s, start to drop column %s", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, colName);
monSaveAuditLog(MON_DDL_CMD_DROP_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);
SSdbRow row = { SSdbRow row = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -2498,6 +2529,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg) { ...@@ -2498,6 +2529,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg) {
if (col < 0) { if (col < 0) {
mError("msg:%p, app:%p ctable:%s, change column, name: %s", pMsg, pMsg->rpcMsg.ahandle, mError("msg:%p, app:%p ctable:%s, change column, name: %s", pMsg, pMsg->rpcMsg.ahandle,
pTable->info.tableId, name); pTable->info.tableId, name);
monSaveAuditLog(MON_DDL_CMD_MODIFY_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, false);
return TSDB_CODE_MND_FIELD_NOT_EXIST; return TSDB_CODE_MND_FIELD_NOT_EXIST;
} }
...@@ -2508,6 +2540,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg) { ...@@ -2508,6 +2540,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg) {
mInfo("msg:%p, app:%p ctable %s, start to modify column %s len to %d", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, mInfo("msg:%p, app:%p ctable %s, start to modify column %s len to %d", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId,
name, schema->bytes); name, schema->bytes);
monSaveAuditLog(MON_DDL_CMD_MODIFY_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);
SSdbRow row = { SSdbRow row = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -3559,7 +3592,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro ...@@ -3559,7 +3592,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pTable->sql, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pTable->sql, pShow->bytes[cols]);
cols++; cols++;
numOfRows++; numOfRows++;
...@@ -3594,13 +3627,13 @@ static int32_t mnodeCompactSuperTables() { ...@@ -3594,13 +3627,13 @@ static int32_t mnodeCompactSuperTables() {
}; };
//mInfo("compact super %" PRIu64, pTable->uid); //mInfo("compact super %" PRIu64, pTable->uid);
sdbInsertCompactRow(&row); sdbInsertCompactRow(&row);
} }
mInfo("end to compact super table..."); mInfo("end to compact super table...");
return 0; return 0;
} }
static int32_t mnodeCompactChildTables() { static int32_t mnodeCompactChildTables() {
...@@ -3620,13 +3653,13 @@ static int32_t mnodeCompactChildTables() { ...@@ -3620,13 +3653,13 @@ static int32_t mnodeCompactChildTables() {
}; };
//mInfo("compact child %" PRIu64 ":%d", pTable->uid, pTable->tid); //mInfo("compact child %" PRIu64 ":%d", pTable->uid, pTable->tid);
sdbInsertCompactRow(&row); sdbInsertCompactRow(&row);
} }
mInfo("end to compact child table..."); mInfo("end to compact child table...");
return 0; return 0;
} }
int32_t mnodeCompactTables() { int32_t mnodeCompactTables() {
......
...@@ -108,7 +108,7 @@ static void mnodePrintUserAuth() { ...@@ -108,7 +108,7 @@ static void mnodePrintUserAuth() {
mDebug("failed to auth.txt for write"); mDebug("failed to auth.txt for write");
return; return;
} }
void * pIter = NULL; void * pIter = NULL;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
...@@ -181,7 +181,7 @@ int32_t mnodeInitUsers() { ...@@ -181,7 +181,7 @@ int32_t mnodeInitUsers() {
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_USER, mnodeCancelGetNextUser); mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_USER, mnodeCancelGetNextUser);
mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg);
mDebug("table:%s, hash is created", desc.name); mDebug("table:%s, hash is created", desc.name);
return 0; return 0;
} }
...@@ -195,20 +195,20 @@ SUserObj *mnodeGetUser(char *name) { ...@@ -195,20 +195,20 @@ SUserObj *mnodeGetUser(char *name) {
return (SUserObj *)sdbGetRow(tsUserSdb, name); return (SUserObj *)sdbGetRow(tsUserSdb, name);
} }
void *mnodeGetNextUser(void *pIter, SUserObj **pUser) { void *mnodeGetNextUser(void *pIter, SUserObj **pUser) {
return sdbFetchRow(tsUserSdb, pIter, (void **)pUser); return sdbFetchRow(tsUserSdb, pIter, (void **)pUser);
} }
void mnodeCancelGetNextUser(void *pIter) { void mnodeCancelGetNextUser(void *pIter) {
sdbFreeIter(tsUserSdb, pIter); sdbFreeIter(tsUserSdb, pIter);
} }
void mnodeIncUserRef(SUserObj *pUser) { void mnodeIncUserRef(SUserObj *pUser) {
sdbIncRef(tsUserSdb, pUser); sdbIncRef(tsUserSdb, pUser);
} }
void mnodeDecUserRef(SUserObj *pUser) { void mnodeDecUserRef(SUserObj *pUser) {
sdbDecRef(tsUserSdb, pUser); sdbDecRef(tsUserSdb, pUser);
} }
static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) {
...@@ -464,7 +464,7 @@ char *mnodeGetUserFromMsg(void *pMsg) { ...@@ -464,7 +464,7 @@ char *mnodeGetUserFromMsg(void *pMsg) {
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
SUserObj *pOperUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
if (pOperUser->superAuth) { if (pOperUser->superAuth) {
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
return mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass, pCreate->tags, pMsg); return mnodeCreateUser(pOperUser->pAcct, pCreate->user, pCreate->pass, pCreate->tags, pMsg);
...@@ -477,7 +477,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) { ...@@ -477,7 +477,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) {
int32_t code; int32_t code;
SUserObj *pOperUser = pMsg->pUser; SUserObj *pOperUser = pMsg->pUser;
SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
SUserObj *pUser = mnodeGetUser(pAlter->user); SUserObj *pUser = mnodeGetUser(pAlter->user);
if (pUser == NULL) { if (pUser == NULL) {
...@@ -686,10 +686,10 @@ int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, cha ...@@ -686,10 +686,10 @@ int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, cha
static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg) {
SAuthMsg *pAuthMsg = pMsg->rpcMsg.pCont; SAuthMsg *pAuthMsg = pMsg->rpcMsg.pCont;
SAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SAuthRsp)); SAuthRsp *pAuthRsp = rpcMallocCont(sizeof(SAuthRsp));
pMsg->rpcRsp.rsp = pAuthRsp; pMsg->rpcRsp.rsp = pAuthRsp;
pMsg->rpcRsp.len = sizeof(SAuthRsp); pMsg->rpcRsp.len = sizeof(SAuthRsp);
return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey); return mnodeRetriveAuth(pAuthMsg->user, &pAuthRsp->spi, &pAuthRsp->encrypt, pAuthRsp->secret, pAuthRsp->ckey);
} }
...@@ -711,7 +711,7 @@ int32_t mnodeCompactUsers() { ...@@ -711,7 +711,7 @@ int32_t mnodeCompactUsers() {
}; };
mInfo("compact users %s", pUser->user); mInfo("compact users %s", pUser->user);
sdbInsertCompactRow(&row); sdbInsertCompactRow(&row);
} }
......
...@@ -41,6 +41,9 @@ ...@@ -41,6 +41,9 @@
#define DNODE_INFO_LEN 128 #define DNODE_INFO_LEN 128
#define QUERY_ID_LEN 24 #define QUERY_ID_LEN 24
#define CHECK_INTERVAL 1000 #define CHECK_INTERVAL 1000
#define AUDIT_MAX_RETRIES 10
#define MAX_DDL_TYPE_LEN 32
#define MAX_DDL_OBJ_LEN 512
#define SQL_STR_FMT "\"%s\"" #define SQL_STR_FMT "\"%s\""
...@@ -161,6 +164,7 @@ typedef struct { ...@@ -161,6 +164,7 @@ typedef struct {
} SMonStat; } SMonStat;
static void *monHttpStatusHashTable; static void *monHttpStatusHashTable;
static void *auditConn;
static SMonConn tsMonitor = {0}; static SMonConn tsMonitor = {0};
static SMonStat tsMonStat = {{0}}; static SMonStat tsMonStat = {{0}};
...@@ -175,16 +179,24 @@ static void monSaveDisksInfo(); ...@@ -175,16 +179,24 @@ static void monSaveDisksInfo();
static void monSaveGrantsInfo(); static void monSaveGrantsInfo();
static void monSaveHttpReqInfo(); static void monSaveHttpReqInfo();
static void monGetSysStats(); static void monGetSysStats();
static void *monThreadFunc(void *param); static void *monThreadFunc(void *param);
static void *monAuditFunc(void *param);
static void monBuildMonitorSql(char *sql, int32_t cmd); static void monBuildMonitorSql(char *sql, int32_t cmd);
static void monInitHttpStatusHashTable(); static void monInitHttpStatusHashTable();
static void monCleanupHttpStatusHashTable(); static void monCleanupHttpStatusHashTable();
extern int32_t (*monStartSystemFp)(); extern int32_t (*monStartSystemFp)();
extern void (*monStopSystemFp)(); extern void (*monStopSystemFp)();
extern void (*monExecuteSQLFp)(char *sql); extern void (*monExecuteSQLFp)(char *sql);
extern char * strptime(const char *buf, const char *fmt, struct tm *tm); //make the compilation pass extern char * strptime(const char *buf, const char *fmt, struct tm *tm); //make the compilation pass
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
int32_t monInitSystem() { int32_t monInitSystem() {
if (tsMonitor.ep[0] == 0) { if (tsMonitor.ep[0] == 0) {
strcpy(tsMonitor.ep, tsLocalEp); strcpy(tsMonitor.ep, tsLocalEp);
...@@ -203,12 +215,20 @@ int32_t monInitSystem() { ...@@ -203,12 +215,20 @@ int32_t monInitSystem() {
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&tsMonitor.thread, &thAttr, monThreadFunc, NULL)) { if (pthread_create(&tsMonitor.thread, &thAttr, monThreadFunc, NULL)) {
monError("failed to create thread to for monitor module, reason:%s", strerror(errno)); monError("failed to create thread for monitor module, reason:%s", strerror(errno));
return -1;
}
monDebug("monitor thread is launched");
pthread_t auditThread;
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&auditThread, &thAttr, monAuditFunc, NULL)) {
monError("failed to create audit thread, reason:%s", strerror(errno));
return -1; return -1;
} }
monDebug("audit thread is launched");
pthread_attr_destroy(&thAttr); pthread_attr_destroy(&thAttr);
monDebug("monitor thread is launched");
monStartSystemFp = monStartSystem; monStartSystemFp = monStartSystem;
monStopSystemFp = monStopSystem; monStopSystemFp = monStopSystem;
...@@ -250,6 +270,70 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) { ...@@ -250,6 +270,70 @@ SMonHttpStatus *monGetHttpStatusHashTableEntry(int32_t code) {
return (SMonHttpStatus*)taosHashGet(monHttpStatusHashTable, &code, sizeof(int32_t)); return (SMonHttpStatus*)taosHashGet(monHttpStatusHashTable, &code, sizeof(int32_t));
} }
static void *monAuditFunc(void *param) {
if (!tsEnableAudit) {
return NULL;
}
monDebug("starting to initialize audit database...");
setThreadName("audit");
taosMsleep(1000);
int32_t try = 0;
for (; try < AUDIT_MAX_RETRIES; ++try) {
auditConn = taos_connect(NULL, "monitor", tsInternalPass, "", 0);
if (auditConn == NULL) {
monDebug("audit retry connect, tries: %d", try);
taosMsleep(1000);
} else {
monDebug("audit successfuly connect to database");
break;
}
}
if (try == AUDIT_MAX_RETRIES) {
monError("audit failed to connect to database, reason:%s", tstrerror(terrno));
return NULL;
}
// create database
char sql[512] = {0};
snprintf(sql, sizeof(sql),
"create database if not exists %s replica 1 days 10 keep %s cache %d "
"blocks %d precision 'us'",
tsAuditDbName, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS);
void *res = taos_query(auditConn, sql);
int32_t code = taos_errno(res);
taos_free_result(res);
if (code != 0) {
monError("failed to create database: %s, sql:%s, reason:%s", tsAuditDbName, sql, tstrerror(code));
return NULL;
}
// create table
memset(sql, 0, sizeof(sql));
snprintf(sql, sizeof(sql),
"create table if not exists %s.ddl(ts timestamp"
", user_name binary(%d), ip_addr binary(%d), type binary(%d)"
", object binary(%d), result binary(10)"
")",
tsAuditDbName, TSDB_USER_LEN, IP_LEN_STR,
MAX_DDL_TYPE_LEN, MAX_DDL_OBJ_LEN);
res = taos_query(auditConn, sql);
code = taos_errno(res);
taos_free_result(res);
if (code != 0) {
monError("failed to create table: ddl, exec sql:%s, reason:%s", sql, tstrerror(code));
return NULL;
}
return NULL;
}
static void *monThreadFunc(void *param) { static void *monThreadFunc(void *param) {
monDebug("starting to initialize monitor module ..."); monDebug("starting to initialize monitor module ...");
setThreadName("monitor"); setThreadName("monitor");
...@@ -335,12 +419,6 @@ static void *monThreadFunc(void *param) { ...@@ -335,12 +419,6 @@ static void *monThreadFunc(void *param) {
static void monBuildMonitorSql(char *sql, int32_t cmd) { static void monBuildMonitorSql(char *sql, int32_t cmd) {
memset(sql, 0, SQL_LENGTH); memset(sql, 0, SQL_LENGTH);
#ifdef _STORAGE
char *keepValue = "30,30,30";
#else
char *keepValue = "30";
#endif
if (cmd == MON_CMD_CREATE_DB) { if (cmd == MON_CMD_CREATE_DB) {
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"create database if not exists %s replica %d days 10 keep %s cache %d " "create database if not exists %s replica %d days 10 keep %s cache %d "
...@@ -494,6 +572,11 @@ void monCleanupSystem() { ...@@ -494,6 +572,11 @@ void monCleanupSystem() {
pthread_join(tsMonitor.thread, NULL); pthread_join(tsMonitor.thread, NULL);
} }
if (auditConn != NULL) {
taos_close(tsMonitor.conn);
auditConn = NULL;
}
if (tsMonitor.conn != NULL) { if (tsMonitor.conn != NULL) {
taos_close(tsMonitor.conn); taos_close(tsMonitor.conn);
tsMonitor.conn = NULL; tsMonitor.conn = NULL;
...@@ -1323,6 +1406,116 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { ...@@ -1323,6 +1406,116 @@ static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) {
taos_free_result(result); taos_free_result(result);
} }
static bool monConvDDLType2Str(int8_t type, char *buf, int32_t len) {
if (buf == NULL) {
return false;
}
switch (type) {
case MON_DDL_CMD_CREATE_DATABASE: {
strncpy(buf, "CREATE DATABASE", len);
break;
}
case MON_DDL_CMD_CREATE_TABLE: {
strncpy(buf, "CREATE TABLE", len);
break;
}
case MON_DDL_CMD_CREATE_CHILD_TABLE: {
strncpy(buf, "CREATE CHILD TABLE", len);
break;
}
case MON_DDL_CMD_CREATE_SUPER_TABLE: {
strncpy(buf, "CREATE SUPER TABLE", len);
break;
}
case MON_DDL_CMD_DROP_DATABASE: {
strncpy(buf, "DROP DATABASE", len);
break;
}
case MON_DDL_CMD_DROP_TABLE: {
strncpy(buf, "DROP TABLE", len);
break;
}
case MON_DDL_CMD_DROP_CHILD_TABLE: {
strncpy(buf, "DROP CHILD TABLE", len);
break;
}
case MON_DDL_CMD_DROP_SUPER_TABLE: {
strncpy(buf, "DROP SUPER TABLE", len);
break;
}
case MON_DDL_CMD_DROP_COLUMN: {
strncpy(buf, "DROP COLUMN", len);
break;
}
case MON_DDL_CMD_DROP_TAG: {
strncpy(buf, "DROP TAG", len);
break;
}
case MON_DDL_CMD_ALTER_DATABASE: {
strncpy(buf, "ALTER DATABASE", len);
break;
}
case MON_DDL_CMD_ADD_COLUMN: {
strncpy(buf, "ADD COLUMN", len);
break;
}
case MON_DDL_CMD_ADD_TAG: {
strncpy(buf, "ADD TAG", len);
break;
}
case MON_DDL_CMD_MODIFY_COLUMN: {
strncpy(buf, "MODIFY COLUMN/TAG LENGTH", len);
break;
}
case MON_DDL_CMD_CHANGE_TAG: {
strncpy(buf, "CHANGE TAG NAME", len);
break;
}
default: {
return false;
}
}
return true;
}
void monSaveAuditLog(int8_t type, const char *user, const char *obj, bool result) {
if (tsEnableAudit == 0) { //audit not enabled
return;
}
char sql[1024] = {0};
char typeStr[64] = {0};
if (!monConvDDLType2Str(type, typeStr, (int32_t)sizeof(typeStr))) {
monError("unknown DDL type: %d ", type);
return;
}
snprintf(sql, 1023,
"insert into %s.ddl values(now, "
SQL_STR_FMT", "SQL_STR_FMT", "
SQL_STR_FMT", "SQL_STR_FMT", "
SQL_STR_FMT")",
tsAuditDbName,
(user != NULL) ? user : "NULL",
tsLocalEp,
typeStr,
(obj != NULL) ? obj : "NULL",
result ? "success" : "fail");
monDebug("save ddl info, sql:%s", sql);
void *res = taos_query(auditConn, sql);
int32_t code = taos_errno(res);
taos_free_result(res);
if (code != 0) {
monError("failed to save audit ddl info, reason:%s, sql:%s", tstrerror(code), sql);
} else {
monDebug("successfully save audit ddl info, sql:%s", sql);
}
}
void monSaveAcctLog(SAcctMonitorObj *pMon) { void monSaveAcctLog(SAcctMonitorObj *pMon) {
if (tsMonitor.state != MON_STATE_INITED) return; if (tsMonitor.state != MON_STATE_INITED) return;
...@@ -1399,6 +1592,7 @@ void monSaveDnodeLog(int32_t level, const char *const format, ...) { ...@@ -1399,6 +1592,7 @@ void monSaveDnodeLog(int32_t level, const char *const format, ...) {
taos_query_a(tsMonitor.conn, sql, monExecSqlCb, "log"); taos_query_a(tsMonitor.conn, sql, monExecSqlCb, "log");
} }
void monExecuteSQL(char *sql) { void monExecuteSQL(char *sql) {
if (tsMonitor.state != MON_STATE_INITED) return; if (tsMonitor.state != MON_STATE_INITED) return;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#define TSDB_CFG_MAX_NUM 140 #define TSDB_CFG_MAX_NUM 141
#define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_PRINT_LEN 23
#define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_OPTION_LEN 24
#define TSDB_CFG_VALUE_LEN 41 #define TSDB_CFG_VALUE_LEN 41
......
...@@ -32,20 +32,20 @@ int32_t tsGlobalConfigNum = 0; ...@@ -32,20 +32,20 @@ int32_t tsGlobalConfigNum = 0;
} }
static char *tsGlobalUnit[] = { static char *tsGlobalUnit[] = {
" ", " ",
"(%)", "(%)",
"(GB)", "(GB)",
"(Mb)", "(Mb)",
"(byte)", "(byte)",
"(s)", "(s)",
"(ms)" "(ms)"
}; };
char *tsCfgStatusStr[] = { char *tsCfgStatusStr[] = {
"none", "none",
"system default", "system default",
"config file", "config file",
"taos_options", "taos_options",
"program argument list" "program argument list"
}; };
...@@ -335,7 +335,7 @@ bool taosReadConfigOption(const char *option, char *value, char *value2, char *v ...@@ -335,7 +335,7 @@ bool taosReadConfigOption(const char *option, char *value, char *value2, char *v
taosReadDataDirCfg(value, value2, value3); taosReadDataDirCfg(value, value2, value3);
ret = true; ret = true;
} else { } else {
ret = false; ret = false;
} }
break; break;
default: default:
...@@ -365,8 +365,8 @@ void taosReadGlobalLogCfg() { ...@@ -365,8 +365,8 @@ void taosReadGlobalLogCfg() {
wordfree(&full_path); wordfree(&full_path);
return; return;
} }
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) {
printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1);
wordfree(&full_path); wordfree(&full_path);
...@@ -380,7 +380,7 @@ void taosReadGlobalLogCfg() { ...@@ -380,7 +380,7 @@ void taosReadGlobalLogCfg() {
wordfree(&full_path); wordfree(&full_path);
taosReadLogOption("logDir", tsLogDir); taosReadLogOption("logDir", tsLogDir);
sprintf(fileName, "%s/taos.cfg", configDir); sprintf(fileName, "%s/taos.cfg", configDir);
fp = fopen(fileName, "r"); fp = fopen(fileName, "r");
if (fp == NULL) { if (fp == NULL) {
...@@ -391,10 +391,10 @@ void taosReadGlobalLogCfg() { ...@@ -391,10 +391,10 @@ void taosReadGlobalLogCfg() {
ssize_t _bytes = 0; ssize_t _bytes = 0;
size_t len = 1024; size_t len = 1024;
line = calloc(1, len); line = calloc(1, len);
while (!feof(fp)) { while (!feof(fp)) {
memset(line, 0, len); memset(line, 0, len);
option = value = NULL; option = value = NULL;
olen = vlen = 0; olen = vlen = 0;
...@@ -443,7 +443,7 @@ bool taosReadGlobalCfg() { ...@@ -443,7 +443,7 @@ bool taosReadGlobalCfg() {
ssize_t _bytes = 0; ssize_t _bytes = 0;
size_t len = 1024; size_t len = 1024;
line = calloc(1, len); line = calloc(1, len);
while (!feof(fp)) { while (!feof(fp)) {
memset(line, 0, len); memset(line, 0, len);
...@@ -457,7 +457,7 @@ bool taosReadGlobalCfg() { ...@@ -457,7 +457,7 @@ bool taosReadGlobalCfg() {
} }
line[len - 1] = 0; line[len - 1] = 0;
paGetToken(line, &option, &olen); paGetToken(line, &option, &olen);
if (olen == 0) continue; if (olen == 0) continue;
option[olen] = 0; option[olen] = 0;
...@@ -495,7 +495,7 @@ void taosPrintGlobalCfg() { ...@@ -495,7 +495,7 @@ void taosPrintGlobalCfg() {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
int optionLen = (int)strlen(cfg->option); int optionLen = (int)strlen(cfg->option);
int blankLen = TSDB_CFG_PRINT_LEN - optionLen; int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
blankLen = blankLen < 0 ? 0 : blankLen; blankLen = blankLen < 0 ? 0 : blankLen;
......
...@@ -22,7 +22,7 @@ class TDTestCase: ...@@ -22,7 +22,7 @@ class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql) tdSql.init(conn.cursor(), logSql)
def alterKeepCommunity(self): def alterKeepCommunity(self):
tdLog.notice('running Keep Test, Community Version') tdLog.notice('running Keep Test, Community Version')
tdLog.notice('running parameter test for keep during create') tdLog.notice('running parameter test for keep during create')
...@@ -174,7 +174,7 @@ class TDTestCase: ...@@ -174,7 +174,7 @@ class TDTestCase:
tdSql.error('insert into tb values (now-15d, 10)') tdSql.error('insert into tb values (now-15d, 10)')
tdSql.query('select * from tb') tdSql.query('select * from tb')
tdSql.checkRows(2) tdSql.checkRows(2)
rowNum = 2 rowNum = 2
tdLog.notice('testing keep will be altered if sudden change from small to big') tdLog.notice('testing keep will be altered if sudden change from small to big')
for i in range(30): for i in range(30):
......
...@@ -28,8 +28,8 @@ class TDTestCase: ...@@ -28,8 +28,8 @@ class TDTestCase:
tdSql.prepare() tdSql.prepare()
ret = tdSql.query('select database()') ret = tdSql.query('select database()')
tdSql.checkData(0, 0, "db") tdSql.checkData(0, 0, "db")
ret = tdSql.query('select server_status()') ret = tdSql.query('select server_status()')
tdSql.checkData(0, 0, 1) tdSql.checkData(0, 0, 1)
...@@ -59,10 +59,10 @@ class TDTestCase: ...@@ -59,10 +59,10 @@ class TDTestCase:
if create_time-time_delta < role_time < create_time+time_delta: if create_time-time_delta < role_time < create_time+time_delta:
tdLog.info("role_time {} and create_time {} expected within range".format(role_time, create_time)) tdLog.info("role_time {} and create_time {} expected within range".format(role_time, create_time))
else: else:
tdLog.exit("role_time {} and create_time {} not expected within range".format(role_time, create_time)) tdLog.exit("role_time {} and create_time {} not expected within range".format(role_time, create_time))
ret = tdSql.query('show vgroups') ret = tdSql.query('show vgroups')
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.execute('create stable st (ts timestamp, f int) tags(t int)') tdSql.execute('create stable st (ts timestamp, f int) tags(t int)')
tdSql.execute('create table ct1 using st tags(1)'); tdSql.execute('create table ct1 using st tags(1)');
...@@ -74,8 +74,8 @@ class TDTestCase: ...@@ -74,8 +74,8 @@ class TDTestCase:
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, 2) tdSql.checkData(0, 0, 2)
tdSql.checkData(0, 1, "leader") tdSql.checkData(0, 1, "leader")
cmd = "taos -h 127.0.0.1 -s 'show databases'" cmd = "taos -h 127.0.0.1 -s 'show databases'"
r = os.popen(cmd) r = os.popen(cmd)
text = r.read() text = r.read()
r.close r.close
......
...@@ -68,14 +68,14 @@ class TDTestCase: ...@@ -68,14 +68,14 @@ class TDTestCase:
# TD-6006 # TD-6006
tdSql.error("select * from dev_001 where 'name' is not null") tdSql.error("select * from dev_001 where 'name' is not null")
tdSql.error("select * from dev_001 where \"name\" = 'first'") tdSql.error("select * from dev_001 where \"name\" = 'first'")
# TS-1577 # TS-1577
tdSql.query("show databases") tdSql.query("show databases")
rows = tdSql.queryRows rows = tdSql.queryRows
for i in range(1000): for i in range(1000):
tdSql.execute("create database test%d" % i) tdSql.execute("create database test%d" % i)
tdSql.query("show databases") tdSql.query("show databases")
tdSql.checkRows(rows + 1000) tdSql.checkRows(rows + 1000)
......
...@@ -50,8 +50,8 @@ class TDTestCase: ...@@ -50,8 +50,8 @@ class TDTestCase:
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
break break
return buildPath return buildPath
def run(self): def run(self):
...@@ -122,4 +122,4 @@ class TDTestCase: ...@@ -122,4 +122,4 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
...@@ -43,9 +43,9 @@ class TDTestCase: ...@@ -43,9 +43,9 @@ class TDTestCase:
tdSql.checkData(0, 6, None) tdSql.checkData(0, 6, None)
tdSql.checkData(1, 6, 'test') tdSql.checkData(1, 6, 'test')
# Test case for: https://jira.taosdata.com:18080/browse/TD-2423 # Test case for: https://jira.taosdata.com:18080/browse/TD-2423
tdSql.execute("create table stb(ts timestamp, col1 int, col2 nchar(20)) tags(tg1 int, tg2 binary(20), tg3 nchar(25))") tdSql.execute("create table stb(ts timestamp, col1 int, col2 nchar(20)) tags(tg1 int, tg2 binary(20), tg3 nchar(25))")
tdSql.execute("insert into tb1 using stb(tg1, tg3) tags(1, 'test1') values(now, 1, 'test1')") tdSql.execute("insert into tb1 using stb(tg1, tg3) tags(1, 'test1') values(now, 1, 'test1')")
tdSql.query("select *, tg1, tg2, tg3 from tb1") tdSql.query("select *, tg1, tg2, tg3 from tb1")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 3, 1) tdSql.checkData(0, 3, 1)
...@@ -61,7 +61,7 @@ class TDTestCase: ...@@ -61,7 +61,7 @@ class TDTestCase:
#Test case for TS-1285 #Test case for TS-1285
tdSql.execute("create table stb2(ts timestamp, c1 int) tags(t1 timestamp)") tdSql.execute("create table stb2(ts timestamp, c1 int) tags(t1 timestamp)")
tdSql.execute("insert into tb3 using stb2 tags('2022-01-01 18:26:50.224') values(now, 1)") tdSql.execute("insert into tb3 using stb2 tags('2022-01-01 18:26:50.224') values(now, 1)")
tdSql.execute("alter table tb3 set tag t1='2022-03-03 18:26:50.224'") tdSql.execute("alter table tb3 set tag t1='2022-03-03 18:26:50.224'")
tdSql.query("select * from stb2") tdSql.query("select * from stb2")
tdSql.checkData(0, 2, "2022-03-03 18:26:50.224") tdSql.checkData(0, 2, "2022-03-03 18:26:50.224")
......
...@@ -577,15 +577,15 @@ class TDTestCase: ...@@ -577,15 +577,15 @@ class TDTestCase:
tdSql.execute("use db") tdSql.execute("use db")
tdSql.execute( tdSql.execute(
"create table if not exists st (ts timestamp, tagtype int) tags(dev bigint)") "create table if not exists st (ts timestamp, tagtype int) tags(dev bigint)")
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 63) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 63) - 1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 63) + 1)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 63) + 1))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(2) tdSql.checkRows(2)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -583,13 +583,13 @@ class TDTestCase: ...@@ -583,13 +583,13 @@ class TDTestCase:
"create table if not exists st (ts timestamp, tagtype int) tags(dev binary(5))") "create table if not exists st (ts timestamp, tagtype int) tags(dev binary(5))")
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags("dev_001")') 'CREATE TABLE if not exists dev_001 using st tags("dev_001")')
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags("dev")') 'CREATE TABLE if not exists dev_002 using st tags("dev")')
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(1) tdSql.checkRows(1)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -580,15 +580,15 @@ class TDTestCase: ...@@ -580,15 +580,15 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 31)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 31))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 31))) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 31)))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 31) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 31) - 1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 31) + 1)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 31) + 1))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(2) tdSql.checkRows(2)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -47,16 +47,16 @@ class TDTestCase: ...@@ -47,16 +47,16 @@ class TDTestCase:
print("==============step1 tag format =======") print("==============step1 tag format =======")
tdLog.info("create database ") tdLog.info("create database ")
tdSql.execute("create database db_json") tdSql.execute("create database db_json")
tdSql.execute("use db_json") tdSql.execute("use db_json")
# test tag format # test tag format
tdSql.execute("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json)") tdSql.execute("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json)")
tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json(10000000))") tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json(10000000))")
tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json,jtag1 json)") tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json,jtag1 json)")
tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json,dataBool bool)") tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataStr nchar(50)) tags(jtag json,dataBool bool)")
tdSql.execute("CREATE TABLE if not exists jsons1_1 using jsons1 tags('{\"loc\":\"fff\",\"id\":5}')") tdSql.execute("CREATE TABLE if not exists jsons1_1 using jsons1 tags('{\"loc\":\"fff\",\"id\":5}')")
# two stables: jsons1 jsons2 ,test tag's value and key # two stables: jsons1 jsons2 ,test tag's value and key
tdSql.execute("insert into jsons1_1(ts,dataInt) using jsons1 tags('{\"loc+\":\"fff\",\"id\":5}') values (now,12)") tdSql.execute("insert into jsons1_1(ts,dataInt) using jsons1 tags('{\"loc+\":\"fff\",\"id\":5}') values (now,12)")
tdSql.error("CREATE TABLE if not exists jsons1_1 using jsons1 tags('{oc:\"fff\",\"id\":5}')") tdSql.error("CREATE TABLE if not exists jsons1_1 using jsons1 tags('{oc:\"fff\",\"id\":5}')")
......
...@@ -35,7 +35,7 @@ class TDTestCase: ...@@ -35,7 +35,7 @@ class TDTestCase:
'CREATE TABLE if not exists dev_002 using st tags("dev")') 'CREATE TABLE if not exists dev_002 using st tags("dev")')
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(1) tdSql.checkRows(1)
......
...@@ -580,15 +580,15 @@ class TDTestCase: ...@@ -580,15 +580,15 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 15)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 15))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 15))) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 15)))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 15) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 15) - 1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 15) + 1)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 15) + 1))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(2) tdSql.checkRows(2)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -46,7 +46,7 @@ class TDTestCase: ...@@ -46,7 +46,7 @@ class TDTestCase:
tdLog.info('=============== step2') tdLog.info('=============== step2')
tdSql.query('select * from %s' % (mt)) tdSql.query('select * from %s' % (mt))
tdSql.checkRows(5 * rowNum) tdSql.checkRows(5 * rowNum)
tdSql.query('select * from %s where tgTs = %ld and tgcol2 = 0' % (mt, ts)) tdSql.query('select * from %s where tgTs = %ld and tgcol2 = 0' % (mt, ts))
tdSql.checkRows(rowNum) tdSql.checkRows(rowNum)
...@@ -54,7 +54,7 @@ class TDTestCase: ...@@ -54,7 +54,7 @@ class TDTestCase:
tdSql.checkRows(rowNum) tdSql.checkRows(rowNum)
tdLog.info('=============== step3') tdLog.info('=============== step3')
i = 0 i = 0
while (i < 5): while (i < 5):
tb = "%s%d" % (tbPrefix, i + 100) tb = "%s%d" % (tbPrefix, i + 100)
tdLog.info('create table %s using %s tags(%d, \"%s\", %d)' % (tb, mt, i + 100, tsStr, i + 100)) tdLog.info('create table %s using %s tags(%d, \"%s\", %d)' % (tb, mt, i + 100, tsStr, i + 100))
...@@ -80,7 +80,7 @@ class TDTestCase: ...@@ -80,7 +80,7 @@ class TDTestCase:
tdLog.info('=============== step4') tdLog.info('=============== step4')
i = 0 i = 0
tb = "%s%d"%(tbPrefix, i + 1000) tb = "%s%d"%(tbPrefix, i + 1000)
tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now, 10)' % (tb, mt, i + 100, tsStr, i + 1000)) tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now, 10)' % (tb, mt, i + 100, tsStr, i + 1000))
tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now+2s, 10)' % (tb, mt, i + 100, tsStr, i + 1000)) tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now+2s, 10)' % (tb, mt, i + 100, tsStr, i + 1000))
tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now+3s, 10)' % (tb, mt, i + 100, tsStr, i + 1000)) tdSql.execute('insert into %s using %s tags(%d, \"%s\", %d) values(now+3s, 10)' % (tb, mt, i + 100, tsStr, i + 1000))
...@@ -88,11 +88,11 @@ class TDTestCase: ...@@ -88,11 +88,11 @@ class TDTestCase:
tdSql.checkRows(3) tdSql.checkRows(3)
i = 0 i = 0
tb = "%s%d"%(tbPrefix, i + 10000) tb = "%s%d"%(tbPrefix, i + 10000)
tdSql.execute('create table %s using %s tags(%d, now, %d)' % (tb, mt, i + 10000,i + 10000)) tdSql.execute('create table %s using %s tags(%d, now, %d)' % (tb, mt, i + 10000,i + 10000))
tdSql.checkRows(3) tdSql.checkRows(3)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)
......
...@@ -581,15 +581,15 @@ class TDTestCase: ...@@ -581,15 +581,15 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 7)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % pow(2, 7))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 7))) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1 * pow(2, 7)))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 7) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 7) - 1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 7) + 1)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (-1 * pow(2, 7) + 1))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(2) tdSql.checkRows(2)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -13,12 +13,12 @@ class TDTestCase: ...@@ -13,12 +13,12 @@ class TDTestCase:
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
tdLog.info('======================== dnode1 start') tdLog.info('======================== dnode1 start')
tbPrefix = "ta_cr_tb" tbPrefix = "ta_cr_tb"
mtPrefix = "ta_cr_mt" mtPrefix = "ta_cr_mt"
tbNum = 2 tbNum = 2
rowNum = 10 rowNum = 10
totalNum = 200 totalNum = 200
tagCondsLimit = 1024 tagCondsLimit = 1024
tdLog.info('=============== step1: create tbl and prepare data') tdLog.info('=============== step1: create tbl and prepare data')
...@@ -26,40 +26,40 @@ class TDTestCase: ...@@ -26,40 +26,40 @@ class TDTestCase:
i = 2 i = 2
mt = "%s%d" % (mtPrefix, i) mt = "%s%d" % (mtPrefix, i)
tb = "%s%d" % (tbPrefix, i) tb = "%s%d" % (tbPrefix, i)
sql ='create table %s (ts timestamp, tbcol int) TAGS(tgcol int)'% (mt) sql ='create table %s (ts timestamp, tbcol int) TAGS(tgcol int)'% (mt)
tdLog.info(sql) tdLog.info(sql)
tdSql.execute(sql) tdSql.execute(sql)
for i in range(0, tbNum): for i in range(0, tbNum):
tblName = "%s%d"%(tbPrefix, i) tblName = "%s%d"%(tbPrefix, i)
sql = 'create table %s using %s TAGS(%d)'%(tblName, mt, i) sql = 'create table %s using %s TAGS(%d)'%(tblName, mt, i)
tdSql.execute(sql) tdSql.execute(sql)
for j in range(0, rowNum): for j in range(0, rowNum):
sql = "insert into %s values(now, %d)"%(tblName, j) sql = "insert into %s values(now, %d)"%(tblName, j)
tdSql.execute(sql) tdSql.execute(sql)
sqlPrefix = "select * from %s where "%(mt) sqlPrefix = "select * from %s where "%(mt)
for i in range(2, 2048, 1): for i in range(2, 2048, 1):
conds = "tgcol=1 and "* (i - 1) conds = "tgcol=1 and "* (i - 1)
conds = "%stgcol=1"%(conds) conds = "%stgcol=1"%(conds)
sql = "%s%s"%(sqlPrefix, conds) sql = "%s%s"%(sqlPrefix, conds)
if i >= tagCondsLimit: if i >= tagCondsLimit:
tdSql.error(sql) tdSql.error(sql)
else: else:
tdSql.query(sql) tdSql.query(sql)
#tdSql.checkRows(1) #tdSql.checkRows(1)
for i in range(2, 2048, 1): for i in range(2, 2048, 1):
conds = "" conds = ""
for j in range(0, i - 1): for j in range(0, i - 1):
conds = conds + "tgcol=%d or "%(j%tbNum) conds = conds + "tgcol=%d or "%(j%tbNum)
conds += "tgcol=%d"%(i%tbNum) conds += "tgcol=%d"%(i%tbNum)
sql = sqlPrefix + conds sql = sqlPrefix + conds
if i >= tagCondsLimit: if i >= tagCondsLimit:
tdSql.error(sql) tdSql.error(sql)
else: else:
tdSql.query(sql) tdSql.query(sql)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -580,16 +580,16 @@ class TDTestCase: ...@@ -580,16 +580,16 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 64) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 64) - 1))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 64) - 2)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 64) - 2))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL')) 'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL'))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(3) tdSql.checkRows(3)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -581,16 +581,16 @@ class TDTestCase: ...@@ -581,16 +581,16 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 32) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 32) - 1))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 32) - 2)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 32) - 2))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL')) 'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL'))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(3) tdSql.checkRows(3)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -580,7 +580,7 @@ class TDTestCase: ...@@ -580,7 +580,7 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 16)-1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 16)-1))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 16) - 2)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 16) - 2))
tdSql.execute( tdSql.execute(
...@@ -588,9 +588,9 @@ class TDTestCase: ...@@ -588,9 +588,9 @@ class TDTestCase:
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL')) 'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL'))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(3) tdSql.checkRows(3)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -580,16 +580,16 @@ class TDTestCase: ...@@ -580,16 +580,16 @@ class TDTestCase:
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 8) - 1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 8) - 1))
tdSql.error( tdSql.error(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (-1))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 8) - 2)) 'CREATE TABLE if not exists dev_001 using st tags(%d)' % (pow(2, 8) - 2))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0)) 'CREATE TABLE if not exists dev_002 using st tags(%d)' % (0))
tdSql.execute( tdSql.execute(
'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL')) 'CREATE TABLE if not exists dev_003 using st tags(%s)' % ('NULL'))
print("==============step2") print("==============step2")
tdSql.query("show tables") tdSql.query("show tables")
tdSql.checkRows(3) tdSql.checkRows(3)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -142,6 +142,7 @@ class TDDnode: ...@@ -142,6 +142,7 @@ class TDDnode:
"numOfMnodes": "3", "numOfMnodes": "3",
"numOfThreadsPerCore": "2.0", "numOfThreadsPerCore": "2.0",
"monitor": "0", "monitor": "0",
"audit": "0",
"maxVnodeConnections": "30000", "maxVnodeConnections": "30000",
"maxMgmtConnections": "30000", "maxMgmtConnections": "30000",
"maxMeterConnections": "30000", "maxMeterConnections": "30000",
......
...@@ -85,6 +85,7 @@ echo wdebugFlag 135 >> %TAOS_CFG% ...@@ -85,6 +85,7 @@ echo wdebugFlag 135 >> %TAOS_CFG%
echo cqdebugFlag 135 >> %TAOS_CFG% echo cqdebugFlag 135 >> %TAOS_CFG%
echo monitor 0 >> %TAOS_CFG% echo monitor 0 >> %TAOS_CFG%
echo monitorInterval 1 >> %TAOS_CFG% echo monitorInterval 1 >> %TAOS_CFG%
echo audit 0 >> %TAOS_CFG%
echo http 0 >> %TAOS_CFG% echo http 0 >> %TAOS_CFG%
echo slaveQuery 0 >> %TAOS_CFG% echo slaveQuery 0 >> %TAOS_CFG%
echo numOfThreadsPerCore 2.0 >> %TAOS_CFG% echo numOfThreadsPerCore 2.0 >> %TAOS_CFG%
......
...@@ -139,6 +139,7 @@ echo "wdebugFlag 143" >> $TAOS_CFG ...@@ -139,6 +139,7 @@ echo "wdebugFlag 143" >> $TAOS_CFG
echo "cqdebugFlag 143" >> $TAOS_CFG echo "cqdebugFlag 143" >> $TAOS_CFG
echo "monitor 0" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG
echo "monitorInterval 1" >> $TAOS_CFG echo "monitorInterval 1" >> $TAOS_CFG
echo "audit 0" >> $TAOS_CFG
echo "http 0" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG
echo "slaveQuery 0" >> $TAOS_CFG echo "slaveQuery 0" >> $TAOS_CFG
echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG
......
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import taos
import time
import os
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql
class TDTestCase:
updatecfgDict = {'audit': 1}
def caseDescription(self):
'''
TS-1887 Create Audit db for DDL storage
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
now = time.time()
self.ts = int(round(now * 1000))
def run(self):
#tdSql.prepare()
time.sleep(3)
print("==============step1 test CREATE DDL")
# CREATE DATABASE
tdSql.execute("create database db")
tdSql.execute("use db")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CREATE DATABASE')
tdSql.checkData(0, 4, '0.db')
tdSql.checkData(0, 5, 'success')
# CREATE NORMAL TABLE
tdSql.execute("create table tb (ts timestamp, c0 int)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CREATE TABLE')
tdSql.checkData(0, 4, '0.db.tb')
tdSql.checkData(0, 5, 'success')
# CREATE SUPER TABLE
tdSql.execute("create table stb (ts timestamp, c0 int) tags (t0 int)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CREATE SUPER TABLE')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# CREATE CHILD TABLE
tdSql.execute("create table ctb using stb tags (1)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CREATE CHILD TABLE')
tdSql.checkData(0, 4, '0.db.ctb')
tdSql.checkData(0, 5, 'success')
# CREATE CHILD TABLE(AUTO)
tdSql.execute("insert into ctb_auto using stb tags (2) values (now, 2)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CREATE CHILD TABLE')
tdSql.checkData(0, 4, '0.db.ctb_auto')
tdSql.checkData(0, 5, 'success')
print("==============step2 test ALTER DDL")
# ALTER ATABASE
tdSql.execute("alter database db keep 354")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'ALTER DATABASE')
tdSql.checkData(0, 4, '0.db')
tdSql.checkData(0, 5, 'success')
tdSql.execute("alter database db cachelast 1")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'ALTER DATABASE')
tdSql.checkData(0, 4, '0.db')
tdSql.checkData(0, 5, 'success')
# ADD COLUMN NORMAL TABLE
tdSql.execute("alter table tb add column c1 binary(4)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'ADD COLUMN')
tdSql.checkData(0, 4, '0.db.tb')
tdSql.checkData(0, 5, 'success')
# MODIFY COLUMN NORMAL TABLE
tdSql.execute("alter table tb modify column c1 binary(10)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'MODIFY COLUMN/TAG LENGTH')
tdSql.checkData(0, 4, '0.db.tb')
tdSql.checkData(0, 5, 'success')
# ADD COLUMN SUPER TABLE
tdSql.execute("alter table stb add column c1 binary(4)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'ADD COLUMN')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# ADD TAG SUPER TABLE
tdSql.execute("alter table stb add tag t1 binary(4)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'ADD TAG')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# MODIFY COLUMN SUPER TABLE
tdSql.execute("alter table stb modify column c1 binary(10)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'MODIFY COLUMN/TAG LENGTH')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# MODIFY TAG SUPER TABLE
tdSql.execute("alter table stb modify tag t1 binary(10)")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'MODIFY COLUMN/TAG LENGTH')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# CHANGE TAG NAME SUPER TABLE
tdSql.execute("alter table stb change tag t1 t2")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'CHANGE TAG NAME')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
print("==============step3 test DROP DDL")
# DROP COLUMN NORMAL TABLE
tdSql.execute("alter table tb drop column c1")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP COLUMN')
tdSql.checkData(0, 4, '0.db.tb')
tdSql.checkData(0, 5, 'success')
# DROP COLUMN SUPER TABLE
tdSql.execute("alter table stb drop column c1")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP COLUMN')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# DROP TAG SUPER TABLE
tdSql.execute("alter table stb drop tag t2")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP TAG')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# DROP NORMAL TABLE
tdSql.execute("drop table tb")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP TABLE')
tdSql.checkData(0, 4, '0.db.tb')
tdSql.checkData(0, 5, 'success')
# DROP CHILD TABLE
tdSql.execute("drop table ctb")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP CHILD TABLE')
tdSql.checkData(0, 4, '0.db.ctb')
tdSql.checkData(0, 5, 'success')
# DROP SUPER TABLE
tdSql.execute("drop table stb")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP SUPER TABLE')
tdSql.checkData(0, 4, '0.db.stb')
tdSql.checkData(0, 5, 'success')
# DROP DATABASE
tdSql.execute("drop database db")
tdSql.query("select last(*) from audit.ddl");
tdSql.checkData(0, 3, 'DROP DATABASE')
tdSql.checkData(0, 4, '0.db')
tdSql.checkData(0, 5, 'success')
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
python3 ./test.py -f 0-others/create_col_tag.py python3 ./test.py -f 0-others/create_col_tag.py
\ No newline at end of file python3 ./test.py -f 0-others/audit.py
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册