From 0eeae78538b025ae8d61400f2c2f972eef17f068 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 20 Nov 2019 11:44:09 +0800 Subject: [PATCH 01/42] [TBASE-1128] --- src/client/src/tscSql.c | 6 +----- src/system/detail/src/mgmtShell.c | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6ec8f425ca..6131e96eab 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -63,12 +63,8 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const #ifdef CLUSTER if (ip && ip[0]) { - tscMgmtIpList.numOfIps = 2; strcpy(tscMgmtIpList.ipstr[0], ip); tscMgmtIpList.ip[0] = inet_addr(ip); - - strcpy(tscMgmtIpList.ipstr[1], ip); - tscMgmtIpList.ip[1] = inet_addr(ip); } #else if (ip && ip[0]) { @@ -156,7 +152,7 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, int port) { if (ip == NULL || (ip != NULL && (strcmp("127.0.0.1", ip) == 0 || strcasecmp("localhost", ip) == 0))) { #ifdef CLUSTER - ip = tsPrivateIp; + ip = tsMasterIp; #else ip = tsServerIpStr; #endif diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index e58938bdad..bd8f798e38 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -973,7 +973,10 @@ int mgmtProcessCreateTableMsg(char *pMsg, int msgLen, SConnObj *pConn) { } } - if (code != 0) { + if (code == 1) { + //mTrace("table:%s, wait vgroup create finish", pCreate->meterId, code); + } + else if (code != 0) { mError("table:%s, failed to create table, code:%d", pCreate->meterId, code); } else { mTrace("table:%s, table is created by %s", pCreate->meterId, pConn->pUser->user); From d320f26135e1c757b65301386623209bbef20551 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 20 Nov 2019 14:17:35 +0800 Subject: [PATCH 02/42] [TBASE-1128] --- src/inc/tsdb.h | 34 --------- src/inc/tstatus.h | 70 +++++++++++++++++- src/system/detail/inc/mgmt.h | 17 +---- src/system/detail/src/dnodeMgmt.c | 8 +-- src/system/detail/src/mgmtDb.c | 11 +-- src/system/detail/src/mgmtDnode.c | 6 +- src/system/detail/src/mgmtMeter.c | 3 +- src/system/detail/src/mgmtShell.c | 1 + src/system/detail/src/mgmtVgroup.c | 3 +- src/system/detail/src/vnodeCache.c | 3 +- src/system/detail/src/vnodeMeter.c | 2 +- src/system/detail/src/vnodeShell.c | 3 +- src/system/detail/src/vnodeStore.c | 22 +++--- src/system/detail/src/vnodeStream.c | 3 +- src/system/lite/src/mgmtBalance.spec.c | 4 +- src/system/lite/src/mgmtDnode.spec.c | 2 +- src/system/lite/src/mgmtDnodeInt.spec.c | 8 +-- src/system/lite/src/vnodePeer.spec.c | 2 +- src/util/src/tstatus.c | 96 ++++++++++++++++--------- 19 files changed, 176 insertions(+), 122 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 771046d4d1..81e580b54b 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -44,40 +44,6 @@ extern "C" { #define TSDB_TIME_PRECISION_MILLI_STR "ms" #define TSDB_TIME_PRECISION_MICRO_STR "us" - enum _vnode_status { - TSDB_VNODE_STATUS_OFFLINE, - TSDB_VNODE_STATUS_CREATING, - TSDB_VNODE_STATUS_UNSYNCED, - TSDB_VNODE_STATUS_SLAVE, - TSDB_VNODE_STATUS_MASTER, - TSDB_VNODE_STATUS_CLOSING, - TSDB_VNODE_STATUS_DELETING, -}; - -enum _vnode_sync_status { - STDB_SSTATUS_INIT, - TSDB_SSTATUS_SYNCING, - TSDB_SSTATUS_SYNC_CACHE, - TSDB_SSTATUS_SYNC_FILE, -}; - -enum _dnode_status { - TSDB_DNODE_STATUS_OFFLINE, - TSDB_DNODE_STATUS_READY -}; - -enum _dnode_balance_status { - LB_DNODE_STATE_BALANCED, - LB_DNODE_STATE_BALANCING, - LB_DNODE_STATE_OFFLINE_REMOVING, - LB_DNODE_STATE_SHELL_REMOVING -}; - -enum _vgroup_status { - LB_VGROUP_STATE_READY, - LB_VGROUP_STATE_UPDATE -}; - #define TSDB_DATA_TYPE_BOOL 1 // 1 bytes #define TSDB_DATA_TYPE_TINYINT 2 // 1 byte #define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes diff --git a/src/inc/tstatus.h b/src/inc/tstatus.h index 34319e40b3..0f9bea5ae5 100644 --- a/src/inc/tstatus.h +++ b/src/inc/tstatus.h @@ -20,11 +20,77 @@ extern "C" { #endif +enum _TSDB_VG_STATUS { + TSDB_VG_STATUS_READY, + TSDB_VG_STATUS_IN_PROGRESS, + TSDB_VG_STATUS_COMMITLOG_INIT_FAILED, + TSDB_VG_STATUS_INIT_FAILED, + TSDB_VG_STATUS_FULL +}; + +enum _TSDB_DB_STATUS { + TSDB_DB_STATUS_READY, + TSDB_DB_STATUS_DROPPING, + TSDB_DB_STATUS_DROP_FROM_SDB +}; + +enum _TSDB_VN_STATUS { + TSDB_VN_STATUS_OFFLINE, + TSDB_VN_STATUS_CREATING, + TSDB_VN_STATUS_UNSYNCED, + TSDB_VN_STATUS_SLAVE, + TSDB_VN_STATUS_MASTER, + TSDB_VN_STATUS_CLOSING, + TSDB_VN_STATUS_DELETING, +}; + +enum _TSDB_VN_SYNC_STATUS { + TSDB_VN_SYNC_STATUS_INIT, + TSDB_VN_SYNC_STATUS_SYNCING, + TSDB_VN_SYNC_STATUS_SYNC_CACHE, + TSDB_VN_SYNC_STATUS_SYNC_FILE +}; + +enum _TSDB_VN_DROP_STATUS { + TSDB_VN_DROP_STATUS_READY, + TSDB_VN_DROP_STATUS_DROPPING +}; + +enum _TSDB_DN_STATUS { + TSDB_DN_STATUS_OFFLINE, + TSDB_DN_STATUS_READY +}; + +enum _TSDB_DN_LB_STATUS { + TSDB_DN_LB_STATUS_BALANCED, + TSDB_DN_LB_STATUS_BALANCING, + TSDB_DN_LB_STATUS_OFFLINE_REMOVING, + TSDB_DN_LB_STATE_SHELL_REMOVING +}; + +enum _TSDB_VG_LB_STATUS { + TSDB_VG_LB_STATUS_READY, + TSDB_VG_LB_STATUS_UPDATE +}; + +enum _TSDB_LB_TYPE { + TSDB_LB_TYPE_SCHEDULE, + TSDB_LB_TYPE_SOON, +}; + +enum _TSDB_LB_REASON { + TSDB_LB_REASON_PERIOD, + TSDB_LB_REASON_EVENT, +}; + const char* taosGetVnodeStatusStr(int vnodeStatus); -const char* taosGetDnodeStatusStr(int dnodeStatus); -const char* taosGetDnodeBalanceStateStr(int dnodeBalanceStatus); const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus); const char* taosGetVnodeDropStatusStr(int dropping); +const char* taosGetDnodeStatusStr(int dnodeStatus); +const char* taosGetDnodeLbStatusStr(int dnodeBalanceStatus); +const char* taosGetBalanceTypeStr(int type); +const char* taosBalanceReasonStr(int reason); +const char* taosGetVgroupLbStatusStr(int vglbStatus); #ifdef __cplusplus } diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index 702eb00875..4de31325d0 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -45,17 +45,6 @@ extern int mgmtShellConns; extern int mgmtDnodeConns; extern char mgmtDirectory[]; -enum _TSDB_VG_STATUS { - TSDB_VG_STATUS_READY, - TSDB_VG_STATUS_IN_PROGRESS, - TSDB_VG_STATUS_COMMITLOG_INIT_FAILED, - TSDB_VG_STATUS_INIT_FAILED, - TSDB_VG_STATUS_FULL -}; - -enum _TSDB_DB_STATUS { TSDB_DB_STATUS_READY, TSDB_DB_STATUS_DROPPING, TSDB_DB_STATUS_DROP_FROM_SDB }; - -enum _TSDB_VN_STATUS { TSDB_VN_STATUS_READY, TSDB_VN_STATUS_DROPPING }; typedef struct { uint32_t privateIp; @@ -86,7 +75,7 @@ typedef struct { uint16_t slot; int32_t customScore; // config by user float lbScore; // calc in balance function - int16_t lbState; // set in balance function + int16_t lbStatus; // set in balance function int16_t lastAllocVnode; // increase while create vnode SVnodeLoad vload[TSDB_MAX_VNODES]; char reserved[16]; @@ -148,7 +137,7 @@ typedef struct _vg_obj { int32_t numOfMeters; int32_t lbIp; int32_t lbTime; - int8_t lbState; + int8_t lbStatus; char reserved[16]; char updateEnd[1]; struct _vg_obj *prev, *next; @@ -426,7 +415,7 @@ void mgmtSetDnodeShellRemoving(SDnodeObj *pDnode); void mgmtSetDnodeUnRemove(SDnodeObj *pDnode); void mgmtStartBalanceTimer(int mseconds); void mgmtSetDnodeOfflineOnSdbChanged(); -void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbState, int srcIp); +void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp); bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode); void mgmtSetModuleInDnode(SDnodeObj *pDnode, int moduleType); diff --git a/src/system/detail/src/dnodeMgmt.c b/src/system/detail/src/dnodeMgmt.c index 630e50b44d..9a8cde169e 100644 --- a/src/system/detail/src/dnodeMgmt.c +++ b/src/system/detail/src/dnodeMgmt.c @@ -116,7 +116,7 @@ int vnodeProcessCreateMeterRequest(char *pMsg, int msgLen, SMgmtObj *pObj) { goto _over; } - if (pVnode->syncStatus == TSDB_SSTATUS_SYNCING) { + if (pVnode->syncStatus == TSDB_VN_SYNC_STATUS_SYNCING) { code = vnodeSaveCreateMsgIntoQueue(pVnode, pMsg, msgLen); dTrace("vid:%d, create msg is saved into sync queue", vid); } else { @@ -331,7 +331,7 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { return -1; } - if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_CREATING) { + if (vnodeList[vnode].vnodeStatus == TSDB_VN_STATUS_CREATING) { dTrace("vid:%d, vnode is still under creating", vnode); return 0; } @@ -362,7 +362,7 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { if (vnodeList[vnode].cfg.maxSessions == 0) { dTrace("vid:%d, vnode is empty", vnode); if (pCfg->maxSessions > 0) { - if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_OFFLINE) { + if (vnodeList[vnode].vnodeStatus == TSDB_VN_STATUS_OFFLINE) { dTrace("vid:%d, status:%s, start to create vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); return vnodeCreateVnode(vnode, pCfg, pMsg->vpeerDesc); } else { @@ -373,7 +373,7 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { } else { dTrace("vid:%d, vnode is not empty", vnode); if (pCfg->maxSessions > 0) { - if (vnodeList[vnode].vnodeStatus == TSDB_VNODE_STATUS_DELETING) { + if (vnodeList[vnode].vnodeStatus == TSDB_VN_STATUS_DELETING) { dTrace("vid:%d, status:%s, wait vnode delete finished", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); } else { dTrace("vid:%d, status:%s, start to update vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index 16a028d2de..01b5c00a83 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -20,6 +20,7 @@ #include "mgmtBalance.h" #include "mgmtUtil.h" #include "tschemautil.h" +#include "tstatus.h" void *dbSdb = NULL; int tsDbUpdateSize; @@ -281,8 +282,8 @@ int mgmtSetDbDropping(SDbObj *pDb) { if (pDnode == NULL) continue; SVnodeLoad *pVload = &pDnode->vload[pVnodeGid->vnode]; - if (pVload->dropStatus != TSDB_VN_STATUS_DROPPING) { - pVload->dropStatus = TSDB_VN_STATUS_DROPPING; + if (pVload->dropStatus != TSDB_VN_DROP_STATUS_DROPPING) { + pVload->dropStatus = TSDB_VN_DROP_STATUS_DROPPING; mPrint("dnode:%s vnode:%d db:%s set to dropping status", taosIpStr(pDnode->privateIp), pVnodeGid->vnode, pDb->name); if (mgmtUpdateDnode(pDnode) < 0) { @@ -315,10 +316,10 @@ bool mgmtCheckDropDbFinished(SDbObj *pDb) { SDnodeObj *pDnode = mgmtGetDnode(pVnodeGid->ip); if (pDnode == NULL) continue; - if (pDnode->status == TSDB_DNODE_STATUS_OFFLINE) continue; + if (pDnode->status == TSDB_DN_STATUS_OFFLINE) continue; SVnodeLoad *pVload = &pDnode->vload[pVnodeGid->vnode]; - if (pVload->dropStatus == TSDB_VN_STATUS_DROPPING) { + if (pVload->dropStatus == TSDB_VN_DROP_STATUS_DROPPING) { mTrace("dnode:%s, vnode:%d db:%s wait dropping", taosIpStr(pDnode->privateIp), pVnodeGid->vnode, pDb->name); return false; } @@ -444,7 +445,7 @@ int mgmtAlterDb(SAcctObj *pAcct, SAlterDbMsg *pAlter) { SVgObj *pVgroup = pDb->pHead; while (pVgroup != NULL) { - mgmtUpdateVgroupState(pVgroup, LB_VGROUP_STATE_UPDATE, 0); + mgmtUpdateVgroupState(pVgroup, TSDB_VG_LB_STATUS_UPDATE, 0); if (oldReplicaNum < pDb->cfg.replications) { if (!mgmtAddVnode(pVgroup, NULL, NULL)) { mWarn("db:%s vgroup:%d not enough dnode to add vnode", pAlter->db, pVgroup->vgId); diff --git a/src/system/detail/src/mgmtDnode.c b/src/system/detail/src/mgmtDnode.c index d8cfbbe917..9af594f2ca 100644 --- a/src/system/detail/src/mgmtDnode.c +++ b/src/system/detail/src/mgmtDnode.c @@ -44,9 +44,9 @@ void mgmtSetDnodeMaxVnodes(SDnodeObj *pDnode) { pDnode->openVnodes = 0; #ifdef CLUSTER - pDnode->status = TSDB_DNODE_STATUS_OFFLINE; + pDnode->status = TSDB_DN_STATUS_OFFLINE; #else - pDnode->status = TSDB_DNODE_STATUS_READY; + pDnode->status = TSDB_DN_STATUS_READY; #endif } @@ -201,7 +201,7 @@ int mgmtRetrieveDnodes(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, taosGetDnodeBalanceStateStr(pDnode->lbState)); + strcpy(pWrite, taosGetDnodeLbStatusStr(pDnode->lbStatus)); cols++; tinet_ntoa(ipstr, pDnode->publicIp); diff --git a/src/system/detail/src/mgmtMeter.c b/src/system/detail/src/mgmtMeter.c index 80ea5142e9..658af40212 100644 --- a/src/system/detail/src/mgmtMeter.c +++ b/src/system/detail/src/mgmtMeter.c @@ -27,6 +27,7 @@ #include "tsqlfunction.h" #include "ttime.h" #include "vnodeTagMgmt.h" +#include "tstatus.h" extern int64_t sdbVersion; @@ -661,7 +662,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { pMeter->uid = (((uint64_t)pMeter->gid.vgId) << 40) + ((((uint64_t)pMeter->gid.sid) & ((1ul << 24) - 1ul)) << 16) + ((uint64_t)sdbVersion & ((1ul << 16) - 1ul)); - mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%d db:%s", + mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%ld db:%s", pMeter->meterId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pMeter->uid, pDb->name); } else { pMeter->uid = (((uint64_t)pMeter->createdTime) << 16) + ((uint64_t)sdbVersion & ((1ul << 16) - 1ul)); diff --git a/src/system/detail/src/mgmtShell.c b/src/system/detail/src/mgmtShell.c index bd8f798e38..85705fe62d 100644 --- a/src/system/detail/src/mgmtShell.c +++ b/src/system/detail/src/mgmtShell.c @@ -21,6 +21,7 @@ #include "mgmtProfile.h" #include "taosmsg.h" #include "tlog.h" +#include "tstatus.h" #pragma GCC diagnostic push diff --git a/src/system/detail/src/mgmtVgroup.c b/src/system/detail/src/mgmtVgroup.c index 97a7343e1e..e3bed57b33 100644 --- a/src/system/detail/src/mgmtVgroup.c +++ b/src/system/detail/src/mgmtVgroup.c @@ -19,6 +19,7 @@ #include "mgmt.h" #include "tschemautil.h" #include "tlog.h" +#include "tstatus.h" void * vgSdb = NULL; int tsVgUpdateSize; @@ -312,7 +313,7 @@ int mgmtRetrieveVgroups(SShowObj *pShow, char *data, int rows, SConnObj *pConn) cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, pVgroup->lbState ? "updating" : "ready"); + strcpy(pWrite, taosGetVgroupLbStatusStr(pVgroup->lbStatus)); cols++; for (int i = 0; i < maxReplica; ++i) { diff --git a/src/system/detail/src/vnodeCache.c b/src/system/detail/src/vnodeCache.c index 938e655b49..71132b50ef 100644 --- a/src/system/detail/src/vnodeCache.c +++ b/src/system/detail/src/vnodeCache.c @@ -20,6 +20,7 @@ #include "vnode.h" #include "vnodeCache.h" #include "vnodeUtil.h" +#include "tstatus.h" void vnodeSearchPointInCache(SMeterObj *pObj, SQuery *pQuery); void vnodeProcessCommitTimer(void *param, void *tmrId); @@ -297,7 +298,7 @@ pthread_t vnodeCreateCommitThread(SVnodeObj *pVnode) { taosTmrStopA(&pVnode->commitTimer); - if (pVnode->vnodeStatus == TSDB_VNODE_STATUS_UNSYNCED) { + if (pVnode->vnodeStatus == TSDB_VN_STATUS_UNSYNCED) { taosTmrReset(vnodeProcessCommitTimer, pVnode->cfg.commitTime * 1000, pVnode, vnodeTmrCtrl, &pVnode->commitTimer); dTrace("vid:%d, it is in unsyc state, commit later", pVnode->vnode); return pVnode->commitThread; diff --git a/src/system/detail/src/vnodeMeter.c b/src/system/detail/src/vnodeMeter.c index 14cdf9eb78..06135a7e9e 100644 --- a/src/system/detail/src/vnodeMeter.c +++ b/src/system/detail/src/vnodeMeter.c @@ -484,7 +484,7 @@ int vnodeCreateMeterObj(SMeterObj *pNew, SConnSec *pSec) { vnodeSaveMeterObjToFile(pNew); // vnodeCreateMeterMgmt(pNew, pSec); vnodeCreateStream(pNew); - dTrace("vid:%d sid:%d id:%s, meterObj is created, uid:%ld", pNew->vnode, pNew->sid, pNew->meterId, pNew->uid); + dTrace("vid:%d, sid:%d id:%s, meterObj is created, uid:%ld", pNew->vnode, pNew->sid, pNew->meterId, pNew->uid); } return code; diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c index 5982b7b1b5..9000a7df78 100644 --- a/src/system/detail/src/vnodeShell.c +++ b/src/system/detail/src/vnodeShell.c @@ -28,6 +28,7 @@ #include "vnodeRead.h" #include "vnodeUtil.h" #include "vnodeStore.h" +#include "tstatus.h" #pragma GCC diagnostic ignored "-Wint-conversion" extern int tsMaxQueues; @@ -90,7 +91,7 @@ void *vnodeProcessMsgFromShell(char *msg, void *ahandle, void *thandle) { // if ( vnodeList[vnode].status != TSDB_STATUS_MASTER && pMsg->msgType != TSDB_MSG_TYPE_RETRIEVE ) { #ifdef CLUSTER - if (vnodeList[vnode].vnodeStatus != TSDB_VNODE_STATUS_MASTER) { + if (vnodeList[vnode].vnodeStatus != TSDB_VN_STATUS_MASTER) { taosSendSimpleRsp(thandle, pMsg->msgType + 1, TSDB_CODE_NOT_READY); dTrace("vid:%d sid:%d, shell msg is ignored since in state:%d", vnode, sid, vnodeList[vnode].vnodeStatus); } else { diff --git a/src/system/detail/src/vnodeStore.c b/src/system/detail/src/vnodeStore.c index 572bd88cf7..49fcdfe467 100644 --- a/src/system/detail/src/vnodeStore.c +++ b/src/system/detail/src/vnodeStore.c @@ -78,7 +78,7 @@ int vnodeOpenVnode(int vnode) { return TSDB_CODE_SUCCESS; } - if (!(pVnode->vnodeStatus == TSDB_VNODE_STATUS_OFFLINE || pVnode->vnodeStatus == TSDB_VNODE_STATUS_CREATING)) { + if (!(pVnode->vnodeStatus == TSDB_VN_STATUS_OFFLINE || pVnode->vnodeStatus == TSDB_VN_STATUS_CREATING)) { dError("vid:%d, status:%s, cannot enter open operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_INVALID_VNODE_STATUS; } @@ -140,12 +140,12 @@ static int vnodeCloseVnode(int vnode) { return TSDB_CODE_SUCCESS; } - if (pVnode->vnodeStatus == TSDB_VNODE_STATUS_DELETING) { + if (pVnode->vnodeStatus == TSDB_VN_STATUS_DELETING) { dTrace("vid:%d, status:%s, another thread performed delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_SUCCESS; } else { dTrace("vid:%d, status:%s, enter close operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); - pVnode->vnodeStatus = TSDB_VNODE_STATUS_CLOSING; + pVnode->vnodeStatus = TSDB_VN_STATUS_CLOSING; } // set the meter is dropped flag @@ -155,7 +155,7 @@ static int vnodeCloseVnode(int vnode) { } dTrace("vid:%d, status:%s, enter delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); - pVnode->vnodeStatus = TSDB_VNODE_STATUS_DELETING; + pVnode->vnodeStatus = TSDB_VN_STATUS_DELETING; vnodeCloseStream(vnodeList + vnode); vnodeCancelCommit(vnodeList + vnode); @@ -178,12 +178,12 @@ static int vnodeCloseVnode(int vnode) { int vnodeCreateVnode(int vnode, SVnodeCfg *pCfg, SVPeerDesc *pDesc) { char fileName[128]; - if (vnodeList[vnode].vnodeStatus != TSDB_VNODE_STATUS_OFFLINE) { + if (vnodeList[vnode].vnodeStatus != TSDB_VN_STATUS_OFFLINE) { dError("vid:%d, status:%s, cannot enter create operation", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); return TSDB_CODE_INVALID_VNODE_STATUS; } - vnodeList[vnode].vnodeStatus = TSDB_VNODE_STATUS_CREATING; + vnodeList[vnode].vnodeStatus = TSDB_VN_STATUS_CREATING; sprintf(fileName, "%s/vnode%d", tsDirectory, vnode); mkdir(fileName, 0755); @@ -258,9 +258,9 @@ int vnodeRemoveVnode(int vnode) { if (vnodeList[vnode].cfg.maxSessions > 0) { SVnodeObj* pVnode = &vnodeList[vnode]; - if (pVnode->vnodeStatus == TSDB_VNODE_STATUS_CREATING - || pVnode->vnodeStatus == TSDB_VNODE_STATUS_OFFLINE - || pVnode->vnodeStatus == TSDB_VNODE_STATUS_DELETING) { + if (pVnode->vnodeStatus == TSDB_VN_STATUS_CREATING + || pVnode->vnodeStatus == TSDB_VN_STATUS_OFFLINE + || pVnode->vnodeStatus == TSDB_VN_STATUS_DELETING) { dError("vid:%d, status:%s, cannot enter close/delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_ACTION_IN_PROGRESS; } else { @@ -325,7 +325,7 @@ void vnodeCleanUpOneVnode(int vnode) { again = 1; if (vnodeList[vnode].pCachePool) { - vnodeList[vnode].vnodeStatus = TSDB_VNODE_STATUS_OFFLINE; + vnodeList[vnode].vnodeStatus = TSDB_VN_STATUS_OFFLINE; vnodeClosePeerVnode(vnode); } @@ -354,7 +354,7 @@ void vnodeCleanUpVnodes() { for (int vnode = 0; vnode < TSDB_MAX_VNODES; ++vnode) { if (vnodeList[vnode].pCachePool) { - vnodeList[vnode].vnodeStatus = TSDB_VNODE_STATUS_OFFLINE; + vnodeList[vnode].vnodeStatus = TSDB_VN_STATUS_OFFLINE; vnodeClosePeerVnode(vnode); } } diff --git a/src/system/detail/src/vnodeStream.c b/src/system/detail/src/vnodeStream.c index 562b7eb73c..00e261c4d0 100644 --- a/src/system/detail/src/vnodeStream.c +++ b/src/system/detail/src/vnodeStream.c @@ -17,6 +17,7 @@ #include "taosmsg.h" #include "vnode.h" #include "vnodeUtil.h" +#include "tstatus.h" /* static TAOS *dbConn = NULL; */ void vnodeCloseStreamCallback(void *param); @@ -171,7 +172,7 @@ void vnodeCloseStream(SVnodeObj *pVnode) { void vnodeUpdateStreamRole(SVnodeObj *pVnode) { /* SMeterObj *pObj; */ - int newRole = (pVnode->vnodeStatus == TSDB_VNODE_STATUS_MASTER) ? 1 : 0; + int newRole = (pVnode->vnodeStatus == TSDB_VN_STATUS_MASTER) ? 1 : 0; if (newRole != pVnode->streamRole) { dTrace("vid:%d, stream role is changed to:%d", pVnode->vnode, newRole); pVnode->streamRole = newRole; diff --git a/src/system/lite/src/mgmtBalance.spec.c b/src/system/lite/src/mgmtBalance.spec.c index 5100aea936..7fbc863391 100644 --- a/src/system/lite/src/mgmtBalance.spec.c +++ b/src/system/lite/src/mgmtBalance.spec.c @@ -53,8 +53,8 @@ bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int moduleType) { bool mgmtCheckVnodeReady(SDnodeObj *pDnode, SVgObj *pVgroup, SVnodeGid *pVnode) { return true; } -void mgmtUpdateDnodeState(SDnodeObj *pDnode, int lbState) {} +void mgmtUpdateDnodeState(SDnodeObj *pDnode, int lbStatus) {} -void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbState, int srcIp) {} +void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp) {} bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode) { return false; } \ No newline at end of file diff --git a/src/system/lite/src/mgmtDnode.spec.c b/src/system/lite/src/mgmtDnode.spec.c index 3c7c7f06ba..84c33d7a63 100644 --- a/src/system/lite/src/mgmtDnode.spec.c +++ b/src/system/lite/src/mgmtDnode.spec.c @@ -30,7 +30,7 @@ int mgmtInitDnodes() { dnodeObj.createdTime = (int64_t)tsRebootTime * 1000; dnodeObj.lastReboot = tsRebootTime; dnodeObj.numOfCores = (uint16_t)tsNumOfCores; - dnodeObj.status = TSDB_DNODE_STATUS_READY; + dnodeObj.status = TSDB_DN_STATUS_READY; dnodeObj.alternativeRole = TSDB_DNODE_ROLE_ANY; dnodeObj.numOfTotalVnodes = tsNumOfTotalVnodes; dnodeObj.thandle = (void*)(1); //hack way diff --git a/src/system/lite/src/mgmtDnodeInt.spec.c b/src/system/lite/src/mgmtDnodeInt.spec.c index 10628d0fb0..f994cc63d0 100644 --- a/src/system/lite/src/mgmtDnodeInt.spec.c +++ b/src/system/lite/src/mgmtDnodeInt.spec.c @@ -82,7 +82,7 @@ void mgmtCleanUpDnodeInt() {} void mgmtProcessDnodeStatus(void *handle, void *tmrId) { SDnodeObj *pObj = &dnodeObj; pObj->openVnodes = tsOpenVnodes; - pObj->status = TSDB_DNODE_STATUS_READY; + pObj->status = TSDB_DN_STATUS_READY; float memoryUsedMB = 0; taosGetSysMemory(&memoryUsedMB); @@ -95,8 +95,8 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { // wait vnode dropped if (pVload->dropStatus == TSDB_VN_STATUS_DROPPING) { if (vnodeList[vnode].cfg.maxSessions <= 0) { - pVload->dropStatus = TSDB_VN_STATUS_READY; - pVload->status = TSDB_VN_STATUS_READY; + pVload->dropStatus = TSDB_VN_DROP_STATUS_READY; + pVload->status = TSDB_VN_STATUS_OFFLINE; mPrint("dnode:%s, vid:%d, drop finished", taosIpStr(pObj->privateIp), vnode); taosTmrStart(mgmtMonitorDbDrop, 10000, NULL, mgmtTmr); } @@ -107,7 +107,7 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { } pVload->vnode = vnode; - pVload->status = TSDB_VN_STATUS_READY; + pVload->status = TSDB_VN_STATUS_MASTER; pVload->totalStorage = pVnode->vnodeStatistic.totalStorage; pVload->compStorage = pVnode->vnodeStatistic.compStorage; pVload->pointsWritten = pVnode->vnodeStatistic.pointsWritten; diff --git a/src/system/lite/src/vnodePeer.spec.c b/src/system/lite/src/vnodePeer.spec.c index d33e4ead6e..2950547327 100644 --- a/src/system/lite/src/vnodePeer.spec.c +++ b/src/system/lite/src/vnodePeer.spec.c @@ -31,7 +31,7 @@ void vnodeBroadcastStatusToUnsyncedPeer(SVnodeObj *pVnode) {} int vnodeOpenPeerVnode(int vnode) { SVnodeObj *pVnode = vnodeList + vnode; - pVnode->vnodeStatus = (pVnode->cfg.replications > 1) ? TSDB_VNODE_STATUS_UNSYNCED : TSDB_VNODE_STATUS_MASTER; + pVnode->vnodeStatus = (pVnode->cfg.replications > 1) ? TSDB_VN_STATUS_UNSYNCED : TSDB_VN_STATUS_MASTER; dTrace("vid:%d, status:%s numOfPeers:%d", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus), pVnode->cfg.replications - 1); vnodeUpdateStreamRole(pVnode); return 0; diff --git a/src/util/src/tstatus.c b/src/util/src/tstatus.c index 1e21285960..4e3141b13b 100644 --- a/src/util/src/tstatus.c +++ b/src/util/src/tstatus.c @@ -15,52 +15,78 @@ #include "taosmsg.h" #include "tsdb.h" +#include "tstatus.h" const char* taosGetVnodeStatusStr(int vnodeStatus) { switch (vnodeStatus) { - case TSDB_VNODE_STATUS_OFFLINE:return "offline"; - case TSDB_VNODE_STATUS_CREATING: return "creating"; - case TSDB_VNODE_STATUS_UNSYNCED: return "unsynced"; - case TSDB_VNODE_STATUS_SLAVE: return "slave"; - case TSDB_VNODE_STATUS_MASTER: return "master"; - case TSDB_VNODE_STATUS_CLOSING: return "closing"; - case TSDB_VNODE_STATUS_DELETING: return "deleting"; - default: return "undefined"; - } -} - -const char* taosGetDnodeStatusStr(int dnodeStatus) { - switch (dnodeStatus) { - case TSDB_DNODE_STATUS_OFFLINE: return "offline"; - case TSDB_DNODE_STATUS_READY: return "ready"; - default: return "undefined"; - } -} - -const char* taosGetDnodeBalanceStateStr(int dnodeBalanceStatus) { - switch (dnodeBalanceStatus) { - case LB_DNODE_STATE_BALANCED: return "balanced"; - case LB_DNODE_STATE_BALANCING: return "balancing"; - case LB_DNODE_STATE_OFFLINE_REMOVING: return "offline removing"; - case LB_DNODE_STATE_SHELL_REMOVING: return "removing"; - default: return "undefined"; + case TSDB_VN_STATUS_OFFLINE: return "offline"; + case TSDB_VN_STATUS_CREATING: return "creating"; + case TSDB_VN_STATUS_UNSYNCED: return "unsynced"; + case TSDB_VN_STATUS_SLAVE: return "slave"; + case TSDB_VN_STATUS_MASTER: return "master"; + case TSDB_VN_STATUS_CLOSING: return "closing"; + case TSDB_VN_STATUS_DELETING: return "deleting"; + default: return "undefined"; } } const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus) { switch (vnodeSyncStatus) { - case STDB_SSTATUS_INIT: return "init"; - case TSDB_SSTATUS_SYNCING: return "syncing"; - case TSDB_SSTATUS_SYNC_CACHE: return "sync_cache"; - case TSDB_SSTATUS_SYNC_FILE: return "sync_file"; - default: return "undefined"; + case TSDB_VN_SYNC_STATUS_INIT: return "init"; + case TSDB_VN_SYNC_STATUS_SYNCING: return "syncing"; + case TSDB_VN_SYNC_STATUS_SYNC_CACHE: return "sync_cache"; + case TSDB_VN_SYNC_STATUS_SYNC_FILE: return "sync_file"; + default: return "undefined"; } } const char* taosGetVnodeDropStatusStr(int dropping) { switch (dropping) { - case 0: return "ready"; - case 1: return "dropping"; - default: return "undefined"; + case TSDB_VN_DROP_STATUS_READY: return "ready"; + case TSDB_VN_DROP_STATUS_DROPPING: return "dropping"; + default: return "undefined"; } -} \ No newline at end of file +} + +const char* taosGetDnodeStatusStr(int dnodeStatus) { + switch (dnodeStatus) { + case TSDB_DN_STATUS_OFFLINE: return "offline"; + case TSDB_DN_STATUS_READY: return "ready"; + default: return "undefined"; + } +} + +const char* taosGetDnodeLbStatusStr(int dnodeBalanceStatus) { + switch (dnodeBalanceStatus) { + case TSDB_DN_LB_STATUS_BALANCED: return "balanced"; + case TSDB_DN_LB_STATUS_BALANCING: return "balancing"; + case TSDB_DN_LB_STATUS_OFFLINE_REMOVING: return "offline removing"; + case TSDB_DN_LB_STATE_SHELL_REMOVING: return "removing"; + default: return "undefined"; + } +} + +const char* taosGetVgroupLbStatusStr(int vglbStatus) { + switch (vglbStatus) { + case TSDB_VG_LB_STATUS_READY: return "ready"; + case TSDB_VG_LB_STATUS_UPDATE: return "updating"; + default: return "undefined"; + } +} + +const char* taosGetBalanceTypeStr(int type) { + switch (type) { + case TSDB_LB_TYPE_SCHEDULE: return "schedule"; + case TSDB_LB_TYPE_SOON: return "soon"; + default: return "undefined"; + } +} + +const char* taosBalanceReasonStr(int reason) { + switch (reason) { + case TSDB_LB_REASON_PERIOD: return "period"; + case TSDB_LB_REASON_EVENT: return "event"; + default: return "undefined"; + } +} + From 2830f322d41f5901bc68ef01809ca3319d182dfa Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Wed, 20 Nov 2019 14:19:23 +0800 Subject: [PATCH 03/42] [tbase-1203] --- src/client/src/tscServer.c | 12 ++++++++++++ src/client/src/tscSql.c | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 436bfa327a..d96f94ecc0 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -184,6 +184,15 @@ void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { pSql->vnode = TSC_MGMT_VNODE; #endif } + + // the pSql->res.code is the previous error(status) code. + if (pSql->thandle == NULL && pSql->retry >= pSql->maxRetry) { + if (pSql->res.code != TSDB_CODE_SUCCESS && pSql->res.code != TSDB_CODE_ACTION_IN_PROGRESS) { + *pCode = pSql->res.code; + } + + tscError("%p reach the max retry:%d, code:%d", pSql, pSql->retry, *pCode); + } } void tscGetConnToVnode(SSqlObj *pSql, uint8_t *pCode) { @@ -442,6 +451,9 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { tscTrace("%p it shall be redirected!", pSql); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); pSql->thandle = NULL; + + // reset the retry times for a new mgmt node + pSql->retry = 0; if (pCmd->command > TSDB_SQL_MGMT) { tscProcessMgmtRedirect(pSql, pMsg->content + 1); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6ec8f425ca..9dd9649a01 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -245,9 +245,9 @@ int taos_query_imp(STscObj* pObj, SSqlObj* pSql) { pRes->qhandle = 0; pSql->thandle = NULL; - if (pRes->code != TSDB_CODE_SUCCESS) return pRes->code; - - tscDoQuery(pSql); + if (pRes->code == TSDB_CODE_SUCCESS) { + tscDoQuery(pSql); + } tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj); if (pRes->code != TSDB_CODE_SUCCESS) { From b6c6d40778745bb41ec6ead48a0a9fbf66aa037d Mon Sep 17 00:00:00 2001 From: lihui Date: Wed, 20 Nov 2019 16:48:49 +0800 Subject: [PATCH 04/42] [modify for arm] --- src/os/linux/src/tsystem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/tsystem.c index fa41e8e6d0..b01f0b7926 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/tsystem.c @@ -608,6 +608,7 @@ void taosSetCoreDump() { pPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); } +#ifndef _TD_ARM_ // 2. set the path for saving core file struct __sysctl_args args; int old_usespid = 0; @@ -649,9 +650,10 @@ void taosSetCoreDump() { } pPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid); +#endif #if 0 - // 3. set the path for saving core file + // 3. create the path for saving core file int status; char coredump_dir[32] = "/var/log/taosdump"; if (opendir(coredump_dir) == NULL) { From 7be465854e467a0dcf7223e9c7f9685ca6aa354e Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Wed, 20 Nov 2019 17:04:38 +0800 Subject: [PATCH 05/42] [tbase-1205] [tbase-955] --- src/inc/sql.y | 15 +- src/inc/tsql.h | 1 + src/inc/tsqldef.h | 3 +- src/util/src/sql.c | 1989 ++++++++++++++++++++++--------------- src/util/src/ttokenizer.c | 3 +- 5 files changed, 1209 insertions(+), 802 deletions(-) diff --git a/src/inc/sql.y b/src/inc/sql.y index e04324c5de..1aea945818 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -26,7 +26,6 @@ #include #include #include - #include "tsql.h" #include "tutil.h" } @@ -113,7 +112,7 @@ cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { } cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDCLSQLElems(pInfo, DROP_DATABASE, 2, &X, &Y); } -cmd ::= DROP DNODE IP(X). { setDCLSQLElems(pInfo, DROP_DNODE, 1, &X); } +cmd ::= DROP DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, DROP_DNODE, 1, &X); } cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, DROP_USER, 1, &X); } cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, DROP_ACCOUNT, 1, &X); } @@ -129,8 +128,8 @@ cmd ::= DESCRIBE ids(X) cpxName(Y). { /////////////////////////////////THE ALTER STATEMENT//////////////////////////////////////// cmd ::= ALTER USER ids(X) PASS ids(Y). { setDCLSQLElems(pInfo, ALTER_USER_PASSWD, 2, &X, &Y); } cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setDCLSQLElems(pInfo, ALTER_USER_PRIVILEGES, 2, &X, &Y);} -cmd ::= ALTER DNODE IP(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_DNODE, 2, &X, &Y); } -cmd ::= ALTER DNODE IP(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, ALTER_DNODE, 3, &X, &Y, &Z); } +cmd ::= ALTER DNODE IPTOKEN(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_DNODE, 2, &X, &Y); } +cmd ::= ALTER DNODE IPTOKEN(X) ids(Y) ids(Z). { setDCLSQLElems(pInfo, ALTER_DNODE, 3, &X, &Y, &Z); } cmd ::= ALTER LOCAL ids(X). { setDCLSQLElems(pInfo, ALTER_LOCAL, 1, &X); } cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSQLElems(pInfo, ALTER_LOCAL, 2, &X, &Y); } cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SSQLToken t = {0}; setCreateDBSQL(pInfo, ALTER_DATABASE, &X, &Y, &t);} @@ -642,12 +641,12 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { } ////////////////////////////////////////kill statement/////////////////////////////////////// -cmd ::= KILL CONNECTION IP(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &X);} -cmd ::= KILL STREAM IP(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &X);} -cmd ::= KILL QUERY IP(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &X);} +cmd ::= KILL CONNECTION IPTOKEN(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &X);} +cmd ::= KILL STREAM IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &X);} +cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &X);} %fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL COUNT SUM AVG MIN MAX FIRST LAST TOP BOTTOM STDDEV PERCENTILE APERCENTILE LEASTSQUARES HISTOGRAM DIFF - SPREAD TWA INTERP LAST_ROW NOW IP SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE. \ No newline at end of file + SPREAD TWA INTERP LAST_ROW NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT METRIC TBNAME JOIN METRICS STABLE NULL. \ No newline at end of file diff --git a/src/inc/tsql.h b/src/inc/tsql.h index 0bcd8ffa68..5b033c535e 100644 --- a/src/inc/tsql.h +++ b/src/inc/tsql.h @@ -31,6 +31,7 @@ extern "C" { #define TK_OCT 204 // oct number #define TK_BIN 205 // bin format data 0b111 #define TK_FILE 206 +#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query #define TSQL_SO_ASC 1 #define TSQL_SO_DESC 0 diff --git a/src/inc/tsqldef.h b/src/inc/tsqldef.h index 6d2c166eab..3d056f771c 100644 --- a/src/inc/tsqldef.h +++ b/src/inc/tsqldef.h @@ -80,7 +80,7 @@ #define TK_TABLE 62 #define TK_DATABASE 63 #define TK_DNODE 64 -#define TK_IP 65 +#define TK_IPTOKEN 65 #define TK_USER 66 #define TK_ACCOUNT 67 #define TK_USE 68 @@ -210,7 +210,6 @@ #define TK_JOIN 192 #define TK_METRICS 193 #define TK_STABLE 194 -#define TK_QUESTION 195 #endif diff --git a/src/util/src/sql.c b/src/util/src/sql.c index 7e90e5f939..0feb3df5d9 100644 --- a/src/util/src/sql.c +++ b/src/util/src/sql.c @@ -30,7 +30,6 @@ #include #include #include - #include "tsql.h" #include "tutil.h" /**************** End of %include directives **********************************/ @@ -79,13 +78,15 @@ ** defined, then do no error processing. ** YYNSTATE the combined number of states. ** YYNRULE the number of rules in the grammar +** YYNTOKEN Number of terminal symbols ** YY_MAX_SHIFT Maximum value for shift actions ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions -** YY_MIN_REDUCE Maximum value for reduce actions ** YY_ERROR_ACTION The yy_action[] code for syntax error ** YY_ACCEPT_ACTION The yy_action[] code for accept ** YY_NO_ACTION The yy_action[] code for no-op +** YY_MIN_REDUCE Minimum value for reduce actions +** YY_MAX_REDUCE Maximum value for reduce actions */ #ifndef INTERFACE # define INTERFACE 1 @@ -123,20 +124,17 @@ typedef union { #define YYFALLBACK 1 #define YYNSTATE 251 #define YYNRULE 213 +#define YYNTOKEN 195 #define YY_MAX_SHIFT 250 #define YY_MIN_SHIFTREDUCE 401 #define YY_MAX_SHIFTREDUCE 613 -#define YY_MIN_REDUCE 614 -#define YY_MAX_REDUCE 826 -#define YY_ERROR_ACTION 827 -#define YY_ACCEPT_ACTION 828 -#define YY_NO_ACTION 829 +#define YY_ERROR_ACTION 614 +#define YY_ACCEPT_ACTION 615 +#define YY_NO_ACTION 616 +#define YY_MIN_REDUCE 617 +#define YY_MAX_REDUCE 829 /************* End control #defines *******************************************/ -/* The yyzerominor constant is used to initialize instances of -** YYMINORTYPE objects to zero. */ -static const YYMINORTYPE yyzerominor = { 0 }; - /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. ** @@ -164,9 +162,6 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** -** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE -** and YY_MAX_REDUCE - ** N == YY_ERROR_ACTION A syntax error has occurred. ** ** N == YY_ACCEPT_ACTION The parser accepts its input. @@ -174,21 +169,22 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** +** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE +** and YY_MAX_REDUCE +** ** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as +** Given state S and lookahead X, the action is computed as either: ** -** yy_action[ yy_shift_ofst[S] + X ] +** (A) N = yy_action[ yy_shift_ofst[S] + X ] +** (B) N = yy_default[S] ** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. +** The (A) formula is preferred. The B formula is used instead if +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. ** -** The formula above is for computing the action when the lookahead is +** The formulas above are for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after ** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. +** the yy_shift_ofst[] array. ** ** The following are the tables generated in this section: ** @@ -202,196 +198,214 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (529) +#define YY_ACTTAB_COUNT (530) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 439, 36, 35, 153, 249, 34, 33, 32, 440, 34, - /* 10 */ 33, 32, 43, 45, 49, 37, 38, 74, 78, 244, - /* 20 */ 31, 85, 77, 205, 41, 39, 42, 40, 80, 133, - /* 30 */ 101, 50, 36, 35, 527, 171, 34, 33, 32, 43, - /* 40 */ 45, 154, 37, 38, 114, 115, 224, 31, 65, 68, - /* 50 */ 205, 41, 39, 42, 40, 76, 133, 828, 250, 36, - /* 60 */ 35, 241, 241, 34, 33, 32, 43, 45, 155, 37, - /* 70 */ 38, 128, 126, 245, 31, 89, 88, 205, 41, 39, - /* 80 */ 42, 40, 202, 524, 59, 135, 36, 35, 439, 21, - /* 90 */ 34, 33, 32, 520, 159, 596, 440, 10, 57, 172, - /* 100 */ 135, 135, 227, 226, 101, 45, 439, 37, 38, 158, - /* 110 */ 596, 595, 31, 156, 440, 205, 41, 39, 42, 40, - /* 120 */ 232, 167, 564, 507, 36, 35, 166, 21, 34, 33, - /* 130 */ 32, 510, 402, 403, 404, 405, 406, 407, 408, 409, - /* 140 */ 410, 411, 412, 413, 510, 37, 38, 243, 132, 508, - /* 150 */ 31, 220, 101, 205, 41, 39, 42, 40, 551, 168, - /* 160 */ 200, 507, 36, 35, 97, 134, 34, 33, 32, 510, - /* 170 */ 21, 139, 101, 17, 219, 242, 218, 217, 216, 215, - /* 180 */ 214, 213, 212, 211, 492, 21, 481, 482, 483, 484, - /* 190 */ 485, 486, 487, 488, 489, 490, 491, 163, 577, 11, - /* 200 */ 243, 568, 228, 571, 507, 574, 550, 163, 577, 498, - /* 210 */ 21, 568, 509, 571, 193, 574, 148, 233, 7, 507, - /* 220 */ 561, 62, 111, 87, 86, 142, 60, 178, 242, 160, - /* 230 */ 161, 147, 437, 204, 186, 124, 183, 230, 229, 160, - /* 240 */ 161, 163, 577, 525, 506, 568, 570, 571, 573, 574, - /* 250 */ 41, 39, 42, 40, 495, 61, 494, 27, 36, 35, - /* 260 */ 545, 546, 34, 33, 32, 514, 28, 600, 511, 162, - /* 270 */ 512, 29, 513, 160, 161, 192, 446, 566, 188, 124, - /* 280 */ 248, 247, 422, 438, 522, 150, 124, 18, 601, 536, - /* 290 */ 537, 44, 29, 47, 15, 594, 169, 170, 578, 14, - /* 300 */ 576, 44, 14, 569, 518, 572, 519, 2, 52, 516, - /* 310 */ 576, 517, 504, 567, 503, 575, 47, 592, 22, 591, - /* 320 */ 209, 73, 72, 53, 22, 575, 9, 8, 84, 83, - /* 330 */ 590, 151, 152, 140, 501, 44, 610, 141, 560, 143, - /* 340 */ 144, 145, 146, 137, 576, 131, 138, 136, 164, 557, - /* 350 */ 556, 165, 526, 231, 110, 98, 112, 113, 448, 575, - /* 360 */ 543, 542, 210, 129, 515, 25, 223, 225, 609, 70, - /* 370 */ 189, 608, 606, 116, 466, 26, 23, 130, 435, 79, - /* 380 */ 433, 81, 431, 191, 430, 173, 125, 428, 427, 426, - /* 390 */ 424, 91, 532, 194, 198, 54, 417, 127, 51, 521, - /* 400 */ 421, 203, 419, 46, 102, 95, 201, 530, 103, 531, - /* 410 */ 544, 195, 199, 197, 30, 27, 222, 235, 75, 234, - /* 420 */ 236, 207, 238, 55, 237, 239, 240, 246, 149, 613, - /* 430 */ 63, 66, 174, 429, 175, 176, 90, 92, 177, 423, - /* 440 */ 119, 612, 118, 467, 117, 120, 121, 179, 122, 123, - /* 450 */ 1, 505, 108, 104, 105, 106, 107, 109, 24, 180, - /* 460 */ 181, 182, 611, 184, 185, 604, 12, 13, 187, 190, - /* 470 */ 96, 533, 99, 157, 58, 538, 196, 100, 19, 4, - /* 480 */ 579, 3, 16, 20, 64, 5, 206, 6, 208, 479, - /* 490 */ 478, 477, 476, 475, 474, 473, 472, 470, 47, 221, - /* 500 */ 443, 67, 445, 22, 500, 48, 499, 497, 464, 56, - /* 510 */ 462, 454, 69, 460, 456, 71, 458, 452, 450, 471, - /* 520 */ 469, 82, 441, 425, 415, 93, 614, 616, 94, + /* 0 */ 97, 439, 135, 101, 101, 156, 615, 250, 135, 440, + /* 10 */ 135, 159, 812, 43, 45, 21, 37, 38, 811, 158, + /* 20 */ 812, 31, 439, 726, 205, 41, 39, 42, 40, 10, + /* 30 */ 440, 153, 249, 36, 35, 743, 725, 34, 33, 32, + /* 40 */ 43, 45, 736, 37, 38, 166, 132, 167, 31, 723, + /* 50 */ 193, 205, 41, 39, 42, 40, 202, 767, 59, 200, + /* 60 */ 36, 35, 21, 726, 34, 33, 32, 43, 45, 134, + /* 70 */ 37, 38, 74, 78, 244, 31, 85, 77, 205, 41, + /* 80 */ 39, 42, 40, 80, 740, 220, 498, 36, 35, 439, + /* 90 */ 21, 34, 33, 32, 168, 101, 723, 440, 101, 57, + /* 100 */ 114, 115, 224, 726, 65, 68, 45, 7, 37, 38, + /* 110 */ 62, 111, 241, 31, 230, 229, 205, 41, 39, 42, + /* 120 */ 40, 232, 228, 564, 723, 36, 35, 21, 139, 34, + /* 130 */ 33, 32, 21, 402, 403, 404, 405, 406, 407, 408, + /* 140 */ 409, 410, 411, 412, 413, 808, 37, 38, 243, 766, + /* 150 */ 724, 31, 60, 178, 205, 41, 39, 42, 40, 233, + /* 160 */ 186, 723, 183, 36, 35, 807, 722, 34, 33, 32, + /* 170 */ 653, 171, 806, 124, 17, 219, 242, 218, 217, 216, + /* 180 */ 215, 214, 213, 212, 211, 708, 151, 697, 698, 699, + /* 190 */ 700, 701, 702, 703, 704, 705, 706, 707, 163, 577, + /* 200 */ 11, 133, 568, 133, 571, 76, 574, 662, 163, 577, + /* 210 */ 124, 241, 568, 154, 571, 155, 574, 148, 34, 33, + /* 220 */ 32, 248, 247, 422, 87, 86, 142, 243, 545, 546, + /* 230 */ 160, 161, 147, 522, 204, 172, 18, 152, 227, 226, + /* 240 */ 160, 161, 163, 577, 525, 711, 568, 710, 571, 140, + /* 250 */ 574, 41, 39, 42, 40, 242, 141, 61, 27, 36, + /* 260 */ 35, 73, 72, 34, 33, 32, 514, 654, 28, 511, + /* 270 */ 124, 512, 143, 513, 160, 161, 192, 36, 35, 188, + /* 280 */ 600, 34, 33, 32, 29, 570, 150, 573, 566, 128, + /* 290 */ 126, 245, 44, 89, 88, 601, 536, 169, 170, 29, + /* 300 */ 47, 576, 44, 162, 537, 594, 578, 144, 15, 14, + /* 310 */ 14, 576, 569, 49, 572, 504, 575, 52, 503, 47, + /* 320 */ 145, 209, 22, 146, 567, 22, 575, 518, 826, 519, + /* 330 */ 50, 516, 53, 517, 84, 83, 44, 9, 8, 717, + /* 340 */ 137, 2, 131, 138, 136, 576, 777, 742, 776, 164, + /* 350 */ 773, 772, 165, 231, 98, 759, 758, 112, 113, 664, + /* 360 */ 575, 110, 189, 210, 129, 515, 25, 223, 91, 225, + /* 370 */ 825, 70, 824, 822, 116, 682, 26, 23, 130, 651, + /* 380 */ 532, 79, 649, 54, 81, 647, 646, 173, 125, 644, + /* 390 */ 643, 642, 640, 633, 127, 637, 191, 635, 737, 194, + /* 400 */ 198, 95, 746, 747, 760, 51, 102, 46, 203, 103, + /* 410 */ 201, 199, 197, 195, 30, 27, 222, 75, 234, 235, + /* 420 */ 207, 55, 236, 240, 238, 237, 239, 63, 66, 149, + /* 430 */ 246, 613, 175, 174, 176, 645, 612, 90, 639, 119, + /* 440 */ 123, 177, 683, 117, 118, 120, 106, 104, 721, 122, + /* 450 */ 92, 121, 108, 105, 107, 109, 1, 24, 180, 179, + /* 460 */ 181, 182, 611, 184, 185, 604, 58, 12, 13, 99, + /* 470 */ 190, 187, 96, 533, 157, 538, 196, 100, 19, 64, + /* 480 */ 479, 579, 3, 20, 4, 16, 206, 6, 208, 478, + /* 490 */ 477, 476, 475, 5, 474, 473, 472, 470, 47, 443, + /* 500 */ 67, 445, 22, 221, 500, 48, 499, 497, 56, 464, + /* 510 */ 462, 454, 460, 69, 456, 71, 458, 452, 450, 471, + /* 520 */ 469, 82, 441, 425, 93, 415, 617, 616, 616, 94, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 1, 33, 34, 198, 199, 37, 38, 39, 9, 37, - /* 10 */ 38, 39, 13, 14, 100, 16, 17, 62, 63, 64, - /* 20 */ 21, 66, 67, 24, 25, 26, 27, 28, 73, 247, - /* 30 */ 199, 117, 33, 34, 199, 61, 37, 38, 39, 13, - /* 40 */ 14, 259, 16, 17, 62, 63, 64, 21, 66, 67, - /* 50 */ 24, 25, 26, 27, 28, 71, 247, 196, 197, 33, - /* 60 */ 34, 77, 77, 37, 38, 39, 13, 14, 259, 16, - /* 70 */ 17, 62, 63, 64, 21, 66, 67, 24, 25, 26, - /* 80 */ 27, 28, 251, 248, 253, 247, 33, 34, 1, 199, - /* 90 */ 37, 38, 39, 232, 256, 257, 9, 247, 99, 125, - /* 100 */ 247, 247, 128, 129, 199, 14, 1, 16, 17, 256, - /* 110 */ 257, 257, 21, 216, 9, 24, 25, 26, 27, 28, - /* 120 */ 199, 231, 96, 233, 33, 34, 216, 199, 37, 38, - /* 130 */ 39, 234, 45, 46, 47, 48, 49, 50, 51, 52, - /* 140 */ 53, 54, 55, 56, 234, 16, 17, 58, 247, 228, - /* 150 */ 21, 216, 199, 24, 25, 26, 27, 28, 253, 231, - /* 160 */ 255, 233, 33, 34, 199, 247, 37, 38, 39, 234, - /* 170 */ 199, 247, 199, 84, 85, 86, 87, 88, 89, 90, - /* 180 */ 91, 92, 93, 94, 215, 199, 217, 218, 219, 220, - /* 190 */ 221, 222, 223, 224, 225, 226, 227, 1, 2, 44, - /* 200 */ 58, 5, 231, 7, 233, 9, 253, 1, 2, 5, - /* 210 */ 199, 5, 234, 7, 249, 9, 61, 231, 95, 233, - /* 220 */ 229, 98, 99, 68, 69, 70, 253, 124, 86, 33, - /* 230 */ 34, 76, 203, 37, 131, 206, 133, 33, 34, 33, - /* 240 */ 34, 1, 2, 37, 233, 5, 5, 7, 7, 9, - /* 250 */ 25, 26, 27, 28, 217, 235, 219, 102, 33, 34, - /* 260 */ 110, 111, 37, 38, 39, 2, 246, 96, 5, 57, - /* 270 */ 7, 100, 9, 33, 34, 120, 203, 1, 123, 206, - /* 280 */ 58, 59, 60, 203, 100, 130, 206, 103, 96, 96, - /* 290 */ 96, 95, 100, 100, 100, 96, 33, 34, 96, 100, - /* 300 */ 104, 95, 100, 5, 5, 7, 7, 95, 100, 5, - /* 310 */ 104, 7, 96, 37, 96, 119, 100, 247, 100, 247, - /* 320 */ 96, 126, 127, 115, 100, 119, 126, 127, 71, 72, - /* 330 */ 247, 247, 247, 247, 230, 95, 234, 247, 229, 247, - /* 340 */ 247, 247, 247, 247, 104, 247, 247, 247, 229, 229, - /* 350 */ 229, 229, 199, 229, 236, 199, 199, 199, 199, 119, - /* 360 */ 254, 254, 199, 199, 101, 199, 199, 199, 199, 199, - /* 370 */ 122, 199, 199, 199, 199, 199, 199, 199, 199, 199, - /* 380 */ 199, 199, 199, 258, 199, 199, 199, 199, 199, 199, - /* 390 */ 199, 57, 104, 250, 250, 114, 199, 199, 116, 245, - /* 400 */ 199, 108, 199, 113, 244, 200, 112, 200, 243, 200, - /* 410 */ 200, 105, 107, 106, 118, 102, 74, 49, 83, 82, - /* 420 */ 79, 200, 53, 200, 81, 80, 78, 74, 200, 5, - /* 430 */ 204, 204, 132, 200, 5, 132, 201, 201, 65, 200, - /* 440 */ 208, 5, 212, 214, 213, 211, 209, 132, 210, 207, - /* 450 */ 205, 232, 238, 242, 241, 240, 239, 237, 202, 5, - /* 460 */ 132, 65, 5, 132, 65, 85, 95, 95, 124, 122, - /* 470 */ 121, 96, 95, 1, 100, 96, 95, 95, 100, 109, - /* 480 */ 96, 95, 95, 100, 71, 109, 97, 95, 97, 9, - /* 490 */ 5, 5, 5, 5, 1, 5, 5, 5, 100, 15, - /* 500 */ 75, 71, 65, 100, 5, 16, 5, 96, 5, 95, - /* 510 */ 5, 5, 127, 5, 5, 127, 5, 5, 5, 5, - /* 520 */ 5, 65, 75, 65, 57, 21, 0, 260, 21, + /* 0 */ 199, 1, 247, 199, 199, 216, 196, 197, 247, 9, + /* 10 */ 247, 256, 257, 13, 14, 199, 16, 17, 257, 256, + /* 20 */ 257, 21, 1, 234, 24, 25, 26, 27, 28, 247, + /* 30 */ 9, 198, 199, 33, 34, 199, 234, 37, 38, 39, + /* 40 */ 13, 14, 232, 16, 17, 216, 247, 231, 21, 233, + /* 50 */ 249, 24, 25, 26, 27, 28, 251, 253, 253, 255, + /* 60 */ 33, 34, 199, 234, 37, 38, 39, 13, 14, 247, + /* 70 */ 16, 17, 62, 63, 64, 21, 66, 67, 24, 25, + /* 80 */ 26, 27, 28, 73, 248, 216, 5, 33, 34, 1, + /* 90 */ 199, 37, 38, 39, 231, 199, 233, 9, 199, 99, + /* 100 */ 62, 63, 64, 234, 66, 67, 14, 95, 16, 17, + /* 110 */ 98, 99, 77, 21, 33, 34, 24, 25, 26, 27, + /* 120 */ 28, 199, 231, 96, 233, 33, 34, 199, 247, 37, + /* 130 */ 38, 39, 199, 45, 46, 47, 48, 49, 50, 51, + /* 140 */ 52, 53, 54, 55, 56, 247, 16, 17, 58, 253, + /* 150 */ 228, 21, 253, 124, 24, 25, 26, 27, 28, 231, + /* 160 */ 131, 233, 133, 33, 34, 247, 233, 37, 38, 39, + /* 170 */ 203, 61, 247, 206, 84, 85, 86, 87, 88, 89, + /* 180 */ 90, 91, 92, 93, 94, 215, 247, 217, 218, 219, + /* 190 */ 220, 221, 222, 223, 224, 225, 226, 227, 1, 2, + /* 200 */ 44, 247, 5, 247, 7, 71, 9, 203, 1, 2, + /* 210 */ 206, 77, 5, 259, 7, 259, 9, 61, 37, 38, + /* 220 */ 39, 58, 59, 60, 68, 69, 70, 58, 110, 111, + /* 230 */ 33, 34, 76, 100, 37, 125, 103, 247, 128, 129, + /* 240 */ 33, 34, 1, 2, 37, 217, 5, 219, 7, 247, + /* 250 */ 9, 25, 26, 27, 28, 86, 247, 235, 102, 33, + /* 260 */ 34, 126, 127, 37, 38, 39, 2, 203, 246, 5, + /* 270 */ 206, 7, 247, 9, 33, 34, 120, 33, 34, 123, + /* 280 */ 96, 37, 38, 39, 100, 5, 130, 7, 1, 62, + /* 290 */ 63, 64, 95, 66, 67, 96, 96, 33, 34, 100, + /* 300 */ 100, 104, 95, 57, 96, 96, 96, 247, 100, 100, + /* 310 */ 100, 104, 5, 100, 7, 96, 119, 100, 96, 100, + /* 320 */ 247, 96, 100, 247, 37, 100, 119, 5, 234, 7, + /* 330 */ 117, 5, 115, 7, 71, 72, 95, 126, 127, 230, + /* 340 */ 247, 95, 247, 247, 247, 104, 229, 199, 229, 229, + /* 350 */ 229, 229, 229, 229, 199, 254, 254, 199, 199, 199, + /* 360 */ 119, 236, 122, 199, 199, 101, 199, 199, 57, 199, + /* 370 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + /* 380 */ 104, 199, 199, 114, 199, 199, 199, 199, 199, 199, + /* 390 */ 199, 199, 199, 199, 199, 199, 258, 199, 245, 250, + /* 400 */ 250, 200, 200, 200, 200, 116, 244, 113, 108, 243, + /* 410 */ 112, 107, 106, 105, 118, 102, 74, 83, 82, 49, + /* 420 */ 200, 200, 79, 78, 53, 81, 80, 204, 204, 200, + /* 430 */ 74, 5, 5, 132, 132, 200, 5, 201, 200, 208, + /* 440 */ 207, 65, 214, 213, 212, 211, 240, 242, 232, 210, + /* 450 */ 201, 209, 238, 241, 239, 237, 205, 202, 5, 132, + /* 460 */ 132, 65, 5, 132, 65, 85, 100, 95, 95, 95, + /* 470 */ 122, 124, 121, 96, 1, 96, 95, 95, 100, 71, + /* 480 */ 9, 96, 95, 100, 109, 95, 97, 95, 97, 5, + /* 490 */ 5, 5, 5, 109, 1, 5, 5, 5, 100, 75, + /* 500 */ 71, 65, 100, 15, 5, 16, 5, 96, 95, 5, + /* 510 */ 5, 5, 5, 127, 5, 127, 5, 5, 5, 5, + /* 520 */ 5, 65, 75, 65, 21, 57, 0, 260, 260, 21, + /* 530 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 540 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 550 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 560 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 570 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 580 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 590 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 600 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 610 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 620 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 630 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 640 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 650 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 660 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 670 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 680 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 690 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 700 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 710 */ 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, + /* 720 */ 260, 260, 260, 260, 260, }; -#define YY_SHIFT_USE_DFLT (-87) -#define YY_SHIFT_COUNT (250) -#define YY_SHIFT_MIN (-86) -#define YY_SHIFT_MAX (526) -static const short yy_shift_ofst[] = { - /* 0 */ 155, 89, 196, 240, 105, 105, 105, 105, 105, 105, - /* 10 */ -1, 87, 240, 240, 240, 263, 263, 263, 105, 105, - /* 20 */ 105, 105, 105, -16, 142, -15, -15, -87, 206, 240, - /* 30 */ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, - /* 40 */ 240, 240, 240, 240, 240, 240, 240, 263, 263, 204, - /* 50 */ 204, 204, 204, 204, 204, 123, 204, 105, 105, 150, - /* 60 */ 150, 184, 105, 105, 105, 105, 105, 105, 105, 105, - /* 70 */ 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - /* 80 */ 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, - /* 90 */ 105, 105, 105, 105, 105, 248, 334, 334, 334, 288, - /* 100 */ 288, 334, 281, 282, 290, 293, 294, 305, 307, 306, - /* 110 */ 296, 313, 334, 334, 342, 342, 334, 335, 337, 368, - /* 120 */ 341, 343, 369, 345, 348, 334, 353, 334, 353, -87, - /* 130 */ -87, 26, 53, 53, 53, 53, 53, 91, 129, 225, - /* 140 */ 225, 225, -45, -32, -32, -32, -32, -18, 9, -26, - /* 150 */ 103, -28, -28, 222, 171, 192, 193, 194, 199, 202, - /* 160 */ 241, 298, 276, 212, -86, 208, 216, 218, 224, 299, - /* 170 */ 304, 195, 200, 257, 424, 300, 429, 303, 373, 436, - /* 180 */ 315, 454, 328, 396, 457, 331, 399, 380, 344, 371, - /* 190 */ 372, 347, 349, 374, 375, 377, 472, 381, 379, 382, - /* 200 */ 378, 370, 383, 376, 384, 386, 387, 389, 392, 391, - /* 210 */ 413, 480, 485, 486, 487, 488, 493, 490, 491, 492, - /* 220 */ 398, 425, 484, 430, 437, 489, 385, 388, 403, 499, - /* 230 */ 501, 411, 414, 403, 503, 505, 506, 508, 509, 511, - /* 240 */ 512, 513, 514, 515, 456, 458, 447, 504, 507, 467, +#define YY_SHIFT_COUNT (250) +#define YY_SHIFT_MIN (0) +#define YY_SHIFT_MAX (526) +static const unsigned short int yy_shift_ofst[] = { + /* 0 */ 156, 90, 197, 241, 21, 21, 21, 21, 21, 21, + /* 10 */ 0, 88, 241, 241, 241, 264, 264, 264, 21, 21, + /* 20 */ 21, 21, 21, 134, 169, 35, 35, 530, 207, 241, + /* 30 */ 241, 241, 241, 241, 241, 241, 241, 241, 241, 241, + /* 40 */ 241, 241, 241, 241, 241, 241, 241, 264, 264, 81, + /* 50 */ 81, 81, 81, 81, 81, 12, 81, 21, 21, 118, + /* 60 */ 118, 133, 21, 21, 21, 21, 21, 21, 21, 21, + /* 70 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + /* 80 */ 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + /* 90 */ 21, 21, 21, 21, 21, 240, 311, 311, 311, 276, + /* 100 */ 276, 311, 269, 289, 294, 300, 298, 304, 306, 308, + /* 110 */ 296, 313, 311, 311, 342, 342, 311, 334, 336, 370, + /* 120 */ 343, 344, 371, 346, 345, 311, 356, 311, 356, 530, + /* 130 */ 530, 27, 54, 54, 54, 54, 54, 92, 130, 226, + /* 140 */ 226, 226, 10, 244, 244, 244, 244, 38, 227, 110, + /* 150 */ 29, 181, 181, 163, 184, 199, 200, 208, 209, 210, + /* 160 */ 280, 307, 287, 246, 213, 217, 219, 222, 225, 322, + /* 170 */ 326, 135, 211, 263, 426, 301, 427, 302, 376, 431, + /* 180 */ 327, 453, 328, 396, 457, 331, 399, 380, 347, 372, + /* 190 */ 373, 348, 351, 366, 377, 374, 473, 381, 379, 382, + /* 200 */ 378, 375, 383, 384, 385, 387, 390, 389, 392, 391, + /* 210 */ 408, 471, 484, 485, 486, 487, 493, 490, 491, 492, + /* 220 */ 398, 424, 488, 429, 436, 489, 386, 388, 402, 499, + /* 230 */ 501, 411, 413, 402, 504, 505, 506, 507, 509, 511, + /* 240 */ 512, 513, 514, 515, 456, 458, 447, 503, 508, 468, /* 250 */ 526, }; -#define YY_REDUCE_USE_DFLT (-219) #define YY_REDUCE_COUNT (130) -#define YY_REDUCE_MIN (-218) -#define YY_REDUCE_MAX (256) +#define YY_REDUCE_MIN (-245) +#define YY_REDUCE_MAX (255) static const short yy_reduce_ofst[] = { - /* 0 */ -139, -31, -162, -147, -95, -169, -110, -72, -29, -14, - /* 10 */ -165, -195, -218, -191, -146, -103, -90, -65, -35, -47, - /* 20 */ -27, -79, 11, 29, 37, 73, 80, 20, -150, -99, - /* 30 */ -82, -76, 70, 72, 83, 84, 85, 86, 90, 92, - /* 40 */ 93, 94, 95, 96, 98, 99, 100, -22, 102, -9, - /* 50 */ 109, 119, 120, 121, 122, 104, 124, 153, 156, 106, - /* 60 */ 107, 118, 157, 158, 159, 163, 164, 166, 167, 168, - /* 70 */ 169, 170, 172, 173, 174, 175, 176, 177, 178, 179, - /* 80 */ 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, - /* 90 */ 191, 197, 198, 201, 203, 125, 205, 207, 209, 143, - /* 100 */ 144, 210, 154, 160, 165, 211, 213, 215, 217, 214, - /* 110 */ 220, 219, 221, 223, 226, 227, 228, 229, 231, 230, - /* 120 */ 232, 234, 237, 238, 242, 233, 235, 239, 236, 245, - /* 130 */ 256, + /* 0 */ -190, -30, -245, -237, -196, -195, -184, -137, -109, -72, + /* 10 */ -164, -167, -46, -44, -239, -211, -171, -131, -199, -104, + /* 20 */ -101, -78, -67, -33, 28, 4, 64, 22, -218, -201, + /* 30 */ -178, -119, -102, -82, -75, -61, -10, 2, 9, 25, + /* 40 */ 60, 73, 76, 93, 95, 96, 97, -198, 94, 117, + /* 50 */ 119, 120, 121, 122, 123, 109, 124, 148, 155, 101, + /* 60 */ 102, 125, 158, 159, 160, 164, 165, 167, 168, 170, + /* 70 */ 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + /* 80 */ 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, + /* 90 */ 193, 194, 195, 196, 198, 138, 201, 202, 203, 149, + /* 100 */ 150, 204, 153, 162, 166, 205, 212, 206, 215, 214, + /* 110 */ 218, 216, 220, 221, 223, 224, 229, 228, 230, 232, + /* 120 */ 231, 234, 242, 239, 233, 235, 236, 238, 249, 251, + /* 130 */ 255, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 827, 660, 811, 811, 827, 827, 827, 827, 827, 827, - /* 10 */ 741, 627, 827, 827, 811, 827, 827, 827, 827, 827, - /* 20 */ 827, 827, 827, 662, 649, 662, 662, 736, 827, 827, - /* 30 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 50 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 760, - /* 60 */ 760, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 70 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 647, - /* 80 */ 827, 645, 827, 827, 827, 827, 827, 827, 827, 827, - /* 90 */ 827, 827, 827, 827, 827, 827, 629, 629, 629, 827, - /* 100 */ 827, 629, 767, 771, 765, 753, 761, 752, 748, 747, - /* 110 */ 775, 827, 629, 629, 657, 657, 629, 678, 676, 674, - /* 120 */ 666, 672, 668, 670, 664, 629, 655, 629, 655, 693, - /* 130 */ 706, 827, 815, 816, 776, 810, 766, 794, 793, 806, - /* 140 */ 800, 799, 827, 798, 797, 796, 795, 827, 827, 827, - /* 150 */ 827, 802, 801, 827, 827, 827, 827, 827, 827, 827, - /* 160 */ 827, 827, 827, 778, 772, 768, 827, 827, 827, 827, - /* 170 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 180 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 190 */ 827, 812, 827, 742, 827, 827, 827, 827, 827, 827, - /* 200 */ 762, 827, 754, 827, 827, 827, 827, 827, 827, 715, - /* 210 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 220 */ 681, 827, 827, 827, 827, 827, 827, 827, 820, 827, - /* 230 */ 827, 827, 709, 818, 827, 827, 827, 827, 827, 827, - /* 240 */ 827, 827, 827, 827, 827, 827, 827, 633, 631, 827, - /* 250 */ 827, + /* 0 */ 614, 663, 814, 814, 614, 614, 614, 614, 614, 614, + /* 10 */ 744, 630, 614, 614, 814, 614, 614, 614, 614, 614, + /* 20 */ 614, 614, 614, 665, 652, 665, 665, 739, 614, 614, + /* 30 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 40 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 50 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 763, + /* 60 */ 763, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 70 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 650, + /* 80 */ 614, 648, 614, 614, 614, 614, 614, 614, 614, 614, + /* 90 */ 614, 614, 614, 614, 614, 614, 632, 632, 632, 614, + /* 100 */ 614, 632, 770, 774, 768, 756, 764, 755, 751, 750, + /* 110 */ 778, 614, 632, 632, 660, 660, 632, 681, 679, 677, + /* 120 */ 669, 675, 671, 673, 667, 632, 658, 632, 658, 696, + /* 130 */ 709, 614, 818, 819, 779, 813, 769, 797, 796, 809, + /* 140 */ 803, 802, 614, 801, 800, 799, 798, 614, 614, 614, + /* 150 */ 614, 805, 804, 614, 614, 614, 614, 614, 614, 614, + /* 160 */ 614, 614, 614, 781, 775, 771, 614, 614, 614, 614, + /* 170 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 180 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 190 */ 614, 815, 614, 745, 614, 614, 614, 614, 614, 614, + /* 200 */ 765, 614, 757, 614, 614, 614, 614, 614, 614, 718, + /* 210 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + /* 220 */ 684, 614, 614, 614, 614, 614, 614, 614, 823, 614, + /* 230 */ 614, 614, 712, 821, 614, 614, 614, 614, 614, 614, + /* 240 */ 614, 614, 614, 614, 614, 614, 614, 636, 634, 614, + /* 250 */ 614, }; /********** End of lemon-generated parsing tables *****************************/ @@ -476,7 +490,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* TABLE => nothing */ 1, /* DATABASE => ID */ 0, /* DNODE => nothing */ - 1, /* IP => ID */ + 1, /* IPTOKEN => ID */ 0, /* USER => nothing */ 0, /* ACCOUNT => nothing */ 0, /* USE => nothing */ @@ -512,7 +526,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* USING => nothing */ 0, /* AS => nothing */ 0, /* COMMA => nothing */ - 0, /* NULL => nothing */ + 1, /* NULL => ID */ 0, /* SELECT => nothing */ 0, /* FROM => nothing */ 0, /* VARIABLE => nothing */ @@ -637,17 +651,21 @@ typedef struct yyStackEntry yyStackEntry; /* The state of the parser is completely contained in an instance of ** the following structure */ struct yyParser { - int yyidx; /* Index of top element in stack */ + yyStackEntry *yytos; /* Pointer to top element of the stack */ #ifdef YYTRACKMAXSTACKDEPTH - int yyidxMax; /* Maximum value of yyidx */ + int yyhwm; /* High-water mark of the stack */ #endif +#ifndef YYNOERRORRECOVERY int yyerrcnt; /* Shifts left before out of the error */ +#endif ParseARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ + yyStackEntry yystk0; /* First stack entry */ #else yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ + yyStackEntry *yystackEnd; /* Last entry in the stack */ #endif }; typedef struct yyParser yyParser; @@ -684,77 +702,272 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ } #endif /* NDEBUG */ -#ifndef NDEBUG +#if defined(YYCOVERAGE) || !defined(NDEBUG) /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ static const char *const yyTokenName[] = { - "$", "ID", "BOOL", "TINYINT", - "SMALLINT", "INTEGER", "BIGINT", "FLOAT", - "DOUBLE", "STRING", "TIMESTAMP", "BINARY", - "NCHAR", "OR", "AND", "NOT", - "EQ", "NE", "ISNULL", "NOTNULL", - "IS", "LIKE", "GLOB", "BETWEEN", - "IN", "GT", "GE", "LT", - "LE", "BITAND", "BITOR", "LSHIFT", - "RSHIFT", "PLUS", "MINUS", "DIVIDE", - "TIMES", "STAR", "SLASH", "REM", - "CONCAT", "UMINUS", "UPLUS", "BITNOT", - "SHOW", "DATABASES", "MNODES", "DNODES", - "ACCOUNTS", "USERS", "MODULES", "QUERIES", - "CONNECTIONS", "STREAMS", "CONFIGS", "SCORES", - "GRANTS", "DOT", "TABLES", "STABLES", - "VGROUPS", "DROP", "TABLE", "DATABASE", - "DNODE", "IP", "USER", "ACCOUNT", - "USE", "DESCRIBE", "ALTER", "PASS", - "PRIVILEGE", "LOCAL", "IF", "EXISTS", - "CREATE", "PPS", "TSERIES", "DBS", - "STORAGE", "QTIME", "CONNS", "STATE", - "KEEP", "CACHE", "REPLICA", "DAYS", - "ROWS", "ABLOCKS", "TBLOCKS", "CTIME", - "CLOG", "COMP", "PRECISION", "LP", - "RP", "TAGS", "USING", "AS", - "COMMA", "NULL", "SELECT", "FROM", - "VARIABLE", "INTERVAL", "FILL", "SLIDING", - "ORDER", "BY", "ASC", "DESC", - "GROUP", "HAVING", "LIMIT", "OFFSET", - "SLIMIT", "SOFFSET", "WHERE", "NOW", - "INSERT", "INTO", "VALUES", "RESET", - "QUERY", "ADD", "COLUMN", "TAG", - "CHANGE", "SET", "KILL", "CONNECTION", - "COLON", "STREAM", "ABORT", "AFTER", - "ATTACH", "BEFORE", "BEGIN", "CASCADE", - "CLUSTER", "CONFLICT", "COPY", "DEFERRED", - "DELIMITERS", "DETACH", "EACH", "END", - "EXPLAIN", "FAIL", "FOR", "IGNORE", - "IMMEDIATE", "INITIALLY", "INSTEAD", "MATCH", - "KEY", "OF", "RAISE", "REPLACE", - "RESTRICT", "ROW", "STATEMENT", "TRIGGER", - "VIEW", "ALL", "COUNT", "SUM", - "AVG", "MIN", "MAX", "FIRST", - "LAST", "TOP", "BOTTOM", "STDDEV", - "PERCENTILE", "APERCENTILE", "LEASTSQUARES", "HISTOGRAM", - "DIFF", "SPREAD", "TWA", "INTERP", - "LAST_ROW", "SEMI", "NONE", "PREV", - "LINEAR", "IMPORT", "METRIC", "TBNAME", - "JOIN", "METRICS", "STABLE", "error", - "program", "cmd", "dbPrefix", "ids", - "cpxName", "ifexists", "alter_db_optr", "acct_optr", - "ifnotexists", "db_optr", "pps", "tseries", - "dbs", "streams", "storage", "qtime", - "users", "conns", "state", "keep", - "tagitemlist", "tables", "cache", "replica", - "days", "rows", "ablocks", "tblocks", - "ctime", "clog", "comp", "prec", - "typename", "signed", "create_table_args", "columnlist", - "select", "column", "tagitem", "selcollist", - "from", "where_opt", "interval_opt", "fill_opt", - "sliding_opt", "groupby_opt", "orderby_opt", "having_opt", - "slimit_opt", "limit_opt", "sclp", "expr", - "as", "tablelist", "tmvar", "sortlist", - "sortitem", "item", "sortorder", "grouplist", - "exprlist", "expritem", "insert_value_list", "itemlist", + /* 0 */ "$", + /* 1 */ "ID", + /* 2 */ "BOOL", + /* 3 */ "TINYINT", + /* 4 */ "SMALLINT", + /* 5 */ "INTEGER", + /* 6 */ "BIGINT", + /* 7 */ "FLOAT", + /* 8 */ "DOUBLE", + /* 9 */ "STRING", + /* 10 */ "TIMESTAMP", + /* 11 */ "BINARY", + /* 12 */ "NCHAR", + /* 13 */ "OR", + /* 14 */ "AND", + /* 15 */ "NOT", + /* 16 */ "EQ", + /* 17 */ "NE", + /* 18 */ "ISNULL", + /* 19 */ "NOTNULL", + /* 20 */ "IS", + /* 21 */ "LIKE", + /* 22 */ "GLOB", + /* 23 */ "BETWEEN", + /* 24 */ "IN", + /* 25 */ "GT", + /* 26 */ "GE", + /* 27 */ "LT", + /* 28 */ "LE", + /* 29 */ "BITAND", + /* 30 */ "BITOR", + /* 31 */ "LSHIFT", + /* 32 */ "RSHIFT", + /* 33 */ "PLUS", + /* 34 */ "MINUS", + /* 35 */ "DIVIDE", + /* 36 */ "TIMES", + /* 37 */ "STAR", + /* 38 */ "SLASH", + /* 39 */ "REM", + /* 40 */ "CONCAT", + /* 41 */ "UMINUS", + /* 42 */ "UPLUS", + /* 43 */ "BITNOT", + /* 44 */ "SHOW", + /* 45 */ "DATABASES", + /* 46 */ "MNODES", + /* 47 */ "DNODES", + /* 48 */ "ACCOUNTS", + /* 49 */ "USERS", + /* 50 */ "MODULES", + /* 51 */ "QUERIES", + /* 52 */ "CONNECTIONS", + /* 53 */ "STREAMS", + /* 54 */ "CONFIGS", + /* 55 */ "SCORES", + /* 56 */ "GRANTS", + /* 57 */ "DOT", + /* 58 */ "TABLES", + /* 59 */ "STABLES", + /* 60 */ "VGROUPS", + /* 61 */ "DROP", + /* 62 */ "TABLE", + /* 63 */ "DATABASE", + /* 64 */ "DNODE", + /* 65 */ "IPTOKEN", + /* 66 */ "USER", + /* 67 */ "ACCOUNT", + /* 68 */ "USE", + /* 69 */ "DESCRIBE", + /* 70 */ "ALTER", + /* 71 */ "PASS", + /* 72 */ "PRIVILEGE", + /* 73 */ "LOCAL", + /* 74 */ "IF", + /* 75 */ "EXISTS", + /* 76 */ "CREATE", + /* 77 */ "PPS", + /* 78 */ "TSERIES", + /* 79 */ "DBS", + /* 80 */ "STORAGE", + /* 81 */ "QTIME", + /* 82 */ "CONNS", + /* 83 */ "STATE", + /* 84 */ "KEEP", + /* 85 */ "CACHE", + /* 86 */ "REPLICA", + /* 87 */ "DAYS", + /* 88 */ "ROWS", + /* 89 */ "ABLOCKS", + /* 90 */ "TBLOCKS", + /* 91 */ "CTIME", + /* 92 */ "CLOG", + /* 93 */ "COMP", + /* 94 */ "PRECISION", + /* 95 */ "LP", + /* 96 */ "RP", + /* 97 */ "TAGS", + /* 98 */ "USING", + /* 99 */ "AS", + /* 100 */ "COMMA", + /* 101 */ "NULL", + /* 102 */ "SELECT", + /* 103 */ "FROM", + /* 104 */ "VARIABLE", + /* 105 */ "INTERVAL", + /* 106 */ "FILL", + /* 107 */ "SLIDING", + /* 108 */ "ORDER", + /* 109 */ "BY", + /* 110 */ "ASC", + /* 111 */ "DESC", + /* 112 */ "GROUP", + /* 113 */ "HAVING", + /* 114 */ "LIMIT", + /* 115 */ "OFFSET", + /* 116 */ "SLIMIT", + /* 117 */ "SOFFSET", + /* 118 */ "WHERE", + /* 119 */ "NOW", + /* 120 */ "INSERT", + /* 121 */ "INTO", + /* 122 */ "VALUES", + /* 123 */ "RESET", + /* 124 */ "QUERY", + /* 125 */ "ADD", + /* 126 */ "COLUMN", + /* 127 */ "TAG", + /* 128 */ "CHANGE", + /* 129 */ "SET", + /* 130 */ "KILL", + /* 131 */ "CONNECTION", + /* 132 */ "COLON", + /* 133 */ "STREAM", + /* 134 */ "ABORT", + /* 135 */ "AFTER", + /* 136 */ "ATTACH", + /* 137 */ "BEFORE", + /* 138 */ "BEGIN", + /* 139 */ "CASCADE", + /* 140 */ "CLUSTER", + /* 141 */ "CONFLICT", + /* 142 */ "COPY", + /* 143 */ "DEFERRED", + /* 144 */ "DELIMITERS", + /* 145 */ "DETACH", + /* 146 */ "EACH", + /* 147 */ "END", + /* 148 */ "EXPLAIN", + /* 149 */ "FAIL", + /* 150 */ "FOR", + /* 151 */ "IGNORE", + /* 152 */ "IMMEDIATE", + /* 153 */ "INITIALLY", + /* 154 */ "INSTEAD", + /* 155 */ "MATCH", + /* 156 */ "KEY", + /* 157 */ "OF", + /* 158 */ "RAISE", + /* 159 */ "REPLACE", + /* 160 */ "RESTRICT", + /* 161 */ "ROW", + /* 162 */ "STATEMENT", + /* 163 */ "TRIGGER", + /* 164 */ "VIEW", + /* 165 */ "ALL", + /* 166 */ "COUNT", + /* 167 */ "SUM", + /* 168 */ "AVG", + /* 169 */ "MIN", + /* 170 */ "MAX", + /* 171 */ "FIRST", + /* 172 */ "LAST", + /* 173 */ "TOP", + /* 174 */ "BOTTOM", + /* 175 */ "STDDEV", + /* 176 */ "PERCENTILE", + /* 177 */ "APERCENTILE", + /* 178 */ "LEASTSQUARES", + /* 179 */ "HISTOGRAM", + /* 180 */ "DIFF", + /* 181 */ "SPREAD", + /* 182 */ "TWA", + /* 183 */ "INTERP", + /* 184 */ "LAST_ROW", + /* 185 */ "SEMI", + /* 186 */ "NONE", + /* 187 */ "PREV", + /* 188 */ "LINEAR", + /* 189 */ "IMPORT", + /* 190 */ "METRIC", + /* 191 */ "TBNAME", + /* 192 */ "JOIN", + /* 193 */ "METRICS", + /* 194 */ "STABLE", + /* 195 */ "error", + /* 196 */ "program", + /* 197 */ "cmd", + /* 198 */ "dbPrefix", + /* 199 */ "ids", + /* 200 */ "cpxName", + /* 201 */ "ifexists", + /* 202 */ "alter_db_optr", + /* 203 */ "acct_optr", + /* 204 */ "ifnotexists", + /* 205 */ "db_optr", + /* 206 */ "pps", + /* 207 */ "tseries", + /* 208 */ "dbs", + /* 209 */ "streams", + /* 210 */ "storage", + /* 211 */ "qtime", + /* 212 */ "users", + /* 213 */ "conns", + /* 214 */ "state", + /* 215 */ "keep", + /* 216 */ "tagitemlist", + /* 217 */ "tables", + /* 218 */ "cache", + /* 219 */ "replica", + /* 220 */ "days", + /* 221 */ "rows", + /* 222 */ "ablocks", + /* 223 */ "tblocks", + /* 224 */ "ctime", + /* 225 */ "clog", + /* 226 */ "comp", + /* 227 */ "prec", + /* 228 */ "typename", + /* 229 */ "signed", + /* 230 */ "create_table_args", + /* 231 */ "columnlist", + /* 232 */ "select", + /* 233 */ "column", + /* 234 */ "tagitem", + /* 235 */ "selcollist", + /* 236 */ "from", + /* 237 */ "where_opt", + /* 238 */ "interval_opt", + /* 239 */ "fill_opt", + /* 240 */ "sliding_opt", + /* 241 */ "groupby_opt", + /* 242 */ "orderby_opt", + /* 243 */ "having_opt", + /* 244 */ "slimit_opt", + /* 245 */ "limit_opt", + /* 246 */ "sclp", + /* 247 */ "expr", + /* 248 */ "as", + /* 249 */ "tablelist", + /* 250 */ "tmvar", + /* 251 */ "sortlist", + /* 252 */ "sortitem", + /* 253 */ "item", + /* 254 */ "sortorder", + /* 255 */ "grouplist", + /* 256 */ "exprlist", + /* 257 */ "expritem", + /* 258 */ "insert_value_list", + /* 259 */ "itemlist", }; -#endif /* NDEBUG */ +#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -784,15 +997,15 @@ static const char *const yyRuleName[] = { /* 21 */ "cmd ::= SHOW dbPrefix VGROUPS", /* 22 */ "cmd ::= DROP TABLE ifexists ids cpxName", /* 23 */ "cmd ::= DROP DATABASE ifexists ids", - /* 24 */ "cmd ::= DROP DNODE IP", + /* 24 */ "cmd ::= DROP DNODE IPTOKEN", /* 25 */ "cmd ::= DROP USER ids", /* 26 */ "cmd ::= DROP ACCOUNT ids", /* 27 */ "cmd ::= USE ids", /* 28 */ "cmd ::= DESCRIBE ids cpxName", /* 29 */ "cmd ::= ALTER USER ids PASS ids", /* 30 */ "cmd ::= ALTER USER ids PRIVILEGE ids", - /* 31 */ "cmd ::= ALTER DNODE IP ids", - /* 32 */ "cmd ::= ALTER DNODE IP ids ids", + /* 31 */ "cmd ::= ALTER DNODE IPTOKEN ids", + /* 32 */ "cmd ::= ALTER DNODE IPTOKEN ids ids", /* 33 */ "cmd ::= ALTER LOCAL ids", /* 34 */ "cmd ::= ALTER LOCAL ids ids", /* 35 */ "cmd ::= ALTER DATABASE ids alter_db_optr", @@ -804,7 +1017,7 @@ static const char *const yyRuleName[] = { /* 41 */ "ifexists ::=", /* 42 */ "ifnotexists ::= IF NOT EXISTS", /* 43 */ "ifnotexists ::=", - /* 44 */ "cmd ::= CREATE DNODE IP", + /* 44 */ "cmd ::= CREATE DNODE IPTOKEN", /* 45 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", /* 46 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", /* 47 */ "cmd ::= CREATE USER ids PASS ids", @@ -970,33 +1183,43 @@ static const char *const yyRuleName[] = { /* 207 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", /* 208 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", /* 209 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 210 */ "cmd ::= KILL CONNECTION IP COLON INTEGER", - /* 211 */ "cmd ::= KILL STREAM IP COLON INTEGER COLON INTEGER", - /* 212 */ "cmd ::= KILL QUERY IP COLON INTEGER COLON INTEGER", + /* 210 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", + /* 211 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", + /* 212 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", }; #endif /* NDEBUG */ #if YYSTACKDEPTH<=0 /* -** Try to increase the size of the parser stack. +** Try to increase the size of the parser stack. Return the number +** of errors. Return 0 on success. */ -static void yyGrowStack(yyParser *p){ +static int yyGrowStack(yyParser *p){ int newSize; + int idx; yyStackEntry *pNew; newSize = p->yystksz*2 + 100; - pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; + if( p->yystack==&p->yystk0 ){ + pNew = malloc(newSize*sizeof(pNew[0])); + if( pNew ) pNew[0] = p->yystk0; + }else{ + pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); + } if( pNew ){ p->yystack = pNew; - p->yystksz = newSize; + p->yytos = &p->yystack[idx]; #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", - yyTracePrompt, p->yystksz); + fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", + yyTracePrompt, p->yystksz, newSize); } #endif + p->yystksz = newSize; } + return pNew==0; } #endif @@ -1009,6 +1232,34 @@ static void yyGrowStack(yyParser *p){ # define YYMALLOCARGTYPE size_t #endif +/* Initialize a new parser that has already been allocated. +*/ +void ParseInit(void *yypParser){ + yyParser *pParser = (yyParser*)yypParser; +#ifdef YYTRACKMAXSTACKDEPTH + pParser->yyhwm = 0; +#endif +#if YYSTACKDEPTH<=0 + pParser->yytos = NULL; + pParser->yystack = NULL; + pParser->yystksz = 0; + if( yyGrowStack(pParser) ){ + pParser->yystack = &pParser->yystk0; + pParser->yystksz = 1; + } +#endif +#ifndef YYNOERRORRECOVERY + pParser->yyerrcnt = -1; +#endif + pParser->yytos = pParser->yystack; + pParser->yystack[0].stateno = 0; + pParser->yystack[0].major = 0; +#if YYSTACKDEPTH>0 + pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like @@ -1024,19 +1275,11 @@ static void yyGrowStack(yyParser *p){ void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ yyParser *pParser; pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; -#ifdef YYTRACKMAXSTACKDEPTH - pParser->yyidxMax = 0; -#endif -#if YYSTACKDEPTH<=0 - pParser->yystack = NULL; - pParser->yystksz = 0; - yyGrowStack(pParser); -#endif - } + if( pParser ) ParseInit(pParser); return pParser; } +#endif /* Parse_ENGINEALWAYSONSTACK */ + /* The following function deletes the "minor type" or semantic value ** associated with a symbol. The symbol can be either a terminal @@ -1118,8 +1361,9 @@ tVariantDestroy(&(yypminor->yy186)); */ static void yy_pop_parser_stack(yyParser *pParser){ yyStackEntry *yytos; - assert( pParser->yyidx>=0 ); - yytos = &pParser->yystack[pParser->yyidx--]; + assert( pParser->yytos!=0 ); + assert( pParser->yytos > pParser->yystack ); + yytos = pParser->yytos--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", @@ -1130,6 +1374,18 @@ static void yy_pop_parser_stack(yyParser *pParser){ yy_destructor(pParser, yytos->major, &yytos->minor); } +/* +** Clear all secondary memory allocations from the parser +*/ +void ParseFinalize(void *p){ + yyParser *pParser = (yyParser*)p; + while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); +#if YYSTACKDEPTH<=0 + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); +#endif +} + +#ifndef Parse_ENGINEALWAYSONSTACK /* ** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. @@ -1142,16 +1398,13 @@ void ParseFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ - yyParser *pParser = (yyParser*)p; #ifndef YYPARSEFREENEVERNULL - if( pParser==0 ) return; + if( p==0 ) return; #endif - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); -#if YYSTACKDEPTH<=0 - free(pParser->yystack); -#endif - (*freeProc)((void*)pParser); + ParseFinalize(p); + (*freeProc)(p); } +#endif /* Parse_ENGINEALWAYSONSTACK */ /* ** Return the peak depth of the stack for a parser. @@ -1159,7 +1412,44 @@ void ParseFree( #ifdef YYTRACKMAXSTACKDEPTH int ParseStackPeak(void *p){ yyParser *pParser = (yyParser*)p; - return pParser->yyidxMax; + return pParser->yyhwm; +} +#endif + +/* This array of booleans keeps track of the parser statement +** coverage. The element yycoverage[X][Y] is set when the parser +** is in state X and has a lookahead token Y. In a well-tested +** systems, every element of this matrix should end up being set. +*/ +#if defined(YYCOVERAGE) +static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; +#endif + +/* +** Write into out a description of every state/lookahead combination that +** +** (1) has not been used by the parser, and +** (2) is not a syntax error. +** +** Return the number of missed state/lookahead combinations. +*/ +#if defined(YYCOVERAGE) +int ParseCoverage(FILE *out){ + int stateno, iLookAhead, i; + int nMissed = 0; + for(stateno=0; statenoyystack[pParser->yyidx].stateno; + int stateno = pParser->yytos->stateno; - if( stateno>=YY_MIN_REDUCE ) return stateno; + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); +#if defined(YYCOVERAGE) + yycoverage[stateno][iLookAhead] = 1; +#endif do{ i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; + assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); assert( iLookAhead!=YYNOCODE ); + assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK - YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ - iLookAhead = iFallback; - continue; + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); } +#endif + assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ + iLookAhead = iFallback; + continue; + } #endif #ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( + { + int j = i - iLookAhead + YYWILDCARD; + if( #if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && + j>=0 && #endif #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j0 + ){ #ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", - yyTracePrompt, yyTokenName[iLookAhead], - yyTokenName[YYWILDCARD]); - } -#endif /* NDEBUG */ - return yy_action[j]; + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); } +#endif /* NDEBUG */ + return yy_action[j]; } -#endif /* YYWILDCARD */ } +#endif /* YYWILDCARD */ return yy_default[stateno]; }else{ return yy_action[i]; @@ -1246,7 +1538,6 @@ static int yy_find_reduce_action( assert( stateno<=YY_REDUCE_COUNT ); #endif i = yy_reduce_ofst[stateno]; - assert( i!=YY_REDUCE_USE_DFLT ); assert( iLookAhead!=YYNOCODE ); i += iLookAhead; #ifdef YYERRORSYMBOL @@ -1263,15 +1554,14 @@ static int yy_find_reduce_action( /* ** The following routine is called if the stack overflows. */ -static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ +static void yyStackOverflow(yyParser *yypParser){ ParseARG_FETCH; - yypParser->yyidx--; #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ /******** Begin %stack_overflow code ******************************************/ @@ -1283,20 +1573,21 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ ** Print tracing information for a SHIFT action */ #ifndef NDEBUG -static void yyTraceShift(yyParser *yypParser, int yyNewState){ +static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ if( yyTraceFILE ){ if( yyNewStateyystack[yypParser->yyidx].major], + fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], yyNewState); }else{ - fprintf(yyTraceFILE,"%sShift '%s'\n", - yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); + fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", + yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], + yyNewState - YY_MIN_REDUCE); } } } #else -# define yyTraceShift(X,Y) +# define yyTraceShift(X,Y,Z) #endif /* @@ -1306,256 +1597,261 @@ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ + ParseTOKENTYPE yyMinor /* The minor token to shift in */ ){ yyStackEntry *yytos; - yypParser->yyidx++; + yypParser->yytos++; #ifdef YYTRACKMAXSTACKDEPTH - if( yypParser->yyidx>yypParser->yyidxMax ){ - yypParser->yyidxMax = yypParser->yyidx; + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); } #endif #if YYSTACKDEPTH>0 - if( yypParser->yyidx>=YYSTACKDEPTH ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>yypParser->yystackEnd ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } #else - if( yypParser->yyidx>=yypParser->yystksz ){ - yyGrowStack(yypParser); - if( yypParser->yyidx>=yypParser->yystksz ){ - yyStackOverflow(yypParser, yypMinor); + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ + if( yyGrowStack(yypParser) ){ + yypParser->yytos--; + yyStackOverflow(yypParser); return; } } #endif - yytos = &yypParser->yystack[yypParser->yyidx]; + if( yyNewState > YY_MAX_SHIFT ){ + yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; + } + yytos = yypParser->yytos; yytos->stateno = (YYACTIONTYPE)yyNewState; yytos->major = (YYCODETYPE)yyMajor; - yytos->minor = *yypMinor; - yyTraceShift(yypParser, yyNewState); + yytos->minor.yy0 = yyMinor; + yyTraceShift(yypParser, yyNewState, "Shift"); } /* The following table contains information about every rule that ** is used during the reduce. */ static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 196, 1 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 197, 2 }, - { 198, 0 }, - { 198, 2 }, - { 200, 0 }, - { 200, 2 }, - { 197, 3 }, - { 197, 5 }, - { 197, 3 }, - { 197, 5 }, - { 197, 3 }, - { 197, 5 }, - { 197, 4 }, - { 197, 3 }, - { 197, 3 }, - { 197, 3 }, - { 197, 2 }, - { 197, 3 }, - { 197, 5 }, - { 197, 5 }, - { 197, 4 }, - { 197, 5 }, - { 197, 3 }, - { 197, 4 }, - { 197, 4 }, - { 197, 4 }, - { 197, 6 }, - { 199, 1 }, - { 199, 1 }, - { 201, 2 }, - { 201, 0 }, - { 204, 3 }, - { 204, 0 }, - { 197, 3 }, - { 197, 6 }, - { 197, 5 }, - { 197, 5 }, - { 206, 0 }, - { 206, 2 }, - { 207, 0 }, - { 207, 2 }, - { 208, 0 }, - { 208, 2 }, - { 209, 0 }, - { 209, 2 }, - { 210, 0 }, - { 210, 2 }, - { 211, 0 }, - { 211, 2 }, - { 212, 0 }, - { 212, 2 }, - { 213, 0 }, - { 213, 2 }, - { 214, 0 }, - { 214, 2 }, - { 203, 9 }, - { 215, 2 }, - { 217, 2 }, - { 218, 2 }, - { 219, 2 }, - { 220, 2 }, - { 221, 2 }, - { 222, 2 }, - { 223, 2 }, - { 224, 2 }, - { 225, 2 }, - { 226, 2 }, - { 227, 2 }, - { 205, 0 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 205, 2 }, - { 202, 0 }, - { 202, 2 }, - { 202, 2 }, - { 228, 1 }, - { 228, 4 }, - { 229, 1 }, - { 229, 2 }, - { 229, 2 }, - { 197, 6 }, - { 230, 3 }, - { 230, 7 }, - { 230, 7 }, - { 230, 2 }, - { 231, 3 }, - { 231, 1 }, - { 233, 2 }, - { 216, 3 }, - { 216, 1 }, - { 234, 1 }, - { 234, 1 }, - { 234, 1 }, - { 234, 1 }, - { 234, 1 }, - { 234, 2 }, - { 234, 2 }, - { 234, 2 }, - { 234, 2 }, - { 197, 1 }, - { 232, 12 }, - { 246, 2 }, - { 246, 0 }, - { 235, 3 }, - { 235, 2 }, - { 248, 2 }, - { 248, 1 }, - { 248, 0 }, - { 236, 2 }, - { 249, 2 }, - { 249, 4 }, - { 250, 1 }, - { 238, 4 }, - { 238, 0 }, - { 239, 0 }, - { 239, 6 }, - { 239, 4 }, - { 240, 4 }, - { 240, 0 }, - { 242, 0 }, - { 242, 3 }, - { 251, 4 }, - { 251, 2 }, - { 253, 2 }, - { 254, 1 }, - { 254, 1 }, - { 254, 0 }, - { 241, 0 }, - { 241, 3 }, - { 255, 3 }, - { 255, 1 }, - { 243, 0 }, - { 243, 2 }, - { 245, 0 }, - { 245, 2 }, - { 245, 4 }, - { 245, 4 }, - { 244, 0 }, - { 244, 2 }, - { 244, 4 }, - { 244, 4 }, - { 237, 0 }, - { 237, 2 }, - { 247, 3 }, - { 247, 1 }, - { 247, 3 }, - { 247, 3 }, - { 247, 1 }, - { 247, 2 }, - { 247, 2 }, - { 247, 1 }, - { 247, 2 }, - { 247, 2 }, - { 247, 1 }, - { 247, 1 }, - { 247, 1 }, - { 247, 1 }, - { 247, 4 }, - { 247, 4 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 3 }, - { 247, 5 }, - { 256, 3 }, - { 256, 1 }, - { 257, 1 }, - { 257, 0 }, - { 197, 4 }, - { 258, 4 }, - { 258, 5 }, - { 259, 3 }, - { 259, 1 }, - { 197, 3 }, - { 197, 7 }, - { 197, 7 }, - { 197, 7 }, - { 197, 7 }, - { 197, 8 }, - { 197, 9 }, - { 197, 5 }, - { 197, 7 }, - { 197, 7 }, + { 196, -1 }, /* (0) program ::= cmd */ + { 197, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 197, -2 }, /* (2) cmd ::= SHOW MNODES */ + { 197, -2 }, /* (3) cmd ::= SHOW DNODES */ + { 197, -2 }, /* (4) cmd ::= SHOW ACCOUNTS */ + { 197, -2 }, /* (5) cmd ::= SHOW USERS */ + { 197, -2 }, /* (6) cmd ::= SHOW MODULES */ + { 197, -2 }, /* (7) cmd ::= SHOW QUERIES */ + { 197, -2 }, /* (8) cmd ::= SHOW CONNECTIONS */ + { 197, -2 }, /* (9) cmd ::= SHOW STREAMS */ + { 197, -2 }, /* (10) cmd ::= SHOW CONFIGS */ + { 197, -2 }, /* (11) cmd ::= SHOW SCORES */ + { 197, -2 }, /* (12) cmd ::= SHOW GRANTS */ + { 198, 0 }, /* (13) dbPrefix ::= */ + { 198, -2 }, /* (14) dbPrefix ::= ids DOT */ + { 200, 0 }, /* (15) cpxName ::= */ + { 200, -2 }, /* (16) cpxName ::= DOT ids */ + { 197, -3 }, /* (17) cmd ::= SHOW dbPrefix TABLES */ + { 197, -5 }, /* (18) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 197, -3 }, /* (19) cmd ::= SHOW dbPrefix STABLES */ + { 197, -5 }, /* (20) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 197, -3 }, /* (21) cmd ::= SHOW dbPrefix VGROUPS */ + { 197, -5 }, /* (22) cmd ::= DROP TABLE ifexists ids cpxName */ + { 197, -4 }, /* (23) cmd ::= DROP DATABASE ifexists ids */ + { 197, -3 }, /* (24) cmd ::= DROP DNODE IPTOKEN */ + { 197, -3 }, /* (25) cmd ::= DROP USER ids */ + { 197, -3 }, /* (26) cmd ::= DROP ACCOUNT ids */ + { 197, -2 }, /* (27) cmd ::= USE ids */ + { 197, -3 }, /* (28) cmd ::= DESCRIBE ids cpxName */ + { 197, -5 }, /* (29) cmd ::= ALTER USER ids PASS ids */ + { 197, -5 }, /* (30) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 197, -4 }, /* (31) cmd ::= ALTER DNODE IPTOKEN ids */ + { 197, -5 }, /* (32) cmd ::= ALTER DNODE IPTOKEN ids ids */ + { 197, -3 }, /* (33) cmd ::= ALTER LOCAL ids */ + { 197, -4 }, /* (34) cmd ::= ALTER LOCAL ids ids */ + { 197, -4 }, /* (35) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 197, -4 }, /* (36) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 197, -6 }, /* (37) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 199, -1 }, /* (38) ids ::= ID */ + { 199, -1 }, /* (39) ids ::= STRING */ + { 201, -2 }, /* (40) ifexists ::= IF EXISTS */ + { 201, 0 }, /* (41) ifexists ::= */ + { 204, -3 }, /* (42) ifnotexists ::= IF NOT EXISTS */ + { 204, 0 }, /* (43) ifnotexists ::= */ + { 197, -3 }, /* (44) cmd ::= CREATE DNODE IPTOKEN */ + { 197, -6 }, /* (45) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 197, -5 }, /* (46) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 197, -5 }, /* (47) cmd ::= CREATE USER ids PASS ids */ + { 206, 0 }, /* (48) pps ::= */ + { 206, -2 }, /* (49) pps ::= PPS INTEGER */ + { 207, 0 }, /* (50) tseries ::= */ + { 207, -2 }, /* (51) tseries ::= TSERIES INTEGER */ + { 208, 0 }, /* (52) dbs ::= */ + { 208, -2 }, /* (53) dbs ::= DBS INTEGER */ + { 209, 0 }, /* (54) streams ::= */ + { 209, -2 }, /* (55) streams ::= STREAMS INTEGER */ + { 210, 0 }, /* (56) storage ::= */ + { 210, -2 }, /* (57) storage ::= STORAGE INTEGER */ + { 211, 0 }, /* (58) qtime ::= */ + { 211, -2 }, /* (59) qtime ::= QTIME INTEGER */ + { 212, 0 }, /* (60) users ::= */ + { 212, -2 }, /* (61) users ::= USERS INTEGER */ + { 213, 0 }, /* (62) conns ::= */ + { 213, -2 }, /* (63) conns ::= CONNS INTEGER */ + { 214, 0 }, /* (64) state ::= */ + { 214, -2 }, /* (65) state ::= STATE ids */ + { 203, -9 }, /* (66) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 215, -2 }, /* (67) keep ::= KEEP tagitemlist */ + { 217, -2 }, /* (68) tables ::= TABLES INTEGER */ + { 218, -2 }, /* (69) cache ::= CACHE INTEGER */ + { 219, -2 }, /* (70) replica ::= REPLICA INTEGER */ + { 220, -2 }, /* (71) days ::= DAYS INTEGER */ + { 221, -2 }, /* (72) rows ::= ROWS INTEGER */ + { 222, -2 }, /* (73) ablocks ::= ABLOCKS ID */ + { 223, -2 }, /* (74) tblocks ::= TBLOCKS INTEGER */ + { 224, -2 }, /* (75) ctime ::= CTIME INTEGER */ + { 225, -2 }, /* (76) clog ::= CLOG INTEGER */ + { 226, -2 }, /* (77) comp ::= COMP INTEGER */ + { 227, -2 }, /* (78) prec ::= PRECISION STRING */ + { 205, 0 }, /* (79) db_optr ::= */ + { 205, -2 }, /* (80) db_optr ::= db_optr tables */ + { 205, -2 }, /* (81) db_optr ::= db_optr cache */ + { 205, -2 }, /* (82) db_optr ::= db_optr replica */ + { 205, -2 }, /* (83) db_optr ::= db_optr days */ + { 205, -2 }, /* (84) db_optr ::= db_optr rows */ + { 205, -2 }, /* (85) db_optr ::= db_optr ablocks */ + { 205, -2 }, /* (86) db_optr ::= db_optr tblocks */ + { 205, -2 }, /* (87) db_optr ::= db_optr ctime */ + { 205, -2 }, /* (88) db_optr ::= db_optr clog */ + { 205, -2 }, /* (89) db_optr ::= db_optr comp */ + { 205, -2 }, /* (90) db_optr ::= db_optr prec */ + { 205, -2 }, /* (91) db_optr ::= db_optr keep */ + { 202, 0 }, /* (92) alter_db_optr ::= */ + { 202, -2 }, /* (93) alter_db_optr ::= alter_db_optr replica */ + { 202, -2 }, /* (94) alter_db_optr ::= alter_db_optr tables */ + { 228, -1 }, /* (95) typename ::= ids */ + { 228, -4 }, /* (96) typename ::= ids LP signed RP */ + { 229, -1 }, /* (97) signed ::= INTEGER */ + { 229, -2 }, /* (98) signed ::= PLUS INTEGER */ + { 229, -2 }, /* (99) signed ::= MINUS INTEGER */ + { 197, -6 }, /* (100) cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ + { 230, -3 }, /* (101) create_table_args ::= LP columnlist RP */ + { 230, -7 }, /* (102) create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ + { 230, -7 }, /* (103) create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ + { 230, -2 }, /* (104) create_table_args ::= AS select */ + { 231, -3 }, /* (105) columnlist ::= columnlist COMMA column */ + { 231, -1 }, /* (106) columnlist ::= column */ + { 233, -2 }, /* (107) column ::= ids typename */ + { 216, -3 }, /* (108) tagitemlist ::= tagitemlist COMMA tagitem */ + { 216, -1 }, /* (109) tagitemlist ::= tagitem */ + { 234, -1 }, /* (110) tagitem ::= INTEGER */ + { 234, -1 }, /* (111) tagitem ::= FLOAT */ + { 234, -1 }, /* (112) tagitem ::= STRING */ + { 234, -1 }, /* (113) tagitem ::= BOOL */ + { 234, -1 }, /* (114) tagitem ::= NULL */ + { 234, -2 }, /* (115) tagitem ::= MINUS INTEGER */ + { 234, -2 }, /* (116) tagitem ::= MINUS FLOAT */ + { 234, -2 }, /* (117) tagitem ::= PLUS INTEGER */ + { 234, -2 }, /* (118) tagitem ::= PLUS FLOAT */ + { 197, -1 }, /* (119) cmd ::= select */ + { 232, -12 }, /* (120) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 246, -2 }, /* (121) sclp ::= selcollist COMMA */ + { 246, 0 }, /* (122) sclp ::= */ + { 235, -3 }, /* (123) selcollist ::= sclp expr as */ + { 235, -2 }, /* (124) selcollist ::= sclp STAR */ + { 248, -2 }, /* (125) as ::= AS ids */ + { 248, -1 }, /* (126) as ::= ids */ + { 248, 0 }, /* (127) as ::= */ + { 236, -2 }, /* (128) from ::= FROM tablelist */ + { 249, -2 }, /* (129) tablelist ::= ids cpxName */ + { 249, -4 }, /* (130) tablelist ::= tablelist COMMA ids cpxName */ + { 250, -1 }, /* (131) tmvar ::= VARIABLE */ + { 238, -4 }, /* (132) interval_opt ::= INTERVAL LP tmvar RP */ + { 238, 0 }, /* (133) interval_opt ::= */ + { 239, 0 }, /* (134) fill_opt ::= */ + { 239, -6 }, /* (135) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 239, -4 }, /* (136) fill_opt ::= FILL LP ID RP */ + { 240, -4 }, /* (137) sliding_opt ::= SLIDING LP tmvar RP */ + { 240, 0 }, /* (138) sliding_opt ::= */ + { 242, 0 }, /* (139) orderby_opt ::= */ + { 242, -3 }, /* (140) orderby_opt ::= ORDER BY sortlist */ + { 251, -4 }, /* (141) sortlist ::= sortlist COMMA item sortorder */ + { 251, -2 }, /* (142) sortlist ::= item sortorder */ + { 253, -2 }, /* (143) item ::= ids cpxName */ + { 254, -1 }, /* (144) sortorder ::= ASC */ + { 254, -1 }, /* (145) sortorder ::= DESC */ + { 254, 0 }, /* (146) sortorder ::= */ + { 241, 0 }, /* (147) groupby_opt ::= */ + { 241, -3 }, /* (148) groupby_opt ::= GROUP BY grouplist */ + { 255, -3 }, /* (149) grouplist ::= grouplist COMMA item */ + { 255, -1 }, /* (150) grouplist ::= item */ + { 243, 0 }, /* (151) having_opt ::= */ + { 243, -2 }, /* (152) having_opt ::= HAVING expr */ + { 245, 0 }, /* (153) limit_opt ::= */ + { 245, -2 }, /* (154) limit_opt ::= LIMIT signed */ + { 245, -4 }, /* (155) limit_opt ::= LIMIT signed OFFSET signed */ + { 245, -4 }, /* (156) limit_opt ::= LIMIT signed COMMA signed */ + { 244, 0 }, /* (157) slimit_opt ::= */ + { 244, -2 }, /* (158) slimit_opt ::= SLIMIT signed */ + { 244, -4 }, /* (159) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 244, -4 }, /* (160) slimit_opt ::= SLIMIT signed COMMA signed */ + { 237, 0 }, /* (161) where_opt ::= */ + { 237, -2 }, /* (162) where_opt ::= WHERE expr */ + { 247, -3 }, /* (163) expr ::= LP expr RP */ + { 247, -1 }, /* (164) expr ::= ID */ + { 247, -3 }, /* (165) expr ::= ID DOT ID */ + { 247, -3 }, /* (166) expr ::= ID DOT STAR */ + { 247, -1 }, /* (167) expr ::= INTEGER */ + { 247, -2 }, /* (168) expr ::= MINUS INTEGER */ + { 247, -2 }, /* (169) expr ::= PLUS INTEGER */ + { 247, -1 }, /* (170) expr ::= FLOAT */ + { 247, -2 }, /* (171) expr ::= MINUS FLOAT */ + { 247, -2 }, /* (172) expr ::= PLUS FLOAT */ + { 247, -1 }, /* (173) expr ::= STRING */ + { 247, -1 }, /* (174) expr ::= NOW */ + { 247, -1 }, /* (175) expr ::= VARIABLE */ + { 247, -1 }, /* (176) expr ::= BOOL */ + { 247, -4 }, /* (177) expr ::= ID LP exprlist RP */ + { 247, -4 }, /* (178) expr ::= ID LP STAR RP */ + { 247, -3 }, /* (179) expr ::= expr AND expr */ + { 247, -3 }, /* (180) expr ::= expr OR expr */ + { 247, -3 }, /* (181) expr ::= expr LT expr */ + { 247, -3 }, /* (182) expr ::= expr GT expr */ + { 247, -3 }, /* (183) expr ::= expr LE expr */ + { 247, -3 }, /* (184) expr ::= expr GE expr */ + { 247, -3 }, /* (185) expr ::= expr NE expr */ + { 247, -3 }, /* (186) expr ::= expr EQ expr */ + { 247, -3 }, /* (187) expr ::= expr PLUS expr */ + { 247, -3 }, /* (188) expr ::= expr MINUS expr */ + { 247, -3 }, /* (189) expr ::= expr STAR expr */ + { 247, -3 }, /* (190) expr ::= expr SLASH expr */ + { 247, -3 }, /* (191) expr ::= expr REM expr */ + { 247, -3 }, /* (192) expr ::= expr LIKE expr */ + { 247, -5 }, /* (193) expr ::= expr IN LP exprlist RP */ + { 256, -3 }, /* (194) exprlist ::= exprlist COMMA expritem */ + { 256, -1 }, /* (195) exprlist ::= expritem */ + { 257, -1 }, /* (196) expritem ::= expr */ + { 257, 0 }, /* (197) expritem ::= */ + { 197, -4 }, /* (198) cmd ::= INSERT INTO cpxName insert_value_list */ + { 258, -4 }, /* (199) insert_value_list ::= VALUES LP itemlist RP */ + { 258, -5 }, /* (200) insert_value_list ::= insert_value_list VALUES LP itemlist RP */ + { 259, -3 }, /* (201) itemlist ::= itemlist COMMA expr */ + { 259, -1 }, /* (202) itemlist ::= expr */ + { 197, -3 }, /* (203) cmd ::= RESET QUERY CACHE */ + { 197, -7 }, /* (204) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 197, -7 }, /* (205) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 197, -7 }, /* (206) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 197, -7 }, /* (207) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 197, -8 }, /* (208) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 197, -9 }, /* (209) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 197, -5 }, /* (210) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ + { 197, -7 }, /* (211) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ + { 197, -7 }, /* (212) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -1563,27 +1859,66 @@ static void yy_accept(yyParser*); /* Forward Declaration */ /* ** Perform a reduce action and the shift that must immediately ** follow the reduce. +** +** The yyLookahead and yyLookaheadToken parameters provide reduce actions +** access to the lookahead token (if any). The yyLookahead will be YYNOCODE +** if the lookahead token has already been consumed. As this procedure is +** only called from one place, optimizing compilers will in-line it, which +** means that the extra parameters have no performance impact. */ static void yy_reduce( yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ + unsigned int yyruleno, /* Number of the rule by which to reduce */ + int yyLookahead, /* Lookahead token, or YYNOCODE if none */ + ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ ParseARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; + (void)yyLookahead; + (void)yyLookaheadToken; + yymsp = yypParser->yytos; #ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ yysize = yyRuleInfo[yyruleno].nrhs; - fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, - yyRuleName[yyruleno], yymsp[-yysize].stateno); + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + }else{ + fprintf(yyTraceFILE, "%sReduce %d [%s].\n", + yyTracePrompt, yyruleno, yyRuleName[yyruleno]); + } } #endif /* NDEBUG */ - yygotominor = yyzerominor; + + /* Check that the stack is large enough to grow by a single entry + ** if the RHS of the rule is empty. This ensures that there is room + ** enough on the stack to push the LHS value */ + if( yyRuleInfo[yyruleno].nrhs==0 ){ +#ifdef YYTRACKMAXSTACKDEPTH + if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); + } +#endif +#if YYSTACKDEPTH>0 + if( yypParser->yytos>=yypParser->yystackEnd ){ + yyStackOverflow(yypParser); + return; + } +#else + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ + if( yyGrowStack(yypParser) ){ + yyStackOverflow(yypParser); + return; + } + yymsp = yypParser->yytos; + } +#endif + } switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -1595,7 +1930,9 @@ static void yy_reduce( ** break; */ /********** Begin reduce actions **********************************************/ + YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ + case 79: /* db_optr ::= */ yytestcase(yyruleno==79); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -1637,16 +1974,17 @@ static void yy_reduce( case 13: /* dbPrefix ::= */ case 41: /* ifexists ::= */ yytestcase(yyruleno==41); case 43: /* ifnotexists ::= */ yytestcase(yyruleno==43); -{yygotominor.yy0.n = 0;} +{yymsp[1].minor.yy0.n = 0;} break; case 14: /* dbPrefix ::= ids DOT */ -{yygotominor.yy0 = yymsp[-1].minor.yy0; } +{yylhsminor.yy0 = yymsp[-1].minor.yy0; } + yymsp[-1].minor.yy0 = yylhsminor.yy0; break; case 15: /* cpxName ::= */ -{yygotominor.yy0.n = 0; } +{yymsp[1].minor.yy0.n = 0; } break; case 16: /* cpxName ::= DOT ids */ -{yygotominor.yy0 = yymsp[0].minor.yy0; yygotominor.yy0.n += 1; } +{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n += 1; } break; case 17: /* cmd ::= SHOW dbPrefix TABLES */ { @@ -1686,7 +2024,7 @@ static void yy_reduce( case 23: /* cmd ::= DROP DATABASE ifexists ids */ { setDCLSQLElems(pInfo, DROP_DATABASE, 2, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0); } break; - case 24: /* cmd ::= DROP DNODE IP */ + case 24: /* cmd ::= DROP DNODE IPTOKEN */ { setDCLSQLElems(pInfo, DROP_DNODE, 1, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= DROP USER ids */ @@ -1710,10 +2048,10 @@ static void yy_reduce( case 30: /* cmd ::= ALTER USER ids PRIVILEGE ids */ { setDCLSQLElems(pInfo, ALTER_USER_PRIVILEGES, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 31: /* cmd ::= ALTER DNODE IP ids */ + case 31: /* cmd ::= ALTER DNODE IPTOKEN ids */ { setDCLSQLElems(pInfo, ALTER_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 32: /* cmd ::= ALTER DNODE IP ids ids */ + case 32: /* cmd ::= ALTER DNODE IPTOKEN ids ids */ { setDCLSQLElems(pInfo, ALTER_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 33: /* cmd ::= ALTER LOCAL ids */ @@ -1733,13 +2071,16 @@ static void yy_reduce( break; case 38: /* ids ::= ID */ case 39: /* ids ::= STRING */ yytestcase(yyruleno==39); -{yygotominor.yy0 = yymsp[0].minor.yy0; } +{yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 40: /* ifexists ::= IF EXISTS */ - case 42: /* ifnotexists ::= IF NOT EXISTS */ yytestcase(yyruleno==42); -{yygotominor.yy0.n = 1;} +{yymsp[-1].minor.yy0.n = 1;} break; - case 44: /* cmd ::= CREATE DNODE IP */ + case 42: /* ifnotexists ::= IF NOT EXISTS */ +{yymsp[-2].minor.yy0.n = 1;} + break; + case 44: /* cmd ::= CREATE DNODE IPTOKEN */ { setDCLSQLElems(pInfo, CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 45: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ @@ -1762,7 +2103,7 @@ static void yy_reduce( case 64: /* state ::= */ yytestcase(yyruleno==64); case 133: /* interval_opt ::= */ yytestcase(yyruleno==133); case 138: /* sliding_opt ::= */ yytestcase(yyruleno==138); -{yygotominor.yy0.n = 0; } +{yymsp[1].minor.yy0.n = 0; } break; case 49: /* pps ::= PPS INTEGER */ case 51: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==51); @@ -1773,23 +2114,24 @@ static void yy_reduce( case 61: /* users ::= USERS INTEGER */ yytestcase(yyruleno==61); case 63: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==63); case 65: /* state ::= STATE ids */ yytestcase(yyruleno==65); -{yygotominor.yy0 = yymsp[0].minor.yy0; } +{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 66: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yygotominor.yy279.users = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yygotominor.yy279.dbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yygotominor.yy279.tseries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yygotominor.yy279.streams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yygotominor.yy279.pps = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yygotominor.yy279.storage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yygotominor.yy279.qtime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yygotominor.yy279.conns = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yygotominor.yy279.stat = yymsp[0].minor.yy0; + yylhsminor.yy279.users = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy279.dbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy279.tseries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy279.streams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy279.pps = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy279.storage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy279.qtime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy279.conns = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy279.stat = yymsp[0].minor.yy0; } + yymsp[-8].minor.yy279 = yylhsminor.yy279; break; case 67: /* keep ::= KEEP tagitemlist */ -{ yygotominor.yy56 = yymsp[0].minor.yy56; } +{ yymsp[-1].minor.yy56 = yymsp[0].minor.yy56; } break; case 68: /* tables ::= TABLES INTEGER */ case 69: /* cache ::= CACHE INTEGER */ yytestcase(yyruleno==69); @@ -1802,65 +2144,81 @@ static void yy_reduce( case 76: /* clog ::= CLOG INTEGER */ yytestcase(yyruleno==76); case 77: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==77); case 78: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==78); - case 79: /* db_optr ::= */ yytestcase(yyruleno==79); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 80: /* db_optr ::= db_optr tables */ case 94: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==94); -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.tablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.tablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 81: /* db_optr ::= db_optr cache */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 82: /* db_optr ::= db_optr replica */ case 93: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==93); -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 83: /* db_optr ::= db_optr days */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 84: /* db_optr ::= db_optr rows */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.rowPerFileBlock = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.rowPerFileBlock = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 85: /* db_optr ::= db_optr ablocks */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.numOfAvgCacheBlocks = strtod(yymsp[0].minor.yy0.z, NULL); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.numOfAvgCacheBlocks = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 86: /* db_optr ::= db_optr tblocks */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.numOfBlocksPerTable = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.numOfBlocksPerTable = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 87: /* db_optr ::= db_optr ctime */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 88: /* db_optr ::= db_optr clog */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.commitLog = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.commitLog = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 89: /* db_optr ::= db_optr comp */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 90: /* db_optr ::= db_optr prec */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.precision = yymsp[0].minor.yy0; } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 91: /* db_optr ::= db_optr keep */ -{ yygotominor.yy398 = yymsp[-1].minor.yy398; yygotominor.yy398.keep = yymsp[0].minor.yy56; } +{ yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.keep = yymsp[0].minor.yy56; } + yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 92: /* alter_db_optr ::= */ -{ memset(&yygotominor.yy398, 0, sizeof(SCreateDBInfo));} +{ memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));} break; case 95: /* typename ::= ids */ -{ tSQLSetColumnType (&yygotominor.yy223, &yymsp[0].minor.yy0); } +{ tSQLSetColumnType (&yylhsminor.yy223, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy223 = yylhsminor.yy223; break; case 96: /* typename ::= ids LP signed RP */ { yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy389; // negative value of name length - tSQLSetColumnType(&yygotominor.yy223, &yymsp[-3].minor.yy0); + tSQLSetColumnType(&yylhsminor.yy223, &yymsp[-3].minor.yy0); } + yymsp[-3].minor.yy223 = yylhsminor.yy223; break; case 97: /* signed ::= INTEGER */ - case 98: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==98); -{ yygotominor.yy389 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yylhsminor.yy389 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy389 = yylhsminor.yy389; + break; + case 98: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy389 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 99: /* signed ::= MINUS INTEGER */ -{ yygotominor.yy389 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy389 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 100: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ { @@ -1870,54 +2228,61 @@ static void yy_reduce( break; case 101: /* create_table_args ::= LP columnlist RP */ { - yygotominor.yy158 = tSetCreateSQLElems(yymsp[-1].minor.yy471, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); - setSQLInfo(pInfo, yygotominor.yy158, NULL, TSQL_CREATE_NORMAL_METER); + yymsp[-2].minor.yy158 = tSetCreateSQLElems(yymsp[-1].minor.yy471, NULL, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METER); + setSQLInfo(pInfo, yymsp[-2].minor.yy158, NULL, TSQL_CREATE_NORMAL_METER); } break; case 102: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ { - yygotominor.yy158 = tSetCreateSQLElems(yymsp[-5].minor.yy471, yymsp[-1].minor.yy471, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METRIC); - setSQLInfo(pInfo, yygotominor.yy158, NULL, TSQL_CREATE_NORMAL_METRIC); + yymsp[-6].minor.yy158 = tSetCreateSQLElems(yymsp[-5].minor.yy471, yymsp[-1].minor.yy471, NULL, NULL, NULL, TSQL_CREATE_NORMAL_METRIC); + setSQLInfo(pInfo, yymsp[-6].minor.yy158, NULL, TSQL_CREATE_NORMAL_METRIC); } break; case 103: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; - yygotominor.yy158 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy56, NULL, TSQL_CREATE_METER_FROM_METRIC); - setSQLInfo(pInfo, yygotominor.yy158, NULL, TSQL_CREATE_METER_FROM_METRIC); + yymsp[-6].minor.yy158 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy56, NULL, TSQL_CREATE_METER_FROM_METRIC); + setSQLInfo(pInfo, yymsp[-6].minor.yy158, NULL, TSQL_CREATE_METER_FROM_METRIC); } break; case 104: /* create_table_args ::= AS select */ { - yygotominor.yy158 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy24, TSQL_CREATE_STREAM); - setSQLInfo(pInfo, yygotominor.yy158, NULL, TSQL_CREATE_STREAM); + yymsp[-1].minor.yy158 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy24, TSQL_CREATE_STREAM); + setSQLInfo(pInfo, yymsp[-1].minor.yy158, NULL, TSQL_CREATE_STREAM); } break; case 105: /* columnlist ::= columnlist COMMA column */ -{yygotominor.yy471 = tFieldListAppend(yymsp[-2].minor.yy471, &yymsp[0].minor.yy223); } +{yylhsminor.yy471 = tFieldListAppend(yymsp[-2].minor.yy471, &yymsp[0].minor.yy223); } + yymsp[-2].minor.yy471 = yylhsminor.yy471; break; case 106: /* columnlist ::= column */ -{yygotominor.yy471 = tFieldListAppend(NULL, &yymsp[0].minor.yy223);} +{yylhsminor.yy471 = tFieldListAppend(NULL, &yymsp[0].minor.yy223);} + yymsp[0].minor.yy471 = yylhsminor.yy471; break; case 107: /* column ::= ids typename */ { - tSQLSetColumnInfo(&yygotominor.yy223, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy223); + tSQLSetColumnInfo(&yylhsminor.yy223, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy223); } + yymsp[-1].minor.yy223 = yylhsminor.yy223; break; case 108: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yygotominor.yy56 = tVariantListAppend(yymsp[-2].minor.yy56, &yymsp[0].minor.yy186, -1); } +{ yylhsminor.yy56 = tVariantListAppend(yymsp[-2].minor.yy56, &yymsp[0].minor.yy186, -1); } + yymsp[-2].minor.yy56 = yylhsminor.yy56; break; case 109: /* tagitemlist ::= tagitem */ -{ yygotominor.yy56 = tVariantListAppend(NULL, &yymsp[0].minor.yy186, -1); } +{ yylhsminor.yy56 = tVariantListAppend(NULL, &yymsp[0].minor.yy186, -1); } + yymsp[0].minor.yy56 = yylhsminor.yy56; break; case 110: /* tagitem ::= INTEGER */ case 111: /* tagitem ::= FLOAT */ yytestcase(yyruleno==111); case 112: /* tagitem ::= STRING */ yytestcase(yyruleno==112); case 113: /* tagitem ::= BOOL */ yytestcase(yyruleno==113); -{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yygotominor.yy186, &yymsp[0].minor.yy0); } +{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy186, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy186 = yylhsminor.yy186; break; case 114: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yygotominor.yy186, &yymsp[0].minor.yy0); } +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy186, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy186 = yylhsminor.yy186; break; case 115: /* tagitem ::= MINUS INTEGER */ case 116: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==116); @@ -1927,8 +2292,9 @@ static void yy_reduce( yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yygotominor.yy186, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy186, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy186 = yylhsminor.yy186; break; case 119: /* cmd ::= select */ { @@ -1937,53 +2303,61 @@ static void yy_reduce( break; case 120: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yygotominor.yy24 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy498, yymsp[-9].minor.yy56, yymsp[-8].minor.yy90, yymsp[-4].minor.yy56, yymsp[-3].minor.yy56, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy56, &yymsp[0].minor.yy294, &yymsp[-1].minor.yy294); + yylhsminor.yy24 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy498, yymsp[-9].minor.yy56, yymsp[-8].minor.yy90, yymsp[-4].minor.yy56, yymsp[-3].minor.yy56, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy56, &yymsp[0].minor.yy294, &yymsp[-1].minor.yy294); } + yymsp[-11].minor.yy24 = yylhsminor.yy24; break; case 121: /* sclp ::= selcollist COMMA */ -{yygotominor.yy498 = yymsp[-1].minor.yy498;} +{yylhsminor.yy498 = yymsp[-1].minor.yy498;} + yymsp[-1].minor.yy498 = yylhsminor.yy498; break; case 122: /* sclp ::= */ -{yygotominor.yy498 = 0;} +{yymsp[1].minor.yy498 = 0;} break; case 123: /* selcollist ::= sclp expr as */ { - yygotominor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498, yymsp[-1].minor.yy90, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498, yymsp[-1].minor.yy90, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } + yymsp[-2].minor.yy498 = yylhsminor.yy498; break; case 124: /* selcollist ::= sclp STAR */ { tSQLExpr *pNode = tSQLExprIdValueCreate(NULL, TK_ALL); - yygotominor.yy498 = tSQLExprListAppend(yymsp[-1].minor.yy498, pNode, 0); + yylhsminor.yy498 = tSQLExprListAppend(yymsp[-1].minor.yy498, pNode, 0); } + yymsp[-1].minor.yy498 = yylhsminor.yy498; break; case 125: /* as ::= AS ids */ - case 126: /* as ::= ids */ yytestcase(yyruleno==126); -{ yygotominor.yy0 = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } + break; + case 126: /* as ::= ids */ +{ yylhsminor.yy0 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 127: /* as ::= */ -{ yygotominor.yy0.n = 0; } +{ yymsp[1].minor.yy0.n = 0; } break; case 128: /* from ::= FROM tablelist */ - case 140: /* orderby_opt ::= ORDER BY sortlist */ yytestcase(yyruleno==140); - case 148: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==148); -{yygotominor.yy56 = yymsp[0].minor.yy56;} +{yymsp[-1].minor.yy56 = yymsp[0].minor.yy56;} break; case 129: /* tablelist ::= ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yygotominor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} + yymsp[-1].minor.yy56 = yylhsminor.yy56; break; case 130: /* tablelist ::= tablelist COMMA ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yygotominor.yy56 = tVariantListAppendToken(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy0, -1); } +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy56 = tVariantListAppendToken(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy0, -1); } + yymsp[-3].minor.yy56 = yylhsminor.yy56; break; case 131: /* tmvar ::= VARIABLE */ -{yygotominor.yy0 = yymsp[0].minor.yy0;} +{yylhsminor.yy0 = yymsp[0].minor.yy0;} + yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 132: /* interval_opt ::= INTERVAL LP tmvar RP */ case 137: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==137); -{yygotominor.yy0 = yymsp[-1].minor.yy0; } +{yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; case 134: /* fill_opt ::= */ -{yygotominor.yy56 = 0; } +{yymsp[1].minor.yy56 = 0; } break; case 135: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { @@ -1992,182 +2366,224 @@ static void yy_reduce( tVariantCreate(&A, &yymsp[-3].minor.yy0); tVariantListInsert(yymsp[-1].minor.yy56, &A, -1, 0); - yygotominor.yy56 = yymsp[-1].minor.yy56; + yymsp[-5].minor.yy56 = yymsp[-1].minor.yy56; } break; case 136: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yygotominor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; case 139: /* orderby_opt ::= */ case 147: /* groupby_opt ::= */ yytestcase(yyruleno==147); -{yygotominor.yy56 = 0;} +{yymsp[1].minor.yy56 = 0;} + break; + case 140: /* orderby_opt ::= ORDER BY sortlist */ + case 148: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==148); +{yymsp[-2].minor.yy56 = yymsp[0].minor.yy56;} break; case 141: /* sortlist ::= sortlist COMMA item sortorder */ { - yygotominor.yy56 = tVariantListAppend(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); + yylhsminor.yy56 = tVariantListAppend(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); } + yymsp[-3].minor.yy56 = yylhsminor.yy56; break; case 142: /* sortlist ::= item sortorder */ { - yygotominor.yy56 = tVariantListAppend(NULL, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); + yylhsminor.yy56 = tVariantListAppend(NULL, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); } + yymsp[-1].minor.yy56 = yylhsminor.yy56; break; case 143: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yygotominor.yy186, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy186, &yymsp[-1].minor.yy0); } + yymsp[-1].minor.yy186 = yylhsminor.yy186; break; case 144: /* sortorder ::= ASC */ -{yygotominor.yy332 = TSQL_SO_ASC; } +{yymsp[0].minor.yy332 = TSQL_SO_ASC; } break; case 145: /* sortorder ::= DESC */ -{yygotominor.yy332 = TSQL_SO_DESC;} +{yymsp[0].minor.yy332 = TSQL_SO_DESC;} break; case 146: /* sortorder ::= */ -{yygotominor.yy332 = TSQL_SO_ASC;} +{yymsp[1].minor.yy332 = TSQL_SO_ASC;} break; case 149: /* grouplist ::= grouplist COMMA item */ { - yygotominor.yy56 = tVariantListAppend(yymsp[-2].minor.yy56, &yymsp[0].minor.yy186, -1); + yylhsminor.yy56 = tVariantListAppend(yymsp[-2].minor.yy56, &yymsp[0].minor.yy186, -1); } + yymsp[-2].minor.yy56 = yylhsminor.yy56; break; case 150: /* grouplist ::= item */ { - yygotominor.yy56 = tVariantListAppend(NULL, &yymsp[0].minor.yy186, -1); + yylhsminor.yy56 = tVariantListAppend(NULL, &yymsp[0].minor.yy186, -1); } + yymsp[0].minor.yy56 = yylhsminor.yy56; break; case 151: /* having_opt ::= */ case 161: /* where_opt ::= */ yytestcase(yyruleno==161); case 197: /* expritem ::= */ yytestcase(yyruleno==197); -{yygotominor.yy90 = 0;} +{yymsp[1].minor.yy90 = 0;} break; case 152: /* having_opt ::= HAVING expr */ case 162: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==162); - case 196: /* expritem ::= expr */ yytestcase(yyruleno==196); -{yygotominor.yy90 = yymsp[0].minor.yy90;} +{yymsp[-1].minor.yy90 = yymsp[0].minor.yy90;} break; case 153: /* limit_opt ::= */ case 157: /* slimit_opt ::= */ yytestcase(yyruleno==157); -{yygotominor.yy294.limit = -1; yygotominor.yy294.offset = 0;} +{yymsp[1].minor.yy294.limit = -1; yymsp[1].minor.yy294.offset = 0;} break; case 154: /* limit_opt ::= LIMIT signed */ case 158: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==158); -{yygotominor.yy294.limit = yymsp[0].minor.yy389; yygotominor.yy294.offset = 0;} +{yymsp[-1].minor.yy294.limit = yymsp[0].minor.yy389; yymsp[-1].minor.yy294.offset = 0;} break; case 155: /* limit_opt ::= LIMIT signed OFFSET signed */ case 159: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==159); -{yygotominor.yy294.limit = yymsp[-2].minor.yy389; yygotominor.yy294.offset = yymsp[0].minor.yy389;} +{yymsp[-3].minor.yy294.limit = yymsp[-2].minor.yy389; yymsp[-3].minor.yy294.offset = yymsp[0].minor.yy389;} break; case 156: /* limit_opt ::= LIMIT signed COMMA signed */ case 160: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==160); -{yygotominor.yy294.limit = yymsp[0].minor.yy389; yygotominor.yy294.offset = yymsp[-2].minor.yy389;} +{yymsp[-3].minor.yy294.limit = yymsp[0].minor.yy389; yymsp[-3].minor.yy294.offset = yymsp[-2].minor.yy389;} break; case 163: /* expr ::= LP expr RP */ -{yygotominor.yy90 = yymsp[-1].minor.yy90; } +{yymsp[-2].minor.yy90 = yymsp[-1].minor.yy90; } break; case 164: /* expr ::= ID */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 165: /* expr ::= ID DOT ID */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 166: /* expr ::= ID DOT STAR */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 167: /* expr ::= INTEGER */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 168: /* expr ::= MINUS INTEGER */ case 169: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==169); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy90 = yylhsminor.yy90; break; case 170: /* expr ::= FLOAT */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 171: /* expr ::= MINUS FLOAT */ case 172: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==172); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy90 = yylhsminor.yy90; break; case 173: /* expr ::= STRING */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 174: /* expr ::= NOW */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 175: /* expr ::= VARIABLE */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 176: /* expr ::= BOOL */ -{yygotominor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} +{yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 177: /* expr ::= ID LP exprlist RP */ { - yygotominor.yy90 = tSQLExprCreateFunction(yymsp[-1].minor.yy498, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy90 = tSQLExprCreateFunction(yymsp[-1].minor.yy498, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy90 = yylhsminor.yy90; break; case 178: /* expr ::= ID LP STAR RP */ { - yygotominor.yy90 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy90 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy90 = yylhsminor.yy90; break; case 179: /* expr ::= expr AND expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_AND);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_AND);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 180: /* expr ::= expr OR expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_OR); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_OR); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 181: /* expr ::= expr LT expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LT);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LT);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 182: /* expr ::= expr GT expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GT);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GT);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 183: /* expr ::= expr LE expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LE);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LE);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 184: /* expr ::= expr GE expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GE);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GE);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 185: /* expr ::= expr NE expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_NE);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_NE);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 186: /* expr ::= expr EQ expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_EQ);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_EQ);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 187: /* expr ::= expr PLUS expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_PLUS); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_PLUS); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 188: /* expr ::= expr MINUS expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_MINUS); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_MINUS); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 189: /* expr ::= expr STAR expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_STAR); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_STAR); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 190: /* expr ::= expr SLASH expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_DIVIDE);} +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_DIVIDE);} + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 191: /* expr ::= expr REM expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_REM); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_REM); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 192: /* expr ::= expr LIKE expr */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LIKE); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LIKE); } + yymsp[-2].minor.yy90 = yylhsminor.yy90; break; case 193: /* expr ::= expr IN LP exprlist RP */ -{yygotominor.yy90 = tSQLExprCreate(yymsp[-4].minor.yy90, (tSQLExpr*)yymsp[-1].minor.yy498, TK_IN); } +{yylhsminor.yy90 = tSQLExprCreate(yymsp[-4].minor.yy90, (tSQLExpr*)yymsp[-1].minor.yy498, TK_IN); } + yymsp[-4].minor.yy90 = yylhsminor.yy90; break; case 194: /* exprlist ::= exprlist COMMA expritem */ case 201: /* itemlist ::= itemlist COMMA expr */ yytestcase(yyruleno==201); -{yygotominor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498,yymsp[0].minor.yy90,0);} +{yylhsminor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498,yymsp[0].minor.yy90,0);} + yymsp[-2].minor.yy498 = yylhsminor.yy498; break; case 195: /* exprlist ::= expritem */ case 202: /* itemlist ::= expr */ yytestcase(yyruleno==202); -{yygotominor.yy498 = tSQLExprListAppend(0,yymsp[0].minor.yy90,0);} +{yylhsminor.yy498 = tSQLExprListAppend(0,yymsp[0].minor.yy90,0);} + yymsp[0].minor.yy498 = yylhsminor.yy498; + break; + case 196: /* expritem ::= expr */ +{yylhsminor.yy90 = yymsp[0].minor.yy90;} + yymsp[0].minor.yy90 = yylhsminor.yy90; break; case 198: /* cmd ::= INSERT INTO cpxName insert_value_list */ { @@ -2175,10 +2591,11 @@ static void yy_reduce( } break; case 199: /* insert_value_list ::= VALUES LP itemlist RP */ -{yygotominor.yy74 = tSQLListListAppend(NULL, yymsp[-1].minor.yy498);} +{yymsp[-3].minor.yy74 = tSQLListListAppend(NULL, yymsp[-1].minor.yy498);} break; case 200: /* insert_value_list ::= insert_value_list VALUES LP itemlist RP */ -{yygotominor.yy74 = tSQLListListAppend(yymsp[-4].minor.yy74, yymsp[-1].minor.yy498);} +{yylhsminor.yy74 = tSQLListListAppend(yymsp[-4].minor.yy74, yymsp[-1].minor.yy498);} + yymsp[-4].minor.yy74 = yylhsminor.yy74; break; case 203: /* cmd ::= RESET QUERY CACHE */ { setDCLSQLElems(pInfo, RESET_QUERY_CACHE, 0);} @@ -2245,44 +2662,36 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); } break; - case 210: /* cmd ::= KILL CONNECTION IP COLON INTEGER */ + case 210: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &yymsp[-2].minor.yy0);} break; - case 211: /* cmd ::= KILL STREAM IP COLON INTEGER COLON INTEGER */ + case 211: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ {yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &yymsp[-4].minor.yy0);} break; - case 212: /* cmd ::= KILL QUERY IP COLON INTEGER COLON INTEGER */ + case 212: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ {yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &yymsp[-4].minor.yy0);} break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyruleno>=0 && yyrulenoyyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - /* If the reduce action popped at least - ** one element off the stack, then we can push the new element back - ** onto the stack here, and skip the stack overflow test in yy_shift(). - ** That gives a significant speed improvement. */ - if( yysize ){ - yypParser->yyidx++; - yymsp -= yysize-1; - yymsp->stateno = (YYACTIONTYPE)yyact; - yymsp->major = (YYCODETYPE)yygoto; - yymsp->minor = yygotominor; - yyTraceShift(yypParser, yyact); - }else{ - yy_shift(yypParser,yyact,yygoto,&yygotominor); - } - }else{ - assert( yyact == YY_ACCEPT_ACTION ); - yy_accept(yypParser); - } + yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto); + + /* There are no SHIFTREDUCE actions on nonterminals because the table + ** generator has simplified them to pure REDUCE actions. */ + assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); + + /* It is not possible for a REDUCE to be followed by an error */ + assert( yyact!=YY_ERROR_ACTION ); + + yymsp += yysize+1; + yypParser->yytos = yymsp; + yymsp->stateno = (YYACTIONTYPE)yyact; + yymsp->major = (YYCODETYPE)yygoto; + yyTraceShift(yypParser, yyact, "... then shift"); } /* @@ -2298,7 +2707,7 @@ static void yy_parse_failed( fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ /************ Begin %parse_failure code ***************************************/ @@ -2313,10 +2722,10 @@ static void yy_parse_failed( static void yy_syntax_error( yyParser *yypParser, /* The parser */ int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ + ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ ParseARG_FETCH; -#define TOKEN (yyminor.yy0) +#define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ pInfo->validSql = false; @@ -2356,7 +2765,10 @@ static void yy_accept( fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); } #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif + assert( yypParser->yytos==yypParser->yystack ); /* Here code is inserted which will be executed whenever the ** parser accepts */ /*********** Begin %parse_accept code *****************************************/ @@ -2391,7 +2803,7 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ + unsigned int yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif @@ -2400,29 +2812,8 @@ void Parse( #endif yyParser *yypParser; /* The parser */ - /* (re)initialize the parser, if necessary */ yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ -#if YYSTACKDEPTH<=0 - if( yypParser->yystksz <=0 ){ - /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ - yyminorunion = yyzerominor; - yyStackOverflow(yypParser, &yyminorunion); - return; - } -#endif - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n", - yyTracePrompt); - } -#endif - } - yyminorunion.yy0 = yyminor; + assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif @@ -2430,21 +2821,34 @@ void Parse( #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); + int stateno = yypParser->yytos->stateno; + if( stateno < YY_MIN_REDUCE ){ + fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno); + }else{ + fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", + yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + } } #endif do{ yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); - if( yyact <= YY_MAX_SHIFTREDUCE ){ - if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; - yy_shift(yypParser,yyact,yymajor,&yyminorunion); + if( yyact >= YY_MIN_REDUCE ){ + yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + }else if( yyact <= YY_MAX_SHIFTREDUCE ){ + yy_shift(yypParser,yyact,yymajor,yyminor); +#ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; +#endif yymajor = YYNOCODE; - }else if( yyact <= YY_MAX_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE); + }else if( yyact==YY_ACCEPT_ACTION ){ + yypParser->yytos--; + yy_accept(yypParser); + return; }else{ assert( yyact == YY_ERROR_ACTION ); + yyminorunion.yy0 = yyminor; #ifdef YYERRORSYMBOL int yymx; #endif @@ -2474,9 +2878,9 @@ void Parse( ** */ if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor,yyminor); } - yymx = yypParser->yystack[yypParser->yyidx].major; + yymx = yypParser->yytos->major; if( yymx==YYERRORSYMBOL || yyerrorhit ){ #ifndef NDEBUG if( yyTraceFILE ){ @@ -2484,26 +2888,26 @@ void Parse( yyTracePrompt,yyTokenName[yymajor]); } #endif - yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); + yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_reduce_action( - yypParser->yystack[yypParser->yyidx].stateno, + while( yypParser->yytos >= yypParser->yystack + && yymx != YYERRORSYMBOL + && (yyact = yy_find_reduce_action( + yypParser->yytos->stateno, YYERRORSYMBOL)) >= YY_MIN_REDUCE ){ yy_pop_parser_stack(yypParser); } - if( yypParser->yyidx < 0 || yymajor==0 ){ + if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); } } yypParser->yyerrcnt = 3; @@ -2516,7 +2920,7 @@ void Parse( ** Applications can set this macro (for example inside %include) if ** they intend to abandon the parse upon the first syntax error seen. */ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; @@ -2531,24 +2935,29 @@ void Parse( ** three input tokens have been successfully shifted. */ if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_syntax_error(yypParser,yymajor, yyminor); } yypParser->yyerrcnt = 3; yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); +#ifndef YYNOERRORRECOVERY + yypParser->yyerrcnt = -1; +#endif } yymajor = YYNOCODE; #endif } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ - int i; + yyStackEntry *i; + char cDiv = '['; fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', - yyTokenName[yypParser->yystack[i].major]); + for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ + fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); + cDiv = ' '; + } fprintf(yyTraceFILE,"]\n"); } #endif diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 99f0f5bb91..85da925297 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -96,7 +96,6 @@ static SKeyword keywordTable[] = { {"TABLE", TK_TABLE}, {"DATABASE", TK_DATABASE}, {"DNODE", TK_DNODE}, - {"IP", TK_IP}, {"USER", TK_USER}, {"ACCOUNT", TK_ACCOUNT}, {"USE", TK_USE}, @@ -523,7 +522,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { } if (seg == 4) { // ip address - *tokenType = TK_IP; + *tokenType = TK_IPTOKEN; return i; } From 7a51794504eb5713885fc79d0a9834241e4f6dcf Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Wed, 20 Nov 2019 17:47:56 +0800 Subject: [PATCH 06/42] [tbase-1205] [tbase-955] --- src/inc/sql.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/sql.y b/src/inc/sql.y index 1aea945818..c465323b90 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -154,7 +154,7 @@ ifnotexists(X) ::= . {X.n = 0;} /////////////////////////////////THE CREATE STATEMENT/////////////////////////////////////// //create option for dnode/db/user/account -cmd ::= CREATE DNODE IP(X). { setDCLSQLElems(pInfo, CREATE_DNODE, 1, &X);} +cmd ::= CREATE DNODE IPTOKEN(X). { setDCLSQLElems(pInfo, CREATE_DNODE, 1, &X);} cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSQL(pInfo, CREATE_ACCOUNT, &X, &Y, &Z);} cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDBSQL(pInfo, CREATE_DATABASE, &X, &Y, &Z);} From 507ee7c3c7719454c22215354ba0248e62749908 Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 20 Nov 2019 19:36:35 +0800 Subject: [PATCH 07/42] [TBASE-1129] --- src/inc/tstatus.h | 12 ------------ src/os/linux/src/tlinux.c | 6 ++++-- src/util/src/tstatus.c | 17 ----------------- src/util/src/tutil.c | 2 +- 4 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/inc/tstatus.h b/src/inc/tstatus.h index 0f9bea5ae5..18900d3b29 100644 --- a/src/inc/tstatus.h +++ b/src/inc/tstatus.h @@ -73,23 +73,11 @@ enum _TSDB_VG_LB_STATUS { TSDB_VG_LB_STATUS_UPDATE }; -enum _TSDB_LB_TYPE { - TSDB_LB_TYPE_SCHEDULE, - TSDB_LB_TYPE_SOON, -}; - -enum _TSDB_LB_REASON { - TSDB_LB_REASON_PERIOD, - TSDB_LB_REASON_EVENT, -}; - const char* taosGetVnodeStatusStr(int vnodeStatus); const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus); const char* taosGetVnodeDropStatusStr(int dropping); const char* taosGetDnodeStatusStr(int dnodeStatus); const char* taosGetDnodeLbStatusStr(int dnodeBalanceStatus); -const char* taosGetBalanceTypeStr(int type); -const char* taosBalanceReasonStr(int reason); const char* taosGetVgroupLbStatusStr(int vglbStatus); #ifdef __cplusplus diff --git a/src/os/linux/src/tlinux.c b/src/os/linux/src/tlinux.c index 6a7225b476..c4d9425b40 100644 --- a/src/os/linux/src/tlinux.c +++ b/src/os/linux/src/tlinux.c @@ -287,8 +287,10 @@ ssize_t tsendfile(int dfd, int sfd, off_t *offset, size_t size) { ssize_t sentbytes; while (leftbytes > 0) { - // TODO : Think to check if file is larger than 1GB - if (leftbytes > 1000000000) leftbytes = 1000000000; + /* + * TODO : Think to check if file is larger than 1GB + */ + //if (leftbytes > 1000000000) leftbytes = 1000000000; sentbytes = sendfile(dfd, sfd, offset, leftbytes); if (sentbytes == -1) { if (errno == EINTR) { diff --git a/src/util/src/tstatus.c b/src/util/src/tstatus.c index 4e3141b13b..f38655ac45 100644 --- a/src/util/src/tstatus.c +++ b/src/util/src/tstatus.c @@ -73,20 +73,3 @@ const char* taosGetVgroupLbStatusStr(int vglbStatus) { default: return "undefined"; } } - -const char* taosGetBalanceTypeStr(int type) { - switch (type) { - case TSDB_LB_TYPE_SCHEDULE: return "schedule"; - case TSDB_LB_TYPE_SOON: return "soon"; - default: return "undefined"; - } -} - -const char* taosBalanceReasonStr(int reason) { - switch (reason) { - case TSDB_LB_REASON_PERIOD: return "period"; - case TSDB_LB_REASON_EVENT: return "event"; - default: return "undefined"; - } -} - diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 8413294bcc..e0dcb0aa3f 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -490,7 +490,7 @@ char *taosIpStr(uint32_t ipInt) { static int ipStrIndex = 0; char *ipStr = ipStrArray[(ipStrIndex++) % 3]; - sprintf(ipStr, "0x%x:%d.%d.%d.%d", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, ipInt >> 24); + sprintf(ipStr, "0x%x:%u.%u.%u.%u", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, (uint8_t)(ipInt >> 24)); return ipStr; } From 2ae838b6904b4cb8b793d91151921b944ffb7f7e Mon Sep 17 00:00:00 2001 From: slguan Date: Wed, 20 Nov 2019 23:20:19 +0800 Subject: [PATCH 08/42] [TBASE-1129] --- src/system/detail/src/dnodeMgmt.c | 25 +++++++++++++------------ src/system/detail/src/mgmtDnode.c | 7 ++++--- src/system/detail/src/mgmtMeter.c | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/system/detail/src/dnodeMgmt.c b/src/system/detail/src/dnodeMgmt.c index 9a8cde169e..d9029db655 100644 --- a/src/system/detail/src/dnodeMgmt.c +++ b/src/system/detail/src/dnodeMgmt.c @@ -377,21 +377,22 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { dTrace("vid:%d, status:%s, wait vnode delete finished", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); } else { dTrace("vid:%d, status:%s, start to update vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); - } - /* - if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { - vnodeCleanUpOneVnode(vnode); - } - vnodeConfigVPeers(vnode, pCfg->replications, pMsg->vpeerDesc); - vnodeSaveVnodeCfg(vnode, pCfg, pMsg->vpeerDesc); + if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { + vnodeCleanUpOneVnode(vnode); + } - if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { - vnodeUpdateHeadFile(vnode, vnodeList[vnode].cfg.maxSessions, pCfg->maxSessions); - vnodeList[vnode].cfg.maxSessions = pCfg->maxSessions; - vnodeOpenVnode(vnode); + vnodeConfigVPeers(vnode, pCfg->replications, pMsg->vpeerDesc); + vnodeSaveVnodeCfg(vnode, pCfg, pMsg->vpeerDesc); + + /* + if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { + vnodeUpdateHeadFile(vnode, vnodeList[vnode].cfg.maxSessions, pCfg->maxSessions); + vnodeList[vnode].cfg.maxSessions = pCfg->maxSessions; + vnodeOpenVnode(vnode); + } + */ } - */ return 0; } else { dTrace("vid:%d, status:%s, start to delete vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); diff --git a/src/system/detail/src/mgmtDnode.c b/src/system/detail/src/mgmtDnode.c index 9af594f2ca..3ee54b9f19 100644 --- a/src/system/detail/src/mgmtDnode.c +++ b/src/system/detail/src/mgmtDnode.c @@ -53,11 +53,12 @@ void mgmtSetDnodeMaxVnodes(SDnodeObj *pDnode) { void mgmtCalcNumOfFreeVnodes(SDnodeObj *pDnode) { int totalVnodes = 0; + mTrace("dnode:%s, begin calc free vnodes", taosIpStr(pDnode->privateIp)); for (int i = 0; i < pDnode->numOfVnodes; ++i) { SVnodeLoad *pVload = pDnode->vload + i; if (pVload->vgId != 0) { - mTrace("dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s", - taosIpStr(pDnode->privateIp), i, pVload->vgId, + mTrace("%d-dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s", + totalVnodes, taosIpStr(pDnode->privateIp), i, pVload->vgId, pVload->status, taosGetDnodeStatusStr(pVload->status), pVload->dropStatus, taosGetVnodeDropStatusStr(pVload->dropStatus), pVload->syncStatus, taosGetVnodeSyncStatusStr(pVload->syncStatus)); @@ -66,7 +67,7 @@ void mgmtCalcNumOfFreeVnodes(SDnodeObj *pDnode) { } pDnode->numOfFreeVnodes = pDnode->numOfVnodes - totalVnodes; - mTrace("dnode:%s, calc free vnodes, numOfVnodes:%d, numOfFreeVnodes:%d, totalVnodes:%d", + mTrace("dnode:%s, numOfVnodes:%d, numOfFreeVnodes:%d, totalVnodes:%d", taosIpStr(pDnode->privateIp), pDnode->numOfVnodes, pDnode->numOfFreeVnodes, totalVnodes); } diff --git a/src/system/detail/src/mgmtMeter.c b/src/system/detail/src/mgmtMeter.c index 658af40212..f1e12d763f 100644 --- a/src/system/detail/src/mgmtMeter.c +++ b/src/system/detail/src/mgmtMeter.c @@ -618,7 +618,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { if (pDb->vgStatus == TSDB_VG_STATUS_IN_PROGRESS) { mgmtDestroyMeter(pMeter); - mTrace("table:%s, vgroup in creating progress", pCreate->meterId); + //mTrace("table:%s, vgroup in creating progress", pCreate->meterId); return TSDB_CODE_ACTION_IN_PROGRESS; } From a797219bd60a12ea4a427d37072919e3a4a80560 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 21 Nov 2019 16:45:38 +0800 Subject: [PATCH 09/42] [tbase-1210] --- src/client/inc/tscUtil.h | 6 +- src/client/inc/tsclient.h | 7 +- src/client/src/tscLocal.c | 100 ++++- src/client/src/tscSQLParser.c | 86 +++- src/client/src/tscSQLParserImpl.c | 22 +- src/client/src/tscServer.c | 7 + src/client/src/tscUtil.c | 17 +- src/inc/sql.y | 12 +- src/util/src/sql.c | 714 +++++++++++++++--------------- 9 files changed, 581 insertions(+), 390 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 47f25babe0..6666fa24a6 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -127,7 +127,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size); void tscFieldInfoSetValFromSchema(SFieldInfo* pFieldInfo, int32_t index, SSchema* pSchema); void tscFieldInfoSetValFromField(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* pField); -void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, char* name, int16_t bytes); +void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes); void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visible); void tscFieldInfoCalOffset(SSqlCmd* pCmd); @@ -143,7 +143,9 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo); void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex); SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type, - int16_t size, /*int16_t colId,*/ int16_t interSize); + int16_t size, int16_t interSize); +SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId); + SSqlExpr* tscSqlExprUpdate(SSqlCmd* pCmd, int32_t index, int16_t functionId, int16_t srcColumnIndex, int16_t type, int16_t size); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 7341d674d3..e8e68e1362 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -92,7 +92,12 @@ enum _sql_cmd { */ TSDB_SQL_RETRIEVE_EMPTY_RESULT, - TSDB_SQL_RESET_CACHE, + TSDB_SQL_RESET_CACHE, // 40 + TSDB_SQL_SERV_STATUS, + TSDB_SQL_CURRENT_DB, + TSDB_SQL_SERV_VERSION, + TSDB_SQL_CLI_VERSION, + TSDB_SQL_CURRENT_USER, TSDB_SQL_CFG_LOCAL, TSDB_SQL_MAX diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index a18a98c8c1..5ae72acd57 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -26,6 +26,8 @@ #include "tschemautil.h" #include "tsocket.h" +static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength); + static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) { char buf[512] = {0}; @@ -39,7 +41,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type case TSDB_DATA_TYPE_DOUBLE: { #ifdef _TD_ARM_32_ double dv = 0; - *(int64_t*)(&dv) = *(int64_t*)pData; + *(int64_t *)(&dv) = *(int64_t *)pData; len = sprintf(buf, "%f", dv); #else len = sprintf(buf, "%lf", *(double *)pData); @@ -47,12 +49,11 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type if (strncasecmp("nan", buf, 3) == 0) { len = 4; } - } - break; + } break; case TSDB_DATA_TYPE_FLOAT: { #ifdef _TD_ARM_32_ float fv = 0; - *(int32_t*)(&fv) = *(int32_t*)pData; + *(int32_t *)(&fv) = *(int32_t *)pData; len = sprintf(buf, "%f", fv); #else len = sprintf(buf, "%f", *(float *)pData); @@ -60,8 +61,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type if (strncasecmp("nan", buf, 3) == 0) { len = 4; } - } - break; + } break; case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_BIGINT: len = sprintf(buf, "%lld", *(int64_t *)pData); @@ -203,23 +203,21 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { case TSDB_DATA_TYPE_FLOAT: { #ifdef _TD_ARM_32_ float fv = 0; - *(int32_t*)(&fv) = *(int32_t*)pTagValue; + *(int32_t *)(&fv) = *(int32_t *)pTagValue; sprintf(target, "%f", fv); #else sprintf(target, "%f", *(float *)pTagValue); #endif - } - break; + } break; case TSDB_DATA_TYPE_DOUBLE: { #ifdef _TD_ARM_32_ double dv = 0; - *(int64_t*)(&dv) = *(int64_t*)pTagValue; + *(int64_t *)(&dv) = *(int64_t *)pTagValue; sprintf(target, "%lf", dv); #else sprintf(target, "%lf", *(double *)pTagValue); #endif - } - break; + } break; case TSDB_DATA_TYPE_TINYINT: sprintf(target, "%d", *(int8_t *)pTagValue); break; @@ -391,6 +389,68 @@ static int tscProcessQueryTags(SSqlObj *pSql) { } } +static void tscProcessCurrentUser(SSqlObj *pSql) { + SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0); + tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN); +} + +static void tscProcessCurrentDB(SSqlObj *pSql) { + char db[TSDB_DB_NAME_LEN + 1] = {0}; + extractDBName(pSql->pTscObj->db, db); + + // no use db is invoked before. + if (strlen(db) == 0) { + setNull(db, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + } + + SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0); + tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN); +} + +static void tscProcessServerVer(SSqlObj *pSql) { + const char* v = pSql->pTscObj->sversion; + + SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0); + tscSetLocalQueryResult(pSql, v, pExpr->aliasName, tListLen(pSql->pTscObj->sversion)); +} + +static void tscProcessClientVer(SSqlObj *pSql) { + SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0); + tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version)); +} + +static void tscProcessServStatus(SSqlObj *pSql) { + STscObj* pObj = pSql->pTscObj; + + if (pObj->pHb != NULL) { + if (pObj->pHb->res.code == TSDB_CODE_NETWORK_UNAVAIL) { + pSql->res.code = TSDB_CODE_NETWORK_UNAVAIL; + return; + } + } else { + if (pSql->res.code == TSDB_CODE_NETWORK_UNAVAIL) { + return; + } + } + + SSqlExpr* pExpr = tscSqlExprGet(&pSql->cmd, 0); + tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2); +} + +void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength) { + SSqlCmd *pCmd = &pSql->cmd; + SSqlRes *pRes = &pSql->res; + + pCmd->numOfCols = 1; + pCmd->order.order = TSQL_SO_ASC; + + tscFieldInfoSetValue(&pCmd->fieldsInfo, 0, TSDB_DATA_TYPE_BINARY, columnName, valueLength); + tscInitResObjForLocalQuery(pSql, 1, valueLength); + + TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, 0); + strncpy(pRes->data, val, pField->bytes); +} + int tscProcessLocalCmd(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; @@ -402,13 +462,23 @@ int tscProcessLocalCmd(SSqlObj *pSql) { pSql->res.code = (uint8_t)tscProcessQueryTags(pSql); } else if (pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT) { /* - * pass the qhandle check, in order to call partial release function to - * free allocated resources and remove the SqlObj from linked list + * set the qhandle to be 1 in order to pass the qhandle check, and to call partial release function to + * free allocated resources and remove the SqlObj from sql query linked list */ - pSql->res.qhandle = 0x1; // pass the qhandle check + pSql->res.qhandle = 0x1; pSql->res.numOfRows = 0; } else if (pCmd->command == TSDB_SQL_RESET_CACHE) { taosClearDataCache(tscCacheHandle); + } else if (pCmd->command == TSDB_SQL_SERV_VERSION) { + tscProcessServerVer(pSql); + } else if (pCmd->command == TSDB_SQL_CLI_VERSION) { + tscProcessClientVer(pSql); + } else if (pCmd->command == TSDB_SQL_CURRENT_USER) { + tscProcessCurrentUser(pSql); + } else if (pCmd->command == TSDB_SQL_CURRENT_DB) { + tscProcessCurrentDB(pSql); + } else if (pCmd->command == TSDB_SQL_SERV_STATUS) { + tscProcessServStatus(pSql); } else { pSql->res.code = TSDB_CODE_INVALID_SQL; tscError("%p not support command:%d", pSql, pCmd->command); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f5727677c5..1f3da720f1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -117,7 +117,8 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString); static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex); static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex); static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql); - +static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd); + static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) { assert(QUERY_IS_STABLE_QUERY(pCmd->type)); @@ -877,7 +878,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { case TSQL_QUERY_METER: { SQuerySQL* pQuerySql = pInfo->pQueryInfo; - assert(pQuerySql != NULL && pQuerySql->from->nExpr > 0); + assert(pQuerySql != NULL && (pQuerySql->from == NULL || pQuerySql->from->nExpr > 0)); const char* msg0 = "invalid table name"; const char* msg1 = "table name too long"; @@ -895,6 +896,19 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { setErrMsg(pCmd, msg8); return TSDB_CODE_INVALID_SQL; } + + /* + * handle the sql expression without from subclause + * select current_database(); + * select server_version(); + * select client_version(); + * select server_state(); + */ + if (pQuerySql->from == NULL) { + assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL && + pQuerySql->pSortOrder == NULL); + return doLocalQueryProcess(pQuerySql, pCmd); + } if (pQuerySql->from->nExpr > TSDB_MAX_JOIN_TABLE_NUM) { setErrMsg(pCmd, msg7); @@ -1120,7 +1134,7 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); - if (pQuerySql->interval.type == 0) { + if (pQuerySql->interval.type == 0 || pQuerySql->interval.n == 0) { return TSDB_CODE_SUCCESS; } @@ -4971,8 +4985,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { } typedef struct SDNodeDynConfOption { - char* name; - int32_t len; + char* name; // command name + int32_t len; // name string length } SDNodeDynConfOption; int32_t validateDNodeConfig(tDCLSQL* pOptions) { @@ -4980,7 +4994,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { return TSDB_CODE_INVALID_SQL; } - SDNodeDynConfOption DNODE_DYNAMIC_CFG_OPTIONS[14] = { + const SDNodeDynConfOption DNODE_DYNAMIC_CFG_OPTIONS[14] = { {"resetLog", 8}, {"resetQueryCache", 15}, {"dDebugFlag", 10}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"mDebugFlag", 10}, {"sdbDebugFlag", 12}, {"httpDebugFlag", 13}, {"monitorDebugFlag", 16}, {"qDebugflag", 10}, @@ -4991,7 +5005,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { if (pOptions->nTokens == 2) { // reset log and reset query cache does not need value for (int32_t i = 0; i < 2; ++i) { - SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; + const SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { return TSDB_CODE_SUCCESS; } @@ -5014,7 +5028,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { } for (int32_t i = 2; i < tListLen(DNODE_DYNAMIC_CFG_OPTIONS) - 1; ++i) { - SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; + const SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { /* options is valid */ @@ -5031,8 +5045,10 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { return TSDB_CODE_INVALID_SQL; } - SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, - {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}}; + SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = { + {"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, + {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9} + }; SSQLToken* pOptionToken = &pOptions->a[0]; @@ -5686,3 +5702,53 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { return checkUpdateTagPrjFunctions(pCmd); } } + +int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) { + const char* msg1 = "only one expression allowed"; + const char* msg2 = "invalid expression in select clause"; + const char* msg3 = "invalid function"; + + tSQLExprList* pExprList = pQuerySql->pSelection; + if (pExprList->nExpr != 1) { + setErrMsg(pCmd, msg1); + return TSDB_CODE_INVALID_SQL; + } + + tSQLExpr* pExpr = pExprList->a[0].pNode; + if (pExpr->operand.z == NULL) { + setErrMsg(pCmd, msg2); + return TSDB_CODE_INVALID_SQL; + } + + SDNodeDynConfOption functionsInfo[5] = { + {"database()", 10}, {"server_version()", 16}, {"server_status()", 15}, {"client_version()", 16}, {"current_user()", 14} + }; + + int32_t index = -1; + for(int32_t i = 0; i < tListLen(functionsInfo); ++i) { + if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 && + functionsInfo[i].len == pExpr->operand.n) { + index = i; + break; + } + } + + SSqlExpr* pExpr1 = tscSqlExprInsertEmpty(pCmd, 0, TSDB_FUNC_TAG_DUMMY); + if (pExprList->a[0].aliasName != NULL) { + strncpy(pExpr1->aliasName, pExprList->a[0].aliasName, tListLen(pExpr1->aliasName)); + } else { + strncpy(pExpr1->aliasName, functionsInfo[index].name, tListLen(pExpr1->aliasName)); + } + + switch(index) { + case 0: pCmd->command = TSDB_SQL_CURRENT_DB;return TSDB_CODE_SUCCESS; + case 1: pCmd->command = TSDB_SQL_SERV_VERSION;return TSDB_CODE_SUCCESS; + case 2: pCmd->command = TSDB_SQL_SERV_STATUS;return TSDB_CODE_SUCCESS; + case 3: pCmd->command = TSDB_SQL_CLI_VERSION;return TSDB_CODE_SUCCESS; + case 4: pCmd->command = TSDB_SQL_CURRENT_USER;return TSDB_CODE_SUCCESS; + default: { + setErrMsg(pCmd, msg3); + return TSDB_CODE_INVALID_SQL; + } + } +} diff --git a/src/client/src/tscSQLParserImpl.c b/src/client/src/tscSQLParserImpl.c index 4fefe1665c..7715b32c3c 100644 --- a/src/client/src/tscSQLParserImpl.c +++ b/src/client/src/tscSQLParserImpl.c @@ -500,7 +500,7 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *type) { SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit) { - assert(pSelection != NULL && pFrom != NULL && pInterval != NULL && pLimit != NULL && pGLimit != NULL); + assert(pSelection != NULL); SQuerySQL *pQuery = calloc(1, sizeof(SQuerySQL)); pQuery->selectToken = *pSelectToken; @@ -512,13 +512,23 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, pQuery->pSortOrder = pSortOrder; pQuery->pWhere = pWhere; - pQuery->limit = *pLimit; - pQuery->slimit = *pGLimit; + if (pLimit != NULL) { + pQuery->limit = *pLimit; + } + + if (pGLimit != NULL) { + pQuery->slimit = *pGLimit; + } - pQuery->interval = *pInterval; - pQuery->sliding = *pSliding; + if (pInterval != NULL) { + pQuery->interval = *pInterval; + } + + if (pSliding != NULL) { + pQuery->sliding = *pSliding; + } + pQuery->fillType = pFill; - return pQuery; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d96f94ecc0..d498d7b291 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -3807,7 +3807,14 @@ void tscInitMsgs() { tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromVnode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_TAGS] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_METRIC] = tscProcessRetrieveMetricRsp; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 25564a75ea..b73ea5caaf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -720,7 +720,7 @@ static void evic(SFieldInfo* pFieldInfo, int32_t index) { } } -static void setValueImpl(TAOS_FIELD* pField, int8_t type, char* name, int16_t bytes) { +static void setValueImpl(TAOS_FIELD* pField, int8_t type, const char* name, int16_t bytes) { pField->type = type; strncpy(pField->name, name, TSDB_COL_NAME_LEN); pField->bytes = bytes; @@ -764,7 +764,7 @@ void tscFieldInfoUpdateVisible(SFieldInfo* pFieldInfo, int32_t index, bool visib } } -void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, char* name, int16_t bytes) { +void tscFieldInfoSetValue(SFieldInfo* pFieldInfo, int32_t index, int8_t type, const char* name, int16_t bytes) { ensureSpace(pFieldInfo, pFieldInfo->numOfOutputCols + 1); evic(pFieldInfo, index); @@ -896,6 +896,19 @@ static void _exprEvic(SSqlExprInfo* pExprInfo, int32_t index) { } } +SSqlExpr* tscSqlExprInsertEmpty(SSqlCmd* pCmd, int32_t index, int16_t functionId) { + SSqlExprInfo* pExprInfo = &pCmd->exprsInfo; + + _exprCheckSpace(pExprInfo, pExprInfo->numOfExprs + 1); + _exprEvic(pExprInfo, index); + + SSqlExpr* pExpr = &pExprInfo->pExprs[index]; + pExpr->functionId = functionId; + + pExprInfo->numOfExprs++; + return pExpr; +} + SSqlExpr* tscSqlExprInsert(SSqlCmd* pCmd, int32_t index, int16_t functionId, SColumnIndex* pColIndex, int16_t type, int16_t size, int16_t interSize) { SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pColIndex->tableIndex); diff --git a/src/inc/sql.y b/src/inc/sql.y index c465323b90..453485b0d9 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -349,6 +349,14 @@ select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) fill_ A = tSetQuerySQLElems(&T, W, X, Y, P, Z, &K, &S, F, &L, &G); } +// Support for the SQL exprssion without from & where subclauses, e.g., +// select current_database(), +// select server_version(), select client_version(), +// select server_state(); +select(A) ::= SELECT(T) selcollist(W). { + A = tSetQuerySQLElems(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +} + // selcollist is a list of expressions that are to become the return // values of the SELECT statement. The "*" in statements like // "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL. @@ -391,7 +399,7 @@ tmvar(A) ::= VARIABLE(X). {A = X;} %type interval_opt {SSQLToken} interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N = E; } -interval_opt(N) ::= . {N.n = 0; } +interval_opt(N) ::= . {N.n = 0; N.z = NULL; N.type = 0; } %type fill_opt {tVariantList*} %destructor fill_opt {tVariantListDestroy($$);} @@ -412,7 +420,7 @@ fill_opt(N) ::= FILL LP ID(Y) RP. { %type sliding_opt {SSQLToken} sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; } -sliding_opt(K) ::= . {K.n = 0; } +sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; } %type orderby_opt {tVariantList*} %destructor orderby_opt {tVariantListDestroy($$);} diff --git a/src/util/src/sql.c b/src/util/src/sql.c index 0feb3df5d9..f67af9b046 100644 --- a/src/util/src/sql.c +++ b/src/util/src/sql.c @@ -123,16 +123,16 @@ typedef union { #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 #define YYNSTATE 251 -#define YYNRULE 213 +#define YYNRULE 214 #define YYNTOKEN 195 #define YY_MAX_SHIFT 250 #define YY_MIN_SHIFTREDUCE 401 -#define YY_MAX_SHIFTREDUCE 613 -#define YY_ERROR_ACTION 614 -#define YY_ACCEPT_ACTION 615 -#define YY_NO_ACTION 616 -#define YY_MIN_REDUCE 617 -#define YY_MAX_REDUCE 829 +#define YY_MAX_SHIFTREDUCE 614 +#define YY_ERROR_ACTION 615 +#define YY_ACCEPT_ACTION 616 +#define YY_NO_ACTION 617 +#define YY_MIN_REDUCE 618 +#define YY_MAX_REDUCE 831 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -200,59 +200,59 @@ typedef union { *********** Begin parsing tables **********************************************/ #define YY_ACTTAB_COUNT (530) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 97, 439, 135, 101, 101, 156, 615, 250, 135, 440, - /* 10 */ 135, 159, 812, 43, 45, 21, 37, 38, 811, 158, - /* 20 */ 812, 31, 439, 726, 205, 41, 39, 42, 40, 10, - /* 30 */ 440, 153, 249, 36, 35, 743, 725, 34, 33, 32, - /* 40 */ 43, 45, 736, 37, 38, 166, 132, 167, 31, 723, - /* 50 */ 193, 205, 41, 39, 42, 40, 202, 767, 59, 200, - /* 60 */ 36, 35, 21, 726, 34, 33, 32, 43, 45, 134, + /* 0 */ 97, 439, 135, 101, 101, 156, 616, 250, 135, 440, + /* 10 */ 135, 159, 814, 43, 45, 21, 37, 38, 813, 158, + /* 20 */ 814, 31, 439, 727, 205, 41, 39, 42, 40, 10, + /* 30 */ 440, 153, 249, 36, 35, 745, 726, 34, 33, 32, + /* 40 */ 43, 45, 737, 37, 38, 166, 132, 167, 31, 724, + /* 50 */ 193, 205, 41, 39, 42, 40, 202, 769, 59, 200, + /* 60 */ 36, 35, 21, 727, 34, 33, 32, 43, 45, 134, /* 70 */ 37, 38, 74, 78, 244, 31, 85, 77, 205, 41, - /* 80 */ 39, 42, 40, 80, 740, 220, 498, 36, 35, 439, - /* 90 */ 21, 34, 33, 32, 168, 101, 723, 440, 101, 57, - /* 100 */ 114, 115, 224, 726, 65, 68, 45, 7, 37, 38, + /* 80 */ 39, 42, 40, 80, 742, 220, 498, 36, 35, 439, + /* 90 */ 21, 34, 33, 32, 168, 101, 724, 440, 101, 57, + /* 100 */ 114, 115, 224, 727, 65, 68, 45, 7, 37, 38, /* 110 */ 62, 111, 241, 31, 230, 229, 205, 41, 39, 42, - /* 120 */ 40, 232, 228, 564, 723, 36, 35, 21, 139, 34, + /* 120 */ 40, 232, 228, 565, 724, 36, 35, 21, 139, 34, /* 130 */ 33, 32, 21, 402, 403, 404, 405, 406, 407, 408, - /* 140 */ 409, 410, 411, 412, 413, 808, 37, 38, 243, 766, - /* 150 */ 724, 31, 60, 178, 205, 41, 39, 42, 40, 233, - /* 160 */ 186, 723, 183, 36, 35, 807, 722, 34, 33, 32, - /* 170 */ 653, 171, 806, 124, 17, 219, 242, 218, 217, 216, - /* 180 */ 215, 214, 213, 212, 211, 708, 151, 697, 698, 699, - /* 190 */ 700, 701, 702, 703, 704, 705, 706, 707, 163, 577, - /* 200 */ 11, 133, 568, 133, 571, 76, 574, 662, 163, 577, - /* 210 */ 124, 241, 568, 154, 571, 155, 574, 148, 34, 33, - /* 220 */ 32, 248, 247, 422, 87, 86, 142, 243, 545, 546, - /* 230 */ 160, 161, 147, 522, 204, 172, 18, 152, 227, 226, - /* 240 */ 160, 161, 163, 577, 525, 711, 568, 710, 571, 140, - /* 250 */ 574, 41, 39, 42, 40, 242, 141, 61, 27, 36, - /* 260 */ 35, 73, 72, 34, 33, 32, 514, 654, 28, 511, + /* 140 */ 409, 410, 411, 412, 413, 810, 37, 38, 243, 768, + /* 150 */ 725, 31, 60, 178, 205, 41, 39, 42, 40, 233, + /* 160 */ 186, 724, 183, 36, 35, 809, 723, 34, 33, 32, + /* 170 */ 654, 171, 808, 124, 17, 219, 242, 218, 217, 216, + /* 180 */ 215, 214, 213, 212, 211, 709, 151, 698, 699, 700, + /* 190 */ 701, 702, 703, 704, 705, 706, 707, 708, 163, 578, + /* 200 */ 11, 133, 569, 133, 572, 76, 575, 663, 163, 578, + /* 210 */ 124, 241, 569, 154, 572, 155, 575, 148, 34, 33, + /* 220 */ 32, 248, 247, 422, 87, 86, 142, 243, 546, 547, + /* 230 */ 160, 161, 147, 523, 204, 172, 18, 152, 227, 226, + /* 240 */ 160, 161, 163, 578, 526, 712, 569, 711, 572, 140, + /* 250 */ 575, 41, 39, 42, 40, 242, 141, 61, 27, 36, + /* 260 */ 35, 73, 72, 34, 33, 32, 514, 655, 28, 511, /* 270 */ 124, 512, 143, 513, 160, 161, 192, 36, 35, 188, - /* 280 */ 600, 34, 33, 32, 29, 570, 150, 573, 566, 128, - /* 290 */ 126, 245, 44, 89, 88, 601, 536, 169, 170, 29, - /* 300 */ 47, 576, 44, 162, 537, 594, 578, 144, 15, 14, - /* 310 */ 14, 576, 569, 49, 572, 504, 575, 52, 503, 47, - /* 320 */ 145, 209, 22, 146, 567, 22, 575, 518, 826, 519, - /* 330 */ 50, 516, 53, 517, 84, 83, 44, 9, 8, 717, - /* 340 */ 137, 2, 131, 138, 136, 576, 777, 742, 776, 164, - /* 350 */ 773, 772, 165, 231, 98, 759, 758, 112, 113, 664, - /* 360 */ 575, 110, 189, 210, 129, 515, 25, 223, 91, 225, - /* 370 */ 825, 70, 824, 822, 116, 682, 26, 23, 130, 651, - /* 380 */ 532, 79, 649, 54, 81, 647, 646, 173, 125, 644, - /* 390 */ 643, 642, 640, 633, 127, 637, 191, 635, 737, 194, - /* 400 */ 198, 95, 746, 747, 760, 51, 102, 46, 203, 103, + /* 280 */ 601, 34, 33, 32, 29, 571, 150, 574, 567, 128, + /* 290 */ 126, 245, 44, 89, 88, 602, 537, 169, 170, 29, + /* 300 */ 47, 577, 44, 162, 538, 595, 579, 144, 15, 14, + /* 310 */ 14, 577, 570, 49, 573, 504, 576, 52, 503, 47, + /* 320 */ 145, 209, 22, 146, 568, 22, 576, 518, 828, 519, + /* 330 */ 50, 516, 53, 517, 84, 83, 44, 9, 8, 718, + /* 340 */ 137, 2, 131, 138, 136, 577, 779, 744, 778, 164, + /* 350 */ 775, 774, 165, 231, 98, 761, 760, 112, 113, 665, + /* 360 */ 576, 110, 189, 210, 129, 515, 25, 223, 91, 225, + /* 370 */ 827, 70, 826, 824, 116, 683, 26, 23, 130, 652, + /* 380 */ 533, 79, 650, 54, 81, 648, 647, 173, 125, 645, + /* 390 */ 644, 643, 641, 634, 127, 638, 191, 636, 738, 194, + /* 400 */ 198, 95, 748, 749, 762, 51, 102, 46, 203, 103, /* 410 */ 201, 199, 197, 195, 30, 27, 222, 75, 234, 235, /* 420 */ 207, 55, 236, 240, 238, 237, 239, 63, 66, 149, - /* 430 */ 246, 613, 175, 174, 176, 645, 612, 90, 639, 119, - /* 440 */ 123, 177, 683, 117, 118, 120, 106, 104, 721, 122, + /* 430 */ 246, 614, 175, 174, 176, 646, 613, 90, 640, 119, + /* 440 */ 123, 177, 684, 117, 118, 120, 106, 104, 722, 122, /* 450 */ 92, 121, 108, 105, 107, 109, 1, 24, 180, 179, - /* 460 */ 181, 182, 611, 184, 185, 604, 58, 12, 13, 99, - /* 470 */ 190, 187, 96, 533, 157, 538, 196, 100, 19, 64, - /* 480 */ 479, 579, 3, 20, 4, 16, 206, 6, 208, 478, + /* 460 */ 181, 182, 612, 184, 185, 605, 58, 12, 13, 99, + /* 470 */ 190, 187, 96, 534, 157, 539, 196, 100, 19, 64, + /* 480 */ 479, 580, 3, 20, 4, 16, 206, 6, 208, 478, /* 490 */ 477, 476, 475, 5, 474, 473, 472, 470, 47, 443, /* 500 */ 67, 445, 22, 221, 500, 48, 499, 497, 56, 464, /* 510 */ 462, 454, 460, 69, 456, 71, 458, 452, 450, 471, - /* 520 */ 469, 82, 441, 425, 93, 415, 617, 616, 616, 94, + /* 520 */ 469, 82, 441, 425, 93, 415, 618, 617, 617, 94, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 199, 1, 247, 199, 199, 216, 196, 197, 247, 9, @@ -380,32 +380,32 @@ static const short yy_reduce_ofst[] = { /* 130 */ 255, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 614, 663, 814, 814, 614, 614, 614, 614, 614, 614, - /* 10 */ 744, 630, 614, 614, 814, 614, 614, 614, 614, 614, - /* 20 */ 614, 614, 614, 665, 652, 665, 665, 739, 614, 614, - /* 30 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 40 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 50 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 763, - /* 60 */ 763, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 70 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 650, - /* 80 */ 614, 648, 614, 614, 614, 614, 614, 614, 614, 614, - /* 90 */ 614, 614, 614, 614, 614, 614, 632, 632, 632, 614, - /* 100 */ 614, 632, 770, 774, 768, 756, 764, 755, 751, 750, - /* 110 */ 778, 614, 632, 632, 660, 660, 632, 681, 679, 677, - /* 120 */ 669, 675, 671, 673, 667, 632, 658, 632, 658, 696, - /* 130 */ 709, 614, 818, 819, 779, 813, 769, 797, 796, 809, - /* 140 */ 803, 802, 614, 801, 800, 799, 798, 614, 614, 614, - /* 150 */ 614, 805, 804, 614, 614, 614, 614, 614, 614, 614, - /* 160 */ 614, 614, 614, 781, 775, 771, 614, 614, 614, 614, - /* 170 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 180 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 190 */ 614, 815, 614, 745, 614, 614, 614, 614, 614, 614, - /* 200 */ 765, 614, 757, 614, 614, 614, 614, 614, 614, 718, - /* 210 */ 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, - /* 220 */ 684, 614, 614, 614, 614, 614, 614, 614, 823, 614, - /* 230 */ 614, 614, 712, 821, 614, 614, 614, 614, 614, 614, - /* 240 */ 614, 614, 614, 614, 614, 614, 614, 636, 634, 614, - /* 250 */ 614, + /* 0 */ 615, 664, 816, 816, 615, 615, 615, 615, 615, 615, + /* 10 */ 746, 631, 615, 615, 816, 615, 615, 615, 615, 615, + /* 20 */ 615, 615, 615, 666, 653, 666, 666, 741, 615, 615, + /* 30 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + /* 40 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + /* 50 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 765, + /* 60 */ 765, 739, 615, 615, 615, 615, 615, 615, 615, 615, + /* 70 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 651, + /* 80 */ 615, 649, 615, 615, 615, 615, 615, 615, 615, 615, + /* 90 */ 615, 615, 615, 615, 615, 615, 633, 633, 633, 615, + /* 100 */ 615, 633, 772, 776, 770, 758, 766, 757, 753, 752, + /* 110 */ 780, 615, 633, 633, 661, 661, 633, 682, 680, 678, + /* 120 */ 670, 676, 672, 674, 668, 633, 659, 633, 659, 697, + /* 130 */ 710, 615, 820, 821, 781, 815, 771, 799, 798, 811, + /* 140 */ 805, 804, 615, 803, 802, 801, 800, 615, 615, 615, + /* 150 */ 615, 807, 806, 615, 615, 615, 615, 615, 615, 615, + /* 160 */ 615, 615, 615, 783, 777, 773, 615, 615, 615, 615, + /* 170 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + /* 180 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + /* 190 */ 615, 817, 615, 747, 615, 615, 615, 615, 615, 615, + /* 200 */ 767, 615, 759, 615, 615, 615, 615, 615, 615, 719, + /* 210 */ 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + /* 220 */ 685, 615, 615, 615, 615, 615, 615, 615, 825, 615, + /* 230 */ 615, 615, 713, 823, 615, 615, 615, 615, 615, 615, + /* 240 */ 615, 615, 615, 615, 615, 615, 615, 637, 635, 615, + /* 250 */ 615, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1094,98 +1094,99 @@ static const char *const yyRuleName[] = { /* 118 */ "tagitem ::= PLUS FLOAT", /* 119 */ "cmd ::= select", /* 120 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", - /* 121 */ "sclp ::= selcollist COMMA", - /* 122 */ "sclp ::=", - /* 123 */ "selcollist ::= sclp expr as", - /* 124 */ "selcollist ::= sclp STAR", - /* 125 */ "as ::= AS ids", - /* 126 */ "as ::= ids", - /* 127 */ "as ::=", - /* 128 */ "from ::= FROM tablelist", - /* 129 */ "tablelist ::= ids cpxName", - /* 130 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 131 */ "tmvar ::= VARIABLE", - /* 132 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 133 */ "interval_opt ::=", - /* 134 */ "fill_opt ::=", - /* 135 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 136 */ "fill_opt ::= FILL LP ID RP", - /* 137 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 138 */ "sliding_opt ::=", - /* 139 */ "orderby_opt ::=", - /* 140 */ "orderby_opt ::= ORDER BY sortlist", - /* 141 */ "sortlist ::= sortlist COMMA item sortorder", - /* 142 */ "sortlist ::= item sortorder", - /* 143 */ "item ::= ids cpxName", - /* 144 */ "sortorder ::= ASC", - /* 145 */ "sortorder ::= DESC", - /* 146 */ "sortorder ::=", - /* 147 */ "groupby_opt ::=", - /* 148 */ "groupby_opt ::= GROUP BY grouplist", - /* 149 */ "grouplist ::= grouplist COMMA item", - /* 150 */ "grouplist ::= item", - /* 151 */ "having_opt ::=", - /* 152 */ "having_opt ::= HAVING expr", - /* 153 */ "limit_opt ::=", - /* 154 */ "limit_opt ::= LIMIT signed", - /* 155 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 156 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 157 */ "slimit_opt ::=", - /* 158 */ "slimit_opt ::= SLIMIT signed", - /* 159 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 160 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 161 */ "where_opt ::=", - /* 162 */ "where_opt ::= WHERE expr", - /* 163 */ "expr ::= LP expr RP", - /* 164 */ "expr ::= ID", - /* 165 */ "expr ::= ID DOT ID", - /* 166 */ "expr ::= ID DOT STAR", - /* 167 */ "expr ::= INTEGER", - /* 168 */ "expr ::= MINUS INTEGER", - /* 169 */ "expr ::= PLUS INTEGER", - /* 170 */ "expr ::= FLOAT", - /* 171 */ "expr ::= MINUS FLOAT", - /* 172 */ "expr ::= PLUS FLOAT", - /* 173 */ "expr ::= STRING", - /* 174 */ "expr ::= NOW", - /* 175 */ "expr ::= VARIABLE", - /* 176 */ "expr ::= BOOL", - /* 177 */ "expr ::= ID LP exprlist RP", - /* 178 */ "expr ::= ID LP STAR RP", - /* 179 */ "expr ::= expr AND expr", - /* 180 */ "expr ::= expr OR expr", - /* 181 */ "expr ::= expr LT expr", - /* 182 */ "expr ::= expr GT expr", - /* 183 */ "expr ::= expr LE expr", - /* 184 */ "expr ::= expr GE expr", - /* 185 */ "expr ::= expr NE expr", - /* 186 */ "expr ::= expr EQ expr", - /* 187 */ "expr ::= expr PLUS expr", - /* 188 */ "expr ::= expr MINUS expr", - /* 189 */ "expr ::= expr STAR expr", - /* 190 */ "expr ::= expr SLASH expr", - /* 191 */ "expr ::= expr REM expr", - /* 192 */ "expr ::= expr LIKE expr", - /* 193 */ "expr ::= expr IN LP exprlist RP", - /* 194 */ "exprlist ::= exprlist COMMA expritem", - /* 195 */ "exprlist ::= expritem", - /* 196 */ "expritem ::= expr", - /* 197 */ "expritem ::=", - /* 198 */ "cmd ::= INSERT INTO cpxName insert_value_list", - /* 199 */ "insert_value_list ::= VALUES LP itemlist RP", - /* 200 */ "insert_value_list ::= insert_value_list VALUES LP itemlist RP", - /* 201 */ "itemlist ::= itemlist COMMA expr", - /* 202 */ "itemlist ::= expr", - /* 203 */ "cmd ::= RESET QUERY CACHE", - /* 204 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 205 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 206 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 207 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 208 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 209 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 210 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", - /* 211 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", - /* 212 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", + /* 121 */ "select ::= SELECT selcollist", + /* 122 */ "sclp ::= selcollist COMMA", + /* 123 */ "sclp ::=", + /* 124 */ "selcollist ::= sclp expr as", + /* 125 */ "selcollist ::= sclp STAR", + /* 126 */ "as ::= AS ids", + /* 127 */ "as ::= ids", + /* 128 */ "as ::=", + /* 129 */ "from ::= FROM tablelist", + /* 130 */ "tablelist ::= ids cpxName", + /* 131 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 132 */ "tmvar ::= VARIABLE", + /* 133 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 134 */ "interval_opt ::=", + /* 135 */ "fill_opt ::=", + /* 136 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 137 */ "fill_opt ::= FILL LP ID RP", + /* 138 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 139 */ "sliding_opt ::=", + /* 140 */ "orderby_opt ::=", + /* 141 */ "orderby_opt ::= ORDER BY sortlist", + /* 142 */ "sortlist ::= sortlist COMMA item sortorder", + /* 143 */ "sortlist ::= item sortorder", + /* 144 */ "item ::= ids cpxName", + /* 145 */ "sortorder ::= ASC", + /* 146 */ "sortorder ::= DESC", + /* 147 */ "sortorder ::=", + /* 148 */ "groupby_opt ::=", + /* 149 */ "groupby_opt ::= GROUP BY grouplist", + /* 150 */ "grouplist ::= grouplist COMMA item", + /* 151 */ "grouplist ::= item", + /* 152 */ "having_opt ::=", + /* 153 */ "having_opt ::= HAVING expr", + /* 154 */ "limit_opt ::=", + /* 155 */ "limit_opt ::= LIMIT signed", + /* 156 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 157 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 158 */ "slimit_opt ::=", + /* 159 */ "slimit_opt ::= SLIMIT signed", + /* 160 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 161 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 162 */ "where_opt ::=", + /* 163 */ "where_opt ::= WHERE expr", + /* 164 */ "expr ::= LP expr RP", + /* 165 */ "expr ::= ID", + /* 166 */ "expr ::= ID DOT ID", + /* 167 */ "expr ::= ID DOT STAR", + /* 168 */ "expr ::= INTEGER", + /* 169 */ "expr ::= MINUS INTEGER", + /* 170 */ "expr ::= PLUS INTEGER", + /* 171 */ "expr ::= FLOAT", + /* 172 */ "expr ::= MINUS FLOAT", + /* 173 */ "expr ::= PLUS FLOAT", + /* 174 */ "expr ::= STRING", + /* 175 */ "expr ::= NOW", + /* 176 */ "expr ::= VARIABLE", + /* 177 */ "expr ::= BOOL", + /* 178 */ "expr ::= ID LP exprlist RP", + /* 179 */ "expr ::= ID LP STAR RP", + /* 180 */ "expr ::= expr AND expr", + /* 181 */ "expr ::= expr OR expr", + /* 182 */ "expr ::= expr LT expr", + /* 183 */ "expr ::= expr GT expr", + /* 184 */ "expr ::= expr LE expr", + /* 185 */ "expr ::= expr GE expr", + /* 186 */ "expr ::= expr NE expr", + /* 187 */ "expr ::= expr EQ expr", + /* 188 */ "expr ::= expr PLUS expr", + /* 189 */ "expr ::= expr MINUS expr", + /* 190 */ "expr ::= expr STAR expr", + /* 191 */ "expr ::= expr SLASH expr", + /* 192 */ "expr ::= expr REM expr", + /* 193 */ "expr ::= expr LIKE expr", + /* 194 */ "expr ::= expr IN LP exprlist RP", + /* 195 */ "exprlist ::= exprlist COMMA expritem", + /* 196 */ "exprlist ::= expritem", + /* 197 */ "expritem ::= expr", + /* 198 */ "expritem ::=", + /* 199 */ "cmd ::= INSERT INTO cpxName insert_value_list", + /* 200 */ "insert_value_list ::= VALUES LP itemlist RP", + /* 201 */ "insert_value_list ::= insert_value_list VALUES LP itemlist RP", + /* 202 */ "itemlist ::= itemlist COMMA expr", + /* 203 */ "itemlist ::= expr", + /* 204 */ "cmd ::= RESET QUERY CACHE", + /* 205 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 206 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 207 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 208 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 209 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 210 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 211 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", + /* 212 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", + /* 213 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1760,98 +1761,99 @@ static const struct { { 234, -2 }, /* (118) tagitem ::= PLUS FLOAT */ { 197, -1 }, /* (119) cmd ::= select */ { 232, -12 }, /* (120) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ - { 246, -2 }, /* (121) sclp ::= selcollist COMMA */ - { 246, 0 }, /* (122) sclp ::= */ - { 235, -3 }, /* (123) selcollist ::= sclp expr as */ - { 235, -2 }, /* (124) selcollist ::= sclp STAR */ - { 248, -2 }, /* (125) as ::= AS ids */ - { 248, -1 }, /* (126) as ::= ids */ - { 248, 0 }, /* (127) as ::= */ - { 236, -2 }, /* (128) from ::= FROM tablelist */ - { 249, -2 }, /* (129) tablelist ::= ids cpxName */ - { 249, -4 }, /* (130) tablelist ::= tablelist COMMA ids cpxName */ - { 250, -1 }, /* (131) tmvar ::= VARIABLE */ - { 238, -4 }, /* (132) interval_opt ::= INTERVAL LP tmvar RP */ - { 238, 0 }, /* (133) interval_opt ::= */ - { 239, 0 }, /* (134) fill_opt ::= */ - { 239, -6 }, /* (135) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 239, -4 }, /* (136) fill_opt ::= FILL LP ID RP */ - { 240, -4 }, /* (137) sliding_opt ::= SLIDING LP tmvar RP */ - { 240, 0 }, /* (138) sliding_opt ::= */ - { 242, 0 }, /* (139) orderby_opt ::= */ - { 242, -3 }, /* (140) orderby_opt ::= ORDER BY sortlist */ - { 251, -4 }, /* (141) sortlist ::= sortlist COMMA item sortorder */ - { 251, -2 }, /* (142) sortlist ::= item sortorder */ - { 253, -2 }, /* (143) item ::= ids cpxName */ - { 254, -1 }, /* (144) sortorder ::= ASC */ - { 254, -1 }, /* (145) sortorder ::= DESC */ - { 254, 0 }, /* (146) sortorder ::= */ - { 241, 0 }, /* (147) groupby_opt ::= */ - { 241, -3 }, /* (148) groupby_opt ::= GROUP BY grouplist */ - { 255, -3 }, /* (149) grouplist ::= grouplist COMMA item */ - { 255, -1 }, /* (150) grouplist ::= item */ - { 243, 0 }, /* (151) having_opt ::= */ - { 243, -2 }, /* (152) having_opt ::= HAVING expr */ - { 245, 0 }, /* (153) limit_opt ::= */ - { 245, -2 }, /* (154) limit_opt ::= LIMIT signed */ - { 245, -4 }, /* (155) limit_opt ::= LIMIT signed OFFSET signed */ - { 245, -4 }, /* (156) limit_opt ::= LIMIT signed COMMA signed */ - { 244, 0 }, /* (157) slimit_opt ::= */ - { 244, -2 }, /* (158) slimit_opt ::= SLIMIT signed */ - { 244, -4 }, /* (159) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 244, -4 }, /* (160) slimit_opt ::= SLIMIT signed COMMA signed */ - { 237, 0 }, /* (161) where_opt ::= */ - { 237, -2 }, /* (162) where_opt ::= WHERE expr */ - { 247, -3 }, /* (163) expr ::= LP expr RP */ - { 247, -1 }, /* (164) expr ::= ID */ - { 247, -3 }, /* (165) expr ::= ID DOT ID */ - { 247, -3 }, /* (166) expr ::= ID DOT STAR */ - { 247, -1 }, /* (167) expr ::= INTEGER */ - { 247, -2 }, /* (168) expr ::= MINUS INTEGER */ - { 247, -2 }, /* (169) expr ::= PLUS INTEGER */ - { 247, -1 }, /* (170) expr ::= FLOAT */ - { 247, -2 }, /* (171) expr ::= MINUS FLOAT */ - { 247, -2 }, /* (172) expr ::= PLUS FLOAT */ - { 247, -1 }, /* (173) expr ::= STRING */ - { 247, -1 }, /* (174) expr ::= NOW */ - { 247, -1 }, /* (175) expr ::= VARIABLE */ - { 247, -1 }, /* (176) expr ::= BOOL */ - { 247, -4 }, /* (177) expr ::= ID LP exprlist RP */ - { 247, -4 }, /* (178) expr ::= ID LP STAR RP */ - { 247, -3 }, /* (179) expr ::= expr AND expr */ - { 247, -3 }, /* (180) expr ::= expr OR expr */ - { 247, -3 }, /* (181) expr ::= expr LT expr */ - { 247, -3 }, /* (182) expr ::= expr GT expr */ - { 247, -3 }, /* (183) expr ::= expr LE expr */ - { 247, -3 }, /* (184) expr ::= expr GE expr */ - { 247, -3 }, /* (185) expr ::= expr NE expr */ - { 247, -3 }, /* (186) expr ::= expr EQ expr */ - { 247, -3 }, /* (187) expr ::= expr PLUS expr */ - { 247, -3 }, /* (188) expr ::= expr MINUS expr */ - { 247, -3 }, /* (189) expr ::= expr STAR expr */ - { 247, -3 }, /* (190) expr ::= expr SLASH expr */ - { 247, -3 }, /* (191) expr ::= expr REM expr */ - { 247, -3 }, /* (192) expr ::= expr LIKE expr */ - { 247, -5 }, /* (193) expr ::= expr IN LP exprlist RP */ - { 256, -3 }, /* (194) exprlist ::= exprlist COMMA expritem */ - { 256, -1 }, /* (195) exprlist ::= expritem */ - { 257, -1 }, /* (196) expritem ::= expr */ - { 257, 0 }, /* (197) expritem ::= */ - { 197, -4 }, /* (198) cmd ::= INSERT INTO cpxName insert_value_list */ - { 258, -4 }, /* (199) insert_value_list ::= VALUES LP itemlist RP */ - { 258, -5 }, /* (200) insert_value_list ::= insert_value_list VALUES LP itemlist RP */ - { 259, -3 }, /* (201) itemlist ::= itemlist COMMA expr */ - { 259, -1 }, /* (202) itemlist ::= expr */ - { 197, -3 }, /* (203) cmd ::= RESET QUERY CACHE */ - { 197, -7 }, /* (204) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 197, -7 }, /* (205) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 197, -7 }, /* (206) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 197, -7 }, /* (207) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 197, -8 }, /* (208) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 197, -9 }, /* (209) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 197, -5 }, /* (210) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ - { 197, -7 }, /* (211) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ - { 197, -7 }, /* (212) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ + { 232, -2 }, /* (121) select ::= SELECT selcollist */ + { 246, -2 }, /* (122) sclp ::= selcollist COMMA */ + { 246, 0 }, /* (123) sclp ::= */ + { 235, -3 }, /* (124) selcollist ::= sclp expr as */ + { 235, -2 }, /* (125) selcollist ::= sclp STAR */ + { 248, -2 }, /* (126) as ::= AS ids */ + { 248, -1 }, /* (127) as ::= ids */ + { 248, 0 }, /* (128) as ::= */ + { 236, -2 }, /* (129) from ::= FROM tablelist */ + { 249, -2 }, /* (130) tablelist ::= ids cpxName */ + { 249, -4 }, /* (131) tablelist ::= tablelist COMMA ids cpxName */ + { 250, -1 }, /* (132) tmvar ::= VARIABLE */ + { 238, -4 }, /* (133) interval_opt ::= INTERVAL LP tmvar RP */ + { 238, 0 }, /* (134) interval_opt ::= */ + { 239, 0 }, /* (135) fill_opt ::= */ + { 239, -6 }, /* (136) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 239, -4 }, /* (137) fill_opt ::= FILL LP ID RP */ + { 240, -4 }, /* (138) sliding_opt ::= SLIDING LP tmvar RP */ + { 240, 0 }, /* (139) sliding_opt ::= */ + { 242, 0 }, /* (140) orderby_opt ::= */ + { 242, -3 }, /* (141) orderby_opt ::= ORDER BY sortlist */ + { 251, -4 }, /* (142) sortlist ::= sortlist COMMA item sortorder */ + { 251, -2 }, /* (143) sortlist ::= item sortorder */ + { 253, -2 }, /* (144) item ::= ids cpxName */ + { 254, -1 }, /* (145) sortorder ::= ASC */ + { 254, -1 }, /* (146) sortorder ::= DESC */ + { 254, 0 }, /* (147) sortorder ::= */ + { 241, 0 }, /* (148) groupby_opt ::= */ + { 241, -3 }, /* (149) groupby_opt ::= GROUP BY grouplist */ + { 255, -3 }, /* (150) grouplist ::= grouplist COMMA item */ + { 255, -1 }, /* (151) grouplist ::= item */ + { 243, 0 }, /* (152) having_opt ::= */ + { 243, -2 }, /* (153) having_opt ::= HAVING expr */ + { 245, 0 }, /* (154) limit_opt ::= */ + { 245, -2 }, /* (155) limit_opt ::= LIMIT signed */ + { 245, -4 }, /* (156) limit_opt ::= LIMIT signed OFFSET signed */ + { 245, -4 }, /* (157) limit_opt ::= LIMIT signed COMMA signed */ + { 244, 0 }, /* (158) slimit_opt ::= */ + { 244, -2 }, /* (159) slimit_opt ::= SLIMIT signed */ + { 244, -4 }, /* (160) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 244, -4 }, /* (161) slimit_opt ::= SLIMIT signed COMMA signed */ + { 237, 0 }, /* (162) where_opt ::= */ + { 237, -2 }, /* (163) where_opt ::= WHERE expr */ + { 247, -3 }, /* (164) expr ::= LP expr RP */ + { 247, -1 }, /* (165) expr ::= ID */ + { 247, -3 }, /* (166) expr ::= ID DOT ID */ + { 247, -3 }, /* (167) expr ::= ID DOT STAR */ + { 247, -1 }, /* (168) expr ::= INTEGER */ + { 247, -2 }, /* (169) expr ::= MINUS INTEGER */ + { 247, -2 }, /* (170) expr ::= PLUS INTEGER */ + { 247, -1 }, /* (171) expr ::= FLOAT */ + { 247, -2 }, /* (172) expr ::= MINUS FLOAT */ + { 247, -2 }, /* (173) expr ::= PLUS FLOAT */ + { 247, -1 }, /* (174) expr ::= STRING */ + { 247, -1 }, /* (175) expr ::= NOW */ + { 247, -1 }, /* (176) expr ::= VARIABLE */ + { 247, -1 }, /* (177) expr ::= BOOL */ + { 247, -4 }, /* (178) expr ::= ID LP exprlist RP */ + { 247, -4 }, /* (179) expr ::= ID LP STAR RP */ + { 247, -3 }, /* (180) expr ::= expr AND expr */ + { 247, -3 }, /* (181) expr ::= expr OR expr */ + { 247, -3 }, /* (182) expr ::= expr LT expr */ + { 247, -3 }, /* (183) expr ::= expr GT expr */ + { 247, -3 }, /* (184) expr ::= expr LE expr */ + { 247, -3 }, /* (185) expr ::= expr GE expr */ + { 247, -3 }, /* (186) expr ::= expr NE expr */ + { 247, -3 }, /* (187) expr ::= expr EQ expr */ + { 247, -3 }, /* (188) expr ::= expr PLUS expr */ + { 247, -3 }, /* (189) expr ::= expr MINUS expr */ + { 247, -3 }, /* (190) expr ::= expr STAR expr */ + { 247, -3 }, /* (191) expr ::= expr SLASH expr */ + { 247, -3 }, /* (192) expr ::= expr REM expr */ + { 247, -3 }, /* (193) expr ::= expr LIKE expr */ + { 247, -5 }, /* (194) expr ::= expr IN LP exprlist RP */ + { 256, -3 }, /* (195) exprlist ::= exprlist COMMA expritem */ + { 256, -1 }, /* (196) exprlist ::= expritem */ + { 257, -1 }, /* (197) expritem ::= expr */ + { 257, 0 }, /* (198) expritem ::= */ + { 197, -4 }, /* (199) cmd ::= INSERT INTO cpxName insert_value_list */ + { 258, -4 }, /* (200) insert_value_list ::= VALUES LP itemlist RP */ + { 258, -5 }, /* (201) insert_value_list ::= insert_value_list VALUES LP itemlist RP */ + { 259, -3 }, /* (202) itemlist ::= itemlist COMMA expr */ + { 259, -1 }, /* (203) itemlist ::= expr */ + { 197, -3 }, /* (204) cmd ::= RESET QUERY CACHE */ + { 197, -7 }, /* (205) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 197, -7 }, /* (206) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 197, -7 }, /* (207) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 197, -7 }, /* (208) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 197, -8 }, /* (209) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 197, -9 }, /* (210) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 197, -5 }, /* (211) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ + { 197, -7 }, /* (212) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ + { 197, -7 }, /* (213) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2101,8 +2103,6 @@ static void yy_reduce( case 60: /* users ::= */ yytestcase(yyruleno==60); case 62: /* conns ::= */ yytestcase(yyruleno==62); case 64: /* state ::= */ yytestcase(yyruleno==64); - case 133: /* interval_opt ::= */ yytestcase(yyruleno==133); - case 138: /* sliding_opt ::= */ yytestcase(yyruleno==138); {yymsp[1].minor.yy0.n = 0; } break; case 49: /* pps ::= PPS INTEGER */ @@ -2307,59 +2307,69 @@ static void yy_reduce( } yymsp[-11].minor.yy24 = yylhsminor.yy24; break; - case 121: /* sclp ::= selcollist COMMA */ + case 121: /* select ::= SELECT selcollist */ +{ + yylhsminor.yy24 = tSetQuerySQLElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy498, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +} + yymsp[-1].minor.yy24 = yylhsminor.yy24; + break; + case 122: /* sclp ::= selcollist COMMA */ {yylhsminor.yy498 = yymsp[-1].minor.yy498;} yymsp[-1].minor.yy498 = yylhsminor.yy498; break; - case 122: /* sclp ::= */ + case 123: /* sclp ::= */ {yymsp[1].minor.yy498 = 0;} break; - case 123: /* selcollist ::= sclp expr as */ + case 124: /* selcollist ::= sclp expr as */ { yylhsminor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498, yymsp[-1].minor.yy90, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } yymsp[-2].minor.yy498 = yylhsminor.yy498; break; - case 124: /* selcollist ::= sclp STAR */ + case 125: /* selcollist ::= sclp STAR */ { tSQLExpr *pNode = tSQLExprIdValueCreate(NULL, TK_ALL); yylhsminor.yy498 = tSQLExprListAppend(yymsp[-1].minor.yy498, pNode, 0); } yymsp[-1].minor.yy498 = yylhsminor.yy498; break; - case 125: /* as ::= AS ids */ + case 126: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 126: /* as ::= ids */ + case 127: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 127: /* as ::= */ + case 128: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 128: /* from ::= FROM tablelist */ + case 129: /* from ::= FROM tablelist */ {yymsp[-1].minor.yy56 = yymsp[0].minor.yy56;} break; - case 129: /* tablelist ::= ids cpxName */ + case 130: /* tablelist ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} yymsp[-1].minor.yy56 = yylhsminor.yy56; break; - case 130: /* tablelist ::= tablelist COMMA ids cpxName */ + case 131: /* tablelist ::= tablelist COMMA ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy56 = tVariantListAppendToken(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy0, -1); } yymsp[-3].minor.yy56 = yylhsminor.yy56; break; - case 131: /* tmvar ::= VARIABLE */ + case 132: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 132: /* interval_opt ::= INTERVAL LP tmvar RP */ - case 137: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==137); + case 133: /* interval_opt ::= INTERVAL LP tmvar RP */ + case 138: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==138); {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 134: /* fill_opt ::= */ + case 134: /* interval_opt ::= */ + case 139: /* sliding_opt ::= */ yytestcase(yyruleno==139); +{yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } + break; + case 135: /* fill_opt ::= */ {yymsp[1].minor.yy56 = 0; } break; - case 135: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 136: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); @@ -2369,33 +2379,33 @@ static void yy_reduce( yymsp[-5].minor.yy56 = yymsp[-1].minor.yy56; } break; - case 136: /* fill_opt ::= FILL LP ID RP */ + case 137: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-3].minor.yy56 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 139: /* orderby_opt ::= */ - case 147: /* groupby_opt ::= */ yytestcase(yyruleno==147); + case 140: /* orderby_opt ::= */ + case 148: /* groupby_opt ::= */ yytestcase(yyruleno==148); {yymsp[1].minor.yy56 = 0;} break; - case 140: /* orderby_opt ::= ORDER BY sortlist */ - case 148: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==148); + case 141: /* orderby_opt ::= ORDER BY sortlist */ + case 149: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==149); {yymsp[-2].minor.yy56 = yymsp[0].minor.yy56;} break; - case 141: /* sortlist ::= sortlist COMMA item sortorder */ + case 142: /* sortlist ::= sortlist COMMA item sortorder */ { yylhsminor.yy56 = tVariantListAppend(yymsp[-3].minor.yy56, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); } yymsp[-3].minor.yy56 = yylhsminor.yy56; break; - case 142: /* sortlist ::= item sortorder */ + case 143: /* sortlist ::= item sortorder */ { yylhsminor.yy56 = tVariantListAppend(NULL, &yymsp[-1].minor.yy186, yymsp[0].minor.yy332); } yymsp[-1].minor.yy56 = yylhsminor.yy56; break; - case 143: /* item ::= ids cpxName */ + case 144: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2404,210 +2414,210 @@ static void yy_reduce( } yymsp[-1].minor.yy186 = yylhsminor.yy186; break; - case 144: /* sortorder ::= ASC */ + case 145: /* sortorder ::= ASC */ {yymsp[0].minor.yy332 = TSQL_SO_ASC; } break; - case 145: /* sortorder ::= DESC */ + case 146: /* sortorder ::= DESC */ {yymsp[0].minor.yy332 = TSQL_SO_DESC;} break; - case 146: /* sortorder ::= */ + case 147: /* sortorder ::= */ {yymsp[1].minor.yy332 = TSQL_SO_ASC;} break; - case 149: /* grouplist ::= grouplist COMMA item */ + case 150: /* grouplist ::= grouplist COMMA item */ { yylhsminor.yy56 = tVariantListAppend(yymsp[-2].minor.yy56, &yymsp[0].minor.yy186, -1); } yymsp[-2].minor.yy56 = yylhsminor.yy56; break; - case 150: /* grouplist ::= item */ + case 151: /* grouplist ::= item */ { yylhsminor.yy56 = tVariantListAppend(NULL, &yymsp[0].minor.yy186, -1); } yymsp[0].minor.yy56 = yylhsminor.yy56; break; - case 151: /* having_opt ::= */ - case 161: /* where_opt ::= */ yytestcase(yyruleno==161); - case 197: /* expritem ::= */ yytestcase(yyruleno==197); + case 152: /* having_opt ::= */ + case 162: /* where_opt ::= */ yytestcase(yyruleno==162); + case 198: /* expritem ::= */ yytestcase(yyruleno==198); {yymsp[1].minor.yy90 = 0;} break; - case 152: /* having_opt ::= HAVING expr */ - case 162: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==162); + case 153: /* having_opt ::= HAVING expr */ + case 163: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==163); {yymsp[-1].minor.yy90 = yymsp[0].minor.yy90;} break; - case 153: /* limit_opt ::= */ - case 157: /* slimit_opt ::= */ yytestcase(yyruleno==157); + case 154: /* limit_opt ::= */ + case 158: /* slimit_opt ::= */ yytestcase(yyruleno==158); {yymsp[1].minor.yy294.limit = -1; yymsp[1].minor.yy294.offset = 0;} break; - case 154: /* limit_opt ::= LIMIT signed */ - case 158: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==158); + case 155: /* limit_opt ::= LIMIT signed */ + case 159: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==159); {yymsp[-1].minor.yy294.limit = yymsp[0].minor.yy389; yymsp[-1].minor.yy294.offset = 0;} break; - case 155: /* limit_opt ::= LIMIT signed OFFSET signed */ - case 159: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==159); + case 156: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 160: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==160); {yymsp[-3].minor.yy294.limit = yymsp[-2].minor.yy389; yymsp[-3].minor.yy294.offset = yymsp[0].minor.yy389;} break; - case 156: /* limit_opt ::= LIMIT signed COMMA signed */ - case 160: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==160); + case 157: /* limit_opt ::= LIMIT signed COMMA signed */ + case 161: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==161); {yymsp[-3].minor.yy294.limit = yymsp[0].minor.yy389; yymsp[-3].minor.yy294.offset = yymsp[-2].minor.yy389;} break; - case 163: /* expr ::= LP expr RP */ + case 164: /* expr ::= LP expr RP */ {yymsp[-2].minor.yy90 = yymsp[-1].minor.yy90; } break; - case 164: /* expr ::= ID */ + case 165: /* expr ::= ID */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 165: /* expr ::= ID DOT ID */ + case 166: /* expr ::= ID DOT ID */ {yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 166: /* expr ::= ID DOT STAR */ + case 167: /* expr ::= ID DOT STAR */ {yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 167: /* expr ::= INTEGER */ + case 168: /* expr ::= INTEGER */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 168: /* expr ::= MINUS INTEGER */ - case 169: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==169); + case 169: /* expr ::= MINUS INTEGER */ + case 170: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==170); {yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} yymsp[-1].minor.yy90 = yylhsminor.yy90; break; - case 170: /* expr ::= FLOAT */ + case 171: /* expr ::= FLOAT */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 171: /* expr ::= MINUS FLOAT */ - case 172: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==172); + case 172: /* expr ::= MINUS FLOAT */ + case 173: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==173); {yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} yymsp[-1].minor.yy90 = yylhsminor.yy90; break; - case 173: /* expr ::= STRING */ + case 174: /* expr ::= STRING */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 174: /* expr ::= NOW */ + case 175: /* expr ::= NOW */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 175: /* expr ::= VARIABLE */ + case 176: /* expr ::= VARIABLE */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 176: /* expr ::= BOOL */ + case 177: /* expr ::= BOOL */ {yylhsminor.yy90 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 177: /* expr ::= ID LP exprlist RP */ + case 178: /* expr ::= ID LP exprlist RP */ { yylhsminor.yy90 = tSQLExprCreateFunction(yymsp[-1].minor.yy498, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy90 = yylhsminor.yy90; break; - case 178: /* expr ::= ID LP STAR RP */ + case 179: /* expr ::= ID LP STAR RP */ { yylhsminor.yy90 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy90 = yylhsminor.yy90; break; - case 179: /* expr ::= expr AND expr */ + case 180: /* expr ::= expr AND expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_AND);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 180: /* expr ::= expr OR expr */ + case 181: /* expr ::= expr OR expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_OR); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 181: /* expr ::= expr LT expr */ + case 182: /* expr ::= expr LT expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LT);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 182: /* expr ::= expr GT expr */ + case 183: /* expr ::= expr GT expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GT);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 183: /* expr ::= expr LE expr */ + case 184: /* expr ::= expr LE expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LE);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 184: /* expr ::= expr GE expr */ + case 185: /* expr ::= expr GE expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_GE);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 185: /* expr ::= expr NE expr */ + case 186: /* expr ::= expr NE expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_NE);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 186: /* expr ::= expr EQ expr */ + case 187: /* expr ::= expr EQ expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_EQ);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 187: /* expr ::= expr PLUS expr */ + case 188: /* expr ::= expr PLUS expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_PLUS); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 188: /* expr ::= expr MINUS expr */ + case 189: /* expr ::= expr MINUS expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_MINUS); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 189: /* expr ::= expr STAR expr */ + case 190: /* expr ::= expr STAR expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_STAR); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 190: /* expr ::= expr SLASH expr */ + case 191: /* expr ::= expr SLASH expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_DIVIDE);} yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 191: /* expr ::= expr REM expr */ + case 192: /* expr ::= expr REM expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_REM); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 192: /* expr ::= expr LIKE expr */ + case 193: /* expr ::= expr LIKE expr */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-2].minor.yy90, yymsp[0].minor.yy90, TK_LIKE); } yymsp[-2].minor.yy90 = yylhsminor.yy90; break; - case 193: /* expr ::= expr IN LP exprlist RP */ + case 194: /* expr ::= expr IN LP exprlist RP */ {yylhsminor.yy90 = tSQLExprCreate(yymsp[-4].minor.yy90, (tSQLExpr*)yymsp[-1].minor.yy498, TK_IN); } yymsp[-4].minor.yy90 = yylhsminor.yy90; break; - case 194: /* exprlist ::= exprlist COMMA expritem */ - case 201: /* itemlist ::= itemlist COMMA expr */ yytestcase(yyruleno==201); + case 195: /* exprlist ::= exprlist COMMA expritem */ + case 202: /* itemlist ::= itemlist COMMA expr */ yytestcase(yyruleno==202); {yylhsminor.yy498 = tSQLExprListAppend(yymsp[-2].minor.yy498,yymsp[0].minor.yy90,0);} yymsp[-2].minor.yy498 = yylhsminor.yy498; break; - case 195: /* exprlist ::= expritem */ - case 202: /* itemlist ::= expr */ yytestcase(yyruleno==202); + case 196: /* exprlist ::= expritem */ + case 203: /* itemlist ::= expr */ yytestcase(yyruleno==203); {yylhsminor.yy498 = tSQLExprListAppend(0,yymsp[0].minor.yy90,0);} yymsp[0].minor.yy498 = yylhsminor.yy498; break; - case 196: /* expritem ::= expr */ + case 197: /* expritem ::= expr */ {yylhsminor.yy90 = yymsp[0].minor.yy90;} yymsp[0].minor.yy90 = yylhsminor.yy90; break; - case 198: /* cmd ::= INSERT INTO cpxName insert_value_list */ + case 199: /* cmd ::= INSERT INTO cpxName insert_value_list */ { tSetInsertSQLElems(pInfo, &yymsp[-1].minor.yy0, yymsp[0].minor.yy74); } break; - case 199: /* insert_value_list ::= VALUES LP itemlist RP */ + case 200: /* insert_value_list ::= VALUES LP itemlist RP */ {yymsp[-3].minor.yy74 = tSQLListListAppend(NULL, yymsp[-1].minor.yy498);} break; - case 200: /* insert_value_list ::= insert_value_list VALUES LP itemlist RP */ + case 201: /* insert_value_list ::= insert_value_list VALUES LP itemlist RP */ {yylhsminor.yy74 = tSQLListListAppend(yymsp[-4].minor.yy74, yymsp[-1].minor.yy498);} yymsp[-4].minor.yy74 = yylhsminor.yy74; break; - case 203: /* cmd ::= RESET QUERY CACHE */ + case 204: /* cmd ::= RESET QUERY CACHE */ { setDCLSQLElems(pInfo, RESET_QUERY_CACHE, 0);} break; - case 204: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 205: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy471, NULL, ALTER_TABLE_ADD_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_ADD_COLUMN); } break; - case 205: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 206: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2618,14 +2628,14 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_DROP_COLUMN); } break; - case 206: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 207: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy471, NULL, ALTER_TABLE_TAGS_ADD); setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_ADD); } break; - case 207: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 208: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2636,7 +2646,7 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_DROP); } break; - case 208: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 209: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -2650,7 +2660,7 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_CHG); } break; - case 209: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 210: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -2662,13 +2672,13 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, ALTER_TABLE_TAGS_SET); } break; - case 210: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ + case 211: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_CONNECTION, 1, &yymsp[-2].minor.yy0);} break; - case 211: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ + case 212: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ {yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_STREAM, 1, &yymsp[-4].minor.yy0);} break; - case 212: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ + case 213: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ {yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setDCLSQLElems(pInfo, KILL_QUERY, 1, &yymsp[-4].minor.yy0);} break; default: From a423258f04288a65573c43848cfacfd50ccd55c4 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 21 Nov 2019 16:49:25 +0800 Subject: [PATCH 10/42] [tbase-1211] --- src/system/detail/src/vnodeImport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/detail/src/vnodeImport.c b/src/system/detail/src/vnodeImport.c index 0d3cd2b338..b2b937b066 100644 --- a/src/system/detail/src/vnodeImport.c +++ b/src/system/detail/src/vnodeImport.c @@ -702,8 +702,8 @@ int vnodeFindKeyInFile(SImportInfo *pImport, int order) { if (pImport->key != key && pImport->pos > 0) { if ( pObj->sversion != pBlock->sversion ) { - dError("vid:%d sid:%d id:%s, import sversion not matached, expected:%d received:%d", pObj->vnode, pObj->sid, - pBlock->sversion, pObj->sversion); + dError("vid:%d sid:%d id:%s, import sversion not matched, expected:%d received:%d", pObj->vnode, pObj->sid, + pObj->meterId, pBlock->sversion, pObj->sversion); code = TSDB_CODE_OTHERS; } else { pImport->offset = pBlock->offset; From 03abae0c6d936414a6f18e336ec13c6eb9159fae Mon Sep 17 00:00:00 2001 From: lihui Date: Thu, 21 Nov 2019 17:18:14 +0800 Subject: [PATCH 11/42] [TBASE-1123] --- src/client/src/tscAsync.c | 5 +- src/client/src/tscSql.c | 3 + src/client/src/tscSystem.c | 10 +- src/inc/tglobalcfg.h | 2 + src/inc/tnote.h | 64 +++++++++++ src/modules/http/src/httpSql.c | 6 +- src/modules/http/src/httpSystem.c | 4 +- src/util/src/tglobalcfg.c | 5 + src/util/src/tnote.c | 171 ++++++++++++++++-------------- 9 files changed, 182 insertions(+), 88 deletions(-) create mode 100644 src/inc/tnote.h diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index aad0295959..8b324afc5e 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -24,6 +24,7 @@ #include "tsocket.h" #include "tsql.h" #include "tutil.h" +#include "tnote.h" void tscProcessFetchRow(SSchedMsg *pMsg); void tscProcessAsyncRetrieve(void *param, TAOS_RES *tres, int numOfRows); @@ -53,7 +54,9 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *, tscError("sql string too long"); tscQueueAsyncError(fp, param); return; - } + } + + taosNotePrintTsc(sqlstr); SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj)); if (pSql == NULL) { diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 13c5669fec..be7c19ca98 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -27,6 +27,7 @@ #include "tsql.h" #include "ttimer.h" #include "tutil.h" +#include "tnote.h" TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) { @@ -274,6 +275,8 @@ int taos_query(TAOS *taos, const char *sqlstr) { return pRes->code; } + taosNotePrintTsc(sqlstr); + void *sql = realloc(pSql->sqlstr, sqlLen + 1); if (sql == NULL) { pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 2c5ad2939a..60b90ac328 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -45,6 +45,10 @@ extern int tscEmbedded; int tscNumOfThreads; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; +extern int tsTscEnableRecordSql; +extern int tsNumOfLogLines; +void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); + void tscCheckDiskUsage(void *para, void *unused) { taosGetDisk(); taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr); @@ -85,6 +89,10 @@ void taos_init_imp() { taosSetCoreDump(); + if (tsTscEnableRecordSql != 0) { + taosInitNote(tsNumOfLogLines / 10, 1, (char*)"tsc_note"); + } + #ifdef CLUSTER tscMgmtIpList.numOfIps = 2; strcpy(tscMgmtIpList.ipstr[0], tsMasterIp); @@ -354,4 +362,4 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { atomic_store_32(&lock, 0); return ret; -} \ No newline at end of file +} diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 577f3e8c89..8f0cf79fe6 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -150,6 +150,8 @@ extern int tsHttpEnableRecordSql; extern int tsTelegrafUseFieldNum; extern int tsAdminRowLimit; +extern int tsTscEnableRecordSql; + extern char tsMonitorDbName[]; extern char tsInternalPass[]; extern int tsMonitorInterval; diff --git a/src/inc/tnote.h b/src/inc/tnote.h new file mode 100644 index 0000000000..1b53be22a2 --- /dev/null +++ b/src/inc/tnote.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_TNOTE_H +#define TDENGINE_TNOTE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "unistd.h" +#include "os.h" +#include "tutil.h" +#include "tglobalcfg.h" + +#define MAX_NOTE_LINE_SIZE 66000 +#define NOTE_FILE_NAME_LEN 300 + +typedef struct _taosNoteInfo { + int taosNoteFileNum ; + int taosNoteMaxLines; + int taosNoteLines; + char taosNoteName[NOTE_FILE_NAME_LEN]; + int taosNoteFlag; + int taosNoteFd; + int taosNoteOpenInProgress; + pthread_mutex_t taosNoteMutex; +}taosNoteInfo; + +void taosNotePrint(taosNoteInfo * pNote, const char * const format, ...); + +extern taosNoteInfo m_HttpNote; +extern taosNoteInfo m_TscNote; + +extern int tsHttpEnableRecordSql; +extern int tsTscEnableRecordSql; + +#define taosNotePrintHttp(...) \ + if (tsHttpEnableRecordSql) { \ + taosNotePrint(&m_HttpNote, __VA_ARGS__); \ + } + +#define taosNotePrintTsc(...) \ + if (tsTscEnableRecordSql) { \ + taosNotePrint(&m_TscNote, __VA_ARGS__); \ + } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/modules/http/src/httpSql.c b/src/modules/http/src/httpSql.c index 0e3b211abb..732d0179ff 100644 --- a/src/modules/http/src/httpSql.c +++ b/src/modules/http/src/httpSql.c @@ -24,11 +24,11 @@ #include "httpResp.h" #include "taos.h" #include "tsclient.h" +#include "tnote.h" void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos); void httpProcessMultiSql(HttpContext *pContext); -void taosNotePrint(const char * const format, ...); void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numOfRows) { HttpContext *pContext = (HttpContext *)param; @@ -165,7 +165,7 @@ void httpProcessMultiSql(HttpContext *pContext) { char *sql = httpGetCmdsString(pContext, cmd->sql); httpDump("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, start query, sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, sql); - taosNotePrint(sql); + taosNotePrintHttp(sql); taos_query_a(pContext->session->taos, sql, httpProcessMultiSqlCallBack, (void *)pContext); } @@ -298,7 +298,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) { httpDump("context:%p, fd:%d, ip:%s, user:%s, start query, sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, sql); - taosNotePrint(sql); + taosNotePrintHttp(sql); taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext); } diff --git a/src/modules/http/src/httpSystem.c b/src/modules/http/src/httpSystem.c index df49251f13..c33cd44444 100644 --- a/src/modules/http/src/httpSystem.c +++ b/src/modules/http/src/httpSystem.c @@ -42,7 +42,7 @@ #endif static HttpServer *httpServer = NULL; -void taosInitNote(int numOfNoteLines, int maxNotes); +void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); int httpInitSystem() { taos_init(); @@ -61,7 +61,7 @@ int httpInitSystem() { pthread_mutex_init(&httpServer->serverMutex, NULL); if (tsHttpEnableRecordSql != 0) { - taosInitNote(tsNumOfLogLines / 10, 1); + taosInitNote(tsNumOfLogLines / 10, 1, (char*)"http_note"); } restInitHandle(httpServer); adminInitHandle(httpServer); diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 99c2b8e530..286983b0b2 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -162,6 +162,8 @@ int tsHttpEnableRecordSql = 0; int tsTelegrafUseFieldNum = 0; int tsAdminRowLimit = 10240; +int tsTscEnableRecordSql = 0; + int tsRpcTimer = 300; int tsRpcMaxTime = 600; // seconds; @@ -767,6 +769,9 @@ static void doInitGlobalConfig() { 0, 255, 0, TSDB_CFG_UTYPE_NONE); + tsInitConfigOption(cfg++, "tscEnableRecordSql", &tsTscEnableRecordSql, TSDB_CFG_VTYPE_INT, + TSDB_CFG_CTYPE_B_CONFIG, + 1, 100000, 0, TSDB_CFG_UTYPE_NONE); // version info tsInitConfigOption(cfg++, "gitinfo", gitinfo, TSDB_CFG_VTYPE_STRING, TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 709ac2742e..d12cc6e613 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -13,42 +13,50 @@ * along with this program. If not, see . */ -#include "os.h" -#include "tutil.h" -#include "tglobalcfg.h" +#include "tnote.h" -#define MAX_NOTE_LINE_SIZE 66000 -#define NOTE_FILE_NAME_LEN 300 +taosNoteInfo m_HttpNote; +taosNoteInfo m_TscNote; -static int taosNoteFileNum = 1; -static int taosNoteMaxLines = 0; -static int taosNoteLines = 0; -static char taosNoteName[NOTE_FILE_NAME_LEN]; -static int taosNoteFlag = 0; -static int taosNoteFd = -1; -static int taosNoteOpenInProgress = 0; -static pthread_mutex_t taosNoteMutex; -void taosNotePrint(const char * const format, ...); -int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum); +int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInfo * pNote); -void taosInitNote(int numOfNoteLines, int maxNotes) +void taosInitNote(int numOfNoteLines, int maxNotes, char* lable) { + taosNoteInfo * pNote = NULL; char temp[128] = { 0 }; - sprintf(temp, "%s/taosnote", logDir); - if (taosOpenNoteWithMaxLines(temp, numOfNoteLines, maxNotes) < 0) + + if (strcasecmp(lable, "http_note") == 0) { + pNote = &m_HttpNote; + sprintf(temp, "%s/httpnote", logDir); + } else if (strcasecmp(lable, "tsc_note") == 0) { + pNote = &m_TscNote; + sprintf(temp, "%s/tscnote-%d", logDir, getpid()); + } else { + return; + } + + memset(pNote, 0, sizeof(taosNoteInfo)); + pNote->taosNoteFileNum = 1; + //pNote->taosNoteMaxLines = 0; + //pNote->taosNoteLines = 0; + //pNote->taosNoteFlag = 0; + pNote->taosNoteFd = -1; + //pNote->taosNoteOpenInProgress = 0; + + if (taosOpenNoteWithMaxLines(temp, numOfNoteLines, maxNotes, pNote) < 0) fprintf(stderr, "failed to init note file\n"); - taosNotePrint("=================================================="); - taosNotePrint("=================== new note ==================="); - taosNotePrint("=================================================="); + taosNotePrint(pNote, "=================================================="); + taosNotePrint(pNote, "=================== new note ==================="); + taosNotePrint(pNote, "=================================================="); } -void taosCloseNoteByFd(int oldFd); -bool taosLockNote(int fd) +void taosCloseNoteByFd(int oldFd, taosNoteInfo * pNote); +bool taosLockNote(int fd, taosNoteInfo * pNote) { if (fd < 0) return false; - if (taosNoteFileNum > 1) { + if (pNote->taosNoteFileNum > 1) { int ret = (int)(flock(fd, LOCK_EX | LOCK_NB)); if (ret == 0) { return true; @@ -58,11 +66,11 @@ bool taosLockNote(int fd) return false; } -void taosUnLockNote(int fd) +void taosUnLockNote(int fd, taosNoteInfo * pNote) { if (fd < 0) return; - if (taosNoteFileNum > 1) { + if (pNote->taosNoteFileNum > 1) { flock(fd, LOCK_UN | LOCK_NB); } } @@ -70,50 +78,51 @@ void taosUnLockNote(int fd) void *taosThreadToOpenNewNote(void *param) { char name[NOTE_FILE_NAME_LEN]; + taosNoteInfo * pNote = (taosNoteInfo *)param; - taosNoteFlag ^= 1; - taosNoteLines = 0; - sprintf(name, "%s.%d", taosNoteName, taosNoteFlag); + pNote->taosNoteFlag ^= 1; + pNote->taosNoteLines = 0; + sprintf(name, "%s.%d", pNote->taosNoteName, pNote->taosNoteFlag); umask(0); int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); - taosLockNote(fd); + taosLockNote(fd, pNote); lseek(fd, 0, SEEK_SET); - int oldFd = taosNoteFd; - taosNoteFd = fd; - taosNoteLines = 0; - taosNoteOpenInProgress = 0; - taosNotePrint("=============== new note is opened ============="); + int oldFd = pNote->taosNoteFd; + pNote->taosNoteFd = fd; + pNote->taosNoteLines = 0; + pNote->taosNoteOpenInProgress = 0; + taosNotePrint(pNote, "=============== new note is opened ============="); - taosCloseNoteByFd(oldFd); + taosCloseNoteByFd(oldFd, pNote); return NULL; } -int taosOpenNewNote() +int taosOpenNewNote(taosNoteInfo * pNote) { - pthread_mutex_lock(&taosNoteMutex); + pthread_mutex_lock(&pNote->taosNoteMutex); - if (taosNoteLines > taosNoteMaxLines && taosNoteOpenInProgress == 0) { - taosNoteOpenInProgress = 1; + if (pNote->taosNoteLines > pNote->taosNoteMaxLines && pNote->taosNoteOpenInProgress == 0) { + pNote->taosNoteOpenInProgress = 1; - taosNotePrint("=============== open new note =================="); + taosNotePrint(pNote, "=============== open new note =================="); pthread_t pattern; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_create(&pattern, &attr, taosThreadToOpenNewNote, NULL); + pthread_create(&pattern, &attr, taosThreadToOpenNewNote, (void*)pNote); pthread_attr_destroy(&attr); } - pthread_mutex_unlock(&taosNoteMutex); + pthread_mutex_unlock(&pNote->taosNoteMutex); - return taosNoteFd; + return pNote->taosNoteFd; } -bool taosCheckNoteIsOpen(char *noteName) +bool taosCheckNoteIsOpen(char *noteName, taosNoteInfo * pNote) { int exist = access(noteName, F_OK); if (exist != 0) { @@ -126,8 +135,8 @@ bool taosCheckNoteIsOpen(char *noteName) return true; } - if (taosLockNote(fd)) { - taosUnLockNote(fd); + if (taosLockNote(fd, pNote)) { + taosUnLockNote(fd, pNote); close(fd); return false; } @@ -137,80 +146,80 @@ bool taosCheckNoteIsOpen(char *noteName) } } -void taosGetNoteName(char *fn) +void taosGetNoteName(char *fn, taosNoteInfo * pNote) { - if (taosNoteFileNum > 1) { - for (int i = 0; i < taosNoteFileNum; i++) { + if (pNote->taosNoteFileNum > 1) { + for (int i = 0; i < pNote->taosNoteFileNum; i++) { char fileName[NOTE_FILE_NAME_LEN]; sprintf(fileName, "%s%d.0", fn, i); - bool file1open = taosCheckNoteIsOpen(fileName); + bool file1open = taosCheckNoteIsOpen(fileName, pNote); sprintf(fileName, "%s%d.1", fn, i); - bool file2open = taosCheckNoteIsOpen(fileName); + bool file2open = taosCheckNoteIsOpen(fileName, pNote); if (!file1open && !file2open) { - sprintf(taosNoteName, "%s%d", fn, i); + sprintf(pNote->taosNoteName, "%s%d", fn, i); return; } } } - strcpy(taosNoteName, fn); + strcpy(pNote->taosNoteName, fn); } -int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum) +int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInfo * pNote) { char name[NOTE_FILE_NAME_LEN] = "\0"; struct stat notestat0, notestat1; int size; - taosNoteMaxLines = maxLines; - taosNoteFileNum = maxNoteNum; - taosGetNoteName(fn); + pNote->taosNoteMaxLines = maxLines; + pNote->taosNoteFileNum = maxNoteNum; + taosGetNoteName(fn, pNote); strcpy(name, fn); strcat(name, ".0"); // if none of the note files exist, open 0, if both exists, open the old one if (stat(name, ¬estat0) < 0) { - taosNoteFlag = 0; + pNote->taosNoteFlag = 0; } else { strcpy(name, fn); strcat(name, ".1"); if (stat(name, ¬estat1) < 0) { - taosNoteFlag = 1; + pNote->taosNoteFlag = 1; } else { - taosNoteFlag = (notestat0.st_mtime > notestat1.st_mtime) ? 0 : 1; + pNote->taosNoteFlag = (notestat0.st_mtime > notestat1.st_mtime) ? 0 : 1; } } - sprintf(name, "%s.%d", taosNoteName, taosNoteFlag); - pthread_mutex_init(&taosNoteMutex, NULL); + sprintf(name, "%s.%d", pNote->taosNoteName, pNote->taosNoteFlag); + pthread_mutex_init(&pNote->taosNoteMutex, NULL); umask(0); - taosNoteFd = open(name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + pNote->taosNoteFd = open(name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); - if (taosNoteFd < 0) { + if (pNote->taosNoteFd < 0) { fprintf(stderr, "failed to open note file:%s reason:%s\n", name, strerror(errno)); return -1; } - taosLockNote(taosNoteFd); + taosLockNote(pNote->taosNoteFd, pNote); // only an estimate for number of lines struct stat filestat; - fstat(taosNoteFd, &filestat); + fstat(pNote->taosNoteFd, &filestat); size = (int)filestat.st_size; - taosNoteLines = size / 60; + pNote->taosNoteLines = size / 60; - lseek(taosNoteFd, 0, SEEK_END); + lseek(pNote->taosNoteFd, 0, SEEK_END); return 0; } -void taosNotePrint(const char * const format, ...) +void taosNotePrint(taosNoteInfo * pNote, const char * const format, ...) { va_list argpointer; char buffer[MAX_NOTE_LINE_SIZE]; @@ -222,7 +231,7 @@ void taosNotePrint(const char * const format, ...) gettimeofday(&timeSecs, NULL); curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)timeSecs.tv_usec); + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %lx ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int)timeSecs.tv_usec, pthread_self()); va_start(argpointer, format); len += vsnprintf(buffer + len, MAX_NOTE_LINE_SIZE - len, format, argpointer); @@ -233,26 +242,26 @@ void taosNotePrint(const char * const format, ...) buffer[len++] = '\n'; buffer[len] = 0; - if (taosNoteFd >= 0) { - twrite(taosNoteFd, buffer, (unsigned int)len); + if (pNote->taosNoteFd >= 0) { + twrite(pNote->taosNoteFd, buffer, (unsigned int)len); - if (taosNoteMaxLines > 0) { - taosNoteLines++; - if ((taosNoteLines > taosNoteMaxLines) && (taosNoteOpenInProgress == 0)) - taosOpenNewNote(); + if (pNote->taosNoteMaxLines > 0) { + pNote->taosNoteLines++; + if ((pNote->taosNoteLines > pNote->taosNoteMaxLines) && (pNote->taosNoteOpenInProgress == 0)) + taosOpenNewNote(pNote); } } } -void taosCloseNote() +void taosCloseNote(taosNoteInfo * pNote) { - taosCloseNoteByFd(taosNoteFd); + taosCloseNoteByFd(pNote->taosNoteFd, pNote); } -void taosCloseNoteByFd(int fd) +void taosCloseNoteByFd(int fd, taosNoteInfo * pNote) { if (fd >= 0) { - taosUnLockNote(fd); + taosUnLockNote(fd, pNote); close(fd); } } From c8921fe9169e4edfb3d89619a39a1dedca0c2e16 Mon Sep 17 00:00:00 2001 From: lihui Date: Thu, 21 Nov 2019 17:38:23 +0800 Subject: [PATCH 12/42] [TBASE-1123] --- src/os/linux/src/tsystem.c | 6 +++++- src/util/src/tglobalcfg.c | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/tsystem.c index b01f0b7926..70b970e2a8 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/tsystem.c @@ -586,9 +586,13 @@ void taosKillSystem() { kill(tsProcId, 2); } - +extern int tsEnableCoreFile; int _sysctl(struct __sysctl_args *args ); void taosSetCoreDump() { + if (0 == tsEnableCoreFile) { + return; + } + // 1. set ulimit -c unlimited struct rlimit rlim; struct rlimit rlim_new; diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 286983b0b2..e9cfbbc718 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -163,6 +163,7 @@ int tsTelegrafUseFieldNum = 0; int tsAdminRowLimit = 10240; int tsTscEnableRecordSql = 0; +int tsEnableCoreFile = 0; int tsRpcTimer = 300; int tsRpcMaxTime = 600; // seconds; @@ -772,6 +773,11 @@ static void doInitGlobalConfig() { tsInitConfigOption(cfg++, "tscEnableRecordSql", &tsTscEnableRecordSql, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG, 1, 100000, 0, TSDB_CFG_UTYPE_NONE); + + tsInitConfigOption(cfg++, "enableCoreFile", &tsEnableCoreFile, TSDB_CFG_VTYPE_INT, + TSDB_CFG_CTYPE_B_CONFIG, + 1, 100000, 0, TSDB_CFG_UTYPE_NONE); + // version info tsInitConfigOption(cfg++, "gitinfo", gitinfo, TSDB_CFG_VTYPE_STRING, TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, @@ -1161,4 +1167,4 @@ void tsPrintGlobalConfigSpec() { pPrint(" dataDir: %s", dataDir); } -#endif \ No newline at end of file +#endif From 322abab8c8c0a5c50f86dbf2b3717e386cba8f52 Mon Sep 17 00:00:00 2001 From: lihui Date: Thu, 21 Nov 2019 17:54:13 +0800 Subject: [PATCH 13/42] [TBASE-1123] --- src/util/src/tglobalcfg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index e9cfbbc718..a62523c61d 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -790,6 +790,7 @@ static void doInitGlobalConfig() { 0, 0, 0, TSDB_CFG_UTYPE_NONE); tsGlobalConfigNum = (int)(cfg - tsGlobalConfig); + assert(tsGlobalConfigNum <= TSDB_CFG_MAX_NUM); } static pthread_once_t initGlobalConfig = PTHREAD_ONCE_INIT; From 24863d6dc0a61c4e10a2b0f89c47ec7d66b768c2 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 21 Nov 2019 18:28:55 +0800 Subject: [PATCH 14/42] [tbase-1212] --- src/system/detail/inc/vnodeUtil.h | 2 ++ src/system/detail/src/vnodeImport.c | 41 ++++++++++++++++------------- src/system/detail/src/vnodeMeter.c | 10 +++++-- src/system/detail/src/vnodeShell.c | 35 ++++-------------------- src/system/detail/src/vnodeStream.c | 11 +++----- src/system/detail/src/vnodeUtil.c | 20 ++++++++++++++ 6 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/system/detail/inc/vnodeUtil.h b/src/system/detail/inc/vnodeUtil.h index 8705794660..b0f573ba2d 100644 --- a/src/system/detail/inc/vnodeUtil.h +++ b/src/system/detail/inc/vnodeUtil.h @@ -81,6 +81,8 @@ int32_t vnodeSetMeterState(SMeterObj* pMeterObj, int32_t state); void vnodeClearMeterState(SMeterObj* pMeterObj, int32_t state); bool vnodeIsMeterState(SMeterObj* pMeterObj, int32_t state); void vnodeSetMeterDeleting(SMeterObj* pMeterObj); +int32_t vnodeSetMeterInsertImportStateEx(SMeterObj* pObj, int32_t st); + bool vnodeIsSafeToDeleteMeter(SVnodeObj* pVnode, int32_t sid); void vnodeFreeColumnInfo(SColumnInfo* pColumnInfo); bool isGroupbyNormalCol(SSqlGroupbyExpr* pExpr); diff --git a/src/system/detail/src/vnodeImport.c b/src/system/detail/src/vnodeImport.c index b2b937b066..4cc8e84e7e 100644 --- a/src/system/detail/src/vnodeImport.c +++ b/src/system/detail/src/vnodeImport.c @@ -286,12 +286,9 @@ void vnodeProcessImportTimer(void *param, void *tmrId) { SShellObj *pShell = pImport->pShell; pImport->retry++; - - //slow query will block the import operation - int32_t state = vnodeSetMeterState(pObj, TSDB_METER_STATE_IMPORTING); - if (state >= TSDB_METER_STATE_DELETING) { - dError("vid:%d sid:%d id:%s, meter is deleted, failed to import, state:%d", - pObj->vnode, pObj->sid, pObj->meterId, state); + + int32_t code = vnodeSetMeterInsertImportStateEx(pObj, TSDB_METER_STATE_IMPORTING); + if (code == TSDB_CODE_NOT_ACTIVE_TABLE) { return; } @@ -303,14 +300,14 @@ void vnodeProcessImportTimer(void *param, void *tmrId) { //if the num == 0, it will never be increased before state is set to TSDB_METER_STATE_READY int32_t commitInProcess = 0; pthread_mutex_lock(&pPool->vmutex); - if (((commitInProcess = pPool->commitInProcess) == 1) || num > 0 || state != TSDB_METER_STATE_READY) { + if (((commitInProcess = pPool->commitInProcess) == 1) || num > 0 || code == TSDB_CODE_ACTION_IN_PROGRESS) { pthread_mutex_unlock(&pPool->vmutex); vnodeClearMeterState(pObj, TSDB_METER_STATE_IMPORTING); if (pImport->retry < 1000) { dTrace("vid:%d sid:%d id:%s, import failed, retry later. commit in process or queries on it, or not ready." "commitInProcess:%d, numOfQueries:%d, state:%d", pObj->vnode, pObj->sid, pObj->meterId, - commitInProcess, num, state); + commitInProcess, num, pObj->state); taosTmrStart(vnodeProcessImportTimer, 10, pImport, vnodeTmrCtrl); return; @@ -320,15 +317,14 @@ void vnodeProcessImportTimer(void *param, void *tmrId) { } else { pPool->commitInProcess = 1; pthread_mutex_unlock(&pPool->vmutex); - int code = vnodeImportData(pObj, pImport); + int32_t ret = vnodeImportData(pObj, pImport); if (pShell) { - pShell->code = code; + pShell->code = ret; pShell->numOfTotalPoints += pImport->importedRows; } } vnodeClearMeterState(pObj, TSDB_METER_STATE_IMPORTING); - pVnode->version++; // send response back to shell @@ -912,16 +908,12 @@ int vnodeImportPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi } if (*((TSKEY *)(pSubmit->payLoad + (rows - 1) * pObj->bytesPerPoint)) > pObj->lastKey) { - vnodeClearMeterState(pObj, TSDB_METER_STATE_IMPORTING); - vnodeSetMeterState(pObj, TSDB_METER_STATE_INSERT); code = vnodeInsertPoints(pObj, cont, contLen, TSDB_DATA_SOURCE_LOG, NULL, pObj->sversion, &pointsImported, now); if (pShell) { pShell->code = code; pShell->numOfTotalPoints += pointsImported; } - - vnodeClearMeterState(pObj, TSDB_METER_STATE_INSERT); } else { SImportInfo *pNew, import; @@ -933,7 +925,11 @@ int vnodeImportPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi import.pShell = pShell; import.payload = payload; import.rows = rows; - + + if ((code = vnodeSetMeterInsertImportStateEx(pObj, TSDB_METER_STATE_IMPORTING)) != TSDB_CODE_SUCCESS) { + return code; + } + int32_t num = 0; pthread_mutex_lock(&pVnode->vmutex); num = pObj->numOfQueries; @@ -944,7 +940,8 @@ int vnodeImportPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi pthread_mutex_lock(&pPool->vmutex); if (((commitInProcess = pPool->commitInProcess) == 1) || num > 0) { pthread_mutex_unlock(&pPool->vmutex); - + vnodeClearMeterState(pObj, TSDB_METER_STATE_IMPORTING); + pNew = (SImportInfo *)malloc(sizeof(SImportInfo)); memcpy(pNew, &import, sizeof(SImportInfo)); pNew->signature = pNew; @@ -956,19 +953,25 @@ int vnodeImportPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi dTrace("vid:%d sid:%d id:%s, import later, commit in process:%d, numOfQueries:%d", pObj->vnode, pObj->sid, pObj->meterId, commitInProcess, pObj->numOfQueries); + /* + * vnodeProcessImportTimer will set the import status for this table, so need to + * set the import flag here + */ taosTmrStart(vnodeProcessImportTimer, 10, pNew, vnodeTmrCtrl); return 0; } else { pPool->commitInProcess = 1; pthread_mutex_unlock(&pPool->vmutex); - int code = vnodeImportData(pObj, &import); + + int ret = vnodeImportData(pObj, &import); if (pShell) { - pShell->code = code; + pShell->code = ret; pShell->numOfTotalPoints += import.importedRows; } } } + vnodeClearMeterState(pObj, TSDB_METER_STATE_IMPORTING); pVnode->version++; if (pShell) { diff --git a/src/system/detail/src/vnodeMeter.c b/src/system/detail/src/vnodeMeter.c index 14cdf9eb78..42353c36a4 100644 --- a/src/system/detail/src/vnodeMeter.c +++ b/src/system/detail/src/vnodeMeter.c @@ -572,7 +572,7 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi dTrace("vid:%d sid:%d id:%s, cache is full, freePoints:%d, notFreeSlots:%d", pObj->vnode, pObj->sid, pObj->meterId, pObj->freePoints, pPool->notFreeSlots); vnodeProcessCommitTimer(pVnode, NULL); - return TSDB_CODE_ACTION_IN_PROGRESS; + return code; } // FIXME: Here should be after the comparison of sversions. @@ -608,7 +608,11 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi pObj->vnode, pObj->sid, pObj->meterId, pVnode->lastKeyOnFile, numOfPoints,firstKey, lastKey, minAllowedKey, maxAllowedKey); return TSDB_CODE_TIMESTAMP_OUT_OF_RANGE; } - + + if ((code = vnodeSetMeterInsertImportStateEx(pObj, TSDB_METER_STATE_INSERT)) != TSDB_CODE_SUCCESS) { + goto _over; + } + for (i = 0; i < numOfPoints; ++i) { // meter will be dropped, abort current insertion if (pObj->state >= TSDB_METER_STATE_DELETING) { @@ -654,6 +658,8 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi pthread_mutex_unlock(&(pVnode->vmutex)); _over: + vnodeClearMeterState(pObj, TSDB_METER_STATE_INSERT); + dTrace("vid:%d sid:%d id:%s, %d out of %d points are inserted, lastKey:%ld source:%d, vnode total storage: %ld", pObj->vnode, pObj->sid, pObj->meterId, points, numOfPoints, pObj->lastKey, source, pVnode->vnodeStatistic.totalStorage); diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c index a5f5259887..b8516e127b 100644 --- a/src/system/detail/src/vnodeShell.c +++ b/src/system/detail/src/vnodeShell.c @@ -565,40 +565,15 @@ int vnodeProcessShellSubmitRequest(char *pMsg, int msgLen, SShellObj *pObj) { int subMsgLen = sizeof(pBlocks->numOfRows) + htons(pBlocks->numOfRows) * pMeterObj->bytesPerPoint; int sversion = htonl(pBlocks->sversion); - int32_t state = TSDB_METER_STATE_READY; if (pSubmit->import) { - state = vnodeSetMeterState(pMeterObj, TSDB_METER_STATE_IMPORTING); + code = vnodeImportPoints(pMeterObj, (char *) &(pBlocks->numOfRows), subMsgLen, TSDB_DATA_SOURCE_SHELL, pObj, + sversion, &numOfPoints, now); } else { - state = vnodeSetMeterState(pMeterObj, TSDB_METER_STATE_INSERT); + code = vnodeInsertPoints(pMeterObj, (char *) &(pBlocks->numOfRows), subMsgLen, TSDB_DATA_SOURCE_SHELL, NULL, + sversion, &numOfPoints, now); } - if (state == TSDB_METER_STATE_READY) { - // meter status is ready for insert/import - if (pSubmit->import) { - code = vnodeImportPoints(pMeterObj, (char *) &(pBlocks->numOfRows), subMsgLen, TSDB_DATA_SOURCE_SHELL, pObj, - sversion, &numOfPoints, now); - vnodeClearMeterState(pMeterObj, TSDB_METER_STATE_IMPORTING); - } else { - code = vnodeInsertPoints(pMeterObj, (char *) &(pBlocks->numOfRows), subMsgLen, TSDB_DATA_SOURCE_SHELL, NULL, - sversion, &numOfPoints, now); - vnodeClearMeterState(pMeterObj, TSDB_METER_STATE_INSERT); - } - - if (code != TSDB_CODE_SUCCESS) {break;} - } else { - if (vnodeIsMeterState(pMeterObj, TSDB_METER_STATE_DELETING)) { - dTrace("vid:%d sid:%d id:%s, it is removed, state:%d", pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, - pMeterObj->state); - code = TSDB_CODE_NOT_ACTIVE_TABLE; - break; - } else {// waiting for 300ms by default and try again - dTrace("vid:%d sid:%d id:%s, try submit again since in state:%d", pMeterObj->vnode, pMeterObj->sid, - pMeterObj->meterId, pMeterObj->state); - - code = TSDB_CODE_ACTION_IN_PROGRESS; - break; - } - } + if (code != TSDB_CODE_SUCCESS) {break;} numOfTotalPoints += numOfPoints; pBlocks = (SShellSubmitBlock *)((char *)pBlocks + sizeof(SShellSubmitBlock) + diff --git a/src/system/detail/src/vnodeStream.c b/src/system/detail/src/vnodeStream.c index 562b7eb73c..874e59448d 100644 --- a/src/system/detail/src/vnodeStream.c +++ b/src/system/detail/src/vnodeStream.c @@ -55,14 +55,11 @@ void vnodeProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { contLen += sizeof(SSubmitMsg); int32_t numOfPoints = 0; + int32_t code = vnodeInsertPoints(pObj, (char *)pMsg, contLen, TSDB_DATA_SOURCE_SHELL, NULL, pObj->sversion, + &numOfPoints, taosGetTimestamp(vnodeList[pObj->vnode].cfg.precision)); - int32_t state = vnodeSetMeterState(pObj, TSDB_METER_STATE_INSERT); - if (state == TSDB_METER_STATE_READY) { - vnodeInsertPoints(pObj, (char *)pMsg, contLen, TSDB_DATA_SOURCE_SHELL, NULL, pObj->sversion, &numOfPoints, taosGetTimestamp(vnodeList[pObj->vnode].cfg.precision)); - vnodeClearMeterState(pObj, TSDB_METER_STATE_INSERT); - } else { - dError("vid:%d sid:%d id:%s, failed to insert continuous query results, state:%d", pObj->vnode, pObj->sid, - pObj->meterId, state); + if (code != TSDB_CODE_SUCCESS) { + dError("vid:%d sid:%d id:%s, failed to insert continuous query results", pObj->vnode, pObj->sid, pObj->meterId); } assert(numOfPoints >= 0 && numOfPoints <= 1); diff --git a/src/system/detail/src/vnodeUtil.c b/src/system/detail/src/vnodeUtil.c index b8c463f50b..52b27f5d6d 100644 --- a/src/system/detail/src/vnodeUtil.c +++ b/src/system/detail/src/vnodeUtil.c @@ -668,6 +668,26 @@ void vnodeSetMeterDeleting(SMeterObj* pMeterObj) { pMeterObj->state |= TSDB_METER_STATE_DELETING; } +int32_t vnodeSetMeterInsertImportStateEx(SMeterObj* pObj, int32_t st) { + int32_t code = TSDB_CODE_SUCCESS; + + int32_t state = vnodeSetMeterState(pObj, st); + if (state != TSDB_METER_STATE_READY) {//return to denote import is not performed + if (vnodeIsMeterState(pObj, TSDB_METER_STATE_DELETING)) { + dTrace("vid:%d sid:%d id:%s, meter is deleted, state:%d", pObj->vnode, pObj->sid, pObj->meterId, + pObj->state); + code = TSDB_CODE_NOT_ACTIVE_TABLE; + } else {// waiting for 300ms by default and try again + dTrace("vid:%d sid:%d id:%s, try submit again since in state:%d", pObj->vnode, pObj->sid, + pObj->meterId, pObj->state); + + code = TSDB_CODE_ACTION_IN_PROGRESS; + } + } + + return code; +} + bool vnodeIsSafeToDeleteMeter(SVnodeObj* pVnode, int32_t sid) { SMeterObj* pObj = pVnode->meterList[sid]; From d8292d663031060e57e31fe5a28616809f8dd285 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 21 Nov 2019 18:58:05 +0800 Subject: [PATCH 15/42] [TBASE-1213] --- src/modules/http/inc/httpHandle.h | 2 +- src/modules/http/src/httpServer.c | 6 +++--- src/modules/http/src/httpSystem.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/http/inc/httpHandle.h b/src/modules/http/inc/httpHandle.h index e7ac0365c2..4f34a43cbd 100644 --- a/src/modules/http/inc/httpHandle.h +++ b/src/modules/http/inc/httpHandle.h @@ -63,7 +63,7 @@ #define HTTP_WRITE_RETRY_TIMES 500 #define HTTP_WRITE_WAIT_TIME_MS 5 #define HTTP_EXPIRED_TIME 60000 -#define HTTP_DELAY_CLOSE_TIME_MS 1000 +#define HTTP_DELAY_CLOSE_TIME_MS 500 #define HTTP_COMPRESS_IDENTITY 0 #define HTTP_COMPRESS_GZIP 2 diff --git a/src/modules/http/src/httpServer.c b/src/modules/http/src/httpServer.c index ae8f9eeaad..333b770a5f 100644 --- a/src/modules/http/src/httpServer.c +++ b/src/modules/http/src/httpServer.c @@ -107,9 +107,9 @@ void httpCleanUpContextTimer(HttpContext *pContext) { } void httpCleanUpContext(HttpContext *pContext) { - httpTrace("context:%p, start the clean up operation", pContext); - atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0); - if (pContext->signature != NULL) { + httpTrace("context:%p, start the clean up operation, sig:%p", pContext, pContext->signature); + void *sig = atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0); + if (sig == NULL) { httpTrace("context:%p is freed by another thread.", pContext); return; } diff --git a/src/modules/http/src/httpSystem.c b/src/modules/http/src/httpSystem.c index df49251f13..93d2b1d2cd 100644 --- a/src/modules/http/src/httpSystem.c +++ b/src/modules/http/src/httpSystem.c @@ -89,7 +89,7 @@ int httpStartSystem() { } if (httpServer->timerHandle == NULL) { - httpServer->timerHandle = taosTmrInit(tsHttpCacheSessions * 20 + 100, 1000, 60000, "http"); + httpServer->timerHandle = taosTmrInit(tsHttpCacheSessions * 20 + 100, 200, 60000, "http"); } if (httpServer->timerHandle == NULL) { httpError("http init timer failed"); From 86ad416657a1fb1a7ebc184101c8604ec51cdc68 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 21 Nov 2019 18:58:58 +0800 Subject: [PATCH 16/42] [TBASE-1129] --- src/inc/tstatus.h | 6 ++++++ src/system/detail/src/vnodeStream.c | 13 +++++++------ src/util/src/tstatus.c | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/inc/tstatus.h b/src/inc/tstatus.h index 18900d3b29..1584783078 100644 --- a/src/inc/tstatus.h +++ b/src/inc/tstatus.h @@ -73,12 +73,18 @@ enum _TSDB_VG_LB_STATUS { TSDB_VG_LB_STATUS_UPDATE }; +enum _TSDB_VN_STREAM_STATUS { + TSDB_VN_STREAM_STATUS_STOP, + TSDB_VN_STREAM_STATUS_START +}; + const char* taosGetVnodeStatusStr(int vnodeStatus); const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus); const char* taosGetVnodeDropStatusStr(int dropping); const char* taosGetDnodeStatusStr(int dnodeStatus); const char* taosGetDnodeLbStatusStr(int dnodeBalanceStatus); const char* taosGetVgroupLbStatusStr(int vglbStatus); +const char* taosGetVnodeStreamStatusStr(int vnodeStreamStatus); #ifdef __cplusplus } diff --git a/src/system/detail/src/vnodeStream.c b/src/system/detail/src/vnodeStream.c index 00e261c4d0..69a33acc54 100644 --- a/src/system/detail/src/vnodeStream.c +++ b/src/system/detail/src/vnodeStream.c @@ -81,7 +81,7 @@ void vnodeOpenStreams(void *param, void *tmrId) { SVnodeObj *pVnode = (SVnodeObj *)param; SMeterObj *pObj; - if (pVnode->streamRole == 0) return; + if (pVnode->streamRole == TSDB_VN_STREAM_STATUS_STOP) return; if (pVnode->meterList == NULL) return; taosTmrStopA(&pVnode->streamTimer); @@ -120,7 +120,7 @@ void vnodeCreateStream(SMeterObj *pObj) { SVnodeObj *pVnode = vnodeList + pObj->vnode; - if (pVnode->streamRole == 0) return; + if (pVnode->streamRole == TSDB_VN_STREAM_STATUS_STOP) return; if (pObj->pStream) return; dTrace("vid:%d sid:%d id:%s stream:%s is created", pObj->vnode, pObj->sid, pObj->meterId, pObj->pSql); @@ -155,7 +155,7 @@ void vnodeRemoveStream(SMeterObj *pObj) { // Close all streams in a vnode void vnodeCloseStream(SVnodeObj *pVnode) { SMeterObj *pObj; - dTrace("vid:%d, stream is closed, old role:%d", pVnode->vnode, pVnode->streamRole); + dTrace("vid:%d, stream is closed, old role %s", pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole)); // stop stream computing for (int sid = 0; sid < pVnode->cfg.maxSessions; ++sid) { @@ -172,9 +172,10 @@ void vnodeCloseStream(SVnodeObj *pVnode) { void vnodeUpdateStreamRole(SVnodeObj *pVnode) { /* SMeterObj *pObj; */ - int newRole = (pVnode->vnodeStatus == TSDB_VN_STATUS_MASTER) ? 1 : 0; + int newRole = (pVnode->vnodeStatus == TSDB_VN_STATUS_MASTER) ? TSDB_VN_STREAM_STATUS_START : TSDB_VN_STREAM_STATUS_STOP; if (newRole != pVnode->streamRole) { - dTrace("vid:%d, stream role is changed to:%d", pVnode->vnode, newRole); + dTrace("vid:%d, stream role is changed from %s to %s", + pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole), taosGetVnodeStreamStatusStr(newRole)); pVnode->streamRole = newRole; if (newRole) { vnodeOpenStreams(pVnode, NULL); @@ -182,7 +183,7 @@ void vnodeUpdateStreamRole(SVnodeObj *pVnode) { vnodeCloseStream(pVnode); } } else { - dTrace("vid:%d, stream role is keep to:%d", pVnode->vnode, newRole); + dTrace("vid:%d, stream role is keep to %s", pVnode->vnode, taosGetVnodeStreamStatusStr(newRole)); } } diff --git a/src/util/src/tstatus.c b/src/util/src/tstatus.c index f38655ac45..64f1c5d4f1 100644 --- a/src/util/src/tstatus.c +++ b/src/util/src/tstatus.c @@ -73,3 +73,11 @@ const char* taosGetVgroupLbStatusStr(int vglbStatus) { default: return "undefined"; } } + +const char* taosGetVnodeStreamStatusStr(int vnodeStreamStatus) { + switch (vnodeStreamStatus) { + case TSDB_VN_STREAM_STATUS_START: return "start"; + case TSDB_VN_STREAM_STATUS_STOP: return "stop"; + default: return "undefined"; + } +} From aeb19d1eb074a1bc6d869f36f73ff929f50299f8 Mon Sep 17 00:00:00 2001 From: lihui Date: Thu, 21 Nov 2019 19:24:06 +0800 Subject: [PATCH 17/42] [TBASE-1215] --- src/client/inc/tsclient.h | 2 +- src/client/src/tscServer.c | 4 ++-- src/inc/taosmsg.h | 4 ++-- src/system/detail/inc/mgmt.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 7341d674d3..7767dfd551 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -346,7 +346,7 @@ typedef struct _tsc_obj { char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; char acctId[TSDB_DB_NAME_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_METER_ID_LEN]; char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 436bfa327a..69d1f89079 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1795,7 +1795,7 @@ int tscBuildCreateDbMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pCreateDbMsg = (SCreateDbMsg *)pMsg; - strcpy(pCreateDbMsg->db, pMeterMetaInfo->name); + strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); pMsg += sizeof(SCreateDbMsg); msgLen = pMsg - pStart; @@ -2017,7 +2017,7 @@ int tscBuildDropDbMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pDropDbMsg = (SDropDbMsg *)pMsg; - strcpy(pDropDbMsg->db, pMeterMetaInfo->name); + strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db)); pDropDbMsg->ignoreNotExists = htons(pCmd->existsCheck ? 1 : 0); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index d02251c212..5cc06a751c 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -309,7 +309,7 @@ typedef struct { } SCreateMsg; typedef struct { - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_METER_ID_LEN]; short ignoreNotExists; } SDropDbMsg, SUseDbMsg; @@ -594,7 +594,7 @@ typedef struct { // NOTE: sizeof(SVnodeCfg) < TSDB_FILE_HEADER_LEN/4 typedef struct { char acct[TSDB_USER_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_METER_ID_LEN+2]; // 8bytes align uint32_t vgId; int32_t maxSessions; int32_t cacheBlockSize; diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index 7cdc36a446..112e75ef1e 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -157,7 +157,7 @@ typedef struct _vg_obj { } SVgObj; typedef struct _db_obj { - char name[TSDB_DB_NAME_LEN + 1]; + char name[TSDB_METER_ID_LEN + 1]; int64_t createdTime; SDbCfg cfg; int32_t numOfVgroups; From 7725aa1c9a690f343d983eecc0ef5447d6f2ea41 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 22 Nov 2019 00:09:00 +0800 Subject: [PATCH 18/42] [TBASE-1129] --- src/inc/tstatus.h | 2 ++ src/system/detail/src/dnodeMgmt.c | 18 +++++++++--------- src/system/detail/src/mgmtDnodeInt.c | 5 +++-- src/system/detail/src/vnodeCache.c | 4 ++-- src/system/detail/src/vnodeFile.c | 10 ++++------ src/system/detail/src/vnodeStore.c | 18 +++++++++--------- src/system/detail/src/vnodeStream.c | 8 ++++---- src/system/lite/src/vnodeFile.spec.c | 2 +- src/system/lite/src/vnodePeer.spec.c | 2 +- src/util/src/tstatus.c | 20 ++++++++++++++++++++ 10 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/inc/tstatus.h b/src/inc/tstatus.h index 1584783078..53b5cb9547 100644 --- a/src/inc/tstatus.h +++ b/src/inc/tstatus.h @@ -78,6 +78,8 @@ enum _TSDB_VN_STREAM_STATUS { TSDB_VN_STREAM_STATUS_START }; +const char* taosGetVgroupStatusStr(int vgroupStatus); +const char* taosGetDbStatusStr(int dbStatus); const char* taosGetVnodeStatusStr(int vnodeStatus); const char* taosGetVnodeSyncStatusStr(int vnodeSyncStatus); const char* taosGetVnodeDropStatusStr(int dropping); diff --git a/src/system/detail/src/dnodeMgmt.c b/src/system/detail/src/dnodeMgmt.c index d9029db655..2d184afd41 100644 --- a/src/system/detail/src/dnodeMgmt.c +++ b/src/system/detail/src/dnodeMgmt.c @@ -350,33 +350,33 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { pCfg->rowsInFileBlock = htonl(pCfg->rowsInFileBlock); if (pCfg->replications > 0) { - dTrace("vid:%d, vpeer cfg received, replica:%d session:%d, vnodeList replica:%d session:%d", + dPrint("vid:%d, vpeer cfg received, replica:%d session:%d, vnodeList replica:%d session:%d", vnode, pCfg->replications, pCfg->maxSessions, vnodeList[vnode].cfg.replications, vnodeList[vnode].cfg.maxSessions); for (i = 0; i < pCfg->replications; ++i) { pMsg->vpeerDesc[i].vnode = htonl(pMsg->vpeerDesc[i].vnode); pMsg->vpeerDesc[i].ip = htonl(pMsg->vpeerDesc[i].ip); - dTrace("vid:%d, vpeer:%d ip:0x%x vid:%d ", vnode, i, pMsg->vpeerDesc[i].ip, pMsg->vpeerDesc[i].vnode); + dPrint("vid:%d, vpeer:%d ip:0x%x vid:%d ", vnode, i, pMsg->vpeerDesc[i].ip, pMsg->vpeerDesc[i].vnode); } } if (vnodeList[vnode].cfg.maxSessions == 0) { - dTrace("vid:%d, vnode is empty", vnode); + dPrint("vid:%d, vnode is empty", vnode); if (pCfg->maxSessions > 0) { if (vnodeList[vnode].vnodeStatus == TSDB_VN_STATUS_OFFLINE) { - dTrace("vid:%d, status:%s, start to create vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + dPrint("vid:%d, status:%s, start to create vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); return vnodeCreateVnode(vnode, pCfg, pMsg->vpeerDesc); } else { - dTrace("vid:%d, status:%s, cannot preform create vnode operation", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + dPrint("vid:%d, status:%s, cannot preform create vnode operation", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); return TSDB_CODE_INVALID_VNODE_STATUS; } } } else { - dTrace("vid:%d, vnode is not empty", vnode); + dPrint("vid:%d, vnode is not empty", vnode); if (pCfg->maxSessions > 0) { if (vnodeList[vnode].vnodeStatus == TSDB_VN_STATUS_DELETING) { - dTrace("vid:%d, status:%s, wait vnode delete finished", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + dPrint("vid:%d, status:%s, wait vnode delete finished", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); } else { - dTrace("vid:%d, status:%s, start to update vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + dPrint("vid:%d, status:%s, start to update vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); if (pCfg->maxSessions != vnodeList[vnode].cfg.maxSessions) { vnodeCleanUpOneVnode(vnode); @@ -395,7 +395,7 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { } return 0; } else { - dTrace("vid:%d, status:%s, start to delete vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + dPrint("vid:%d, status:%s, start to delete vnode", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); vnodeRemoveVnode(vnode); } } diff --git a/src/system/detail/src/mgmtDnodeInt.c b/src/system/detail/src/mgmtDnodeInt.c index 9310182a14..6390b7009f 100644 --- a/src/system/detail/src/mgmtDnodeInt.c +++ b/src/system/detail/src/mgmtDnodeInt.c @@ -99,7 +99,7 @@ int mgmtProcessVpeerCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { *pMsg = 0; pMsg++; pMsg = mgmtBuildVpeersIe(pMsg, pVgroup, vnode); - mTrace("dnode:%s, vnode:%d, vgroup:%d, send create meter msg, code:%d", taosIpStr(pObj->privateIp), vnode, pVgroup->vgId, *pMsg); + mTrace("dnode:%s, vnode:%d, vgroup:%d, send create vnode msg, code:%d", taosIpStr(pObj->privateIp), vnode, pVgroup->vgId, *pMsg); } else { mTrace("dnode:%s, vnode:%d, no vgroup info, vgroup:%d", taosIpStr(pObj->privateIp), vnode, pObj->vload[vnode].vgId); *pMsg = TSDB_CODE_NOT_ACTIVE_VNODE; @@ -128,7 +128,8 @@ int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) { } if (pDb->vgStatus != TSDB_VG_STATUS_IN_PROGRESS) { - mTrace("dnode:%s, db:%s vpeer rsp already disposed, vgroup status:%d code:%d", taosIpStr(pObj->privateIp), pRsp->more, pDb->vgStatus, pRsp->code); + mTrace("dnode:%s, db:%s vpeer rsp already disposed, vgroup status:%s code:%d", + taosIpStr(pObj->privateIp), pRsp->more, taosGetVgroupStatusStr(pDb->vgStatus), pRsp->code); return 0; } diff --git a/src/system/detail/src/vnodeCache.c b/src/system/detail/src/vnodeCache.c index 71132b50ef..c88cbeee4b 100644 --- a/src/system/detail/src/vnodeCache.c +++ b/src/system/detail/src/vnodeCache.c @@ -78,7 +78,7 @@ void *vnodeOpenCachePool(int vnode) { } } - dTrace("vid:%d, cache pool is allocated:0x%x", vnode, pCachePool); + dPrint("vid:%d, cache pool is allocated:0x%x", vnode, pCachePool); return pCachePool; @@ -103,7 +103,7 @@ void vnodeCloseCachePool(int vnode) { taosTmrStopA(&pVnode->commitTimer); if (pVnode->commitInProcess) pthread_cancel(pVnode->commitThread); - dTrace("vid:%d, cache pool closed, count:%d", vnode, pCachePool->count); + dPrint("vid:%d, cache pool closed, count:%d", vnode, pCachePool->count); int maxAllocBlock = (1024 * 1024 * 1024) / pVnode->cfg.cacheBlockSize; while (blockId < pVnode->cfg.cacheNumOfBlocks.totalBlocks) { diff --git a/src/system/detail/src/vnodeFile.c b/src/system/detail/src/vnodeFile.c index c8c7d2debe..ae92ce44a3 100644 --- a/src/system/detail/src/vnodeFile.c +++ b/src/system/detail/src/vnodeFile.c @@ -125,10 +125,8 @@ int vnodeCreateHeadDataFile(int vnode, int fileId, char *headName, char *dataNam if (symlink(dDataName, dataName) != 0) return -1; if (symlink(dLastName, lastName) != 0) return -1; - dTrace( - "vid:%d, fileId:%d, empty header file:%s dataFile:%s lastFile:%s on " - "disk:%s is created ", - vnode, fileId, headName, dataName, lastName, path); + dPrint("vid:%d, fileId:%d, empty header file:%s dataFile:%s lastFile:%s on disk:%s is created ", + vnode, fileId, headName, dataName, lastName, path); return 0; } @@ -309,7 +307,7 @@ int vnodeOpenCommitFiles(SVnodeObj *pVnode, int noTempLast) { vnodeRecoverFromPeer(pVnode, fileId); goto _error; } else { - dTrace("vid:%d, data file:%s is opened to write", vnode, name); + dPrint("vid:%d, data file:%s is opened to write", vnode, name); } // open last file @@ -414,7 +412,7 @@ void vnodeRemoveFile(int vnode, int fileId) { remove(dDataName); remove(dLastName); - dTrace("vid:%d fileId:%d on disk: %s is removed, numOfFiles:%d maxFiles:%d", vnode, fileId, path, + dPrint("vid:%d fileId:%d on disk: %s is removed, numOfFiles:%d maxFiles:%d", vnode, fileId, path, pVnode->numOfFiles, pVnode->maxFiles); } diff --git a/src/system/detail/src/vnodeStore.c b/src/system/detail/src/vnodeStore.c index 49fcdfe467..ea64181577 100644 --- a/src/system/detail/src/vnodeStore.c +++ b/src/system/detail/src/vnodeStore.c @@ -59,7 +59,7 @@ static int vnodeInitStoreVnode(int vnode) { } pthread_mutex_init(&(pVnode->vmutex), NULL); - dTrace("vid:%d, storage initialized, version:%ld fileId:%d numOfFiles:%d", vnode, pVnode->version, pVnode->fileId, + dPrint("vid:%d, storage initialized, version:%ld fileId:%d numOfFiles:%d", vnode, pVnode->version, pVnode->fileId, pVnode->numOfFiles); return 0; @@ -83,7 +83,7 @@ int vnodeOpenVnode(int vnode) { return TSDB_CODE_INVALID_VNODE_STATUS; } - dTrace("vid:%d, status:%s, start to open", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dPrint("vid:%d, status:%s, start to open", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); pthread_mutex_lock(&dmutex); // not enough memory, abort @@ -104,7 +104,7 @@ int vnodeOpenVnode(int vnode) { vnodeOpenStreams(pVnode, NULL); #endif - dTrace("vid:%d, vnode is opened, openVnodes:%d, status:%s", vnode, tsOpenVnodes, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dPrint("vid:%d, vnode is opened, openVnodes:%d, status:%s", vnode, tsOpenVnodes, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_SUCCESS; } @@ -141,10 +141,10 @@ static int vnodeCloseVnode(int vnode) { } if (pVnode->vnodeStatus == TSDB_VN_STATUS_DELETING) { - dTrace("vid:%d, status:%s, another thread performed delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dPrint("vid:%d, status:%s, another thread performed delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_SUCCESS; } else { - dTrace("vid:%d, status:%s, enter close operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dPrint("vid:%d, status:%s, enter close operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); pVnode->vnodeStatus = TSDB_VN_STATUS_CLOSING; } @@ -154,7 +154,7 @@ static int vnodeCloseVnode(int vnode) { return TSDB_CODE_ACTION_IN_PROGRESS; } - dTrace("vid:%d, status:%s, enter delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dPrint("vid:%d, status:%s, enter delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); pVnode->vnodeStatus = TSDB_VN_STATUS_DELETING; vnodeCloseStream(vnodeList + vnode); @@ -235,7 +235,7 @@ static void vnodeRemoveDataFiles(int vnode) { if (tcode >= 0) { remove(dfilePath); - dTrace("Data file %s is removed, link file %s", dfilePath, linkFile); + dPrint("Data file %s is removed, link file %s", dfilePath, linkFile); } } else { remove(de->d_name); @@ -250,7 +250,7 @@ static void vnodeRemoveDataFiles(int vnode) { sprintf(vnodeDir, "%s/vnode%d", tsDirectory, vnode); rmdir(vnodeDir); - dTrace("vid:%d, vnode is removed!", vnode); + dPrint("vid:%d, vnode is removed!", vnode); } int vnodeRemoveVnode(int vnode) { @@ -273,7 +273,7 @@ int vnodeRemoveVnode(int vnode) { } } else { - dTrace("vid:%d, max sessions:%d, this vnode already dropped!!!", vnode, vnodeList[vnode].cfg.maxSessions); + dPrint("vid:%d, max sessions:%d, this vnode already dropped!!!", vnode, vnodeList[vnode].cfg.maxSessions); vnodeList[vnode].cfg.maxSessions = 0; //reset value vnodeCalcOpenVnodes(); } diff --git a/src/system/detail/src/vnodeStream.c b/src/system/detail/src/vnodeStream.c index 69a33acc54..00447cced8 100644 --- a/src/system/detail/src/vnodeStream.c +++ b/src/system/detail/src/vnodeStream.c @@ -155,7 +155,7 @@ void vnodeRemoveStream(SMeterObj *pObj) { // Close all streams in a vnode void vnodeCloseStream(SVnodeObj *pVnode) { SMeterObj *pObj; - dTrace("vid:%d, stream is closed, old role %s", pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole)); + dPrint("vid:%d, stream is closed, old role %s", pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole)); // stop stream computing for (int sid = 0; sid < pVnode->cfg.maxSessions; ++sid) { @@ -174,16 +174,16 @@ void vnodeUpdateStreamRole(SVnodeObj *pVnode) { int newRole = (pVnode->vnodeStatus == TSDB_VN_STATUS_MASTER) ? TSDB_VN_STREAM_STATUS_START : TSDB_VN_STREAM_STATUS_STOP; if (newRole != pVnode->streamRole) { - dTrace("vid:%d, stream role is changed from %s to %s", + dPrint("vid:%d, stream role is changed from %s to %s", pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole), taosGetVnodeStreamStatusStr(newRole)); pVnode->streamRole = newRole; - if (newRole) { + if (newRole == TSDB_VN_STREAM_STATUS_START) { vnodeOpenStreams(pVnode, NULL); } else { vnodeCloseStream(pVnode); } } else { - dTrace("vid:%d, stream role is keep to %s", pVnode->vnode, taosGetVnodeStreamStatusStr(newRole)); + dPrint("vid:%d, stream role is keep to %s", pVnode->vnode, taosGetVnodeStreamStatusStr(pVnode->streamRole)); } } diff --git a/src/system/lite/src/vnodeFile.spec.c b/src/system/lite/src/vnodeFile.spec.c index 53651a8cc9..7b26ed6c9f 100644 --- a/src/system/lite/src/vnodeFile.spec.c +++ b/src/system/lite/src/vnodeFile.spec.c @@ -97,7 +97,7 @@ int vnodeCheckNewHeaderFile(int fd, SVnodeObj *pVnode) { } _correct_exit: - dTrace("vid: %d new header file %s is correct", pVnode->vnode, pVnode->nfn); + dPrint("vid: %d new header file %s is correct", pVnode->vnode, pVnode->nfn); tfree(pBlocks); tfree(pHeader); return 0; diff --git a/src/system/lite/src/vnodePeer.spec.c b/src/system/lite/src/vnodePeer.spec.c index 2950547327..d7da8b66f4 100644 --- a/src/system/lite/src/vnodePeer.spec.c +++ b/src/system/lite/src/vnodePeer.spec.c @@ -32,7 +32,7 @@ void vnodeBroadcastStatusToUnsyncedPeer(SVnodeObj *pVnode) {} int vnodeOpenPeerVnode(int vnode) { SVnodeObj *pVnode = vnodeList + vnode; pVnode->vnodeStatus = (pVnode->cfg.replications > 1) ? TSDB_VN_STATUS_UNSYNCED : TSDB_VN_STATUS_MASTER; - dTrace("vid:%d, status:%s numOfPeers:%d", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus), pVnode->cfg.replications - 1); + dPrint("vid:%d, status:%s numOfPeers:%d", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus), pVnode->cfg.replications - 1); vnodeUpdateStreamRole(pVnode); return 0; } diff --git a/src/util/src/tstatus.c b/src/util/src/tstatus.c index 64f1c5d4f1..1ab007715d 100644 --- a/src/util/src/tstatus.c +++ b/src/util/src/tstatus.c @@ -17,6 +17,26 @@ #include "tsdb.h" #include "tstatus.h" +const char* taosGetVgroupStatusStr(int vgroupStatus) { + switch (vgroupStatus) { + case TSDB_VG_STATUS_READY: return "ready"; + case TSDB_VG_STATUS_IN_PROGRESS: return "inprogress"; + case TSDB_VG_STATUS_COMMITLOG_INIT_FAILED: return "commitlog_init_failed"; + case TSDB_VG_STATUS_INIT_FAILED: return "init_failed"; + case TSDB_VG_STATUS_FULL: return "full"; + default: return "undefined"; + } +} + +const char* taosGetDbStatusStr(int dbStatus) { + switch (dbStatus) { + case TSDB_DB_STATUS_READY: return "ready"; + case TSDB_DB_STATUS_DROPPING: return "dropping"; + case TSDB_DB_STATUS_DROP_FROM_SDB: return "drop_from_sdb"; + default: return "undefined"; + } +} + const char* taosGetVnodeStatusStr(int vnodeStatus) { switch (vnodeStatus) { case TSDB_VN_STATUS_OFFLINE: return "offline"; From a93e4876364cff2d7d09528090071703e765ae80 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Fri, 22 Nov 2019 10:27:50 +0800 Subject: [PATCH 19/42] [tbase-1212] --- src/inc/sql.y | 2 +- src/system/detail/src/vnodeMeter.c | 8 +++----- src/util/src/sql.c | 4 +++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/inc/sql.y b/src/inc/sql.y index 453485b0d9..0fb7f6ef60 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -218,7 +218,7 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; } prec(Y) ::= PRECISION STRING(X). { Y = X; } %type db_optr {SCreateDBInfo} -db_optr ::= . {} +db_optr(Y) ::= . {memset(&Y, 0, sizeof(SCreateDBInfo));} db_optr(Y) ::= db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); } diff --git a/src/system/detail/src/vnodeMeter.c b/src/system/detail/src/vnodeMeter.c index 42353c36a4..74d72b4c67 100644 --- a/src/system/detail/src/vnodeMeter.c +++ b/src/system/detail/src/vnodeMeter.c @@ -596,7 +596,7 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi } pData = pSubmit->payLoad; - code = 0; + code = TSDB_CODE_SUCCESS; TSKEY firstKey = *((TSKEY *)pData); TSKEY lastKey = *((TSKEY *)(pData + pObj->bytesPerPoint * (numOfPoints - 1))); @@ -613,8 +613,7 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi goto _over; } - for (i = 0; i < numOfPoints; ++i) { - // meter will be dropped, abort current insertion + for (i = 0; i < numOfPoints; ++i) { // meter will be dropped, abort current insertion if (pObj->state >= TSDB_METER_STATE_DELETING) { dWarn("vid:%d sid:%d id:%s, meter is dropped, abort insert, state:%d", pObj->vnode, pObj->sid, pObj->meterId, pObj->state); @@ -656,10 +655,9 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi pVnode->version++; pthread_mutex_unlock(&(pVnode->vmutex)); + vnodeClearMeterState(pObj, TSDB_METER_STATE_INSERT); _over: - vnodeClearMeterState(pObj, TSDB_METER_STATE_INSERT); - dTrace("vid:%d sid:%d id:%s, %d out of %d points are inserted, lastKey:%ld source:%d, vnode total storage: %ld", pObj->vnode, pObj->sid, pObj->meterId, points, numOfPoints, pObj->lastKey, source, pVnode->vnodeStatistic.totalStorage); diff --git a/src/util/src/sql.c b/src/util/src/sql.c index f67af9b046..2922fd8672 100644 --- a/src/util/src/sql.c +++ b/src/util/src/sql.c @@ -1934,7 +1934,6 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 79: /* db_optr ::= */ yytestcase(yyruleno==79); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2146,6 +2145,9 @@ static void yy_reduce( case 78: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==78); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; + case 79: /* db_optr ::= */ +{memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));} + break; case 80: /* db_optr ::= db_optr tables */ case 94: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==94); { yylhsminor.yy398 = yymsp[-1].minor.yy398; yylhsminor.yy398.tablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } From ccfd17df51aca5a5cfc1ae0fdc6862b0f97c2a29 Mon Sep 17 00:00:00 2001 From: lihui Date: Fri, 22 Nov 2019 12:26:04 +0800 Subject: [PATCH 20/42] [modify packging script] --- packaging/deb/DEBIAN/preinst | 8 +- packaging/deb/DEBIAN/prerm | 4 +- packaging/deb/makedeb.sh | 3 +- packaging/release.sh | 32 +++-- packaging/rpm/tdengine.spec | 16 +-- packaging/tools/install.sh | 125 ++++++++++++++----- packaging/tools/install_client.sh | 199 +++++++++++++++++++++++++++++- packaging/tools/makeclient.sh | 79 ++++++++++++ packaging/tools/makepkg.sh | 44 ++++--- packaging/tools/post.sh | 64 ++++++---- packaging/tools/preun.sh | 46 ++++--- packaging/tools/remove.sh | 49 +++++--- packaging/tools/remove_client.sh | 75 +++++++++++ 13 files changed, 610 insertions(+), 134 deletions(-) create mode 100755 packaging/tools/makeclient.sh create mode 100755 packaging/tools/remove_client.sh diff --git a/packaging/deb/DEBIAN/preinst b/packaging/deb/DEBIAN/preinst index b313f90e90..352060556c 100644 --- a/packaging/deb/DEBIAN/preinst +++ b/packaging/deb/DEBIAN/preinst @@ -9,13 +9,13 @@ fi if pidof taosd &> /dev/null; then if pidof systemd &> /dev/null; then ${csudo} systemctl stop taosd || : - elif $(which insserv &> /dev/null); then - ${csudo} service taosd stop || : - elif $(which update-rc.d &> /dev/null); then + elif $(which service &> /dev/null); then ${csudo} service taosd stop || : else pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi fi echo "Stop taosd service success!" sleep 1 diff --git a/packaging/deb/DEBIAN/prerm b/packaging/deb/DEBIAN/prerm index 1af6a04943..d24502a1cb 100644 --- a/packaging/deb/DEBIAN/prerm +++ b/packaging/deb/DEBIAN/prerm @@ -35,6 +35,8 @@ else ${csudo} rm -f ${data_link_dir} || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi fi diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index e4c795f1b8..5766bd6836 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -24,8 +24,7 @@ fi mkdir -p ${pkg_dir} cd ${pkg_dir} -versioninfo=$(${script_dir}/../tools/get_version.sh ${script_dir}/../../src/util/src/version.c) -libfile="libtaos.so.${versioninfo}" +libfile="libtaos.so.${tdengine_ver}" # create install dir install_home_path="/usr/local/taos" diff --git a/packaging/release.sh b/packaging/release.sh index 2091bed220..6a00f0b79d 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -3,7 +3,9 @@ # Generate the deb package for ubunt, or rpm package for centos, or tar.gz package for other linux os set -e -#set -x +# set -x + +armver=$1 curr_dir=$(pwd) script_dir="$(dirname $(readlink -f $0))" @@ -110,21 +112,28 @@ echo "char gitinfo[128] = \"$(git rev-parse --verify HEAD)\";" >> ${versioninfo echo "char buildinfo[512] = \"Built by ${USER} at ${build_time}\";" >> ${versioninfo} # 2. cmake executable file -#default use debug mode -compile_mode="debug" -if [[ $1 == "Release" ]] || [[ $1 == "release" ]]; then - compile_mode="Release" -fi -compile_dir="${top_dir}/${compile_mode}" +compile_dir="${top_dir}/debug" if [ -d ${compile_dir} ]; then - ${csudo} rm -rf ${compile_dir} + ${csudo} rm -rf ${compile_dir} fi ${csudo} mkdir -p ${compile_dir} cd ${compile_dir} -${csudo} cmake -DCMAKE_BUILD_TYPE=${compile_mode} ${top_dir} -${csudo} make + +# arm only support lite ver +if [ -z "$armver" ]; then + cmake ${top_dir}/../ +elif [ "$armver" == "arm64" ]; then + cmake ${top_dir}/../ -DVERSION=lite -DARMVER=arm64 +elif [ "$armver" == "arm32" ]; then + cmake ${top_dir}/../ -DVERSION=lite -DARMVER=arm32 +else + echo "input parameter error!!!" + return +fi + +make cd ${curr_dir} @@ -153,7 +162,8 @@ ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${version} echo "do tar.gz package for all systems" cd ${script_dir}/tools -${csudo} ./makepkg.sh ${compile_dir} ${version} "${build_time}" +${csudo} ./makepkg.sh ${compile_dir} ${version} "${build_time}" ${armver} +${csudo} ./makeclient.sh ${compile_dir} ${version} "${build_time}" ${armver} # 4. Clean up temporary compile directories #${csudo} rm -rf ${compile_dir} diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 9ede4102e7..c0c0eacfae 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -39,8 +39,7 @@ echo topdir: %{_topdir} echo version: %{_version} echo buildroot: %{buildroot} -versioninfo=$(%{_compiledir}/../packaging/tools/get_version.sh ../../src/util/src/version.c) -libfile="libtaos.so.${versioninfo}" +libfile="libtaos.so.%{_version}" # create install path, and cp file mkdir -p %{buildroot}%{homepath}/bin @@ -80,18 +79,17 @@ fi if pidof taosd &> /dev/null; then if pidof systemd &> /dev/null; then ${csudo} systemctl stop taosd || : - elif $(which insserv &> /dev/null); then - ${csudo} service taosd stop || : - elif $(which update-rc.d &> /dev/null); then + elif $(which service &> /dev/null); then ${csudo} service taosd stop || : else pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi fi echo "Stop taosd service success!" sleep 1 fi - # if taos.cfg already softlink, remove it if [ -f %{cfg_install_dir}/taos.cfg ]; then ${csudo} rm -f %{homepath}/cfg/taos.cfg || : @@ -146,7 +144,9 @@ if [ $1 -eq 0 ];then ${csudo} rm -f ${data_link_dir} || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi fi fi diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 4b653dec9c..2911452fb4 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# This file is used to install TAOS time-series database on linux systems. The operating system +# This file is used to install database on linux systems. The operating system # is required to use systemd to manage services at boot set -e @@ -41,19 +41,58 @@ if command -v sudo > /dev/null; then csudo="sudo" fi +initd_mod=0 service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 -elif $(which update-rc.d &> /dev/null); then +elif $(which service &> /dev/null); then service_mod=1 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" + if $(which chkconfig &> /dev/null); then + initd_mod=1 + elif $(which insserv &> /dev/null); then + initd_mod=2 + elif $(which update-rc.d &> /dev/null); then + initd_mod=3 + else + service_mod=2 + fi else service_mod=2 fi + +# get the operating system type for using the corresponding init file +# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification +#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) +osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2) +#echo "osinfo: ${osinfo}" +os_type=0 +if echo $osinfo | grep -qwi "ubuntu" ; then + echo "this is ubuntu system" + os_type=1 +elif echo $osinfo | grep -qwi "debian" ; then + echo "this is debian system" + os_type=1 +elif echo $osinfo | grep -qwi "Kylin" ; then + echo "this is Kylin system" + os_type=1 +elif echo $osinfo | grep -qwi "centos" ; then + echo "this is centos system" + os_type=2 +elif echo $osinfo | grep -qwi "fedora" ; then + echo "this is fedora system" + os_type=2 +else + echo "this is other linux system" + os_type=0 +fi + function kill_taosd() { pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 pid || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi } function install_main_path() { @@ -81,7 +120,7 @@ function install_bin() { #Make link [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : - [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : + [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : @@ -89,7 +128,7 @@ function install_bin() { function install_lib() { # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : + ${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* @@ -98,7 +137,7 @@ function install_lib() { } function install_header() { - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h @@ -107,16 +146,17 @@ function install_header() { function install_config() { #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : - if [ ! -f ${cfg_install_dir}/taos.cfg ]; then + if [ ! -f ${cfg_install_dir}/taos.cfg ]; then ${csudo} mkdir -p ${cfg_install_dir} [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} ${csudo} chmod 644 ${cfg_install_dir}/* fi ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org - ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg + ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg } + function install_log() { ${csudo} rm -rf ${log_dir} || : ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} @@ -139,14 +179,26 @@ function install_examples() { } function clean_service_on_sysvinit() { - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then ${csudo} service taosd stop || : fi - ${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + + if ((${initd_mod}==1)); then + ${csudo} chkconfig --del taosd || : + elif ((${initd_mod}==2)); then + ${csudo} insserv -r taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d -f taosd remove || : + fi + ${csudo} rm -f ${service_config_dir}/taosd || : - ${csudo} update-rc.d -f taosd remove || : - ${csudo} init q || : + + if $(which init &> /dev/null); then + ${csudo} init q || : + fi } function install_service_on_sysvinit() { @@ -155,14 +207,27 @@ function install_service_on_sysvinit() { sleep 1 # Install taosd service - ${csudo} cp -f ${script_dir}/init.d/taosd ${install_main_dir}/init.d - ${csudo} cp ${script_dir}/init.d/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - ${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" - # TODO: for centos, change here - ${csudo} update-rc.d taosd defaults - # chkconfig mysqld on + if ((${os_type}==1)); then + ${csudo} cp -f ${script_dir}/init.d/taosd.deb ${install_main_dir}/init.d/taosd + ${csudo} cp ${script_dir}/init.d/taosd.deb ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd + elif ((${os_type}==2)); then + ${csudo} cp -f ${script_dir}/init.d/taosd.rpm ${install_main_dir}/init.d/taosd + ${csudo} cp ${script_dir}/init.d/taosd.rpm ${service_config_dir}/taosd && ${csudo} chmod a+x ${service_config_dir}/taosd + fi + + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + + if ((${initd_mod}==1)); then + ${csudo} chkconfig --add taosd || : + ${csudo} chkconfig --level 2345 taosd on || : + elif ((${initd_mod}==2)); then + ${csudo} insserv taosd || : + ${csudo} insserv -d taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d taosd defaults || : + fi } function clean_service_on_systemd() { @@ -212,7 +277,7 @@ function install_service() { elif ((${service_mod}==1)); then install_service_on_sysvinit else - # must manual start taosd + # must manual stop taosd kill_taosd fi } @@ -266,7 +331,7 @@ function update_TDengine() { echo "File taos.tar.gz does not exist" exit 1 fi - tar -zxf taos.tar.gz + tar -zxf taos.tar.gz # Check if version compatible if ! is_version_compatible; then @@ -274,7 +339,7 @@ function update_TDengine() { return 1 fi - echo -e "${GREEN}Start to update TDEngine...${NC}" + echo -e "${GREEN}Start to update TDengine...${NC}" # Stop the service if running if pidof taosd &> /dev/null; then if ((${service_mod}==0)); then @@ -306,8 +371,7 @@ function update_TDengine() { if ((${service_mod}==0)); then echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} update-rc.d taosd default ${RED} for the first time${NC}" - echo -e " : ${csudo} service taosd start ${RED} after${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" else echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" fi @@ -316,7 +380,7 @@ function update_TDengine() { echo echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" else - install_bin $1 + install_bin install_config echo @@ -332,9 +396,9 @@ function install_TDengine() { echo "File taos.tar.gz does not exist" exit 1 fi - tar -zxf taos.tar.gz + tar -zxf taos.tar.gz - echo -e "${GREEN}Start to install TDEngine...${NC}" + echo -e "${GREEN}Start to install TDengine...${NC}" install_main_path @@ -362,10 +426,9 @@ function install_TDengine() { if ((${service_mod}==0)); then echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} update-rc.d taosd default ${RED} for the first time${NC}" - echo -e " : ${csudo} service taosd start ${RED} after${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" else - echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}" fi echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh index 39437c145e..7560ebca41 100755 --- a/packaging/tools/install_client.sh +++ b/packaging/tools/install_client.sh @@ -1,4 +1,201 @@ #!/bin/bash +# +# This file is used to install TDengine client on linux systems. The operating system +# is required to use systemd to manage services at boot +set -e +#set -x + +# -----------------------Variables definition--------------------- script_dir=$(dirname $(readlink -m "$0")) -${script_dir}/install.sh client +# Dynamic directory +data_dir="/var/lib/taos" +log_dir="/var/log/taos" + +log_link_dir="/usr/local/taos/log" + +cfg_install_dir="/etc/taos" + +bin_link_dir="/usr/bin" +lib_link_dir="/usr/lib" +inc_link_dir="/usr/include" + +#install main path +install_main_dir="/usr/local/taos" + +# old bin dir +bin_dir="/usr/local/taos/bin" + + +# Color setting +RED='\033[0;31m' +GREEN='\033[1;32m' +GREEN_DARK='\033[0;32m' +GREEN_UNDERLINE='\033[4;32m' +NC='\033[0m' + +csudo="" +if command -v sudo > /dev/null; then + csudo="sudo" +fi + +update_flag=0 + +function kill_client() { + pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi +} + +function install_main_path() { + #create install main dir and all sub dir + ${csudo} rm -rf ${install_main_dir} || : + ${csudo} mkdir -p ${install_main_dir} + ${csudo} mkdir -p ${install_main_dir}/cfg + ${csudo} mkdir -p ${install_main_dir}/bin + ${csudo} mkdir -p ${install_main_dir}/connector + ${csudo} mkdir -p ${install_main_dir}/driver + ${csudo} mkdir -p ${install_main_dir}/examples + ${csudo} mkdir -p ${install_main_dir}/include +} + +function install_bin() { + # Remove links + ${csudo} rm -f ${bin_link_dir}/taos || : + ${csudo} rm -f ${bin_link_dir}/taosdump || : + ${csudo} rm -f ${bin_link_dir}/rmtaos || : + + ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* + + #Make link + [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : + [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/remove_client.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_client.sh ${bin_link_dir}/rmtaos || : +} + +function clean_lib() { + sudo rm -f /usr/lib/libtaos.so || : + sudo rm -rf ${lib_dir} || : +} + +function install_lib() { + # Remove links + ${csudo} rm -f ${lib_link_dir}/libtaos.* || : + + ${csudo} cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + + ${csudo} ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + +} + +function install_header() { + ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : + ${csudo} cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* + ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h +} + +function install_config() { + #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : + + if [ ! -f ${cfg_install_dir}/taos.cfg ]; then + ${csudo} mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/cfg/taos.cfg ] && ${csudo} cp ${script_dir}/cfg/taos.cfg ${cfg_install_dir} + ${csudo} chmod 644 ${cfg_install_dir}/* + fi + + ${csudo} cp -f ${script_dir}/cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org + ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg +} + + +function install_log() { + ${csudo} rm -rf ${log_dir} || : + ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} + + ${csudo} ln -s ${log_dir} ${install_main_dir}/log +} + +function install_connector() { + ${csudo} cp -rf ${script_dir}/connector/* ${install_main_dir}/connector +} + +function install_examples() { + if [ -d ${script_dir}/examples ]; then + ${csudo} cp -rf ${script_dir}/examples/* ${install_main_dir}/examples + fi +} + +function update_TDengine() { + # Start to update + if [ ! -e taos.tar.gz ]; then + echo "File taos.tar.gz does not exist" + exit 1 + fi + tar -zxf taos.tar.gz + + echo -e "${GREEN}Start to update TDengine client...${NC}" + # Stop the client shell if running + if pidof taos &> /dev/null; then + kill_client + sleep 1 + fi + + install_main_path + + install_log + install_header + install_lib + install_connector + install_examples + install_bin + install_config + + echo + echo -e "\033[44;32;1mTDengine client is updated successfully!${NC}" + + rm -rf $(tar -tf taos.tar.gz) +} + +function install_TDengine() { + # Start to install + if [ ! -e taos.tar.gz ]; then + echo "File taos.tar.gz does not exist" + exit 1 + fi + tar -zxf taos.tar.gz + + echo -e "${GREEN}Start to install TDengine client...${NC}" + + install_main_path + install_log + install_header + install_lib + install_connector + install_examples + install_bin + install_config + + echo + echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}" + + rm -rf $(tar -tf taos.tar.gz) +} + + +## ==============================Main program starts from here============================ +# Install or updata client and client +# if server is already install, don't install client + if [ -e ${bin_dir}/taosd ]; then + echo -e "\033[44;32;1mThere are already installed TDengine server, so don't need install client!${NC}" + exit 0 + fi + + if [ -x ${bin_dir}/taos ]; then + update_flag=1 + update_TDengine + else + install_TDengine + fi diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh new file mode 100755 index 0000000000..0e52e0970a --- /dev/null +++ b/packaging/tools/makeclient.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# Generate tar.gz package for linux client +set -e +set -x + +curr_dir=$(pwd) +compile_dir=$1 +version=$2 +build_time=$3 +armver=$4 + +script_dir="$(dirname $(readlink -f $0))" +top_dir="$(readlink -m ${script_dir}/../..)" + +# create compressed install file. +build_dir="${compile_dir}/build" +code_dir="${top_dir}/src" +release_dir="${top_dir}/release" +community_dir="${script_dir}/../../../community/src" + +package_name='linux' +install_dir="${release_dir}/TDengine-client-enterprise-${version}-${package_name}-$(echo ${build_time}| tr ': ' -)" + +# Directories and files. +bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${script_dir}/remove_client.sh" +lib_files="${build_dir}/lib/libtaos.so.${version}" +header_files="${community_dir}/inc/taos.h ${community_dir}/inc/taoserror.h" +cfg_dir="${top_dir}/packaging/cfg" +install_files="${script_dir}/install_client.sh" + +# make directories. +mkdir -p ${install_dir} +mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc +mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg +mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* + +cd ${install_dir} +tar -zcv -f taos.tar.gz * --remove-files || : + +cd ${curr_dir} +cp ${install_files} ${install_dir} && chmod a+x ${install_dir}/install* + +# Copy example code +mkdir -p ${install_dir}/examples +cp -r ${top_dir}/tests/examples/c ${install_dir}/examples +cp -r ${top_dir}/tests/examples/JDBC ${install_dir}/examples +cp -r ${top_dir}/tests/examples/matlab ${install_dir}/examples +cp -r ${top_dir}/tests/examples/python ${install_dir}/examples +cp -r ${top_dir}/tests/examples/R ${install_dir}/examples +cp -r ${top_dir}/tests/examples/go ${install_dir}/examples + +# Copy driver +mkdir -p ${install_dir}/driver +cp ${lib_files} ${install_dir}/driver + +# Copy connector +connector_dir="${community_dir}/connector" +mkdir -p ${install_dir}/connector +cp ${build_dir}/lib/*.jar ${install_dir}/connector +cp -r ${connector_dir}/grafana ${install_dir}/connector/ +cp -r ${connector_dir}/python ${install_dir}/connector/ +cp -r ${connector_dir}/go ${install_dir}/connector + +# Copy release note +# cp ${script_dir}/release_note ${install_dir} + +# exit 1 + +cd ${release_dir} +if [ -z "$armver" ]; then + tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files +elif [ "$armver" == "arm64" ]; then + tar -zcv -f "$(basename ${install_dir})-arm64.tar.gz" $(basename ${install_dir}) --remove-files +elif [ "$armver" == "arm32" ]; then + tar -zcv -f "$(basename ${install_dir})-arm32.tar.gz" $(basename ${install_dir}) --remove-files +fi + +cd ${curr_dir} diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 967b14cee9..24f3a0b8d1 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -6,6 +6,7 @@ curr_dir=$(pwd) compile_dir=$1 version=$2 build_time=$3 +armver=$4 script_dir="$(dirname $(readlink -f $0))" top_dir="$(readlink -m ${script_dir}/../..)" @@ -20,11 +21,10 @@ install_dir="${release_dir}/taos-${version}-${package_name}-$(echo ${build_time} # Directories and files. bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdump ${script_dir}/remove.sh" -versioninfo=$(${script_dir}/get_version.sh ${code_dir}/util/src/version.c) -lib_files="${build_dir}/lib/libtaos.so.${versioninfo}" +lib_files="${build_dir}/lib/libtaos.so.${version}" header_files="${code_dir}/inc/taos.h ${code_dir}/inc/taoserror.h" -cfg_files="${top_dir}/packaging/cfg/*.cfg" -install_files="${script_dir}/install.sh ${script_dir}/install_client.sh" +cfg_dir="${top_dir}/packaging/cfg" +install_files="${script_dir}/install.sh" # Init file #init_dir=${script_dir}/deb @@ -33,29 +33,32 @@ install_files="${script_dir}/install.sh ${script_dir}/install_client.sh" #fi #init_files=${init_dir}/taosd # temp use rpm's taosd. TODO: later modify according to os type -init_files=${script_dir}/../rpm/taosd +init_file_deb=${script_dir}/../deb/taosd +init_file_rpm=${script_dir}/../rpm/taosd # make directories. mkdir -p ${install_dir} mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc -mkdir -p ${install_dir}/cfg && cp ${cfg_files} ${install_dir}/cfg +mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* -mkdir -p ${install_dir}/init.d && cp ${init_files} ${install_dir}/init.d +mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/taosd.deb +mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/taosd.rpm cd ${install_dir} -tar -zcv -f taos.tar.gz * --remove-files || : +tar -zcv -f taos.tar.gz * --remove-files || : cd ${curr_dir} cp ${install_files} ${install_dir} && chmod a+x ${install_dir}/install* # Copy example code mkdir -p ${install_dir}/examples -cp -r ${top_dir}/tests/examples/c ${install_dir}/examples -cp -r ${top_dir}/tests/examples/JDBC ${install_dir}/examples -cp -r ${top_dir}/tests/examples/matlab ${install_dir}/examples -cp -r ${top_dir}/tests/examples/python ${install_dir}/examples -cp -r ${top_dir}/tests/examples/R ${install_dir}/examples -cp -r ${top_dir}/tests/examples/go ${install_dir}/examples +examples_dir="${top_dir}/tests/examples" +cp -r ${examples_dir}/c ${install_dir}/examples +cp -r ${examples_dir}/JDBC ${install_dir}/examples +cp -r ${examples_dir}/matlab ${install_dir}/examples +cp -r ${examples_dir}/python ${install_dir}/examples +cp -r ${examples_dir}/R ${install_dir}/examples +cp -r ${examples_dir}/go ${install_dir}/examples # Copy driver mkdir -p ${install_dir}/driver @@ -64,18 +67,23 @@ cp ${lib_files} ${install_dir}/driver # Copy connector connector_dir="${code_dir}/connector" mkdir -p ${install_dir}/connector +cp ${build_dir}/lib/*.jar ${install_dir}/connector cp -r ${connector_dir}/grafana ${install_dir}/connector/ cp -r ${connector_dir}/python ${install_dir}/connector/ cp -r ${connector_dir}/go ${install_dir}/connector -cp ${build_dir}/lib/*.jar ${install_dir}/connector - # Copy release note -cp ${script_dir}/release_note ${install_dir} +# cp ${script_dir}/release_note ${install_dir} # exit 1 cd ${release_dir} -tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files +if [ -z "$armver" ]; then + tar -zcv -f "$(basename ${install_dir}).tar.gz" $(basename ${install_dir}) --remove-files +elif [ "$armver" == "arm64" ]; then + tar -zcv -f "$(basename ${install_dir})-arm64.tar.gz" $(basename ${install_dir}) --remove-files +elif [ "$armver" == "arm32" ]; then + tar -zcv -f "$(basename ${install_dir})-arm32.tar.gz" $(basename ${install_dir}) --remove-files +fi cd ${curr_dir} diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 11f3ab9a9b..a62f7a5eeb 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -42,14 +42,18 @@ initd_mod=0 service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 -elif $(which insserv &> /dev/null); then +elif $(which service &> /dev/null); then service_mod=1 - initd_mod=1 - service_config_dir="/etc/init.d" -elif $(which update-rc.d &> /dev/null); then - service_mod=1 - initd_mod=2 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" + if $(which chkconfig &> /dev/null); then + initd_mod=1 + elif $(which insserv &> /dev/null); then + initd_mod=2 + elif $(which update-rc.d &> /dev/null); then + initd_mod=3 + else + service_mod=2 + fi else service_mod=2 fi @@ -57,7 +61,9 @@ fi function kill_taosd() { # ${csudo} pkill -f taosd || : pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi } function install_include() { @@ -103,20 +109,26 @@ function install_config() { } function clean_service_on_sysvinit() { - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then ${csudo} service taosd stop || : fi - ${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : - ${csudo} rm -f ${service_config_dir}/taosd || : - + if ((${initd_mod}==1)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : + ${csudo} chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : + ${csudo} insserv -r taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d -f taosd remove || : + fi + + ${csudo} rm -f ${service_config_dir}/taosd || : + + if $(which init &> /dev/null); then + ${csudo} init q || : fi -# ${csudo} update-rc.d -f taosd remove || : - ${csudo} init q || : } function install_service_on_sysvinit() { @@ -127,18 +139,24 @@ function install_service_on_sysvinit() { # Install taosd service ${csudo} cp %{init_d_dir}/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - - ${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" - # TODO: for centos, change here - ${csudo} update-rc.d taosd defaults - # chkconfig mysqld on + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" + + if ((${initd_mod}==1)); then + ${csudo} chkconfig --add taosd || : + ${csudo} chkconfig --level 2345 taosd on || : + elif ((${initd_mod}==2)); then + ${csudo} insserv taosd || : + ${csudo} insserv -d taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d taosd defaults || : + fi } function clean_service_on_systemd() { taosd_service_config="${service_config_dir}/taosd.service" - # taosd service already is stoped before install + # taosd service already is stoped before install in preinst script #if systemctl is-active --quiet taosd; then # echo "TDengine is running, stopping it..." # ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null diff --git a/packaging/tools/preun.sh b/packaging/tools/preun.sh index a08f4e304e..0533410802 100755 --- a/packaging/tools/preun.sh +++ b/packaging/tools/preun.sh @@ -26,22 +26,27 @@ initd_mod=0 service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 -elif $(which insserv &> /dev/null); then +elif $(which service &> /dev/null); then service_mod=1 - initd_mod=1 - service_config_dir="/etc/init.d" -elif $(which update-rc.d &> /dev/null); then - service_mod=1 - initd_mod=2 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" + if $(which chkconfig &> /dev/null); then + initd_mod=1 + elif $(which insserv &> /dev/null); then + initd_mod=2 + elif $(which update-rc.d &> /dev/null); then + initd_mod=3 + else + service_mod=2 + fi else service_mod=2 fi - function kill_taosd() { pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi } function clean_service_on_systemd() { @@ -57,20 +62,27 @@ function clean_service_on_systemd() { } function clean_service_on_sysvinit() { - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then + echo "TDengine taosd is running, stopping it..." ${csudo} service taosd stop || : fi - ${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : - ${csudo} rm -f ${service_config_dir}/taosd || : if ((${initd_mod}==1)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : + ${csudo} chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : + ${csudo} insserv -r taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d -f taosd remove || : + fi + + ${csudo} rm -f ${service_config_dir}/taosd || : + + if $(which init &> /dev/null); then + ${csudo} init q || : fi -# ${csudo} update-rc.d -f taosd remove || : - ${csudo} init q || : } function clean_service() { @@ -79,7 +91,7 @@ function clean_service() { elif ((${service_mod}==1)); then clean_service_on_sysvinit else - # must manual start taosd + # must manual stop taosd kill_taosd fi } diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 6c2c6d5ea8..3c9fd6bf7f 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Script to stop the service and uninstall tdengine, but retain the config, data and log files. +# Script to stop the service and uninstall TDengine, but retain the config, data and log files. RED='\033[0;31m' GREEN='\033[1;32m' @@ -27,21 +27,27 @@ initd_mod=0 service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 -elif $(which insserv &> /dev/null); then +elif $(which service &> /dev/null); then service_mod=1 - initd_mod=1 - service_config_dir="/etc/init.d" -elif $(which update-rc.d &> /dev/null); then - service_mod=1 - initd_mod=2 - service_config_dir="/etc/init.d" + service_config_dir="/etc/init.d" + if $(which chkconfig &> /dev/null); then + initd_mod=1 + elif $(which insserv &> /dev/null); then + initd_mod=2 + elif $(which update-rc.d &> /dev/null); then + initd_mod=3 + else + service_mod=2 + fi else service_mod=2 fi function kill_taosd() { pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - ${csudo} kill -9 ${pid} || : + if [ -n "$pid" ]; then + ${csudo} kill -9 $pid || : + fi } function clean_bin() { @@ -87,20 +93,27 @@ function clean_service_on_systemd() { } function clean_service_on_sysvinit() { - restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" + #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof taosd &> /dev/null; then + echo "TDengine taosd is running, stopping it..." ${csudo} service taosd stop || : fi - ${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : - ${csudo} rm -f ${service_config_dir}/taosd || : if ((${initd_mod}==1)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} insserv -r taosd || : + ${csudo} chkconfig --del taosd || : elif ((${initd_mod}==2)); then - ${csudo} grep -q -F "taos" /etc/inittab && ${csudo} update-rc.d -f taosd remove || : + ${csudo} insserv -r taosd || : + elif ((${initd_mod}==3)); then + ${csudo} update-rc.d -f taosd remove || : + fi + + ${csudo} rm -f ${service_config_dir}/taosd || : + + if $(which init &> /dev/null); then + ${csudo} init q || : fi -# ${csudo} update-rc.d -f taosd remove || : - ${csudo} init q || : } function clean_service() { @@ -109,7 +122,7 @@ function clean_service() { elif ((${service_mod}==1)); then clean_service_on_sysvinit else - # must manual start taosd + # must manual stop taosd kill_taosd fi } @@ -140,4 +153,4 @@ elif echo $osinfo | grep -qwi "centos" ; then ${csudo} rpm -e --noscripts tdengine || : fi -echo -e "${GREEN}TDEngine is removed successfully!${NC}" +echo -e "${GREEN}TDengine is removed successfully!${NC}" diff --git a/packaging/tools/remove_client.sh b/packaging/tools/remove_client.sh new file mode 100755 index 0000000000..206de34c1f --- /dev/null +++ b/packaging/tools/remove_client.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# +# Script to stop the client and uninstall database, but retain the config and log files. +set -e +# set -x + +RED='\033[0;31m' +GREEN='\033[1;32m' +NC='\033[0m' + +#install main path +install_main_dir="/usr/local/taos" + +log_link_dir="/usr/local/taos/log" +cfg_link_dir="/usr/local/taos/cfg" +bin_link_dir="/usr/bin" +lib_link_dir="/usr/lib" +inc_link_dir="/usr/include" + +csudo="" +if command -v sudo > /dev/null; then + csudo="sudo" +fi + +function kill_client() { + #pid=$(ps -ef | grep "taos" | grep -v "grep" | awk '{print $2}') + if [ -n "$(pidof taos)" ]; then + ${csudo} kill -9 $pid || : + fi +} + +function clean_bin() { + # Remove link + ${csudo} rm -f ${bin_link_dir}/taos || : + ${csudo} rm -f ${bin_link_dir}/taosump || : + ${csudo} rm -f ${bin_link_dir}/rmtaos || : +} + +function clean_lib() { + # Remove link + ${csudo} rm -f ${lib_link_dir}/libtaos.* || : +} + +function clean_header() { + # Remove link + ${csudo} rm -f ${inc_link_dir}/taos.h || : + ${csudo} rm -f ${inc_link_dir}/taoserror.h || : +} + +function clean_config() { + # Remove link + ${csudo} rm -f ${cfg_link_dir}/* || : +} + +function clean_log() { + # Remove link + ${csudo} rm -rf ${log_link_dir} || : +} + +# Stop client. +kill_client +# Remove binary file and links +clean_bin +# Remove header file. +clean_header +# Remove lib file +clean_lib +# Remove link log directory +clean_log +# Remove link configuration file +clean_config + +${csudo} rm -rf ${install_main_dir} + +echo -e "${GREEN}TDengine client is removed successfully!${NC}" From 026d0b499bd8d4685876e0ad3bc9d987b51de541 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 22 Nov 2019 14:18:41 +0800 Subject: [PATCH 21/42] [TBASE-1128] --- src/modules/http/src/httpServer.c | 4 ++-- src/modules/http/src/httpSystem.c | 2 +- src/modules/monitor/src/monitorSystem.c | 4 ++-- src/rpc/src/tudp.c | 3 ++- src/system/detail/src/dnodeSystem.c | 2 ++ src/system/detail/src/vnodeCommit.c | 2 +- src/system/detail/src/vnodeShell.c | 2 +- src/system/lite/src/dnodeMgmt.spec.c | 2 ++ 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/modules/http/src/httpServer.c b/src/modules/http/src/httpServer.c index 333b770a5f..01d3ef40f2 100644 --- a/src/modules/http/src/httpServer.c +++ b/src/modules/http/src/httpServer.c @@ -527,8 +527,8 @@ void httpAcceptHttpConnection(void *arg) { totalFds += pServer->pThreads[i].numOfFds; } - if (totalFds > tsHttpCacheSessions * 20) { - httpError("fd:%d, ip:%s:%u, totalFds:%d larger than httpCacheSessions:%d*20, refuse connection", + if (totalFds > tsHttpCacheSessions * 100) { + httpError("fd:%d, ip:%s:%u, totalFds:%d larger than httpCacheSessions:%d*100, refuse connection", connFd, inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), totalFds, tsHttpCacheSessions); taosCloseSocket(connFd); continue; diff --git a/src/modules/http/src/httpSystem.c b/src/modules/http/src/httpSystem.c index 93d2b1d2cd..25ab55aed9 100644 --- a/src/modules/http/src/httpSystem.c +++ b/src/modules/http/src/httpSystem.c @@ -89,7 +89,7 @@ int httpStartSystem() { } if (httpServer->timerHandle == NULL) { - httpServer->timerHandle = taosTmrInit(tsHttpCacheSessions * 20 + 100, 200, 60000, "http"); + httpServer->timerHandle = taosTmrInit(tsHttpCacheSessions * 100 + 100, 200, 60000, "http"); } if (httpServer->timerHandle == NULL) { httpError("http init timer failed"); diff --git a/src/modules/monitor/src/monitorSystem.c b/src/modules/monitor/src/monitorSystem.c index 4d6577c8f3..4a8d17cda6 100644 --- a/src/modules/monitor/src/monitorSystem.c +++ b/src/modules/monitor/src/monitorSystem.c @@ -246,9 +246,9 @@ void monitorStopSystem() { } #ifdef CLUSTER - monitorLPrint("dnode:%s is stopped", tsPrivateIp); + monitorLPrint("dnode:%s monitor module is stopped", tsPrivateIp); #else - monitorLPrint("dnode:%s is stopped", tsInternalIp); + monitorLPrint("dnode:%s monitor module is stopped", tsInternalIp); #endif monitor->state = MONITOR_STATE_STOPPED; taosLogFp = NULL; diff --git a/src/rpc/src/tudp.c b/src/rpc/src/tudp.c index 7a4961f90c..58a893f074 100644 --- a/src/rpc/src/tudp.c +++ b/src/rpc/src/tudp.c @@ -506,6 +506,8 @@ void *taosInitUdpConnection(char *ip, short port, char *label, int threads, void pConn->localPort = (int16_t)ntohs(sin.sin_port); } + strcpy(pConn->label, label); + if (pthread_create(&pConn->thread, &thAttr, taosRecvUdpData, pConn) != 0) { tError("%s failed to create thread to process UDP data, reason:%s", label, strerror(errno)); taosCloseSocket(pConn->fd); @@ -513,7 +515,6 @@ void *taosInitUdpConnection(char *ip, short port, char *label, int threads, void return NULL; } - strcpy(pConn->label, label); pConn->shandle = shandle; pConn->processData = fp; pConn->index = i; diff --git a/src/system/detail/src/dnodeSystem.c b/src/system/detail/src/dnodeSystem.c index 8815a8f42d..05a7bef486 100644 --- a/src/system/detail/src/dnodeSystem.c +++ b/src/system/detail/src/dnodeSystem.c @@ -136,6 +136,8 @@ int dnodeInitSystem() { return -1; } + vnodeInitMgmtIp(); + tsPrintGlobalConfig(); dPrint("Server IP address is:%s", tsInternalIp); diff --git a/src/system/detail/src/vnodeCommit.c b/src/system/detail/src/vnodeCommit.c index 73c891f7bb..70c4cfe280 100644 --- a/src/system/detail/src/vnodeCommit.c +++ b/src/system/detail/src/vnodeCommit.c @@ -235,7 +235,7 @@ int vnodeInitCommit(int vnode) { } pVnode->pWrite += size; - dTrace("vid:%d, commit log is initialized", vnode); + dPrint("vid:%d, commit log is initialized", vnode); return 0; } diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c index 9000a7df78..d39fda8042 100644 --- a/src/system/detail/src/vnodeShell.c +++ b/src/system/detail/src/vnodeShell.c @@ -178,7 +178,7 @@ int vnodeOpenShellVnode(int vnode) { return -1; } - dTrace("vid:%d, sessions:%d, shell is opened", vnode, pCfg->maxSessions); + dPrint("vid:%d, sessions:%d, shell is opened", vnode, pCfg->maxSessions); return TSDB_CODE_SUCCESS; } diff --git a/src/system/lite/src/dnodeMgmt.spec.c b/src/system/lite/src/dnodeMgmt.spec.c index 6c424a85af..e40b21ab83 100644 --- a/src/system/lite/src/dnodeMgmt.spec.c +++ b/src/system/lite/src/dnodeMgmt.spec.c @@ -90,4 +90,6 @@ void vnodeProcessMsgFromMgmtSpec(SSchedMsg *sched) { int vnodeInitMgmt() { return 0; } +void vnodeInitMgmtIp() {} + int vnodeSaveCreateMsgIntoQueue(SVnodeObj *pVnode, char *pMsg, int msgLen) { return 0; } \ No newline at end of file From fe632ad6d8626578aeca4e08d422f36cdb278245 Mon Sep 17 00:00:00 2001 From: localvar Date: Fri, 22 Nov 2019 09:58:57 +0000 Subject: [PATCH 22/42] fix TBASE-1217 --- src/util/src/ttimer.c | 56 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index a1a356b13b..e278f5b9f8 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -14,6 +14,7 @@ */ #include "os.h" +#include #include "tlog.h" #include "tsched.h" #include "ttime.h" @@ -253,13 +254,13 @@ static void processExpiredTimer(void* handle, void* arg) { timer->executedBy = taosGetPthreadId(); uint8_t state = atomic_val_compare_exchange_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_EXPIRED); if (state == TIMER_STATE_WAITING) { - const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] execution start."; + const char* fmt = "%s timer[id=" PRIuPTR ", fp=%p, param=%p] execution start."; tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); (*timer->fp)(timer->param, (tmr_h)timer->id); atomic_store_8(&timer->state, TIMER_STATE_STOPPED); - fmt = "%s timer[id=%lld, fp=%p, param=%p] execution end."; + fmt = "%s timer[id=" PRIuPTR ", fp=%p, param=%p] execution end."; tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); } removeTimer(timer->id); @@ -267,7 +268,7 @@ static void processExpiredTimer(void* handle, void* arg) { } static void addToExpired(tmr_obj_t* head) { - const char* fmt = "%s adding expired timer[id=%lld, fp=%p, param=%p] to queue."; + const char* fmt = "%s adding expired timer[id=" PRIuPTR ", fp=%p, param=%p] to queue."; while (head != NULL) { uintptr_t id = head->id; @@ -281,7 +282,7 @@ static void addToExpired(tmr_obj_t* head) { schedMsg.thandle = NULL; taosScheduleTask(tmrQhandle, &schedMsg); - tmrTrace("timer[id=%lld] has been added to queue.", id); + tmrTrace("timer[id=" PRIuPTR "] has been added to queue.", id); head = next; } } @@ -295,7 +296,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon timer->ctrl = ctrl; addTimer(timer); - const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] started"; + const char* fmt = "%s timer[id=" PRIuPTR ", fp=%p, param=%p] started"; tmrTrace(fmt, ctrl->label, timer->id, timer->fp, timer->param); if (mseconds == 0) { @@ -380,40 +381,37 @@ static void taosTimerLoopFunc(int signo) { } static bool doStopTimer(tmr_obj_t* timer, uint8_t state) { - bool reusable = false; - if (state == TIMER_STATE_WAITING) { + bool reusable = false; if (removeFromWheel(timer)) { removeTimer(timer->id); // only safe to reuse the timer when timer is removed from the wheel. // we cannot guarantee the thread safety of the timr in all other cases. reusable = true; } - const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] is cancelled."; + const char* fmt = "%s timer[id=" PRIuPTR ", fp=%p, param=%p] is cancelled."; tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); - } else if (state != TIMER_STATE_EXPIRED) { + return reusable; + } + + if (state != TIMER_STATE_EXPIRED) { // timer already stopped or cancelled, has nothing to do in this case - } else if (timer->executedBy == taosGetPthreadId()) { + return false; + } + + if (timer->executedBy == taosGetPthreadId()) { // taosTmrReset is called in the timer callback, should do nothing in this // case to avoid dead lock. note taosTmrReset must be the last statement // of the callback funtion, will be a bug otherwise. - } else { - assert(timer->executedBy != taosGetPthreadId()); - - const char* fmt = "%s timer[id=%lld, fp=%p, param=%p] fired, waiting..."; - tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); - - for (int i = 1; atomic_load_8(&timer->state) != TIMER_STATE_STOPPED; i++) { - if (i % 1000 == 0) { - sched_yield(); - } - } - - fmt = "%s timer[id=%lld, fp=%p, param=%p] stopped."; - tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); + return false; } - - return reusable; + + // timer callback is executing in another thread, we SHOULD wait it to stop, + // BUT this may result in dead lock if current thread are holding a lock which + // the timer callback need to acquire. so, we HAVE TO return directly. + const char* fmt = "%s timer[id=" PRIuPTR ", fp=%p, param=%p] is executing and cannot be stopped."; + tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); + return false; } bool taosTmrStop(tmr_h timerId) { @@ -421,7 +419,7 @@ bool taosTmrStop(tmr_h timerId) { tmr_obj_t* timer = findTimer(id); if (timer == NULL) { - tmrTrace("timer[id=%lld] does not exist", id); + tmrTrace("timer[id=" PRIuPTR "] does not exist", id); return false; } @@ -448,7 +446,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle, bool stopped = false; tmr_obj_t* timer = findTimer(id); if (timer == NULL) { - tmrTrace("%s timer[id=%lld] does not exist", ctrl->label, id); + tmrTrace("%s timer[id=" PRIuPTR "] does not exist", ctrl->label, id); } else { uint8_t state = atomic_val_compare_exchange_8(&timer->state, TIMER_STATE_WAITING, TIMER_STATE_CANCELED); if (!doStopTimer(timer, state)) { @@ -463,7 +461,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle, return stopped; } - tmrTrace("%s timer[id=%lld] is reused", ctrl->label, timer->id); + tmrTrace("%s timer[id=" PRIuPTR "] is reused", ctrl->label, timer->id); // wait until there's no other reference to this timer, // so that we can reuse this timer safely. From ada94e72d259d23ebc97af2246296f9f9870aabe Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 22 Nov 2019 19:23:49 +0800 Subject: [PATCH 23/42] [TBASE-1128] --- src/inc/taosmsg.h | 2 +- src/sdb/src/sdbEngine.c | 65 ++++++++++++++++------------ src/system/detail/src/mgmtDnodeInt.c | 21 ++++++++- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index e75404ad98..e59db1debf 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -583,7 +583,7 @@ typedef struct { int64_t compStorage; int64_t pointsWritten; uint8_t syncStatus; - uint8_t reserved; + uint8_t reserved[15]; } SVnodeLoad; typedef struct { diff --git a/src/sdb/src/sdbEngine.c b/src/sdb/src/sdbEngine.c index 326e9a4df2..e0a61f91c5 100644 --- a/src/sdb/src/sdbEngine.c +++ b/src/sdb/src/sdbEngine.c @@ -24,7 +24,12 @@ extern char version[]; const int16_t sdbFileVersion = 0; int sdbExtConns = 0; + +#ifdef CLUSTER +int sdbMaster = 0; +#else int sdbMaster = 1; +#endif void *(*sdbInitIndexFp[])(int maxRows, int dataSize) = {sdbOpenStrHash, sdbOpenIntHash, sdbOpenIntHash}; @@ -98,7 +103,7 @@ int sdbOpenSdbFile(SSdbTable *pTable) { pTable->header.swVersion = swVersion.iversion; pTable->header.sdbFileVersion = sdbFileVersion; if (taosCalcChecksumAppend(0, (uint8_t *)(&pTable->header), size) < 0) { - sdbError("failed to get file header checksum, file: %s", pTable->fn); + sdbError("failed to get file header checksum, file:%s", pTable->fn); tclose(pTable->fd); return -1; } @@ -120,17 +125,17 @@ int sdbOpenSdbFile(SSdbTable *pTable) { ssize_t tsize = read(pTable->fd, &(pTable->header), size); if (tsize < size) { - sdbError("failed to read sdb file header, file: %s", pTable->fn); + sdbError("failed to read sdb file header, file:%s", pTable->fn); tclose(pTable->fd); return -1; } if (pTable->header.swVersion != swVersion.iversion) { - sdbWarn("sdb file %s version not match software version", pTable->fn); + sdbWarn("sdb file:%s version not match software version", pTable->fn); } if (!taosCheckChecksumWhole((uint8_t *)(&pTable->header), size)) { - sdbError("sdb file header is broken since checksum mismatch, file: %s", pTable->fn); + sdbError("sdb file header is broken since checksum mismatch, file:%s", pTable->fn); tclose(pTable->fd); return -1; } @@ -173,17 +178,19 @@ int sdbInitTableByFile(SSdbTable *pTable) { total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); SRowHead *rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { - sdbError("failed to allocate row head memory, sdb: %s", pTable->name); + sdbError("failed to allocate row head memory, sdb:%s", pTable->name); return -1; } + sdbTrace("open sdb file:%s for read", pTable->fn); + // Loop to read sdb file row by row while (1) { memset(rowHead, 0, total_size); bytes = read(pTable->fd, rowHead, sizeof(SRowHead)); if (bytes < 0) { - sdbError("failed to read sdb file: %s", pTable->fn); + sdbError("failed to read sdb file:%s", pTable->fn); goto sdb_exit1; } @@ -196,8 +203,8 @@ int sdbInitTableByFile(SSdbTable *pTable) { } if (rowHead->rowSize < 0 || rowHead->rowSize > pTable->maxRowSize) { - sdbError("error row size in sdb file: %s rowSize: %d maxRowSize: %d", pTable->fn, rowHead->rowSize, - pTable->maxRowSize); + sdbError("error row size in sdb file:%s, id:%d rowSize:%d maxRowSize:%d", + pTable->fn, rowHead->id, rowHead->rowSize, pTable->maxRowSize); pTable->size += sizeof(SRowHead); continue; } @@ -208,13 +215,13 @@ int sdbInitTableByFile(SSdbTable *pTable) { bytes = read(pTable->fd, rowHead->data, rowHead->rowSize + sizeof(TSCKSUM)); if (bytes < rowHead->rowSize + sizeof(TSCKSUM)) { // TODO: Here may cause pTable->size not end of the file - sdbError("failed to read sdb file: %s id: %d rowSize: %d", pTable->fn, rowHead->id, rowHead->rowSize); + sdbError("failed to read sdb file:%s id:%d rowSize:%d", pTable->fn, rowHead->id, rowHead->rowSize); break; } real_size = sizeof(SRowHead) + rowHead->rowSize + sizeof(TSCKSUM); if (!taosCheckChecksumWhole((uint8_t *)rowHead, real_size)) { - sdbError("error sdb checksum, sdb: %s id: %d, skip", pTable->name, rowHead->id); + sdbError("error sdb checksum, sdb:%s id:%d, skip", pTable->name, rowHead->id); pTable->size += real_size; continue; } @@ -225,7 +232,7 @@ int sdbInitTableByFile(SSdbTable *pTable) { if (pMetaRow == NULL) { // New object if (rowHead->id < 0) { /* assert(0); */ - sdbError("error sdb negative id: %d, sdb: %s, skip", rowHead->id, pTable->name); + sdbError("error sdb negative id:%d, sdb:%s, skip", rowHead->id, pTable->name); } else { rowMeta.id = rowHead->id; // TODO: Get rid of the rowMeta.offset and rowSize @@ -366,7 +373,7 @@ int64_t sdbInsertRow(void *handle, void *row, int rowSize) { pTable->id++; sdbVersion++; if (pTable->keyType == SDB_KEYTYPE_AUTO) { - // TODO: here need to change + // TODO:here need to change *((uint32_t *)pObj) = ++pTable->autoIndex; (*(pTable->appTool))(SDB_TYPE_ENCODE, pObj, rowHead->data, pTable->maxRowSize, &(rowHead->rowSize)); } @@ -376,7 +383,7 @@ int64_t sdbInsertRow(void *handle, void *row, int rowSize) { rowHead->delimiter = SDB_DELIMITER; rowHead->id = pTable->id; if (taosCalcChecksumAppend(0, (uint8_t *)rowHead, real_size) < 0) { - sdbError("failed to get checksum while inserting, sdb: %s", pTable->name); + sdbError("failed to get checksum while inserting, sdb:%s", pTable->name); pthread_mutex_unlock(&pTable->mutex); tfree(rowHead); return -1; @@ -470,7 +477,7 @@ int sdbDeleteRow(void *handle, void *row) { total_size = sizeof(SRowHead) + rowSize + sizeof(TSCKSUM); rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { - sdbError("failed to allocate row head memory, sdb: %s", pTable->name); + sdbError("failed to allocate row head memory, sdb:%s", pTable->name); return -1; } memset(rowHead, 0, total_size); @@ -486,7 +493,7 @@ int sdbDeleteRow(void *handle, void *row) { rowHead->id = -(pTable->id); memcpy(rowHead->data, row, rowSize); if (taosCalcChecksumAppend(0, (uint8_t *)rowHead, total_size) < 0) { - sdbError("failed to get checksum while inserting, sdb: %s", pTable->name); + sdbError("failed to get checksum while inserting, sdb:%s", pTable->name); pthread_mutex_unlock(&pTable->mutex); tfree(rowHead); return -1; @@ -498,7 +505,7 @@ int sdbDeleteRow(void *handle, void *row) { sdbFinishCommit(pTable); pTable->numOfRows--; - // TODO: Change the update list here + // TODO:Change the update list here sdbAddIntoUpdateList(pTable, SDB_TYPE_DELETE, pMetaRow); switch (pTable->keyType) { case SDB_KEYTYPE_STRING: @@ -556,7 +563,7 @@ int sdbUpdateRow(void *handle, void *row, int updateSize, char isUpdated) { total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); SRowHead *rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { - sdbError("failed to allocate row head memory, sdb: %s", pTable->name); + sdbError("failed to allocate row head memory, sdb:%s", pTable->name); return -1; } memset(rowHead, 0, total_size); @@ -585,7 +592,7 @@ int sdbUpdateRow(void *handle, void *row, int updateSize, char isUpdated) { rowHead->delimiter = SDB_DELIMITER; rowHead->id = pTable->id; if (taosCalcChecksumAppend(0, (uint8_t *)rowHead, real_size) < 0) { - sdbError("failed to get checksum, sdb: %s id: %d", pTable->name, rowHead->id); + sdbError("failed to get checksum, sdb:%s id:%d", pTable->name, rowHead->id); pthread_mutex_unlock(&pTable->mutex); tfree(rowHead); return -1; @@ -640,7 +647,7 @@ int sdbBatchUpdateRow(void *handle, void *row, int rowSize) { if (pTable == NULL || row == NULL || rowSize <= 0) return -1; pMeta = sdbGetRowMeta(handle, row); if (pMeta == NULL) { - sdbTrace("table: %s, record is not there, batch update failed", pTable->name); + sdbTrace("table:%s, record is not there, batch update failed", pTable->name); return -1; } @@ -650,7 +657,7 @@ int sdbBatchUpdateRow(void *handle, void *row, int rowSize) { total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); SRowHead *rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { - sdbError("failed to allocate row head memory, sdb: %s", pTable->name); + sdbError("failed to allocate row head memory, sdb:%s", pTable->name); return -1; } @@ -748,12 +755,14 @@ void sdbResetTable(SSdbTable *pTable) { return; } + sdbTrace("open sdb file:%s for update", pTable->fn); + while (1) { memset(rowHead, 0, total_size); bytes = read(pTable->fd, rowHead, sizeof(SRowHead)); if (bytes < 0) { - sdbError("failed to read sdb file: %s", pTable->fn); + sdbError("failed to read sdb file:%s", pTable->fn); tfree(rowHead); return; } @@ -767,7 +776,7 @@ void sdbResetTable(SSdbTable *pTable) { } if (rowHead->rowSize < 0 || rowHead->rowSize > pTable->maxRowSize) { - sdbError("error row size in sdb file: %s rowSize: %d maxRowSize: %d", pTable->fn, rowHead->rowSize, + sdbError("error row size in sdb file:%s rowSize:%d maxRowSize:%d", pTable->fn, rowHead->rowSize, pTable->maxRowSize); pTable->size += sizeof(SRowHead); continue; @@ -775,13 +784,13 @@ void sdbResetTable(SSdbTable *pTable) { bytes = read(pTable->fd, rowHead->data, rowHead->rowSize + sizeof(TSCKSUM)); if (bytes < rowHead->rowSize + sizeof(TSCKSUM)) { - sdbError("failed to read sdb file: %s id: %d rowSize: %d", pTable->fn, rowHead->id, rowHead->rowSize); + sdbError("failed to read sdb file:%s id:%d rowSize:%d", pTable->fn, rowHead->id, rowHead->rowSize); break; } real_size = sizeof(SRowHead) + rowHead->rowSize + sizeof(TSCKSUM); if (!taosCheckChecksumWhole((uint8_t *)rowHead, real_size)) { - sdbError("error sdb checksum, sdb: %s id: %d, skip", pTable->name, rowHead->id); + sdbError("error sdb checksum, sdb:%s id:%d, skip", pTable->name, rowHead->id); pTable->size += real_size; continue; } @@ -790,10 +799,10 @@ void sdbResetTable(SSdbTable *pTable) { pMetaRow = sdbGetRow(pTable, rowHead->data); if (pMetaRow == NULL) { // New object if (rowHead->id < 0) { - sdbError("error sdb negative id: %d, sdb: %s, skip", rowHead->id, pTable->name); + sdbError("error sdb negative id:%d, sdb:%s, skip", rowHead->id, pTable->name); } else { rowMeta.id = rowHead->id; - // TODO: Get rid of the rowMeta.offset and rowSize + // TODO:Get rid of the rowMeta.offset and rowSize rowMeta.offset = pTable->size; rowMeta.rowSize = rowHead->rowSize; rowMeta.row = (*(pTable->appTool))(SDB_TYPE_DECODE, NULL, rowHead->data, rowHead->rowSize, NULL); @@ -826,7 +835,7 @@ void sdbResetTable(SSdbTable *pTable) { sdbTrace("table:%s is updated, sdbVerion:%ld id:%ld", pTable->name, sdbVersion, pTable->id); } -// TODO: A problem here : use snapshot file to sync another node will cause +// TODO:A problem here :use snapshot file to sync another node will cause // problem void sdbSaveSnapShot(void *handle) { SSdbTable *pTable = (SSdbTable *)handle; @@ -856,7 +865,7 @@ void sdbSaveSnapShot(void *handle) { total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); SRowHead *rowHead = (SRowHead *)malloc(total_size); if (rowHead == NULL) { - sdbError("failed to allocate memory while saving SDB snapshot, sdb: %s", pTable->name); + sdbError("failed to allocate memory while saving SDB snapshot, sdb:%s", pTable->name); return; } memset(rowHead, 0, size); diff --git a/src/system/detail/src/mgmtDnodeInt.c b/src/system/detail/src/mgmtDnodeInt.c index 6390b7009f..a58f48ead1 100644 --- a/src/system/detail/src/mgmtDnodeInt.c +++ b/src/system/detail/src/mgmtDnodeInt.c @@ -43,6 +43,11 @@ int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { SMeterCfgMsg *pCfg = (SMeterCfgMsg *)cont; SVgObj * pVgroup; + if (!sdbMaster) { + taosSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_METER_CFG_RSP, TSDB_CODE_REDIRECT); + return 0; + } + int vnode = htonl(pCfg->vnode); int sid = htonl(pCfg->sid); @@ -51,6 +56,7 @@ int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { taosSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_METER_CFG_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); return 0; } + pMsg = pStart; if (vnode < pObj->numOfVnodes) { @@ -87,10 +93,18 @@ int mgmtProcessVpeerCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { SVpeerCfgMsg *pCfg = (SVpeerCfgMsg *)cont; SVgObj * pVgroup = NULL; + if (!sdbMaster) { + taosSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VPEER_CFG_RSP, TSDB_CODE_REDIRECT); + return 0; + } + int vnode = htonl(pCfg->vnode); pStart = taosBuildRspMsgToDnode(pObj, TSDB_MSG_TYPE_VPEER_CFG_RSP); - if (pStart == NULL) return 0; + if (pStart == NULL) { + taosSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VPEER_CFG_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); + return 0; + } pMsg = pStart; if (vnode < pObj->numOfVnodes) pVgroup = mgmtGetVgroup(pObj->vload[vnode].vgId); @@ -121,6 +135,11 @@ int mgmtProcessFreeVnodeRsp(char *msg, int msgLen, SDnodeObj *pObj) { return 0; int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) { STaosRsp *pRsp = (STaosRsp *)msg; + if (!sdbMaster) { + taosSendSimpleRspToDnode(pObj, TSDB_MSG_TYPE_VPEERS_RSP, TSDB_CODE_REDIRECT); + return 0; + } + SDbObj *pDb = mgmtGetDb(pRsp->more); if (!pDb) { mError("dnode:%s, db not find, code:%d", taosIpStr(pObj->privateIp), pRsp->code); From 87ab685471d12b6c8c45f1a388e38d808c134b14 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 22 Nov 2019 20:01:22 +0800 Subject: [PATCH 24/42] [TBASE-1128] --- src/system/lite/src/mgmtBalance.spec.c | 3 ++- src/system/lite/src/mgmtDnode.spec.c | 1 + src/system/lite/src/mgmtDnodeInt.spec.c | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/system/lite/src/mgmtBalance.spec.c b/src/system/lite/src/mgmtBalance.spec.c index 7fbc863391..91a93fd1d9 100644 --- a/src/system/lite/src/mgmtBalance.spec.c +++ b/src/system/lite/src/mgmtBalance.spec.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "mgmtBalance.h" +#include "tstatus.h" void mgmtStartBalanceTimer(int mseconds) {} @@ -28,7 +29,7 @@ int mgmtAllocVnodes(SVgObj *pVgroup) { for (int i = 0; i < pDnode->numOfVnodes; i++) { int vnode = (i + pDnode->lastAllocVnode) % pDnode->numOfVnodes; - if (pDnode->vload[vnode].vgId == 0 && pDnode->vload[vnode].status == TSDB_VN_STATUS_READY) { + if (pDnode->vload[vnode].vgId == 0 && pDnode->vload[vnode].status == TSDB_VN_STATUS_OFFLINE) { selectedVnode = vnode; break; } diff --git a/src/system/lite/src/mgmtDnode.spec.c b/src/system/lite/src/mgmtDnode.spec.c index 84c33d7a63..fa14dc1cb8 100644 --- a/src/system/lite/src/mgmtDnode.spec.c +++ b/src/system/lite/src/mgmtDnode.spec.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "mgmt.h" +#include "tstatus.h" SDnodeObj dnodeObj; extern uint32_t tsRebootTime; diff --git a/src/system/lite/src/mgmtDnodeInt.spec.c b/src/system/lite/src/mgmtDnodeInt.spec.c index f994cc63d0..b99815844d 100644 --- a/src/system/lite/src/mgmtDnodeInt.spec.c +++ b/src/system/lite/src/mgmtDnodeInt.spec.c @@ -23,6 +23,7 @@ #include "tutil.h" #include "vnode.h" #include "tsystem.h" +#include "tstatus.h" extern void *dmQhandle; void * mgmtStatusTimer = NULL; @@ -93,7 +94,7 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { SVnodeObj * pVnode = vnodeList + vnode; // wait vnode dropped - if (pVload->dropStatus == TSDB_VN_STATUS_DROPPING) { + if (pVload->dropStatus == TSDB_VN_DROP_STATUS_DROPPING) { if (vnodeList[vnode].cfg.maxSessions <= 0) { pVload->dropStatus = TSDB_VN_DROP_STATUS_READY; pVload->status = TSDB_VN_STATUS_OFFLINE; @@ -116,7 +117,7 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { SVgObj *pVgroup = mgmtGetVgroup(vgId); if (pVgroup == NULL) { mError("vgroup:%d is not there, but associated with vnode %d", vgId, vnode); - pVload->dropStatus = TSDB_VN_STATUS_DROPPING; + pVload->dropStatus = TSDB_VN_DROP_STATUS_DROPPING; continue; } @@ -126,9 +127,9 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) { continue; } - if (pVload->vgId == 0 || pVload->dropStatus == TSDB_VN_STATUS_DROPPING) { + if (pVload->vgId == 0 || pVload->dropStatus == TSDB_VN_DROP_STATUS_DROPPING) { mError("vid:%d, mgmt not exist, drop it", vnode); - pVload->dropStatus = TSDB_VN_STATUS_DROPPING; + pVload->dropStatus = TSDB_VN_DROP_STATUS_DROPPING; } } From 862e8ee00ba9a39ec2184b7918d369a3a3bc2ee5 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 22 Nov 2019 23:22:13 +0800 Subject: [PATCH 25/42] [TBASE-1128] --- src/system/detail/src/mgmtDb.c | 2 +- src/system/lite/src/mgmtBalance.spec.c | 6 +++--- src/system/lite/src/mgmtDnode.spec.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index 01b5c00a83..ba1b966cfb 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -142,7 +142,7 @@ int mgmtCheckDbParams(SCreateDbMsg *pCreate) { if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; // //-1 for balance - if (pCreate->replications <= 0 || pCreate->replications > TSDB_REPLICA_MAX_NUM) { + if (pCreate->replications < 0 || pCreate->replications > TSDB_REPLICA_MAX_NUM) { mTrace("invalid db option replications: %d", pCreate->replications); return TSDB_CODE_INVALID_OPTION; } diff --git a/src/system/lite/src/mgmtBalance.spec.c b/src/system/lite/src/mgmtBalance.spec.c index 91a93fd1d9..3d2f10dcbb 100644 --- a/src/system/lite/src/mgmtBalance.spec.c +++ b/src/system/lite/src/mgmtBalance.spec.c @@ -26,9 +26,10 @@ void mgmtCleanupBalance() {} int mgmtAllocVnodes(SVgObj *pVgroup) { int selectedVnode = -1; SDnodeObj *pDnode = &dnodeObj; + int lastAllocVode = pDnode->lastAllocVnode; for (int i = 0; i < pDnode->numOfVnodes; i++) { - int vnode = (i + pDnode->lastAllocVnode) % pDnode->numOfVnodes; + int vnode = (i + lastAllocVode) % pDnode->numOfVnodes; if (pDnode->vload[vnode].vgId == 0 && pDnode->vload[vnode].status == TSDB_VN_STATUS_OFFLINE) { selectedVnode = vnode; break; @@ -39,8 +40,7 @@ int mgmtAllocVnodes(SVgObj *pVgroup) { mError("vgroup:%d alloc vnode failed, free vnodes:%d", pVgroup->vgId, pDnode->numOfFreeVnodes); return -1; } else { - mTrace("vgroup:%d allocate vnode:%d, last allocated vnode:%d", pVgroup->vgId, selectedVnode, - pDnode->lastAllocVnode); + mTrace("vgroup:%d allocate vnode:%d, last allocated vnode:%d", pVgroup->vgId, selectedVnode, lastAllocVode); pVgroup->vnodeGid[0].vnode = selectedVnode; pDnode->lastAllocVnode = selectedVnode + 1; if (pDnode->lastAllocVnode >= pDnode->numOfVnodes) pDnode->lastAllocVnode = 0; diff --git a/src/system/lite/src/mgmtDnode.spec.c b/src/system/lite/src/mgmtDnode.spec.c index fa14dc1cb8..dc7dd7d472 100644 --- a/src/system/lite/src/mgmtDnode.spec.c +++ b/src/system/lite/src/mgmtDnode.spec.c @@ -37,7 +37,7 @@ int mgmtInitDnodes() { dnodeObj.thandle = (void*)(1); //hack way if (dnodeObj.numOfVnodes == TSDB_INVALID_VNODE_NUM) { mgmtSetDnodeMaxVnodes(&dnodeObj); - mPrint("first access, set total vnodes:%d", dnodeObj.numOfVnodes); + mPrint("dnode first access, set total vnodes:%d", dnodeObj.numOfVnodes); } return 0; } From 1414e2ee104920ceaaf5325129766c02731e8389 Mon Sep 17 00:00:00 2001 From: slguan Date: Sat, 23 Nov 2019 09:44:37 +0800 Subject: [PATCH 26/42] [TBASE-1221] --- src/inc/taosmsg.h | 7 ++++++- src/system/detail/src/vnodeMeter.c | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index f62d0e6897..845090826a 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -594,7 +594,12 @@ typedef struct { // NOTE: sizeof(SVnodeCfg) < TSDB_FILE_HEADER_LEN/4 typedef struct { char acct[TSDB_USER_LEN]; - char db[TSDB_METER_ID_LEN+2]; // 8bytes align + /* + * the message is too large, so it may will overwrite the cfg information in meterobj.v* + * recover to origin codes + */ + //char db[TSDB_METER_ID_LEN+2]; // 8bytes align + char db[TSDB_DB_NAME_LEN]; uint32_t vgId; int32_t maxSessions; int32_t cacheBlockSize; diff --git a/src/system/detail/src/vnodeMeter.c b/src/system/detail/src/vnodeMeter.c index d3f672a886..4195138a29 100644 --- a/src/system/detail/src/vnodeMeter.c +++ b/src/system/detail/src/vnodeMeter.c @@ -112,7 +112,7 @@ FILE *vnodeOpenMeterObjFile(int vnode) { fp = fopen(fileName, "r+"); if (fp != NULL) { if (vnodeCheckFileIntegrity(fp) < 0) { - dError("file:%s is corrupted, need to restore it first", fileName); + dError("file:%s is corrupted, need to restore it first, exit program", fileName); fclose(fp); // todo: how to recover @@ -376,7 +376,11 @@ int vnodeOpenMetersVnode(int vnode) { fseek(fp, TSDB_FILE_HEADER_LEN * 2 / 4, SEEK_SET); fread(&pVnode->cfg, sizeof(SVnodeCfg), 1, fp); + if (vnodeIsValidVnodeCfg(&pVnode->cfg) == false) { + dError("vid:%d, maxSessions:%d cacheBlockSize:%d replications:%d daysPerFile:%d daysToKeep:%d invalid, clear it", + vnode, pVnode->cfg.maxSessions, pVnode->cfg.cacheBlockSize, pVnode->cfg.replications, + pVnode->cfg.daysPerFile, pVnode->cfg.daysToKeep); pVnode->cfg.maxSessions = 0; // error in vnode file return 0; } From b7ba65c3c1e7e2639c09584384f5a686dffdc576 Mon Sep 17 00:00:00 2001 From: Steven Li Date: Fri, 22 Nov 2019 18:47:04 -0800 Subject: [PATCH 27/42] Partial fix of #761, corrected bad characters --- .../tdenginedocs-en/super-table/index.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/documentation/tdenginedocs-en/super-table/index.html b/documentation/tdenginedocs-en/super-table/index.html index 3ebb0775b5..21e7669a19 100644 --- a/documentation/tdenginedocs-en/super-table/index.html +++ b/documentation/tdenginedocs-en/super-table/index.html @@ -6,9 +6,9 @@

Like a table, you can create, show, delete and describe STables. Most query operations on tables can be applied to STable too, including the aggregation and selector functions. For queries on a STable, if no tags filter, the operations are applied to all the tables created via this STable. If there is a tag filter, the operations are applied only to a subset of the tables which satisfy the tag filter conditions. It will be very convenient to use tags to put devices into different groups for aggregation.

Create a STable

Similiar to creating a standard table, syntax is:

-
CREATE TABLE <stable_name> (<field_name> TIMESTAMP, field_name1 field_type,…) TAGS(tag_name tag_type, …)
+
CREATE TABLE <stable_name> (<field_name> TIMESTAMP, field_name1 field_type, ...) TAGS(tag_name tag_type, ...)

New keyword "tags" is introduced, where tag_name is the tag name, and tag_type is the associated data type.

-

Note:

+

Note:

  1. The bytes of all tags together shall be less than 512
  2. Tag's data type can not be time stamp or nchar
  3. @@ -30,12 +30,12 @@ tags (location binary(20), type int) create table t4 using thermometer tags ('shanghai', 20); create table t5 using thermometer tags ('new york', 10);

    Aggregate Tables via STable

    -

    You can group a set of tables together by specifying the tags filter condition, then apply the aggregation operations. The result set can be grouped and ordered based on tag value. Syntax is:

    -
    SELECT function<field_name>,… 
    +

    You can group a set of tables together by specifying the tags filter condition, then apply the aggregation operations. The result set can be grouped and ordered based on tag value. Syntax is:

    +
    SELECT function<field_name>, ... 
      FROM <stable_name> 
    - WHERE <tag_name> <[=|<=|>=|<>] values..> ([AND|OR] …)
    + WHERE <tag_name> <[=|<=|>=|<>] values..> ([AND|OR] ...
      INTERVAL (<time range>)
    - GROUP BY <tag_name>, <tag_name>…
    + GROUP BY <tag_name>, <tag_name> ... 
      ORDER BY <tag_name> <asc|desc>
      SLIMIT <group_limit>
      SOFFSET <group_offset>
    @@ -75,9 +75,9 @@ INTERVAL(10M)
    DROP TABLE <stable_name>

    To delete a STable, all the tables created via this STable shall be deleted first, otherwise, it will fail.

    List the Associated Tables of a STable

    -
    SELECT TBNAME,[TAG_NAME,…] FROM <stable_name> WHERE <tag_name> <[=|=<|>=|<>] values..> ([AND|OR] …)
    +
    SELECT TBNAME,[TAG_NAME, ...] FROM <stable_name> WHERE <tag_name> <[=|=<|>=|<>] values..> ([AND|OR] ...)

    It will list all the tables which satisfy the tag filter conditions. The tables are all created from this specific STable. TBNAME is a new keyword introduced, it is the table name associated with the STable.

    -
    SELECT COUNT(TBNAME) FROM <stable_name> WHERE <tag_name> <[=|=<|>=|<>] values..> ([AND|OR] …)
    +
    SELECT COUNT(TBNAME) FROM <stable_name> WHERE <tag_name> <[=|=<|>=|<>] values..> ([AND|OR] ...)

    The above SQL statement will list the number of tables in a STable, which satisfy the filter condition.

    Management of Tags

    You can add, delete and change the tags for a STable, and you can change the tag value of a table. The SQL commands are listed below.

    From 30773c4ed29c3b5105fbe01ace2ad704200a4fd6 Mon Sep 17 00:00:00 2001 From: lihui Date: Sat, 23 Nov 2019 11:30:11 +0800 Subject: [PATCH 28/42] [TBASE-1215] --- src/client/src/tscServer.c | 2 +- src/system/detail/src/mgmtDb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 1f528bbda3..5b41b6966f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1807,7 +1807,7 @@ int tscBuildCreateDbMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pCreateDbMsg = (SCreateDbMsg *)pMsg; - strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); + (void)extractDBName(pMeterMetaInfo->name, pCreateDbMsg->db); // only send db name, then recombining db name + acctId on the mgmt pMsg += sizeof(SCreateDbMsg); msgLen = pMsg - pStart; diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index ba1b966cfb..a005b24779 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -256,7 +256,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { pDb = malloc(sizeof(SDbObj)); memset(pDb, 0, sizeof(SDbObj)); - strcpy(pDb->name, pCreate->db); + sprintf(pDb->name, "%s.%s", pAcct->acctId, pCreate->db); // set fullname strcpy(pCreate->acct, pAcct->user); pDb->createdTime = taosGetTimestampMs(); pDb->cfg = *pCreate; From 6eeb797cb30474516cd6bc807a79e4bbe28cea59 Mon Sep 17 00:00:00 2001 From: lihui Date: Sat, 23 Nov 2019 11:59:27 +0800 Subject: [PATCH 29/42] [TBASE-1215] --- src/system/detail/src/mgmtDb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index a005b24779..100c353a62 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -256,7 +256,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { pDb = malloc(sizeof(SDbObj)); memset(pDb, 0, sizeof(SDbObj)); - sprintf(pDb->name, "%s.%s", pAcct->acctId, pCreate->db); // set fullname + sprintf(pDb->name, "%d.%s", pAcct->acctId, pCreate->db); // set fullname strcpy(pCreate->acct, pAcct->user); pDb->createdTime = taosGetTimestampMs(); pDb->cfg = *pCreate; From 11370c913f7a60495c04aecce8e0e1062c5dcced Mon Sep 17 00:00:00 2001 From: slguan Date: Sat, 23 Nov 2019 13:47:43 +0800 Subject: [PATCH 30/42] [TBASE-1128] --- src/system/detail/inc/mgmt.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/system/detail/inc/mgmt.h b/src/system/detail/inc/mgmt.h index 27928648e5..3ec4f9ec6a 100644 --- a/src/system/detail/inc/mgmt.h +++ b/src/system/detail/inc/mgmt.h @@ -146,7 +146,10 @@ typedef struct _vg_obj { } SVgObj; typedef struct _db_obj { - char name[TSDB_METER_ID_LEN + 1]; + /* + * this length will cause the storage structure to change, rollback + */ + char name[TSDB_DB_NAME_LEN + 1]; int64_t createdTime; SDbCfg cfg; int32_t numOfVgroups; From 27657f2eb49af2c68a212b44ba7fcf0ecd7a3424 Mon Sep 17 00:00:00 2001 From: lihui Date: Sat, 23 Nov 2019 15:26:33 +0800 Subject: [PATCH 31/42] [TBASE-1215 ROLLBACK] --- src/client/src/tscServer.c | 2 +- src/system/detail/src/mgmtDb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 5b41b6966f..1f528bbda3 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1807,7 +1807,7 @@ int tscBuildCreateDbMsg(SSqlObj *pSql) { pMsg += sizeof(SMgmtHead); pCreateDbMsg = (SCreateDbMsg *)pMsg; - (void)extractDBName(pMeterMetaInfo->name, pCreateDbMsg->db); // only send db name, then recombining db name + acctId on the mgmt + strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); pMsg += sizeof(SCreateDbMsg); msgLen = pMsg - pStart; diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index 100c353a62..ba1b966cfb 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -256,7 +256,7 @@ int mgmtCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate) { pDb = malloc(sizeof(SDbObj)); memset(pDb, 0, sizeof(SDbObj)); - sprintf(pDb->name, "%d.%s", pAcct->acctId, pCreate->db); // set fullname + strcpy(pDb->name, pCreate->db); strcpy(pCreate->acct, pAcct->user); pDb->createdTime = taosGetTimestampMs(); pDb->cfg = *pCreate; From 960aae4f093398f6a972b7ab3a96cad16d0607da Mon Sep 17 00:00:00 2001 From: slguan Date: Sat, 23 Nov 2019 22:42:31 +0800 Subject: [PATCH 32/42] [TBASE-1218] --- src/system/detail/src/dnodeMgmt.c | 5 +++-- src/system/detail/src/mgmtDnodeInt.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/system/detail/src/dnodeMgmt.c b/src/system/detail/src/dnodeMgmt.c index 2d184afd41..c96be41281 100644 --- a/src/system/detail/src/dnodeMgmt.c +++ b/src/system/detail/src/dnodeMgmt.c @@ -350,8 +350,9 @@ int vnodeProcessVPeerCfg(char *msg, int msgLen, SMgmtObj *pMgmtObj) { pCfg->rowsInFileBlock = htonl(pCfg->rowsInFileBlock); if (pCfg->replications > 0) { - dPrint("vid:%d, vpeer cfg received, replica:%d session:%d, vnodeList replica:%d session:%d", - vnode, pCfg->replications, pCfg->maxSessions, vnodeList[vnode].cfg.replications, vnodeList[vnode].cfg.maxSessions); + dPrint("vid:%d, vpeer cfg received, replica:%d session:%d, vnodeList replica:%d session:%d, acct:%s db:%s", + vnode, pCfg->replications, pCfg->maxSessions, vnodeList[vnode].cfg.replications, vnodeList[vnode].cfg.maxSessions, + pCfg->acct, pCfg->db); for (i = 0; i < pCfg->replications; ++i) { pMsg->vpeerDesc[i].vnode = htonl(pMsg->vpeerDesc[i].vnode); pMsg->vpeerDesc[i].ip = htonl(pMsg->vpeerDesc[i].ip); diff --git a/src/system/detail/src/mgmtDnodeInt.c b/src/system/detail/src/mgmtDnodeInt.c index a58f48ead1..6b6571b06c 100644 --- a/src/system/detail/src/mgmtDnodeInt.c +++ b/src/system/detail/src/mgmtDnodeInt.c @@ -142,7 +142,7 @@ int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) { SDbObj *pDb = mgmtGetDb(pRsp->more); if (!pDb) { - mError("dnode:%s, db not find, code:%d", taosIpStr(pObj->privateIp), pRsp->code); + mError("dnode:%s, db:%s not find, code:%d", taosIpStr(pObj->privateIp), pRsp->more, pRsp->code); return 0; } From 5e007a8e3e43b3005442ca70f12005922aca5cc9 Mon Sep 17 00:00:00 2001 From: slguan Date: Sun, 24 Nov 2019 19:48:46 +0800 Subject: [PATCH 33/42] [TBASE-1230] --- src/os/linux/inc/os.h | 1 + src/os/linux/src/tlinux.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index 82cb439a94..e9f1737cd4 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -224,6 +224,7 @@ int64_t str2int64(char *str); void taosSetCoreDump(); +void taosBlockSIGPIPE(); #define BUILDIN_CLZL(val) __builtin_clzl(val) #define BUILDIN_CLZ(val) __builtin_clz(val) diff --git a/src/os/linux/src/tlinux.c b/src/os/linux/src/tlinux.c index 93ea014409..83782f4944 100644 --- a/src/os/linux/src/tlinux.c +++ b/src/os/linux/src/tlinux.c @@ -341,3 +341,13 @@ bool taosSkipSocketCheck() { return false; } + +void taosBlockSIGPIPE() { + sigset_t signal_mask; + sigemptyset(&signal_mask); + sigaddset(&signal_mask, SIGPIPE); + int rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); + if (rc != 0) { + pError("failed to block SIGPIPE"); + } +} From 69c8df7119f78d10f966f3a0965c60f9c4a8280b Mon Sep 17 00:00:00 2001 From: localvar Date: Mon, 25 Nov 2019 09:37:20 +0800 Subject: [PATCH 34/42] fix tbase-1233: go connector cause client crash --- src/connector/go/src/taosSql/rows.go | 15 ++++++++------- src/connector/go/src/taosSql/taosSqlCgo.go | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/connector/go/src/taosSql/rows.go b/src/connector/go/src/taosSql/rows.go index 6407fc334e..5040dca06d 100755 --- a/src/connector/go/src/taosSql/rows.go +++ b/src/connector/go/src/taosSql/rows.go @@ -118,14 +118,15 @@ func (rows *taosSqlRows) ColumnTypeScanType(i int) reflect.Type { return rows.rs.columns[i].scanType() } -func (rows *taosSqlRows) Close() (err error) { - mc := rows.mc - if mc == nil { - return nil +func (rows *taosSqlRows) Close() error { + if rows.mc != nil { + result := C.taos_use_result(rows.mc.taos) + if result != nil { + C.taos_free_result(result) + } + rows.mc = nil } - - rows.mc = nil - return err + return nil } func (rows *taosSqlRows) HasNextResultSet() (b bool) { diff --git a/src/connector/go/src/taosSql/taosSqlCgo.go b/src/connector/go/src/taosSql/taosSqlCgo.go index fcef14045f..cc3aaa1658 100755 --- a/src/connector/go/src/taosSql/taosSqlCgo.go +++ b/src/connector/go/src/taosSql/taosSqlCgo.go @@ -39,7 +39,7 @@ func (mc *taosConn) taosConnect(ip, user, pass, db string, port int) (taos unsaf defer C.free(unsafe.Pointer(cpass)) defer C.free(unsafe.Pointer(cdb)) - taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.int)(port)) + taosObj := C.taos_connect(cip, cuser, cpass, cdb, (C.ushort)(port)) if taosObj == nil { return nil, errors.New("taos_connect() fail!") } From 0457d50708c8368583929a1468ce6eba09bf4959 Mon Sep 17 00:00:00 2001 From: slguan Date: Mon, 25 Nov 2019 09:40:29 +0800 Subject: [PATCH 35/42] [TBASE-1228] --- src/system/detail/src/vnodeStore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/detail/src/vnodeStore.c b/src/system/detail/src/vnodeStore.c index ea64181577..e49a84ed5b 100644 --- a/src/system/detail/src/vnodeStore.c +++ b/src/system/detail/src/vnodeStore.c @@ -261,7 +261,7 @@ int vnodeRemoveVnode(int vnode) { if (pVnode->vnodeStatus == TSDB_VN_STATUS_CREATING || pVnode->vnodeStatus == TSDB_VN_STATUS_OFFLINE || pVnode->vnodeStatus == TSDB_VN_STATUS_DELETING) { - dError("vid:%d, status:%s, cannot enter close/delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); + dTrace("vid:%d, status:%s, cannot enter close/delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); return TSDB_CODE_ACTION_IN_PROGRESS; } else { int32_t ret = vnodeCloseVnode(vnode); From 6c2cf346933e22582552492c227c4f3c2d307ac4 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 25 Nov 2019 13:23:05 +0800 Subject: [PATCH 36/42] refactor some codes. --- src/{inc/tsql.h => client/inc/tscSQLParser.h} | 22 +- src/client/inc/tsclient.h | 2 +- src/{util => client}/src/sql.c | 6 +- src/client/src/tscAst.c | 10 +- src/client/src/tscAsync.c | 2 +- src/client/src/tscPrepare.c | 2 +- src/client/src/tscSQLParser.c | 314 ++++++++++++------ src/client/src/tscSQLParserImpl.c | 29 +- src/client/src/tscSecondaryMerge.c | 1 - src/client/src/tscServer.c | 2 +- src/client/src/tscSql.c | 2 +- src/client/src/tscStream.c | 2 +- src/client/src/tscSyntaxtreefunction.c | 2 +- src/inc/sql.y | 7 +- src/inc/tast.h | 4 +- src/inc/tsdb.h | 12 +- src/inc/tsqlfunction.h | 1 - src/inc/tstoken.h | 16 +- src/system/detail/inc/mgmtUtil.h | 1 + src/system/detail/src/mgmtDb.c | 87 +---- src/system/detail/src/mgmtUtil.c | 73 ++++ src/system/detail/src/vnodeQueryProcess.c | 2 +- src/util/src/textbuffer.c | 1 - src/util/src/tglobalcfg.c | 8 +- src/util/src/tstoken.c | 142 -------- src/util/src/ttokenizer.c | 8 +- src/util/src/ttypes.c | 3 +- 27 files changed, 382 insertions(+), 379 deletions(-) rename src/{inc/tsql.h => client/inc/tscSQLParser.h} (94%) rename src/{util => client}/src/sql.c (99%) delete mode 100644 src/util/src/tstoken.c diff --git a/src/inc/tsql.h b/src/client/inc/tscSQLParser.h similarity index 94% rename from src/inc/tsql.h rename to src/client/inc/tscSQLParser.h index 5b033c535e..d899673c6d 100644 --- a/src/inc/tsql.h +++ b/src/client/inc/tscSQLParser.h @@ -23,24 +23,10 @@ extern "C" { #include "taos.h" #include "tsqldef.h" #include "ttypes.h" - -#define TK_SPACE 200 -#define TK_COMMENT 201 -#define TK_ILLEGAL 202 -#define TK_HEX 203 // hex number 0x123 -#define TK_OCT 204 // oct number -#define TK_BIN 205 // bin format data 0b111 -#define TK_FILE 206 -#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query - -#define TSQL_SO_ASC 1 -#define TSQL_SO_DESC 0 +#include "taosmsg.h" #define MAX_TOKEN_LEN 30 -#define TSQL_TBNAME "TBNAME" -#define TSQL_TBNAME_L "tbname" - // token type enum { TSQL_NODE_TYPE_EXPR = 0x1, @@ -278,8 +264,7 @@ typedef struct tSQLExpr { uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr) // the full sql string of function(col, param), which is actually the raw - // field name, - // since the function name is kept in nSQLOptr already + // field name, since the function name is kept in nSQLOptr already SSQLToken operand; struct tSQLExprList *pParam; // function parameters @@ -346,8 +331,6 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken void tSQLExprListDestroy(tSQLExprList *pList); -int32_t tSQLSyntaxNodeToString(tSQLExpr *pNode, char *dst); - SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere, tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval, SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit); @@ -379,6 +362,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken); void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists); void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo); +void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo); // prefix show db.tables; void setDBName(SSQLToken *pCpxName, SSQLToken *pDB); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index e074a115a8..ab4713a9dc 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -35,7 +35,7 @@ extern "C" { #include "tlog.h" #include "tscCache.h" #include "tsdb.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "tsqlfunction.h" #include "tutil.h" diff --git a/src/util/src/sql.c b/src/client/src/sql.c similarity index 99% rename from src/util/src/sql.c rename to src/client/src/sql.c index 2922fd8672..1d71022bed 100644 --- a/src/util/src/sql.c +++ b/src/client/src/sql.c @@ -30,7 +30,7 @@ #include #include #include -#include "tsql.h" +#include "tscSQLParser.h" #include "tutil.h" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols @@ -2146,7 +2146,7 @@ static void yy_reduce( { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 79: /* db_optr ::= */ -{memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));} +{setDefaultCreateDbOption(&yymsp[1].minor.yy398);} break; case 80: /* db_optr ::= db_optr tables */ case 94: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==94); @@ -2199,7 +2199,7 @@ static void yy_reduce( yymsp[-1].minor.yy398 = yylhsminor.yy398; break; case 92: /* alter_db_optr ::= */ -{ memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy398);} break; case 95: /* typename ::= ids */ { tSQLSetColumnType (&yylhsminor.yy223, &yymsp[0].minor.yy0); } diff --git a/src/client/src/tscAst.c b/src/client/src/tscAst.c index 527b1345e2..48e147a337 100644 --- a/src/client/src/tscAst.c +++ b/src/client/src/tscAst.c @@ -21,8 +21,12 @@ #include "tschemautil.h" #include "tsdb.h" #include "tskiplist.h" +#include "tsqldef.h" #include "tsqlfunction.h" +#include "tstoken.h" +#include "ttypes.h" #include "tutil.h" +#include "tscSQLParser.h" /* * @@ -37,10 +41,10 @@ */ static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken); -static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)); +static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *)); static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i); -static void destroySyntaxTree(tSQLSyntaxNode *); +static void destroySyntaxTree(tSQLSyntaxNode *); static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft, const tSQLSyntaxNode *pRight); @@ -255,7 +259,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha t0 = tStrGetToken(str, i, false, 0, NULL); if (t0.n == 0 || t0.type == TK_RP) { - if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr + if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr tSQLSyntaxNodeDestroy(pLeft, NULL); return NULL; } diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 8b324afc5e..75af0abb7d 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -22,7 +22,7 @@ #include "tscUtil.h" #include "tsclient.h" #include "tsocket.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "tutil.h" #include "tnote.h" diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 03f644ac36..532baec205 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -15,7 +15,7 @@ #include "taos.h" #include "tsclient.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "tscUtil.h" #include "ttimer.h" #include "taosmsg.h" diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 1f3da720f1..b2a9deb561 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -25,7 +25,8 @@ #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" -#include "tsql.h" +#include "tscSQLParser.h" + #pragma GCC diagnostic ignored "-Wunused-variable" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" @@ -48,18 +49,15 @@ typedef struct SColumnIdListRes { SColumnList list; } SColumnIdListRes; -static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t fieldIDInResult, int32_t colIdx, int32_t tableIndex); +static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t outputIndex, int32_t colIdx, int32_t tableIndex); static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); - -static bool has(tFieldList* pFieldList, int32_t offset, char* name); - static char* getAccountId(SSqlObj* pSql); +static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name); static void getCurrentDBName(SSqlObj* pSql, SSQLToken* pDBToken); static bool hasSpecifyDB(SSQLToken* pTableName); static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd); - static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSqlCmd* pCmd); static int32_t setObjFullName(char* fullName, char* account, SSQLToken* pDB, SSQLToken* tableName, int32_t* len); @@ -68,20 +66,18 @@ static void getColumnName(tSQLExprItem* pItem, char* resultFieldName, int32_t nL static void getRevisedName(char* resultFieldName, int32_t functionId, int32_t maxLen, char* columnName); static int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem); - static int32_t insertResultField(SSqlCmd* pCmd, int32_t fieldIDInResult, SColumnList* pIdList, int16_t bytes, int8_t type, char* fieldName); static int32_t changeFunctionID(int32_t optr, int16_t* functionId); +static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric); static void setErrMsg(SSqlCmd* pCmd, const char* pzErrMsg); -static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric); - static bool validateIpAddress(char* ip); static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd); static bool functionCompatibleCheck(SSqlCmd* pCmd); +static void setColumnOffsetValueInResultset(SSqlCmd* pCmd); -static void setColumnOffsetValueInResultset(SSqlCmd* pCmd); static int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList); static int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql); @@ -94,7 +90,6 @@ static int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL); static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema, int32_t numOfCols); static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd); -static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField); static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd); static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString); @@ -105,20 +100,23 @@ static int32_t validateLocalConfig(tDCLSQL* pOptions); static int32_t validateColumnName(char* name); static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); -static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd); -static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex); -static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql); +static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField); +static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd); +static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex); -static int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd); +static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql); +static int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql); static int32_t getColumnIndexByNameEx(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex); static int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex); static int32_t optrToString(tSQLExpr* pExpr, char** exprString); +static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex); +static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql); +static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd); +static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate); + static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex); -static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex); -static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql); -static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd); - + static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) { assert(QUERY_IS_STABLE_QUERY(pCmd->type)); @@ -321,7 +319,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return ret; } - if (parseCreateDBOptions(pCreateDB, pCmd) != TSDB_CODE_SUCCESS) { + if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_SQL; } @@ -896,7 +894,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { setErrMsg(pCmd, msg8); return TSDB_CODE_INVALID_SQL; } - + /* * handle the sql expression without from subclause * select current_database(); @@ -906,7 +904,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { */ if (pQuerySql->from == NULL) { assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL && - pQuerySql->pSortOrder == NULL); + pQuerySql->pSortOrder == NULL); return doLocalQueryProcess(pQuerySql, pCmd); } @@ -1511,7 +1509,7 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) { } /* is contained in pFieldList or not */ -static bool has(tFieldList* pFieldList, int32_t startIdx, char* name) { +static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name) { for (int32_t j = startIdx; j < pFieldList->nField; ++j) { if (strncasecmp(name, pFieldList->p[j].name, TSDB_COL_NAME_LEN) == 0) return true; } @@ -4950,29 +4948,29 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { bool isProjectionFunction = false; const char* msg1 = "column projection is not compatible with interval"; const char* msg2 = "interval not allowed for tag queries"; - + // multi-output set/ todo refactor for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { SSqlExpr* pExpr = tscSqlExprGet(pCmd, k); - + // projection query on primary timestamp, the selectivity function needs to be present. if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { bool hasSelectivity = false; - for(int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { + for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) { SSqlExpr* pEx = tscSqlExprGet(pCmd, j); if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) { hasSelectivity = true; break; } } - + if (hasSelectivity) { continue; } } - + if (pExpr->functionId == TSDB_FUNC_PRJ || pExpr->functionId == TSDB_FUNC_DIFF || - pExpr->functionId == TSDB_FUNC_ARITHM) { + pExpr->functionId == TSDB_FUNC_ARITHM) { isProjectionFunction = true; } } @@ -4985,8 +4983,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { } typedef struct SDNodeDynConfOption { - char* name; // command name - int32_t len; // name string length + char* name; // command name + int32_t len; // name string length } SDNodeDynConfOption; int32_t validateDNodeConfig(tDCLSQL* pOptions) { @@ -5045,10 +5043,8 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { return TSDB_CODE_INVALID_SQL; } - SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = { - {"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, - {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9} - }; + SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, + {"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}}; SSQLToken* pOptionToken = &pOptions->a[0]; @@ -5145,7 +5141,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { } if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) { - bool queryOnTags = false; + bool queryOnTags = false; if (tscQueryOnlyMetricTags(pCmd, &queryOnTags) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_SQL; } @@ -5203,73 +5199,95 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) { return TSDB_CODE_SUCCESS; } -static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { - pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default - +static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { + const char* msg = "invalid number of options"; + pMsg->daysToKeep = htonl(-1); pMsg->daysToKeep1 = htonl(-1); pMsg->daysToKeep2 = htonl(-1); - - pMsg->blocksPerMeter = (pCreateDb->numOfBlocksPerTable == 0) ? htons(-1) : htons(pCreateDb->numOfBlocksPerTable); - pMsg->compression = (pCreateDb->compressionLevel == 0) ? -1 : pCreateDb->compressionLevel; - - pMsg->commitLog = (pCreateDb->commitLog == 0) ? -1 : pCreateDb->commitLog; - pMsg->commitTime = (pCreateDb->commitTime == 0) ? htonl(-1) : htonl(pCreateDb->commitTime); - pMsg->maxSessions = (pCreateDb->tablesPerVnode == 0) ? htonl(-1) : htonl(pCreateDb->tablesPerVnode); - pMsg->cacheNumOfBlocks.fraction = (pCreateDb->numOfAvgCacheBlocks == 0) ? -1 : pCreateDb->numOfAvgCacheBlocks; - pMsg->cacheBlockSize = (pCreateDb->cacheBlockSize == 0) ? htonl(-1) : htonl(pCreateDb->cacheBlockSize); - pMsg->rowsInFileBlock = (pCreateDb->rowPerFileBlock == 0) ? htonl(-1) : htonl(pCreateDb->rowPerFileBlock); - pMsg->daysPerFile = (pCreateDb->daysPerFile == 0) ? htonl(-1) : htonl(pCreateDb->daysPerFile); - pMsg->replications = (pCreateDb->replica == 0) ? -1 : pCreateDb->replica; -} - -int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd) { - const char* msg0 = "invalid number of options"; - const char* msg1 = "invalid time precision"; - - SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead)); - setCreateDBOption(pMsg, pCreateDbSql); - - if (pCreateDbSql->keep != NULL) { - switch (pCreateDbSql->keep->nExpr) { + + tVariantList* pKeep = pCreateDb->keep; + if (pKeep != NULL) { + switch (pKeep->nExpr) { case 1: - pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key); + pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key); break; case 2: { - pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key); - pMsg->daysToKeep1 = htonl(pCreateDbSql->keep->a[1].pVar.i64Key); + pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key); + pMsg->daysToKeep1 = htonl(pKeep->a[1].pVar.i64Key); break; } case 3: { - pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key); - pMsg->daysToKeep1 = htonl(pCreateDbSql->keep->a[1].pVar.i64Key); - pMsg->daysToKeep2 = htonl(pCreateDbSql->keep->a[2].pVar.i64Key); + pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key); + pMsg->daysToKeep1 = htonl(pKeep->a[1].pVar.i64Key); + pMsg->daysToKeep2 = htonl(pKeep->a[2].pVar.i64Key); break; } default: { - setErrMsg(pCmd, msg0); + setErrMsg(pCmd, msg); return TSDB_CODE_INVALID_SQL; } } } + + return TSDB_CODE_SUCCESS; +} - SSQLToken* pToken = &pCreateDbSql->precision; +static int32_t setTimePrecisionOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) { + const char* msg = "invalid time precision"; + + pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default + + SSQLToken* pToken = &pCreateDbInfo->precision; if (pToken->n > 0) { pToken->n = strdequote(pToken->z); - + if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 && strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) { // time precision for this db: million second pMsg->precision = TSDB_TIME_PRECISION_MILLI; } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 && - strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) { + strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) { pMsg->precision = TSDB_TIME_PRECISION_MICRO; } else { - setErrMsg(pCmd, msg1); + setErrMsg(pCmd, msg); return TSDB_CODE_INVALID_SQL; } } + + return TSDB_CODE_SUCCESS; +} +static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { + pMsg->blocksPerMeter = htons(pCreateDb->numOfBlocksPerTable); + pMsg->compression = pCreateDb->compressionLevel; + + pMsg->commitLog = (char) pCreateDb->commitLog; + pMsg->commitTime = htonl(pCreateDb->commitTime); + pMsg->maxSessions = htonl(pCreateDb->tablesPerVnode); + pMsg->cacheNumOfBlocks.fraction = pCreateDb->numOfAvgCacheBlocks; + pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize); + pMsg->rowsInFileBlock = htonl(pCreateDb->rowPerFileBlock); + pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); + pMsg->replications = pCreateDb->replica; +} + +int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { + SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead)); + setCreateDBOption(pMsg, pCreateDbSql); + + if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + if (setTimePrecisionOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + + if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_INVALID_SQL; + } + return TSDB_CODE_SUCCESS; } @@ -5381,20 +5399,19 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) { static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { - SSqlExpr *pExpr = tscSqlExprGet(pCmd, i); + SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); if (pExpr->functionId == TSDB_FUNC_PRJ) { - bool qualifiedCol = false; for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) { if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) { qualifiedCol = true; - + pExpr->param[0].i64Key = 1; // limit the output to be 1 for each state value pExpr->numOfParams = 1; break; } } - + assert(qualifiedCol); } } @@ -5465,7 +5482,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { const char* msg1 = "only one selectivity function allowed in presence of tags function"; const char* msg2 = "functions not allowed"; const char* msg3 = "aggregation function should not be mixed up with projection"; - + bool tagColExists = false; int16_t numOfTimestamp = 0; // primary timestamp column int16_t numOfSelectivity = 0; @@ -5479,20 +5496,20 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { break; } } - + for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS) { continue; } - + if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) { numOfSelectivity++; } else { numOfAggregation++; } } - + if (tagColExists) { // check if the selectivity function exists // When the tag projection function on tag column that is not in the group by clause, aggregation function and // selectivity function exist in select clause is not allowed. @@ -5533,7 +5550,7 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { setErrMsg(pCmd, msg3); return TSDB_CODE_INVALID_SQL; } - + if (numOfAggregation > 0 || numOfSelectivity > 0) { // clear the projection type flag pCmd->type &= (~TSDB_QUERY_TYPE_PROJECTION_QUERY); @@ -5696,7 +5713,7 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { setErrMsg(pCmd, msg3); return TSDB_CODE_INVALID_SQL; } - + return TSDB_CODE_SUCCESS; } else { return checkUpdateTagPrjFunctions(pCmd); @@ -5707,48 +5724,145 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) { const char* msg1 = "only one expression allowed"; const char* msg2 = "invalid expression in select clause"; const char* msg3 = "invalid function"; - + tSQLExprList* pExprList = pQuerySql->pSelection; if (pExprList->nExpr != 1) { setErrMsg(pCmd, msg1); return TSDB_CODE_INVALID_SQL; } - + tSQLExpr* pExpr = pExprList->a[0].pNode; if (pExpr->operand.z == NULL) { setErrMsg(pCmd, msg2); return TSDB_CODE_INVALID_SQL; } - - SDNodeDynConfOption functionsInfo[5] = { - {"database()", 10}, {"server_version()", 16}, {"server_status()", 15}, {"client_version()", 16}, {"current_user()", 14} - }; - + + SDNodeDynConfOption functionsInfo[5] = {{"database()", 10}, + {"server_version()", 16}, + {"server_status()", 15}, + {"client_version()", 16}, + {"current_user()", 14}}; + int32_t index = -1; - for(int32_t i = 0; i < tListLen(functionsInfo); ++i) { + for (int32_t i = 0; i < tListLen(functionsInfo); ++i) { if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 && - functionsInfo[i].len == pExpr->operand.n) { + functionsInfo[i].len == pExpr->operand.n) { index = i; break; } } - + SSqlExpr* pExpr1 = tscSqlExprInsertEmpty(pCmd, 0, TSDB_FUNC_TAG_DUMMY); if (pExprList->a[0].aliasName != NULL) { strncpy(pExpr1->aliasName, pExprList->a[0].aliasName, tListLen(pExpr1->aliasName)); } else { strncpy(pExpr1->aliasName, functionsInfo[index].name, tListLen(pExpr1->aliasName)); } - - switch(index) { - case 0: pCmd->command = TSDB_SQL_CURRENT_DB;return TSDB_CODE_SUCCESS; - case 1: pCmd->command = TSDB_SQL_SERV_VERSION;return TSDB_CODE_SUCCESS; - case 2: pCmd->command = TSDB_SQL_SERV_STATUS;return TSDB_CODE_SUCCESS; - case 3: pCmd->command = TSDB_SQL_CLI_VERSION;return TSDB_CODE_SUCCESS; - case 4: pCmd->command = TSDB_SQL_CURRENT_USER;return TSDB_CODE_SUCCESS; + + switch (index) { + case 0: + pCmd->command = TSDB_SQL_CURRENT_DB; + return TSDB_CODE_SUCCESS; + case 1: + pCmd->command = TSDB_SQL_SERV_VERSION; + return TSDB_CODE_SUCCESS; + case 2: + pCmd->command = TSDB_SQL_SERV_STATUS; + return TSDB_CODE_SUCCESS; + case 3: + pCmd->command = TSDB_SQL_CLI_VERSION; + return TSDB_CODE_SUCCESS; + case 4: + pCmd->command = TSDB_SQL_CURRENT_USER; + return TSDB_CODE_SUCCESS; default: { setErrMsg(pCmd, msg3); return TSDB_CODE_INVALID_SQL; } } } + +// can only perform the parameters based on the macro definitation +int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate) { + char msg[512] = {0}; + + if (pCreate->commitLog != -1 && (pCreate->commitLog < 0 || pCreate->commitLog > 1)) { + snprintf(msg, tListLen(msg), "invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + if (pCreate->replications != -1 && + (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM)) { + snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM, + TSDB_REPLICA_MAX_NUM); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + int32_t val = htonl(pCreate->daysPerFile); + if (val != -1 && (val < TSDB_FILE_MIN_PARTITION_RANGE || val > TSDB_FILE_MAX_PARTITION_RANGE)) { + snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, + TSDB_FILE_MIN_PARTITION_RANGE, TSDB_FILE_MAX_PARTITION_RANGE); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + val = htonl(pCreate->rowsInFileBlock); + if (val != -1 && (val < TSDB_MIN_ROWS_IN_FILEBLOCK || val > TSDB_MAX_ROWS_IN_FILEBLOCK)) { + snprintf(msg, tListLen(msg), "invalid db option rowsInFileBlock: %d valid range: [%d, %d]", val, + TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + val = htonl(pCreate->cacheBlockSize); + if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) { + snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, + TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + val = htonl(pCreate->maxSessions); + if (val != -1 && (val < TSDB_MIN_TABLES_PER_VNODE || val > TSDB_MAX_TABLES_PER_VNODE)) { + snprintf(msg, tListLen(msg), "invalid db option maxSessions: %d valid range: [%d, %d]", val, TSDB_MIN_TABLES_PER_VNODE, + TSDB_MAX_TABLES_PER_VNODE); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + if (pCreate->precision != -1 && + (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO)) { + snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI, + TSDB_TIME_PRECISION_MICRO); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + if (pCreate->cacheNumOfBlocks.fraction != -1 && (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || + pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS)) { + snprintf(msg, tListLen(msg), "invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, + TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + val = htonl(pCreate->commitTime); + if (val != -1 && (val < TSDB_MIN_COMMIT_TIME_INTERVAL || val > TSDB_MAX_COMMIT_TIME_INTERVAL)) { + snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, + TSDB_MIN_COMMIT_TIME_INTERVAL, TSDB_MAX_COMMIT_TIME_INTERVAL); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + if (pCreate->compression != -1 && + (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL)) { + snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL, + TSDB_MAX_COMPRESSION_LEVEL); + setErrMsg(pCmd, msg); + return TSDB_CODE_INVALID_SQL; + } + + return TSDB_CODE_SUCCESS; +} diff --git a/src/client/src/tscSQLParserImpl.c b/src/client/src/tscSQLParserImpl.c index 7715b32c3c..5a426959d9 100644 --- a/src/client/src/tscSQLParserImpl.c +++ b/src/client/src/tscSQLParserImpl.c @@ -14,8 +14,10 @@ */ #include "os.h" +#include "taosmsg.h" #include "tglobalcfg.h" -#include "tsql.h" +#include "tlog.h" +#include "tscSQLParser.h" #include "tstoken.h" #include "ttime.h" #include "tutil.h" @@ -515,7 +517,7 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, if (pLimit != NULL) { pQuery->limit = *pLimit; } - + if (pGLimit != NULL) { pQuery->slimit = *pGLimit; } @@ -523,11 +525,11 @@ SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, if (pInterval != NULL) { pQuery->interval = *pInterval; } - + if (pSliding != NULL) { pQuery->sliding = *pSliding; } - + pQuery->fillType = pFill; return pQuery; } @@ -742,3 +744,22 @@ void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken tTokenListAppend(pInfo->pDCLInfo, pPwd); } } + +void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) { + pDBInfo->numOfBlocksPerTable = -1; + pDBInfo->compressionLevel = -1; + + pDBInfo->commitLog = -1; + pDBInfo->commitTime = -1; + pDBInfo->tablesPerVnode = -1; + pDBInfo->numOfAvgCacheBlocks = -1; + + pDBInfo->cacheBlockSize = -1; + pDBInfo->rowPerFileBlock = -1; + pDBInfo->daysPerFile = -1; + + pDBInfo->replica = -1; + pDBInfo->keep = NULL; + + memset(&pDBInfo->precision, 0, sizeof(SSQLToken)); +} diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index c1fe0c8674..5eebddca73 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ - #include "os.h" #include "tlosertree.h" #include "tscSecondaryMerge.h" diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 1f528bbda3..40db4d934f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -24,7 +24,7 @@ #include "tsclient.h" #include "tscompression.h" #include "tsocket.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index bae576d99f..a13503d666 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -24,7 +24,7 @@ #include "tsclient.h" #include "tscompression.h" #include "tsocket.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "ttimer.h" #include "tutil.h" #include "tnote.h" diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index c9809be1e3..288f906594 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -15,7 +15,7 @@ #include "os.h" #include "tlog.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" diff --git a/src/client/src/tscSyntaxtreefunction.c b/src/client/src/tscSyntaxtreefunction.c index bbd30c1fa9..914053f2f1 100644 --- a/src/client/src/tscSyntaxtreefunction.c +++ b/src/client/src/tscSyntaxtreefunction.c @@ -16,7 +16,7 @@ #include "os.h" #include "tscSyntaxtreefunction.h" -#include "tsql.h" +#include "tscSQLParser.h" #include "ttypes.h" #include "tutil.h" diff --git a/src/inc/sql.y b/src/inc/sql.y index 0fb7f6ef60..f25fc912a7 100644 --- a/src/inc/sql.y +++ b/src/inc/sql.y @@ -26,7 +26,7 @@ #include #include #include -#include "tsql.h" +#include "tscSQLParser.h" #include "tutil.h" } @@ -218,7 +218,8 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; } prec(Y) ::= PRECISION STRING(X). { Y = X; } %type db_optr {SCreateDBInfo} -db_optr(Y) ::= . {memset(&Y, 0, sizeof(SCreateDBInfo));} +db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);} + db_optr(Y) ::= db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); } @@ -233,7 +234,7 @@ db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; } db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; } %type alter_db_optr {SCreateDBInfo} -alter_db_optr(Y) ::= . { memset(&Y, 0, sizeof(SCreateDBInfo));} +alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);} alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); } alter_db_optr(Y) ::= alter_db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); } diff --git a/src/inc/tast.h b/src/inc/tast.h index 798a7f89a0..d7950b54f6 100644 --- a/src/inc/tast.h +++ b/src/inc/tast.h @@ -25,7 +25,7 @@ extern "C" { #include #include "taosmsg.h" -#include "tsql.h" +#include "ttypes.h" struct tSQLBinaryExpr; struct SSchema; @@ -49,7 +49,7 @@ typedef struct tQueryInfo { int32_t offset; // offset value in tags int32_t colIdx; // index of column in schema uint8_t optr; // expression operator - SSchema sch; // schema of tags + SSchema sch; // schema of tags tVariant q; // query condition value on the specific schema, filter expression __compar_fn_t compare; // filter function } tQueryInfo; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 81e580b54b..ea356a257a 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -146,8 +146,8 @@ extern "C" { #define TSDB_MAX_MPEERS 5 #define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1) -//#define TSDB_REPLICA_MAX_NUM 3 #define TSDB_REPLICA_MIN_NUM 1 +#define TSDB_REPLICA_MAX_NUM 3 #define TSDB_TBNAME_COLUMN_INDEX (-1) #define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta @@ -162,9 +162,6 @@ extern "C" { #define TSDB_MIN_COMPRESSION_LEVEL 0 #define TSDB_MAX_COMPRESSION_LEVEL 2 -#define TSDB_MIN_CACHE_BLOCKS_PER_METER 32 -#define TSDB_MAX_CACHE_BLOCKS_PER_METER 40960 - #define TSDB_MIN_COMMIT_TIME_INTERVAL 30 #define TSDB_MAX_COMMIT_TIME_INTERVAL 40960 @@ -177,7 +174,9 @@ extern "C" { #define TSDB_MIN_CACHE_BLOCKS 100 #define TSDB_MAX_CACHE_BLOCKS 409600 +#define TSDB_MIN_AVG_BLOCKS 2 #define TSDB_MAX_AVG_BLOCKS 2048 +#define TSDB_DEFAULT_AVG_BLOCKS 4 #define TSDB_MIN_TABLES_PER_VNODE 1 #define TSDB_MAX_TABLES_PER_VNODE 220000 @@ -204,7 +203,7 @@ extern "C" { #define TSDB_MAX_RPC_THREADS 5 -#define TSDB_QUERY_TYPE_QUERY 0 // normal query +#define TSDB_QUERY_TYPE_QUERY 0 // normal query #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01U // free qhandle at vnode /* @@ -220,6 +219,9 @@ extern "C" { #define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40U // select *,columns... query #define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80U // join sub query at the second stage +#define TSQL_SO_ASC 1 +#define TSQL_SO_DESC 0 + #ifdef __cplusplus } #endif diff --git a/src/inc/tsqlfunction.h b/src/inc/tsqlfunction.h index b3243cd811..a5734ed60e 100644 --- a/src/inc/tsqlfunction.h +++ b/src/inc/tsqlfunction.h @@ -24,7 +24,6 @@ extern "C" { #include #include "trpc.h" -#include "tsql.h" #include "ttypes.h" #define TSDB_FUNC_INVALID_ID -1 diff --git a/src/inc/tstoken.h b/src/inc/tstoken.h index 420fdaad9b..3ecf28aa2a 100644 --- a/src/inc/tstoken.h +++ b/src/inc/tstoken.h @@ -22,6 +22,18 @@ extern "C" { #include +#define TK_SPACE 200 +#define TK_COMMENT 201 +#define TK_ILLEGAL 202 +#define TK_HEX 203 // hex number 0x123 +#define TK_OCT 204 // oct number +#define TK_BIN 205 // bin format data 0b111 +#define TK_FILE 206 +#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query + +#define TSQL_TBNAME "TBNAME" +#define TSQL_TBNAME_L "tbname" + // used to denote the minimum unite in sql parsing typedef struct SSQLToken { uint32_t n; @@ -29,10 +41,6 @@ typedef struct SSQLToken { char * z; } SSQLToken; -#if 0 -char *tscGetToken(char *string, char **token, int *tokenLen); -#endif - /** * tokenizer for sql string * @param z diff --git a/src/system/detail/inc/mgmtUtil.h b/src/system/detail/inc/mgmtUtil.h index 6a6b819bf2..04bacbe1db 100644 --- a/src/system/detail/inc/mgmtUtil.h +++ b/src/system/detail/inc/mgmtUtil.h @@ -31,6 +31,7 @@ int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName); int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col); bool mgmtCheckIsMonitorDB(char *db, char *monitordb); +int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate); int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes); int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes); diff --git a/src/system/detail/src/mgmtDb.c b/src/system/detail/src/mgmtDb.c index ba1b966cfb..b571e01942 100644 --- a/src/system/detail/src/mgmtDb.c +++ b/src/system/detail/src/mgmtDb.c @@ -140,90 +140,31 @@ int mgmtCheckDbParams(SCreateDbMsg *pCreate) { if (pCreate->replications < 0) pCreate->replications = tsReplications; // if (pCreate->rowsInFileBlock < 0) pCreate->rowsInFileBlock = tsRowsInFileBlock; // if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; // - //-1 for balance - - if (pCreate->replications < 0 || pCreate->replications > TSDB_REPLICA_MAX_NUM) { - mTrace("invalid db option replications: %d", pCreate->replications); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->commitLog < 0 || pCreate->commitLog > 1) { - mTrace("invalid db option commitLog: %d", pCreate->commitLog); + + if (mgmtCheckDBParams(pCreate) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_OPTION; } - if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) { - mTrace("invalid db option replications: %d", pCreate->replications); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) { - mTrace("invalid db option daysPerFile: %d valid range: %d--%d", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE, - TSDB_FILE_MAX_PARTITION_RANGE); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) { - mTrace("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1, - pCreate->daysToKeep2, pCreate->daysToKeep); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) { - mTrace("invalid db option daystokeep: %d", pCreate->daysToKeep); - return TSDB_CODE_INVALID_OPTION; - } - if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) { - mTrace("invalid db option rowsInFileBlock: %d valid range: %d--%d", pCreate->rowsInFileBlock, - TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); - return TSDB_CODE_INVALID_OPTION; - } - if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { - mTrace("invalid db option cacheBlockSize: %d valid range: %d--%d", pCreate->cacheBlockSize, - TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); - return TSDB_CODE_INVALID_OPTION; - } - if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) { - mTrace("invalid db option maxSessions: %d valid range: %d--%d", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE, - TSDB_MAX_TABLES_PER_VNODE); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) { - mTrace("invalid db option timePrecision: %d valid value: %d,%d", pCreate->precision, TSDB_TIME_PRECISION_MILLI, - TSDB_TIME_PRECISION_MICRO); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->cacheNumOfBlocks.fraction < 0 || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) { - mTrace("invalid db option ablocks: %d valid value: %d,%d", pCreate->precision, 0, TSDB_MAX_AVG_BLOCKS); - return TSDB_CODE_INVALID_OPTION; - } else { - pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions); - } - + pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions); + if (pCreate->cacheNumOfBlocks.totalBlocks > TSDB_MAX_CACHE_BLOCKS) { - mTrace("invalid db option cacheNumOfBlocks: %d valid range: %d", pCreate->cacheNumOfBlocks.totalBlocks, - TSDB_MAX_CACHE_BLOCKS); + mTrace("invalid db option cacheNumOfBlocks: %d valid range: [%d, %d]", pCreate->cacheNumOfBlocks.totalBlocks, + TSDB_MIN_CACHE_BLOCKS, TSDB_MAX_CACHE_BLOCKS); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) { - mTrace("invalid db option commitTime: %d valid range: %d-%d", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL, - TSDB_MAX_COMMIT_TIME_INTERVAL); - return TSDB_CODE_INVALID_OPTION; + // calculate the blocks per table + if (pCreate->blocksPerMeter < 0) { + pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks / 4; } - if (pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) { - mTrace("invalid db option compression: %d", pCreate->compression, TSDB_MIN_COMMIT_TIME_INTERVAL, - TSDB_MAX_COMMIT_TIME_INTERVAL); - return TSDB_CODE_INVALID_OPTION; - } - - if (pCreate->blocksPerMeter < 0) pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks / 4; + if (pCreate->blocksPerMeter > pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4) { pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4; } - if (pCreate->blocksPerMeter < 4) pCreate->blocksPerMeter = 4; + + if (pCreate->blocksPerMeter < TSDB_MIN_AVG_BLOCKS) { + pCreate->blocksPerMeter = TSDB_MIN_AVG_BLOCKS; + } pCreate->maxSessions++; diff --git a/src/system/detail/src/mgmtUtil.c b/src/system/detail/src/mgmtUtil.c index d31198be64..98978767ce 100644 --- a/src/system/detail/src/mgmtUtil.c +++ b/src/system/detail/src/mgmtUtil.c @@ -92,3 +92,76 @@ bool mgmtCheckIsMonitorDB(char *db, char *monitordb) { size_t len = strlen(dbName); return (strncasecmp(dbName, monitordb, len) == 0 && len == strlen(monitordb)); } + +int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate) { + if (pCreate->commitLog < 0 || pCreate->commitLog > 1) { + mError("invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) { + mError("invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM, + TSDB_REPLICA_MAX_NUM); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) { + mError("invalid db option daysPerFile: %d valid range: [%d, %d]", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE, + TSDB_FILE_MAX_PARTITION_RANGE); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) { + mError("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1, + pCreate->daysToKeep2, pCreate->daysToKeep); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) { + mError("invalid db option daystokeep: %d", pCreate->daysToKeep); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) { + mError("invalid db option rowsInFileBlock: %d valid range: [%d, %d]", pCreate->rowsInFileBlock, + TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { + mError("invalid db option cacheBlockSize: %d valid range: [%d, %d]", pCreate->cacheBlockSize, + TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) { + mError("invalid db option maxSessions: %d valid range: [%d, %d]", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE, + TSDB_MAX_TABLES_PER_VNODE); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) { + mError("invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI, + TSDB_TIME_PRECISION_MICRO); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) { + mError("invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, 0, TSDB_MAX_AVG_BLOCKS); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) { + mError("invalid db option commitTime: %d valid range: [%d, %d]", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL, + TSDB_MAX_COMMIT_TIME_INTERVAL); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) { + mError("invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL, + TSDB_MAX_COMPRESSION_LEVEL); + return TSDB_CODE_INVALID_OPTION; + } + + return TSDB_CODE_SUCCESS; +} diff --git a/src/system/detail/src/vnodeQueryProcess.c b/src/system/detail/src/vnodeQueryProcess.c index 7378963301..2fae48b143 100644 --- a/src/system/detail/src/vnodeQueryProcess.c +++ b/src/system/detail/src/vnodeQueryProcess.c @@ -27,7 +27,7 @@ #include "vnodeQueryImpl.h" #define ALL_CACHE_BLOCKS_CHECKED(q) \ - ((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q) || (q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q))) + (((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q)) || ((q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q)))) #define FORWARD_CACHE_BLOCK_CHECK_SLOT(slot, step, maxblocks) (slot) = ((slot) + (step) + (maxblocks)) % (maxblocks); diff --git a/src/util/src/textbuffer.c b/src/util/src/textbuffer.c index 8944dd4391..d76830842b 100644 --- a/src/util/src/textbuffer.c +++ b/src/util/src/textbuffer.c @@ -18,7 +18,6 @@ #include "taosmsg.h" #include "textbuffer.h" #include "tlog.h" -#include "tsql.h" #include "tsqlfunction.h" #include "ttime.h" #include "ttypes.h" diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index a62523c61d..6991e6b8b6 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -84,7 +84,7 @@ short tsCheckHeaderFile = 0; int tsSessionsPerVnode = 1000; int tsCacheBlockSize = 16384; // 256 columns -int tsAverageCacheBlocks = 4; +int tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS; int tsRowsInFileBlock = 4096; float tsFileBlockMinPercent = 0.05; @@ -92,10 +92,10 @@ float tsFileBlockMinPercent = 0.05; short tsNumOfBlocksPerMeter = 100; short tsCommitTime = 3600; // seconds short tsCommitLog = 1; -short tsCompression = 2; +short tsCompression = TSDB_MAX_COMPRESSION_LEVEL; short tsDaysPerFile = 10; int tsDaysToKeep = 3650; -int tsReplications = 1; +int tsReplications = TSDB_REPLICA_MIN_NUM; int tsNumOfMPeers = 3; int tsMaxShellConns = 2000; @@ -522,7 +522,7 @@ static void doInitGlobalConfig() { 0, 1.0, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "ablocks", &tsAverageCacheBlocks, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 2, 128, 0, TSDB_CFG_UTYPE_NONE); + TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "tblocks", &tsNumOfBlocksPerMeter, TSDB_CFG_VTYPE_SHORT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 32, 4096, 0, TSDB_CFG_UTYPE_NONE); diff --git a/src/util/src/tstoken.c b/src/util/src/tstoken.c deleted file mode 100644 index e88d3bada6..0000000000 --- a/src/util/src/tstoken.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include - -#include "os.h" -#include "shash.h" -#include "tstoken.h" -void shiftStr(char *dst, char *src); - -static char operator[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '$', '%', '&', 0, '(', ')', '*', '+', - 0, '-', 0, '/', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '<', '=', '>', 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, '[', 0, ']', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0, 0}; - -static char delimiter[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ',', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ';', 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -bool isCharInDelimiter(char c, char *delimiter) { - for (int i = 0; i < strlen(delimiter); i++) { - if (delimiter[i] == c) return true; - } - return false; -} - -char *tscGetTokenDelimiter(char *string, char **token, int *tokenLen, char *delimiters) { - while (*string != 0) { - if (isCharInDelimiter(*string, delimiters)) { - ++string; - } else { - break; - } - } - - *token = string; - - char *str = string; - *tokenLen = 0; - while (*str != 0) { - if (!isCharInDelimiter(*str, delimiters)) { - *tokenLen = *tokenLen + 1; - str++; - } else { - break; - } - } - - return string; -} - -char *tscGetToken(char *string, char **token, int *tokenLen) { - char quote = 0; - - while (*string != 0) { - if (delimiter[*string]) { - ++string; - } else { - break; - } - } - - char quotaChar = 0; - if (*string == '\'' || *string == '\"') { - quote = 1; - quotaChar = *string; - string++; - } - - *token = string; - /* not in string, return token */ - if (*string > 0 && operator[*string] && quote == 0) { - string++; - /* handle the case: insert into tabx using stable1 tags(-1)/tags(+1) - * values(....) */ - if (operator[*string] &&(*string != '(' && *string != ')' && *string != '-' && *string != '+')) - *tokenLen = 2; - else - *tokenLen = 1; - return *token + *tokenLen; - } - - while (*string != 0) { - if (quote) { - // handle escape situation: '\"', the " should not be eliminated - if (*string == quotaChar) { - if (*(string - 1) != '\\') { - break; - } else { - shiftStr(string - 1, string); - } - } else { - ++string; - } - } else { - if (delimiter[*string]) break; - - if (operator[*string]) break; - - ++string; - } - } - - *tokenLen = (int)(string - *token); - - if (quotaChar != 0 && *string != 0 && *(string + 1) != 0) { - return string + 1; - } else { - return string; - } -} - -void shiftStr(char *dst, char *src) { - int32_t i = 0; - do { - dst[i] = src[i]; - i++; - } while (delimiter[src[i]] == 0); - - src[i - 1] = ' '; -} diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 85da925297..51a43832d4 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -13,14 +13,12 @@ * along with this program. If not, see . */ -#include -#include -#include - #include "os.h" #include "shash.h" -#include "tsql.h" #include "tutil.h" +#include "tsqldef.h" +#include "tstoken.h" +#include "ttypes.h" // All the keywords of the SQL language are stored in a hash table typedef struct SKeyword { diff --git a/src/util/src/ttypes.c b/src/util/src/ttypes.c index 185a63c0eb..98f0741905 100644 --- a/src/util/src/ttypes.c +++ b/src/util/src/ttypes.c @@ -16,7 +16,6 @@ #include "os.h" #include "taos.h" #include "tsdb.h" -#include "tsql.h" #include "tsqldef.h" #include "ttypes.h" #include "tutil.h" @@ -67,6 +66,8 @@ bool isValidDataType(int32_t type, int32_t length) { void tVariantCreate(tVariant *pVar, SSQLToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); } void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { + memset(pVar, 0, sizeof(tVariant)); + switch (type) { case TSDB_DATA_TYPE_BOOL: { int32_t k = strncasecmp(pz, "true", 4); From edd7ce22133d52306e6116f62fcd2079c2d8f728 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 25 Nov 2019 13:24:13 +0800 Subject: [PATCH 37/42] add error code if the query msg is not valid --- src/system/detail/src/vnodeUtil.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/system/detail/src/vnodeUtil.c b/src/system/detail/src/vnodeUtil.c index 52b27f5d6d..68e1e428c0 100644 --- a/src/system/detail/src/vnodeUtil.c +++ b/src/system/detail/src/vnodeUtil.c @@ -283,6 +283,7 @@ SSqlFunctionExpr* vnodeCreateSqlFunctionExpr(SQueryMeterMsg* pQueryMsg, int32_t* int32_t param = pExprs[i].pBase.arg[0].argValue.i64; if (getResultDataInfo(type, bytes, pExprs[i].pBase.functionId, param, &pExprs[i].resType, &pExprs[i].resBytes, &pExprs[i].interResBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { + *code = TSDB_CODE_INVALID_QUERY_MSG; return NULL; } @@ -626,16 +627,16 @@ void vnodeUpdateQueryColumnIndex(SQuery* pQuery, SMeterObj* pMeterObj) { return; } - for(int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { - SSqlFuncExprMsg* pSqlExprMsg = &pQuery->pSelectExpr[i].pBase; + for(int32_t k = 0; k < pQuery->numOfOutputCols; ++k) { + SSqlFuncExprMsg* pSqlExprMsg = &pQuery->pSelectExpr[k].pBase; if (pSqlExprMsg->functionId == TSDB_FUNC_ARITHM || pSqlExprMsg->colInfo.flag == TSDB_COL_TAG) { continue; } SColIndexEx* pColIndexEx = &pSqlExprMsg->colInfo; - for(int32_t j = 0; j < pQuery->numOfCols; ++j) { - if (pColIndexEx->colId == pQuery->colList[j].data.colId) { - pColIndexEx->colIdx = pQuery->colList[j].colIdx; + for(int32_t f = 0; f < pQuery->numOfCols; ++f) { + if (pColIndexEx->colId == pQuery->colList[f].data.colId) { + pColIndexEx->colIdx = pQuery->colList[f].colIdx; break; } } From af036b877654ce59498c8ec033f0b307f7827840 Mon Sep 17 00:00:00 2001 From: slguan Date: Mon, 25 Nov 2019 14:45:29 +0800 Subject: [PATCH 38/42] [TBASE-1235] --- src/system/detail/src/vnodeMeter.c | 4 +++- src/system/detail/src/vnodeShell.c | 4 +++- src/system/detail/src/vnodeStore.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/system/detail/src/vnodeMeter.c b/src/system/detail/src/vnodeMeter.c index 4195138a29..f5619d72b8 100644 --- a/src/system/detail/src/vnodeMeter.c +++ b/src/system/detail/src/vnodeMeter.c @@ -24,6 +24,7 @@ #include "vnodeMgmt.h" #include "vnodeShell.h" #include "vnodeUtil.h" +#include "tstatus.h" #pragma GCC diagnostic ignored "-Wpointer-sign" @@ -717,7 +718,8 @@ void vnodeUpdateMeter(void *param, void *tmrId) { SVnodeObj* pVnode = &vnodeList[pNew->vnode]; if (pVnode->meterList == NULL) { - dTrace("vid:%d sid:%d id:%s, vnode is deleted, abort update schema", pNew->vnode, pNew->sid, pNew->meterId); + dTrace("vid:%d sid:%d id:%s, vnode is deleted, status:%s, abort update schema", + pNew->vnode, pNew->sid, pNew->meterId, taosGetVnodeStatusStr(vnodeList[pNew->vnode].vnodeStatus)); free(pNew->schema); free(pNew); return; diff --git a/src/system/detail/src/vnodeShell.c b/src/system/detail/src/vnodeShell.c index c0d149b0d1..91e6c9527b 100644 --- a/src/system/detail/src/vnodeShell.c +++ b/src/system/detail/src/vnodeShell.c @@ -184,13 +184,15 @@ int vnodeOpenShellVnode(int vnode) { static void vnodeDelayedFreeResource(void *param, void *tmrId) { int32_t vnode = *(int32_t*) param; - dTrace("vid:%d, start to free resources", vnode); + dTrace("vid:%d, start to free resources for 500ms arrived", vnode); taosCloseRpcChann(pShellServer, vnode); // close connection tfree(shellList[vnode]); //free SShellObj tfree(param); memset(vnodeList + vnode, 0, sizeof(SVnodeObj)); + dTrace("vid:%d, status set to %s", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); + vnodeCalcOpenVnodes(); } diff --git a/src/system/detail/src/vnodeStore.c b/src/system/detail/src/vnodeStore.c index e49a84ed5b..fb18f01214 100644 --- a/src/system/detail/src/vnodeStore.c +++ b/src/system/detail/src/vnodeStore.c @@ -250,7 +250,7 @@ static void vnodeRemoveDataFiles(int vnode) { sprintf(vnodeDir, "%s/vnode%d", tsDirectory, vnode); rmdir(vnodeDir); - dPrint("vid:%d, vnode is removed!", vnode); + dPrint("vid:%d, vnode is removed, status:%s", vnode, taosGetVnodeStatusStr(vnodeList[vnode].vnodeStatus)); } int vnodeRemoveVnode(int vnode) { From db8f5a849da1aac3d27e686f4ab19bae47b9d3b1 Mon Sep 17 00:00:00 2001 From: slguan Date: Mon, 25 Nov 2019 14:58:59 +0800 Subject: [PATCH 39/42] [TBASE-1235] --- src/system/detail/src/vnodeStore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/system/detail/src/vnodeStore.c b/src/system/detail/src/vnodeStore.c index fb18f01214..f2617f09b6 100644 --- a/src/system/detail/src/vnodeStore.c +++ b/src/system/detail/src/vnodeStore.c @@ -269,6 +269,7 @@ int vnodeRemoveVnode(int vnode) { return ret; } + dTrace("vid:%d, status:%s, do delete operation", vnode, taosGetVnodeStatusStr(pVnode->vnodeStatus)); vnodeRemoveDataFiles(vnode); } From aceeed3b0104b5835fba346c85583217d8a50ca8 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 25 Nov 2019 16:21:05 +0800 Subject: [PATCH 40/42] [tbase-1007] --- src/system/detail/inc/vnodeQueryImpl.h | 3 +- src/system/detail/inc/vnodeRead.h | 56 ++-- src/system/detail/src/vnodeQueryImpl.c | 296 ++++++++++++---------- src/system/detail/src/vnodeQueryProcess.c | 16 +- 4 files changed, 199 insertions(+), 172 deletions(-) diff --git a/src/system/detail/inc/vnodeQueryImpl.h b/src/system/detail/inc/vnodeQueryImpl.h index 810105d638..57c4149f22 100644 --- a/src/system/detail/inc/vnodeQueryImpl.h +++ b/src/system/detail/inc/vnodeQueryImpl.h @@ -174,7 +174,7 @@ void queryOnBlock(SMeterQuerySupportObj* pSupporter, int64_t* primaryKeys, int32 SBlockInfo* pBlockBasicInfo, SMeterDataInfo* pDataHeadInfoEx, SField* pFields, __block_search_fn_t searchFn); -SMeterDataInfo** vnodeFilterQualifiedMeters(SQInfo* pQInfo, int32_t vid, SQueryFileInfo* pQueryFileInfo, +SMeterDataInfo** vnodeFilterQualifiedMeters(SQInfo* pQInfo, int32_t vid, int32_t fileIndex, tSidSet* pSidSet, SMeterDataInfo* pMeterDataInfo, int32_t* numOfMeters); int32_t vnodeGetVnodeHeaderFileIdx(int32_t* fid, SQueryRuntimeEnv* pRuntimeEnv, int32_t order); @@ -194,6 +194,7 @@ uint32_t getDataBlocksForMeters(SMeterQuerySupportObj* pSupporter, SQuery* pQuer int32_t numOfMeters, SQueryFileInfo* pQueryFileInfo, SMeterDataInfo** pMeterDataInfo); int32_t LoadDatablockOnDemand(SCompBlock* pBlock, SField** pFields, int8_t* blkStatus, SQueryRuntimeEnv* pRuntimeEnv, int32_t fileIdx, int32_t slotIdx, __block_search_fn_t searchFn, bool onDemand); +char *vnodeGetHeaderFileData(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex); /** * Create SMeterQueryInfo. diff --git a/src/system/detail/inc/vnodeRead.h b/src/system/detail/inc/vnodeRead.h index 1de9f97e82..b9bf684f79 100644 --- a/src/system/detail/inc/vnodeRead.h +++ b/src/system/detail/inc/vnodeRead.h @@ -57,9 +57,9 @@ typedef struct SQueryFileInfo { char lastFilePath[256]; int32_t defaultMappingSize; /* default mapping size */ - int32_t headerFd; /* file handler */ - char* pHeaderFileData; /* mmap header files */ - size_t headFileSize; + int32_t headerFd; /* file handler */ + char* pHeaderFileData; /* mmap header files */ + size_t headFileSize; int32_t dataFd; char* pDataFileData; size_t dataFileSize; @@ -107,44 +107,40 @@ typedef struct SOutputRes { } SOutputRes; typedef struct RuntimeEnvironment { - SPositionInfo startPos; /* the start position, used for secondary/third iteration */ - SPositionInfo endPos; /* the last access position in query, served as the start pos of reversed order query */ - SPositionInfo nextPos; /* start position of the next scan */ - SData* colDataBuffer[TSDB_MAX_COLUMNS]; - SResultInfo* resultInfo; - - // Indicate if data block is loaded, the block is first/last/internal block - int8_t blockStatus; - int32_t unzipBufSize; - SData* primaryColBuffer; - char* unzipBuffer; - char* secondaryUnzipBuffer; - SQuery* pQuery; - SMeterObj* pMeterObj; - SQLFunctionCtx* pCtx; - SQueryLoadBlockInfo loadBlockInfo; /* record current block load information */ + SPositionInfo startPos; /* the start position, used for secondary/third iteration */ + SPositionInfo endPos; /* the last access position in query, served as the start pos of reversed order query */ + SPositionInfo nextPos; /* start position of the next scan */ + SData* colDataBuffer[TSDB_MAX_COLUMNS]; + SResultInfo* resultInfo; + uint8_t blockStatus; // Indicate if data block is loaded, the block is first/last/internal block + int32_t unzipBufSize; + SData* primaryColBuffer; + char* unzipBuffer; + char* secondaryUnzipBuffer; + SQuery* pQuery; + SMeterObj* pMeterObj; + SQLFunctionCtx* pCtx; + SQueryLoadBlockInfo loadBlockInfo; /* record current block load information */ SQueryLoadCompBlockInfo loadCompBlockInfo; /* record current compblock information in SQuery */ /* * header files info, avoid to iterate the directory, the data is acquired * during in query preparation function */ - SQueryFileInfo* pHeaderFiles; - uint32_t numOfFiles; /* number of files of one vnode during query execution */ - - int16_t numOfRowsPerPage; - int16_t offset[TSDB_MAX_COLUMNS]; - - int16_t scanFlag; /* denotes reversed scan of data or not */ + SQueryFileInfo* pVnodeFiles; + uint32_t numOfFiles; // the total available number of files for this virtual node during query execution + int32_t mmapedHFileIndex; // the mmaped header file, NOTE: only one header file can be mmap. + int16_t numOfRowsPerPage; + int16_t offset[TSDB_MAX_COLUMNS]; + int16_t scanFlag; // denotes reversed scan of data or not SInterpolationInfo interpoInfo; SData** pInterpoBuf; SOutputRes* pResult; // reference to SQuerySupporter->pResult void* hashList; int32_t usedIndex; // assigned SOutputRes in list - - STSBuf* pTSBuf; - STSCursor cur; - SQueryCostSummary summary; + STSBuf* pTSBuf; + STSCursor cur; + SQueryCostSummary summary; } SQueryRuntimeEnv; /* intermediate result during multimeter query involves interval */ diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c index f7f456ec53..5a6a558436 100644 --- a/src/system/detail/src/vnodeQueryImpl.c +++ b/src/system/detail/src/vnodeQueryImpl.c @@ -47,7 +47,7 @@ static int32_t readDataFromDiskFile(int fd, SQInfo *pQInfo, SQueryFileInfo *pQue __read_data_fn_t readDataFunctor[2] = {copyDataFromMMapBuffer, readDataFromDiskFile}; -static void vnodeInitLoadCompBlockInfo(SQueryLoadCompBlockInfo *pCompBlockLoadInfo); +static void vnodeInitLoadCompBlockInfo(SQueryLoadCompBlockInfo *pCompBlockLoadInfo); static int32_t moveToNextBlock(SQueryRuntimeEnv *pRuntimeEnv, int32_t step, __block_search_fn_t searchFn, bool loadData); static int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, SQuery *pQuery, @@ -57,7 +57,7 @@ static int32_t doMergeMetersResultsToGroupRes(SMeterQuerySupportObj *pSupporter, static TSKEY getTimestampInCacheBlock(SCacheBlock *pBlock, int32_t index); static TSKEY getTimestampInDiskBlock(SQueryRuntimeEnv *pRuntimeEnv, int32_t index); -static void savePointPosition(SPositionInfo *position, int32_t fileId, int32_t slot, int32_t pos); +static void savePointPosition(SPositionInfo *position, int32_t fileId, int32_t slot, int32_t pos); static int32_t getNextDataFileCompInfo(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj *pMeterObj, int32_t step); static void setGroupOutputBuffer(SQueryRuntimeEnv *pRuntimeEnv, SOutputRes *pResult); @@ -195,7 +195,7 @@ static bool vnodeIsCompBlockInfoLoaded(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj // if vnodeFreeFields is called, the pQuery->pFields is NULL if (pLoadCompBlockInfo->fileListIndex == fileIndex && pLoadCompBlockInfo->sid == pMeterObj->sid && pQuery->pFields != NULL && pQuery->fileId > 0) { - assert(pRuntimeEnv->pHeaderFiles[fileIndex].fileID == pLoadCompBlockInfo->fileId && pQuery->numOfBlocks > 0); + assert(pRuntimeEnv->pVnodeFiles[fileIndex].fileID == pLoadCompBlockInfo->fileId && pQuery->numOfBlocks > 0); return true; } @@ -207,7 +207,7 @@ static void vnodeSetCompBlockInfoLoaded(SQueryRuntimeEnv *pRuntimeEnv, int32_t f pLoadCompBlockInfo->sid = sid; pLoadCompBlockInfo->fileListIndex = fileIndex; - pLoadCompBlockInfo->fileId = pRuntimeEnv->pHeaderFiles[fileIndex].fileID; + pLoadCompBlockInfo->fileId = pRuntimeEnv->pVnodeFiles[fileIndex].fileID; } static void vnodeInitLoadCompBlockInfo(SQueryLoadCompBlockInfo *pCompBlockLoadInfo) { @@ -247,6 +247,60 @@ static void vnodeInitDataBlockInfo(SQueryLoadBlockInfo *pBlockLoadInfo) { pBlockLoadInfo->fileListIndex = -1; } +static void doUnmapHeaderFileData(SQueryRuntimeEnv* pRuntimeEnv) { + if (pRuntimeEnv->mmapedHFileIndex >= 0) { + assert(pRuntimeEnv->mmapedHFileIndex < pRuntimeEnv->numOfFiles && pRuntimeEnv->mmapedHFileIndex >= 0); + + SQueryFileInfo *otherVnodeFiles = &pRuntimeEnv->pVnodeFiles[pRuntimeEnv->mmapedHFileIndex]; + munmap(otherVnodeFiles->pHeaderFileData, otherVnodeFiles->headFileSize); + + otherVnodeFiles->pHeaderFileData = NULL; + pRuntimeEnv->mmapedHFileIndex = -1; + } else { + assert(pRuntimeEnv->mmapedHFileIndex == -1); + } +} + +/** + * mmap the data file into memory. For each query, only one header file is allowed to mmap into memory, in order to + * avoid too many mmapped files at the save time to cause OS return the message of "Cannot allocate memory", + * during query processing. + * + * @param pRuntimeEnv + * @param fileIndex + * @return the return value may be null, so any invoker needs to check the returned value + */ +char *vnodeGetHeaderFileData(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex) { + assert(fileIndex >= 0 && fileIndex < pRuntimeEnv->numOfFiles); + + SQuery *pQuery = pRuntimeEnv->pQuery; + SQInfo *pQInfo = (SQInfo *)GET_QINFO_ADDR(pQuery); // only for log output + + SQueryFileInfo *pVnodeFiles = &pRuntimeEnv->pVnodeFiles[fileIndex]; + size_t size = pVnodeFiles->headFileSize; + + if (pVnodeFiles->pHeaderFileData == NULL) { + assert(pRuntimeEnv->mmapedHFileIndex != fileIndex); + doUnmapHeaderFileData(pRuntimeEnv); // do close the other mmaped header file + + pVnodeFiles->pHeaderFileData = mmap(NULL, size, PROT_READ, MAP_SHARED, pVnodeFiles->headerFd, 0); + if (pVnodeFiles->pHeaderFileData == MAP_FAILED) { + pVnodeFiles->pHeaderFileData = NULL; + dError("QInfo:%p failed to map header file:%s, size:%lld, %s", pQInfo, pVnodeFiles->headerFilePath, size, + strerror(errno)); + } else { + pRuntimeEnv->mmapedHFileIndex = fileIndex; // set the value in case of success mmap file + if (madvise(pVnodeFiles->pHeaderFileData, size, MADV_SEQUENTIAL) == -1) { + dError("QInfo:%p failed to advise kernel the usage of header files, reason:%s", pQInfo, strerror(errno)); + } + } + } else { + assert(pRuntimeEnv->mmapedHFileIndex == fileIndex); + } + + return pVnodeFiles->pHeaderFileData; +} + /* * read comp block info from header file * @@ -256,8 +310,7 @@ static int vnodeGetCompBlockInfo(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRuntim SQInfo *pQInfo = (SQInfo *)GET_QINFO_ADDR(pQuery); SVnodeCfg * pCfg = &vnodeList[pMeterObj->vnode].cfg; - SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pHeaderFiles[fileIndex]; - int32_t fd = pQueryFileInfo->headerFd; + SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIndex]; int64_t st = taosGetTimestampUs(); @@ -273,8 +326,11 @@ static int vnodeGetCompBlockInfo(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRuntim pSummary->numOfSeek++; #if 1 - char *data = pRuntimeEnv->pHeaderFiles[fileIndex].pHeaderFileData; - UNUSED(fd); + char *data = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); // failed to load the header file data into memory + if (data == NULL) { + return -1; + } + #else char *data = calloc(1, tmsize + TSDB_FILE_HEADER_LEN); read(fd, data, tmsize + TSDB_FILE_HEADER_LEN); @@ -353,7 +409,7 @@ static int vnodeGetCompBlockInfo(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRuntim int64_t et = taosGetTimestampUs(); qTrace("QInfo:%p vid:%d sid:%d id:%s, fileId:%d, load compblock info, size:%d, elapsed:%f ms", pQInfo, - pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pRuntimeEnv->pHeaderFiles[fileIndex].fileID, + pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pRuntimeEnv->pVnodeFiles[fileIndex].fileID, compBlockSize, (et - st) / 1000.0); pSummary->totalCompInfoSize += compBlockSize; @@ -379,7 +435,7 @@ static void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, int64_t StartQue char *primaryColumnData, int32_t size, int32_t functionId, SField *pField, bool hasNull, int32_t blockStatus, void *param, int32_t scanFlag); -void createGroupResultBuf(SQuery *pQuery, SOutputRes *pOneResult, bool isMetricQuery); +void createGroupResultBuf(SQuery *pQuery, SOutputRes *pOneResult, bool isMetricQuery); static void destroyGroupResultBuf(SOutputRes *pOneOutputRes, int32_t nOutputCols); static int32_t binarySearchForBlockImpl(SCompBlock *pBlock, int32_t numOfBlocks, TSKEY skey, int32_t order) { @@ -439,10 +495,10 @@ static int32_t moveMMapWindow(SQueryFileInfo *pQueryFileInfo, uint64_t offset) { } /* - * 1. there is import data that locate farther from the beginning, but with less timestamp, so we need to move the - * window backwards - * 2. otherwise, move the mmaping window forward - */ + * 1. there is import data that locate farther from the beginning, but with less timestamp, so we need to move the + * window backwards + * 2. otherwise, move the mmaping window forward + */ upperBnd = (offset / pQueryFileInfo->defaultMappingSize + 1) * pQueryFileInfo->defaultMappingSize - 1; /* unmap previous buffer */ @@ -636,7 +692,7 @@ static int32_t loadDataBlockIntoMem(SCompBlock *pBlock, SField **pField, SQueryR SMeterObj *pMeterObj = pRuntimeEnv->pMeterObj; SData ** sdata = pRuntimeEnv->colDataBuffer; - SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pHeaderFiles[fileIdx]; + SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIdx]; SData ** primaryTSBuf = &pRuntimeEnv->primaryColBuffer; void * tmpBuf = pRuntimeEnv->unzipBuffer; @@ -850,9 +906,11 @@ SCacheBlock *getCacheDataBlock(SMeterObj *pMeterObj, SQuery *pQuery, int32_t slo } if (pMeterObj != pBlock->pMeterObj || pBlock->blockId > pQuery->blockId) { - dWarn("QInfo:%p vid:%d sid:%d id:%s, cache block is overwritten, slot:%d blockId:%d qBlockId:%d, meterObj:%p, blockMeterObj:%p", - GET_QINFO_ADDR(pQuery), pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->slot, pBlock->blockId, - pQuery->blockId, pMeterObj, pBlock->pMeterObj); + dWarn( + "QInfo:%p vid:%d sid:%d id:%s, cache block is overwritten, slot:%d blockId:%d qBlockId:%d, meterObj:%p, " + "blockMeterObj:%p", + GET_QINFO_ADDR(pQuery), pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->slot, pBlock->blockId, + pQuery->blockId, pMeterObj, pBlock->pMeterObj); return NULL; } @@ -938,7 +996,7 @@ static bool getQualifiedDataBlock(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRunti break; } - dError("QInfo:%p fileId:%d total numOfBlks:%d blockId:%d into memory failed due to error in disk files", + dError("QInfo:%p fileId:%d total numOfBlks:%d blockId:%d load into memory failed due to error in disk files", GET_QINFO_ADDR(pQuery), pQuery->fileId, pQuery->numOfBlocks, blkIdx); blkIdx += step; } @@ -1110,9 +1168,9 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t for (int32_t k = 0; k < pQuery->numOfOutputCols; ++k) { int32_t functionId = pQuery->pSelectExpr[k].pBase.functionId; -// if (!functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) { -// continue; -// } + // if (!functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) { + // continue; + // } SField dummyField = {0}; @@ -1135,8 +1193,8 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t TSKEY ts = QUERY_IS_ASC_QUERY(pQuery) ? pQuery->skey : pQuery->ekey; - int64_t alignedTimestamp = taosGetIntervalStartTimestamp(ts, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, - pQuery->precision); + int64_t alignedTimestamp = + taosGetIntervalStartTimestamp(ts, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, pQuery->precision); setExecParams(pQuery, &pCtx[k], alignedTimestamp, dataBlock, (char *)primaryKeyCol, forwardStep, functionId, tpField, hasNull, pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag); } @@ -1405,8 +1463,8 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t * char *dataBlock = getDataBlocks(pRuntimeEnv, data, &sasArray[k], k, *forwardStep, isDiskFileBlock); TSKEY ts = QUERY_IS_ASC_QUERY(pQuery) ? pQuery->skey : pQuery->ekey; - int64_t alignedTimestamp = taosGetIntervalStartTimestamp(ts, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, - pQuery->precision); + int64_t alignedTimestamp = + taosGetIntervalStartTimestamp(ts, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, pQuery->precision); setExecParams(pQuery, &pCtx[k], alignedTimestamp, dataBlock, (char *)primaryKeyCol, (*forwardStep), functionId, pFields, hasNull, pRuntimeEnv->blockStatus, &sasArray[k], pRuntimeEnv->scanFlag); @@ -1655,18 +1713,18 @@ int32_t vnodeGetVnodeHeaderFileIdx(int32_t *fid, SQueryRuntimeEnv *pRuntimeEnv, } /* set the initial file for current query */ - if (order == TSQL_SO_ASC && *fid < pRuntimeEnv->pHeaderFiles[0].fileID) { - *fid = pRuntimeEnv->pHeaderFiles[0].fileID; + if (order == TSQL_SO_ASC && *fid < pRuntimeEnv->pVnodeFiles[0].fileID) { + *fid = pRuntimeEnv->pVnodeFiles[0].fileID; return 0; - } else if (order == TSQL_SO_DESC && *fid > pRuntimeEnv->pHeaderFiles[pRuntimeEnv->numOfFiles - 1].fileID) { - *fid = pRuntimeEnv->pHeaderFiles[pRuntimeEnv->numOfFiles - 1].fileID; + } else if (order == TSQL_SO_DESC && *fid > pRuntimeEnv->pVnodeFiles[pRuntimeEnv->numOfFiles - 1].fileID) { + *fid = pRuntimeEnv->pVnodeFiles[pRuntimeEnv->numOfFiles - 1].fileID; return pRuntimeEnv->numOfFiles - 1; } int32_t numOfFiles = pRuntimeEnv->numOfFiles; - if (order == TSQL_SO_DESC && *fid > pRuntimeEnv->pHeaderFiles[numOfFiles - 1].fileID) { - *fid = pRuntimeEnv->pHeaderFiles[numOfFiles - 1].fileID; + if (order == TSQL_SO_DESC && *fid > pRuntimeEnv->pVnodeFiles[numOfFiles - 1].fileID) { + *fid = pRuntimeEnv->pVnodeFiles[numOfFiles - 1].fileID; return numOfFiles - 1; } @@ -1674,12 +1732,12 @@ int32_t vnodeGetVnodeHeaderFileIdx(int32_t *fid, SQueryRuntimeEnv *pRuntimeEnv, int32_t i = 0; int32_t step = 1; - while (i pRuntimeEnv->pHeaderFiles[i].fileID) { + while (i pRuntimeEnv->pVnodeFiles[i].fileID) { i += step; } - if (i < numOfFiles && *fid <= pRuntimeEnv->pHeaderFiles[i].fileID) { - *fid = pRuntimeEnv->pHeaderFiles[i].fileID; + if (i < numOfFiles && *fid <= pRuntimeEnv->pVnodeFiles[i].fileID) { + *fid = pRuntimeEnv->pVnodeFiles[i].fileID; return i; } else { return -1; @@ -1688,12 +1746,12 @@ int32_t vnodeGetVnodeHeaderFileIdx(int32_t *fid, SQueryRuntimeEnv *pRuntimeEnv, int32_t i = numOfFiles - 1; int32_t step = -1; - while (i >= 0 && *fid < pRuntimeEnv->pHeaderFiles[i].fileID) { + while (i >= 0 && *fid < pRuntimeEnv->pVnodeFiles[i].fileID) { i += step; } - if (i >= 0 && *fid >= pRuntimeEnv->pHeaderFiles[i].fileID) { - *fid = pRuntimeEnv->pHeaderFiles[i].fileID; + if (i >= 0 && *fid >= pRuntimeEnv->pVnodeFiles[i].fileID) { + *fid = pRuntimeEnv->pVnodeFiles[i].fileID; return i; } else { return -1; @@ -1723,6 +1781,7 @@ int32_t getNextDataFileCompInfo(SQueryRuntimeEnv *pRuntimeEnv, SMeterObj *pMeter break; } + // failed to mmap header file into memory will cause the retrieval of compblock info failed if (vnodeGetCompBlockInfo(pMeterObj, pRuntimeEnv, fid) > 0) { break; } @@ -1821,13 +1880,13 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, int64_t startQueryTimes } // set the output buffer for the selectivity + tag query -static void setCtxTagColumnInfo(SQuery* pQuery, SQueryRuntimeEnv* pRuntimeEnv) { +static void setCtxTagColumnInfo(SQuery *pQuery, SQueryRuntimeEnv *pRuntimeEnv) { if (isSelectivityWithTagsQuery(pQuery)) { int32_t num = 0; SQLFunctionCtx *pCtx = NULL; int16_t tagLen = 0; - SQLFunctionCtx ** pTagCtx = calloc(pQuery->numOfOutputCols, POINTER_BYTES); + SQLFunctionCtx **pTagCtx = calloc(pQuery->numOfOutputCols, POINTER_BYTES); for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { SSqlFuncExprMsg *pSqlFuncMsg = &pQuery->pSelectExpr[i].pBase; if (pSqlFuncMsg->functionId == TSDB_FUNC_TAG_DUMMY || pSqlFuncMsg->functionId == TSDB_FUNC_TS_DUMMY) { @@ -1973,7 +2032,7 @@ _error_clean: tfree(pRuntimeEnv->resultInfo); tfree(pRuntimeEnv->pCtx); - for(int32_t i = 0; i < pRuntimeEnv->pQuery->numOfCols; ++i) { + for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfCols; ++i) { tfree(pRuntimeEnv->colDataBuffer[i]); } @@ -1993,7 +2052,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } dTrace("QInfo:%p teardown runtime env", GET_QINFO_ADDR(pRuntimeEnv->pQuery)); - for(int32_t i = 0; i < pRuntimeEnv->pQuery->numOfCols; ++i) { + for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfCols; ++i) { tfree(pRuntimeEnv->colDataBuffer[i]); } @@ -2024,7 +2083,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } for (int32_t i = 0; i < pRuntimeEnv->numOfFiles; ++i) { - SQueryFileInfo *pQFileInfo = &(pRuntimeEnv->pHeaderFiles[i]); + SQueryFileInfo *pQFileInfo = &(pRuntimeEnv->pVnodeFiles[i]); if (pQFileInfo->pHeaderFileData != NULL && pQFileInfo->pHeaderFileData != MAP_FAILED) { munmap(pQFileInfo->pHeaderFileData, pQFileInfo->headFileSize); } @@ -2038,9 +2097,9 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { tclose(pQFileInfo->lastFd); } - if (pRuntimeEnv->pHeaderFiles != NULL) { + if (pRuntimeEnv->pVnodeFiles != NULL) { pRuntimeEnv->numOfFiles = 0; - free(pRuntimeEnv->pHeaderFiles); + free(pRuntimeEnv->pVnodeFiles); } if (pRuntimeEnv->pInterpoBuf != NULL) { @@ -2791,11 +2850,17 @@ int64_t loadRequiredBlockIntoMem(SQueryRuntimeEnv *pRuntimeEnv, SPositionInfo *p } /* - * NOTE: the compblock information may not be loaded yet, here loaded it firstly + * NOTE: + * The compblock information may not be loaded yet, here loaded it firstly. * If the compBlock info is loaded, it wont be loaded again. + * + * If failed to load comp block into memory due some how reasons, e.g., empty header file/not enough memory */ int32_t numOfBlocks = vnodeGetCompBlockInfo(pMeterObj, pRuntimeEnv, fileIdx); - assert(numOfBlocks > 0); + if (numOfBlocks <= 0) { + position->fileId = -1; + return -1; + } nextTimestamp = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos); } @@ -2865,71 +2930,28 @@ static int file_order_comparator(const void *p1, const void *p2) { */ static int32_t vnodeOpenVnodeDBFiles(SQInfo *pQInfo, SQueryFileInfo *pVnodeFiles, int32_t fid, int32_t vnodeId, char *fileName, char *prefix) { - __off_t size = 0; + // __off_t size = 0; pVnodeFiles->fileID = fid; pVnodeFiles->defaultMappingSize = DEFAULT_DATA_FILE_MMAP_WINDOW_SIZE; snprintf(pVnodeFiles->headerFilePath, 256, "%s%s", prefix, fileName); - -#if 1 pVnodeFiles->headerFd = open(pVnodeFiles->headerFilePath, O_RDONLY); -#else - int32_t *val = (int32_t *)taosGetStrHashData(fileHandleHashList, pVnodeFiles->headerFilePath); - if (val == NULL) { - pVnodeFiles->headerFd = open(pVnodeFiles->headerFilePath, O_RDONLY); - taosAddStrHash(fileHandleHashList, pVnodeFiles->headerFilePath, (char *)&pVnodeFiles->headerFd); - } else { - pVnodeFiles->headerFd = *val; - } -#endif if (!VALIDFD(pVnodeFiles->headerFd)) { dError("QInfo:%p failed open header file:%s reason:%s", pQInfo, pVnodeFiles->headerFilePath, strerror(errno)); goto _clean; } - struct stat fstat; + struct stat fstat = {0}; if (stat(pVnodeFiles->headerFilePath, &fstat) < 0) return -1; pVnodeFiles->headFileSize = fstat.st_size; - size = fstat.st_size; - - pVnodeFiles->pHeaderFileData = mmap(NULL, size, PROT_READ, MAP_SHARED, pVnodeFiles->headerFd, 0); - if (pVnodeFiles->pHeaderFileData == MAP_FAILED) { - dError("QInfo:%p failed to map header file:%s, %s", pQInfo, pVnodeFiles->headerFilePath, strerror(errno)); - goto _clean; - } - - /* even the advise failed, continue.. */ - if (madvise(pVnodeFiles->pHeaderFileData, size, MADV_SEQUENTIAL) == -1) { - dError("QInfo:%p failed to advise kernel the usage of header files, reason:%s", pQInfo, strerror(errno)); - } snprintf(pVnodeFiles->dataFilePath, 256, "%sv%df%d.data", prefix, vnodeId, fid); snprintf(pVnodeFiles->lastFilePath, 256, "%sv%df%d.last", prefix, vnodeId, fid); -#if 1 pVnodeFiles->dataFd = open(pVnodeFiles->dataFilePath, O_RDONLY); pVnodeFiles->lastFd = open(pVnodeFiles->lastFilePath, O_RDONLY); -#else - val = (int32_t *)taosGetStrHashData(fileHandleHashList, pVnodeFiles->dataFilePath); - if (val == NULL) { - pVnodeFiles->dataFd = open(pVnodeFiles->dataFilePath, O_RDONLY); - taosAddStrHash(fileHandleHashList, pVnodeFiles->dataFilePath, (char *)&pVnodeFiles->dataFd); - } else { - pVnodeFiles->dataFd = *val; - } -#endif - - if (!VALIDFD(pVnodeFiles->dataFd)) { - dError("QInfo:%p failed to open data file:%s, reason:%s", pQInfo, pVnodeFiles->dataFilePath, strerror(errno)); - goto _clean; - } - - if (!VALIDFD(pVnodeFiles->lastFd)) { - dError("QInfo:%p failed to open last file:%s, reason:%s", pQInfo, pVnodeFiles->lastFilePath, strerror(errno)); - goto _clean; - } if (stat(pVnodeFiles->dataFilePath, &fstat) < 0) return -1; pVnodeFiles->dataFileSize = fstat.st_size; @@ -2953,13 +2975,9 @@ static int32_t vnodeOpenVnodeDBFiles(SQInfo *pQInfo, SQueryFileInfo *pVnodeFiles } #endif - return 0; + return TSDB_CODE_SUCCESS; _clean: - if (pVnodeFiles->pHeaderFileData != MAP_FAILED && pVnodeFiles->pDataFileData != NULL) { - munmap(pVnodeFiles->pHeaderFileData, pVnodeFiles->headFileSize); - pVnodeFiles->pHeaderFileData = NULL; - } #if DEFAULT_IO_ENGINE == IO_ENGINE_MMAP if (pVnodeFiles->pDataFileData != MAP_FAILED && pVnodeFiles->pDataFileData != NULL) { @@ -2987,10 +3005,10 @@ static void vnodeOpenAllFiles(SQInfo *pQInfo, int32_t vnodeId) { char suffix[] = ".head"; struct dirent *pEntry = NULL; - int32_t alloc = 4; // default allocated size + size_t alloc = 4; // default allocated size SQueryRuntimeEnv *pRuntimeEnv = &(pQInfo->pMeterQuerySupporter->runtimeEnv); - pRuntimeEnv->pHeaderFiles = calloc(1, sizeof(SQueryFileInfo) * alloc); + pRuntimeEnv->pVnodeFiles = calloc(1, sizeof(SQueryFileInfo) * alloc); SVnodeObj *pVnode = &vnodeList[vnodeId]; while ((pEntry = readdir(pDir)) != NULL) { @@ -3026,11 +3044,11 @@ static void vnodeOpenAllFiles(SQInfo *pQInfo, int32_t vnodeId) { if (++pRuntimeEnv->numOfFiles > alloc) { alloc = alloc << 1; - pRuntimeEnv->pHeaderFiles = realloc(pRuntimeEnv->pHeaderFiles, alloc * sizeof(SQueryFileInfo)); - memset(&pRuntimeEnv->pHeaderFiles[alloc >> 1], 0, (alloc >> 1) * sizeof(SQueryFileInfo)); + pRuntimeEnv->pVnodeFiles = realloc(pRuntimeEnv->pVnodeFiles, alloc * sizeof(SQueryFileInfo)); + memset(&pRuntimeEnv->pVnodeFiles[alloc >> 1], 0, (alloc >> 1) * sizeof(SQueryFileInfo)); } - SQueryFileInfo *pVnodeFiles = &pRuntimeEnv->pHeaderFiles[pRuntimeEnv->numOfFiles - 1]; + SQueryFileInfo *pVnodeFiles = &pRuntimeEnv->pVnodeFiles[pRuntimeEnv->numOfFiles - 1]; int32_t ret = vnodeOpenVnodeDBFiles(pQInfo, pVnodeFiles, fid, vnodeId, pEntry->d_name, dbFilePathPrefix); if (ret < 0) { memset(pVnodeFiles, 0, sizeof(SQueryFileInfo)); // reset information @@ -3043,7 +3061,7 @@ static void vnodeOpenAllFiles(SQInfo *pQInfo, int32_t vnodeId) { dTrace("QInfo:%p find %d data files in %s to be checked", pQInfo, pRuntimeEnv->numOfFiles, dbFilePathPrefix); /* order the files information according their names */ - qsort(pRuntimeEnv->pHeaderFiles, (size_t)pRuntimeEnv->numOfFiles, sizeof(SQueryFileInfo), file_order_comparator); + qsort(pRuntimeEnv->pVnodeFiles, (size_t)pRuntimeEnv->numOfFiles, sizeof(SQueryFileInfo), file_order_comparator); } static void updateOffsetVal(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *pBlockInfo, void *pBlock) { @@ -3122,8 +3140,8 @@ static bool onlyOneQueryType(SQuery *pQuery, int32_t functId, int32_t functIdDst for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { int32_t functionId = pQuery->pSelectExpr[i].pBase.functionId; - if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || - functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAG_DUMMY) { + if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG || + functionId == TSDB_FUNC_TAG_DUMMY) { continue; } @@ -3141,7 +3159,8 @@ static bool onlyLastQuery(SQuery *pQuery) { return onlyOneQueryType(pQuery, TSDB static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { // in case of point-interpolation query, use asc order scan - char msg[] = "QInfo:%p scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%lld-%lld, " + char msg[] = + "QInfo:%p scan order changed for %s query, old:%d, new:%d, qrange exchanged, old qrange:%lld-%lld, " "new qrange:%lld-%lld"; // descending order query @@ -3440,12 +3459,12 @@ void pointInterpSupporterSetData(SQInfo *pQInfo, SPointInterpoSupporter *pPointI // only the function of interp needs the corresponding information if (pCtx->functionId != TSDB_FUNC_INTERP) { - continue; + continue; } pCtx->numOfParams = 4; - SInterpInfo * pInterpInfo = (SInterpInfo *)pRuntimeEnv->pCtx[i].aOutputBuf; + SInterpInfo *pInterpInfo = (SInterpInfo *)pRuntimeEnv->pCtx[i].aOutputBuf; pInterpInfo->pInterpDetail = calloc(1, sizeof(SInterpInfoDetail)); @@ -3624,6 +3643,7 @@ int32_t vnodeQuerySingleMeterPrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete // dataInCache requires lastKey value pQuery->lastKey = pQuery->skey; + pSupporter->runtimeEnv.mmapedHFileIndex = -1; // set the initial value vnodeInitDataBlockInfo(&pSupporter->runtimeEnv.loadBlockInfo); vnodeInitLoadCompBlockInfo(&pSupporter->runtimeEnv.loadCompBlockInfo); @@ -3793,6 +3813,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) changeExecuteScanOrder(pQuery, true); + pSupporter->runtimeEnv.mmapedHFileIndex = -1; // set the initial value vnodeInitDataBlockInfo(&pSupporter->runtimeEnv.loadBlockInfo); vnodeInitLoadCompBlockInfo(&pSupporter->runtimeEnv.loadCompBlockInfo); @@ -3917,13 +3938,13 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) { } // todo merge with doRevisedResultsByLimit -void UNUSED_FUNC truncateResultByLimit(SQInfo *pQInfo, int64_t * final, int32_t *interpo) { +void UNUSED_FUNC truncateResultByLimit(SQInfo *pQInfo, int64_t *final, int32_t *interpo) { SQuery *pQuery = &(pQInfo->query); - if (pQuery->limit.limit > 0 && ((* final) + pQInfo->pointsRead > pQuery->limit.limit)) { - int64_t num = (* final) + pQInfo->pointsRead - pQuery->limit.limit; + if (pQuery->limit.limit > 0 && ((*final) + pQInfo->pointsRead > pQuery->limit.limit)) { + int64_t num = (*final) + pQInfo->pointsRead - pQuery->limit.limit; (*interpo) -= num; - (* final) -= num; + (*final) -= num; setQueryStatus(pQuery, QUERY_COMPLETED); // query completed } @@ -3974,7 +3995,7 @@ TSKEY getTimestampInDiskBlock(SQueryRuntimeEnv *pRuntimeEnv, int32_t index) { // the fields info is not loaded, load it into memory if (pQuery->pFields == NULL || pQuery->pFields[pQuery->slot] == NULL) { - loadDataBlockFieldsInfo(pRuntimeEnv, &pRuntimeEnv->pHeaderFiles[fileIndex], pBlock, &pQuery->pFields[pQuery->slot]); + loadDataBlockFieldsInfo(pRuntimeEnv, &pRuntimeEnv->pVnodeFiles[fileIndex], pBlock, &pQuery->pFields[pQuery->slot]); } SET_DATA_BLOCK_LOADED(pRuntimeEnv->blockStatus); @@ -4006,7 +4027,7 @@ static void getFirstDataBlockInCache(SQueryRuntimeEnv *pRuntimeEnv) { } } -//TODO handle case that the cache is allocated but not assign to SMeterObj +// TODO handle case that the cache is allocated but not assign to SMeterObj void getQueryPositionForCacheInvalid(SQueryRuntimeEnv *pRuntimeEnv, __block_search_fn_t searchFn) { SQuery * pQuery = pRuntimeEnv->pQuery; SQInfo * pQInfo = (SQInfo *)GET_QINFO_ADDR(pQuery); @@ -4464,17 +4485,18 @@ static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, tFilePage pCtx[i].hasNull = true; pCtx[i].nStartQueryTimestamp = timestamp; - pCtx[i].aInputElemBuf = ((char *) inputSrc->data) + - ((int32_t) pRuntimeEnv->offset[i] * pRuntimeEnv->numOfRowsPerPage) + pCtx[i].outputBytes * inputIdx; + pCtx[i].aInputElemBuf = ((char *)inputSrc->data) + + ((int32_t)pRuntimeEnv->offset[i] * pRuntimeEnv->numOfRowsPerPage) + + pCtx[i].outputBytes * inputIdx; - //in case of tag column, the tag information should be extracted from input buffer + // in case of tag column, the tag information should be extracted from input buffer if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TAG) { tVariantDestroy(&pCtx[i].tag); tVariantCreateFromBinary(&pCtx[i].tag, pCtx[i].aInputElemBuf, pCtx[i].inputBytes, pCtx[i].inputType); } } - for(int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { + for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { int32_t functionId = pQuery->pSelectExpr[i].pBase.functionId; if (functionId == TSDB_FUNC_TAG_DUMMY) { continue; @@ -4942,7 +4964,8 @@ void disableFunctForSuppleScan(SQueryRuntimeEnv *pRuntimeEnv, int32_t order) { } } } - } else { + } else { // TODO ERROR!! + // need to handle for each query result, not just the single runtime ctx. for (int32_t i = 0; i < pQuery->numOfOutputCols; ++i) { pRuntimeEnv->pCtx[i].order = (pRuntimeEnv->pCtx[i].order) ^ 1; int32_t functId = pQuery->pSelectExpr[i].pBase.functionId; @@ -5460,15 +5483,18 @@ static int32_t offsetComparator(const void *pLeft, const void *pRight) { * @param pMeterHeadDataInfo * @return */ -SMeterDataInfo **vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, SQueryFileInfo *pQueryFileInfo, - tSidSet *pSidSet, SMeterDataInfo *pMeterDataInfo, int32_t *numOfMeters) { - SQuery * pQuery = &pQInfo->query; +SMeterDataInfo **vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, int32_t fileIndex, tSidSet *pSidSet, + SMeterDataInfo *pMeterDataInfo, int32_t *numOfMeters) { + SQuery *pQuery = &pQInfo->query; + SMeterQuerySupportObj *pSupporter = pQInfo->pMeterQuerySupporter; SMeterSidExtInfo ** pMeterSidExtInfo = pSupporter->pMeterSidExtInfo; + SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv; + SQueryFileInfo * pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIndex]; SVnodeObj *pVnode = &vnodeList[vid]; - char * pHeaderData = pQueryFileInfo->pHeaderFileData; + char * pHeaderData = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); int32_t tmsize = sizeof(SCompHeader) * (pVnode->cfg.maxSessions) + sizeof(TSCKSUM); // file is corrupted, abort query in current file @@ -6467,7 +6493,7 @@ int32_t LoadDatablockOnDemand(SCompBlock *pBlock, SField **pFields, int8_t *blkS int32_t fileIdx, int32_t slotIdx, __block_search_fn_t searchFn, bool onDemand) { SQuery * pQuery = pRuntimeEnv->pQuery; SMeterObj * pMeterObj = pRuntimeEnv->pMeterObj; - SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pHeaderFiles[fileIdx]; + SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIdx]; TSKEY *primaryKeys = (TSKEY *)pRuntimeEnv->primaryColBuffer->data; @@ -6869,7 +6895,7 @@ bool vnodeHasRemainResults(void *handle) { // query has completed if (Q_STATUS_EQUAL(pQuery->over, QUERY_COMPLETED | QUERY_NO_DATA_TO_CHECK)) { - TSKEY ekey = taosGetRevisedEndKey(pSupporter->rawEKey, pQuery->order.order, pQuery->nAggTimeInterval, + TSKEY ekey = taosGetRevisedEndKey(pSupporter->rawEKey, pQuery->order.order, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, pQuery->precision); int32_t numOfTotal = taosGetNumOfResultWithInterpo(pInterpoInfo, (TSKEY *)pRuntimeEnv->pInterpoBuf[0]->data, remain, pQuery->nAggTimeInterval, ekey, pQuery->pointsToRead); @@ -6914,18 +6940,18 @@ static int32_t resultInterpolate(SQInfo *pQInfo, tFilePage **data, tFilePage **p return numOfRes; } -static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char* data, int32_t* size) { - SMeterObj* pObj = pQInfo->pObj; - SQuery* pQuery = &pQInfo->query; +static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data, int32_t *size) { + SMeterObj *pObj = pQInfo->pObj; + SQuery * pQuery = &pQInfo->query; - int tnumOfRows = vnodeList[pObj->vnode].cfg.rowsInFileBlock; + int tnumOfRows = vnodeList[pObj->vnode].cfg.rowsInFileBlock; int32_t dataSize = pQInfo->query.rowSize * numOfRows; if (dataSize >= tsCompressMsgSize && tsCompressMsgSize > 0) { - char* compBuf = malloc((size_t) dataSize); + char *compBuf = malloc((size_t)dataSize); // for metric query, bufIndex always be 0. - char* d = compBuf; + char *d = compBuf; for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { // pQInfo->bufIndex == 0 int32_t bytes = pQuery->pSelectExpr[col].resBytes; @@ -6937,7 +6963,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char* data dTrace("QInfo:%p compress rsp msg, before:%d, after:%d", pQInfo, dataSize, *size); free(compBuf); - } else { // for metric query, bufIndex always be 0. + } else { // for metric query, bufIndex always be 0. for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { // pQInfo->bufIndex == 0 int32_t bytes = pQuery->pSelectExpr[col].resBytes; @@ -6958,9 +6984,9 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char* data * @param numOfRows the number of rows that are not returned in current retrieve * @return */ -int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, int32_t* size) { +int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, int32_t *size) { SQInfo *pQInfo = (SQInfo *)handle; - SQuery * pQuery = &pQInfo->query; + SQuery *pQuery = &pQInfo->query; assert(pQuery->pSelectExpr != NULL && pQuery->numOfOutputCols > 0); @@ -6998,7 +7024,7 @@ int32_t vnodeQueryResultInterpolate(SQInfo *pQInfo, tFilePage **pDst, tFilePage while (1) { numOfRows = taosNumOfRemainPoints(&pRuntimeEnv->interpoInfo); - TSKEY ekey = taosGetRevisedEndKey(pSupporter->rawEKey, pQuery->order.order, pQuery->nAggTimeInterval, + TSKEY ekey = taosGetRevisedEndKey(pSupporter->rawEKey, pQuery->order.order, pQuery->nAggTimeInterval, pQuery->intervalTimeUnit, pQuery->precision); int32_t numOfFinalRows = taosGetNumOfResultWithInterpo(&pRuntimeEnv->interpoInfo, (TSKEY *)pDataSrc[0]->data, numOfRows, diff --git a/src/system/detail/src/vnodeQueryProcess.c b/src/system/detail/src/vnodeQueryProcess.c index 2fae48b143..4f95f8096b 100644 --- a/src/system/detail/src/vnodeQueryProcess.c +++ b/src/system/detail/src/vnodeQueryProcess.c @@ -289,12 +289,11 @@ static SMeterDataInfo *queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMe pQuery->fileId = fid; pSummary->numOfFiles++; - SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pHeaderFiles[fileIdx]; - char * pHeaderData = pQueryFileInfo->pHeaderFileData; + SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIdx]; int32_t numOfQualifiedMeters = 0; - SMeterDataInfo **pReqMeterDataInfo = vnodeFilterQualifiedMeters( - pQInfo, vnodeId, pQueryFileInfo, pSupporter->pSidSet, pMeterDataInfo, &numOfQualifiedMeters); + SMeterDataInfo **pReqMeterDataInfo = vnodeFilterQualifiedMeters(pQInfo, vnodeId, fileIdx, pSupporter->pSidSet, + pMeterDataInfo, &numOfQualifiedMeters); dTrace("QInfo:%p file:%s, %d meters qualified", pQInfo, pQueryFileInfo->dataFilePath, numOfQualifiedMeters); if (pReqMeterDataInfo == NULL) { @@ -312,6 +311,11 @@ static SMeterDataInfo *queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMe continue; } + char *pHeaderData = vnodeGetHeaderFileData(pRuntimeEnv, fileIdx); + if (pHeaderData == NULL) { // failed to mmap header file into buffer + continue; + } + uint32_t numOfBlocks = getDataBlocksForMeters(pSupporter, pQuery, pHeaderData, numOfQualifiedMeters, pQueryFileInfo, pReqMeterDataInfo); @@ -500,7 +504,7 @@ static int64_t doCheckMetersInGroup(SQInfo *pQInfo, int32_t index, int32_t start #if DEFAULT_IO_ENGINE == IO_ENGINE_MMAP for (int32_t i = 0; i < pRuntimeEnv->numOfFiles; ++i) { - resetMMapWindow(&pRuntimeEnv->pHeaderFiles[i]); + resetMMapWindow(&pRuntimeEnv->pVnodeFiles[i]); } #endif @@ -670,7 +674,7 @@ static void vnodeMultiMeterMultiOutputProcessor(SQInfo *pQInfo) { #if DEFAULT_IO_ENGINE == IO_ENGINE_MMAP for (int32_t i = 0; i < pRuntimeEnv->numOfFiles; ++i) { - resetMMapWindow(&pRuntimeEnv->pHeaderFiles[i]); + resetMMapWindow(&pRuntimeEnv->pVnodeFiles[i]); } #endif From cdaa3871a173b025bc08e394f999b08d2155954c Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 25 Nov 2019 17:22:17 +0800 Subject: [PATCH 41/42] refactor code --- src/system/detail/src/vnodeQueryImpl.c | 25 +++++++++++++---------- src/system/detail/src/vnodeQueryProcess.c | 14 ++++++------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c index 5a6a558436..a78c388441 100644 --- a/src/system/detail/src/vnodeQueryImpl.c +++ b/src/system/detail/src/vnodeQueryImpl.c @@ -256,9 +256,9 @@ static void doUnmapHeaderFileData(SQueryRuntimeEnv* pRuntimeEnv) { otherVnodeFiles->pHeaderFileData = NULL; pRuntimeEnv->mmapedHFileIndex = -1; - } else { - assert(pRuntimeEnv->mmapedHFileIndex == -1); } + + assert(pRuntimeEnv->mmapedHFileIndex == -1); } /** @@ -286,12 +286,12 @@ char *vnodeGetHeaderFileData(SQueryRuntimeEnv *pRuntimeEnv, int32_t fileIndex) { pVnodeFiles->pHeaderFileData = mmap(NULL, size, PROT_READ, MAP_SHARED, pVnodeFiles->headerFd, 0); if (pVnodeFiles->pHeaderFileData == MAP_FAILED) { pVnodeFiles->pHeaderFileData = NULL; - dError("QInfo:%p failed to map header file:%s, size:%lld, %s", pQInfo, pVnodeFiles->headerFilePath, size, + dError("QInfo:%p failed to mmap header file:%s, size:%lld, %s", pQInfo, pVnodeFiles->headerFilePath, size, strerror(errno)); } else { pRuntimeEnv->mmapedHFileIndex = fileIndex; // set the value in case of success mmap file if (madvise(pVnodeFiles->pHeaderFileData, size, MADV_SEQUENTIAL) == -1) { - dError("QInfo:%p failed to advise kernel the usage of header files, reason:%s", pQInfo, strerror(errno)); + dError("QInfo:%p failed to advise kernel the usage of header file, reason:%s", pQInfo, strerror(errno)); } } } else { @@ -326,9 +326,9 @@ static int vnodeGetCompBlockInfo(SMeterObj *pMeterObj, SQueryRuntimeEnv *pRuntim pSummary->numOfSeek++; #if 1 - char *data = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); // failed to load the header file data into memory + char *data = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); if (data == NULL) { - return -1; + return -1; // failed to load the header file data into memory } #else @@ -2842,9 +2842,8 @@ int64_t loadRequiredBlockIntoMem(SQueryRuntimeEnv *pRuntimeEnv, SPositionInfo *p * currently opened file is not the start file, reset to the start file */ int32_t fileIdx = vnodeGetVnodeHeaderFileIdx(&pQuery->fileId, pRuntimeEnv, pQuery->order.order); - if (fileIdx < 0) { + if (fileIdx < 0) { // ignore the files on disk dError("QInfo:%p failed to get data file:%d", GET_QINFO_ADDR(pQuery), pQuery->fileId); - // ignore the files on disk position->fileId = -1; return -1; } @@ -5494,11 +5493,15 @@ SMeterDataInfo **vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, int32_t SVnodeObj *pVnode = &vnodeList[vid]; - char * pHeaderData = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); + char * pHeaderFileData = vnodeGetHeaderFileData(pRuntimeEnv, fileIndex); + if (pHeaderFileData == NULL) { // failed to load header file into buffer + return 0; + } + int32_t tmsize = sizeof(SCompHeader) * (pVnode->cfg.maxSessions) + sizeof(TSCKSUM); // file is corrupted, abort query in current file - if (validateHeaderOffsetSegment(pQInfo, pQueryFileInfo->headerFilePath, vid, pHeaderData, tmsize) < 0) { + if (validateHeaderOffsetSegment(pQInfo, pQueryFileInfo->headerFilePath, vid, pHeaderFileData, tmsize) < 0) { *numOfMeters = 0; return 0; } @@ -5549,7 +5552,7 @@ SMeterDataInfo **vnodeFilterQualifiedMeters(SQInfo *pQInfo, int32_t vid, int32_t int64_t headerOffset = TSDB_FILE_HEADER_LEN + sizeof(SCompHeader) * pMeterObj->sid; - SCompHeader *compHeader = (SCompHeader *)(pHeaderData + headerOffset); + SCompHeader *compHeader = (SCompHeader *)(pHeaderFileData + headerOffset); if (compHeader->compInfoOffset == 0) { continue; diff --git a/src/system/detail/src/vnodeQueryProcess.c b/src/system/detail/src/vnodeQueryProcess.c index 4f95f8096b..4703f7f8db 100644 --- a/src/system/detail/src/vnodeQueryProcess.c +++ b/src/system/detail/src/vnodeQueryProcess.c @@ -290,11 +290,14 @@ static SMeterDataInfo *queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMe pSummary->numOfFiles++; SQueryFileInfo *pQueryFileInfo = &pRuntimeEnv->pVnodeFiles[fileIdx]; - + char *pHeaderData = vnodeGetHeaderFileData(pRuntimeEnv, fileIdx); + if (pHeaderData == NULL) { // failed to mmap header file into buffer, ignore current file, try next + continue; + } + int32_t numOfQualifiedMeters = 0; SMeterDataInfo **pReqMeterDataInfo = vnodeFilterQualifiedMeters(pQInfo, vnodeId, fileIdx, pSupporter->pSidSet, pMeterDataInfo, &numOfQualifiedMeters); - dTrace("QInfo:%p file:%s, %d meters qualified", pQInfo, pQueryFileInfo->dataFilePath, numOfQualifiedMeters); if (pReqMeterDataInfo == NULL) { dError("QInfo:%p failed to allocate memory to perform query processing, abort", pQInfo); @@ -304,6 +307,8 @@ static SMeterDataInfo *queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMe return NULL; } + dTrace("QInfo:%p file:%s, %d meters qualified", pQInfo, pQueryFileInfo->dataFilePath, numOfQualifiedMeters); + // none of meters in query set have pHeaderData in this file, try next file if (numOfQualifiedMeters == 0) { fid += step; @@ -311,11 +316,6 @@ static SMeterDataInfo *queryOnMultiDataFiles(SQInfo *pQInfo, SMeterDataInfo *pMe continue; } - char *pHeaderData = vnodeGetHeaderFileData(pRuntimeEnv, fileIdx); - if (pHeaderData == NULL) { // failed to mmap header file into buffer - continue; - } - uint32_t numOfBlocks = getDataBlocksForMeters(pSupporter, pQuery, pHeaderData, numOfQualifiedMeters, pQueryFileInfo, pReqMeterDataInfo); From a48c13aaf1427072013b5d4fe758ab23617e614e Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Mon, 25 Nov 2019 18:06:37 +0800 Subject: [PATCH 42/42] [tbase-1225] --- src/client/src/tscServer.c | 26 +++++++++++++++++++------- src/util/src/tglobalcfg.c | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 40db4d934f..6a66b860d7 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -59,6 +59,22 @@ void tscPrintMgmtIp() { } #endif +/* + * For each management node, try twice at least in case of poor network situation. + * If the client start to connect to a non-management node from the client, and the first retry may fail due to + * the poor network quality. And then, the second retry get the response with redirection command. + * The retry will not be executed since only *two* retry is allowed in case of single management node in the cluster. + * Therefore, we need to multiply the retry times by factor of 2 to fix this problem. + */ +static int32_t tscGetMgmtConnMaxRetryTimes() { + int32_t factor = 2; +#ifdef CLUSTER + return tscMgmtIpList.numOfIps * factor; +#else + return 1*factor; +#endif +} + void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { STscObj *pObj = (STscObj *)param; if (pObj == NULL) return; @@ -134,18 +150,17 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { tscProcessSql(pObj->pHb); } -//TODO HANDLE error from mgmt void tscGetConnToMgmt(SSqlObj *pSql, uint8_t *pCode) { STscObj *pTscObj = pSql->pTscObj; #ifdef CLUSTER - if (pSql->retry < tscMgmtIpList.numOfIps) { + if (pSql->retry < tscGetMgmtConnMaxRetryTimes()) { *pCode = 0; pSql->retry++; pSql->index = pSql->index % tscMgmtIpList.numOfIps; if (pSql->cmd.command > TSDB_SQL_READ && pSql->index == 0) pSql->index = 1; void *thandle = taosGetConnFromCache(tscConnCache, tscMgmtIpList.ip[pSql->index], TSC_MGMT_VNODE, pTscObj->user); #else - if (pSql->retry < 1) { + if (pSql->retry < tscGetMgmtConnMaxRetryTimes()) { *pCode = 0; pSql->retry++; void *thandle = taosGetConnFromCache(tscConnCache, tsServerIp, TSC_MGMT_VNODE, pTscObj->user); @@ -444,16 +459,13 @@ void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle) { } } else { uint16_t rspCode = pMsg->content[0]; -#ifdef CLUSTER +#ifdef CLUSTER if (rspCode == TSDB_CODE_REDIRECT) { tscTrace("%p it shall be redirected!", pSql); taosAddConnIntoCache(tscConnCache, thandle, pSql->ip, pSql->vnode, pObj->user); pSql->thandle = NULL; - - // reset the retry times for a new mgmt node - pSql->retry = 0; if (pCmd->command > TSDB_SQL_MGMT) { tscProcessMgmtRedirect(pSql, pMsg->content + 1); diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 6991e6b8b6..0dd0e4e2ba 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -510,7 +510,7 @@ static void doInitGlobalConfig() { 0, TSDB_MAX_VNODES, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "tables", &tsSessionsPerVnode, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 4, 220000, 0, TSDB_CFG_UTYPE_NONE); + TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE, 0, TSDB_CFG_UTYPE_NONE); tsInitConfigOption(cfg++, "cache", &tsCacheBlockSize, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 100, 1048576, 0, TSDB_CFG_UTYPE_BYTE);