提交 8b05ac99 编写于 作者: S slguan

fix issue #212

上级 8133a76a
......@@ -84,8 +84,7 @@ void taos_query_a(TAOS *taos, char *sqlstr, void (*fp)(void *, TAOS_RES *, int),
pRes->qhandle = 0;
pRes->numOfRows = 1;
strtolower(sqlstr, pSql->sqlstr);
pSql->sqlstr[sqlLen] = 0;
strtolower(pSql->sqlstr, sqlstr);
tscTrace("%p Async SQL: %s, pObj:%p", pSql, pSql->sqlstr, pObj);
int32_t code = tsParseSql(pSql, pObj->acctId, pObj->db, true);
......
......@@ -1949,7 +1949,7 @@ int32_t getColumnIndexByName(SSQLToken* pToken, SSchema* pSchema, int32_t numOfC
return -1;
}
char* r = strnchr(pToken->z, '.', pToken->n);
char* r = strnchr(pToken->z, '.', pToken->n, false);
if (r != NULL) {
r += 1;
......@@ -3172,7 +3172,7 @@ int32_t getTimeRange(int64_t* stime, int64_t* etime, tSQLExpr* pRight, int32_t o
bool parsed = false;
if (pRight->val.nType == TSDB_DATA_TYPE_BINARY) {
strdequote(pRight->val.pz);
char* seg = strnchr(pRight->val.pz, '-', pRight->val.nLen);
char* seg = strnchr(pRight->val.pz, '-', pRight->val.nLen, false);
if (seg != NULL) {
if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) {
parsed = true;
......
......@@ -2807,8 +2807,7 @@ int tscGetMeterMetaEx(SSqlObj *pSql, char *meterId, bool createIfNotExists) {
* successfully created the corresponding table.
*/
static void tscWaitingForCreateTable(SSqlCmd *pCmd) {
int32_t CREATE_METER_ON_DEMAND = 1;
if (pCmd->command == TSDB_SQL_INSERT && pCmd->defaultVal[0] == CREATE_METER_ON_DEMAND) {
if (pCmd->command == TSDB_SQL_INSERT) {
taosMsleep(50); // todo: global config
}
}
......
......@@ -88,7 +88,7 @@ TAOS *taos_connect_imp(char *ip, char *user, char *pass, char *db, int port, voi
strcpy(tmp, db);
strdequote(tmp);
strtolower(tmp, pObj->db);
strtolower(pObj->db, tmp);
}
pthread_mutex_init(&pObj->mutex, NULL);
......@@ -198,8 +198,7 @@ int taos_query(TAOS *taos, char *sqlstr) {
return pRes->code;
}
strtolower(sqlstr, pSql->sqlstr);
pSql->sqlstr[sqlLen] = 0;
strtolower(pSql->sqlstr, sqlstr);
pRes->code = (uint8_t)tsParseSql(pSql, pObj->acctId, pObj->db, false);
......@@ -728,8 +727,7 @@ int taos_validate_sql(TAOS *taos, char *sql) {
return pRes->code;
}
strtolower(sql, pSql->sqlstr);
pSql->sqlstr[sqlLen] = 0;
strtolower(pSql->sqlstr, sql);
pRes->code = (uint8_t)tsParseSql(pSql, pObj->acctId, pObj->db, false);
int code = pRes->code;
......
......@@ -898,7 +898,7 @@ int32_t tscValidateName(SSQLToken* pToken) {
return TSDB_CODE_INVALID_SQL;
}
char* sep = strnchrNoquote(pToken->z, TS_PATH_DELIMITER[0], pToken->n);
char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
if (sep == NULL) { // single part
if (pToken->type == TK_STRING) {
pToken->n = strdequote(pToken->z);
......@@ -911,7 +911,7 @@ int32_t tscValidateName(SSQLToken* pToken) {
if (len == pToken->n) {
return validateQuoteToken(pToken);
} else {
sep = strnchrNoquote(pToken->z, TS_PATH_DELIMITER[0], pToken->n);
sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
if (sep == NULL) {
return TSDB_CODE_INVALID_SQL;
}
......
......@@ -129,6 +129,7 @@ extern "C" {
#define TSDB_CODE_INVALID_QUERY_MSG 106 // failed to validate the sql expression msg by vnode
#define TSDB_CODE_CACHE_BLOCK_TS_DISORDERED 107 // time stamp in cache block is disordered
#define TSDB_CODE_FILE_BLOCK_TS_DISORDERED 108 // time stamp in file block is disordered
#define TSDB_CODE_INVALID_COMMIT_LOG 109 // invalid commit log may be caused by insufficient sotrage
// message type
#define TSDB_MSG_TYPE_REG 1
......
......@@ -49,10 +49,10 @@ void *taosAddDataIntoCache(void *handle, char *key, char *pData, int dataSize, i
* if it is referenced by other object, it will be remain in cache
* @param handle cache object
* @param data not the key, actually referenced data
* @param isForce force model, reduce the ref count and move the data into
* @param remove force model, reduce the ref count and move the data into
* pTrash
*/
void taosRemoveDataFromCache(void *handle, void **data, bool isForce);
void taosRemoveDataFromCache(void *handle, void **data, bool remove);
/**
* update data in cache
......
......@@ -180,12 +180,11 @@ int32_t strdequote(char *src);
void strtrim(char *src);
char *strnchr(char *haystack, char needle, int32_t len);
char *strnchrNoquote(char *haystack, char needle, int32_t len);
char *strnchr(char *haystack, char needle, int32_t len, bool skipquote);
char **strsplit(char *src, const char *delim, int32_t *num);
void strtolower(char *src, char *dst);
void strtolower(char *dst, const char *src);
int64_t strnatoi(char *num, int32_t len);
......
......@@ -1217,6 +1217,7 @@ int taosReSendRspToPeer(SRpcConn *pConn) {
void taosProcessTaosTimer(void *param, void *tmrId) {
STaosHeader *pHeader = NULL;
SRpcConn * pConn = (SRpcConn *)param;
int msgLen;
if (pConn->signature != param) {
tError("pConn Signature:0x%x, pConn:0x%x not matched", pConn->signature, param);
......@@ -1252,6 +1253,7 @@ void taosProcessTaosTimer(void *param, void *tmrId) {
if (pConn->pMsgNode && pConn->pMsgNode->msgLen > 0) {
pHeader = (STaosHeader *)((char *)pConn->pMsgNode + sizeof(SMsgNode));
pHeader->destId = pConn->peerId;
msgLen = pConn->pMsgNode->msgLen;
if (pConn->spi) {
STaosDigest *pDigest = (STaosDigest *)(((char *)pHeader) + pConn->pMsgNode->msgLen - sizeof(STaosDigest));
pDigest->timeStamp = htonl(taosGetTimestampSec());
......@@ -1279,8 +1281,7 @@ void taosProcessTaosTimer(void *param, void *tmrId) {
pthread_mutex_unlock(&pChann->mutex);
if (pHeader) {
(*taosSendData[pServer->type])(pConn->peerIp, pConn->peerPort, (char *)pHeader, pConn->pMsgNode->msgLen,
pConn->chandle);
(*taosSendData[pServer->type])(pConn->peerIp, pConn->peerPort, (char *)pHeader, msgLen, pConn->chandle);
taosTmrReset(taosProcessTaosTimer, tsRpcTimer, pConn, pChann->tmrCtrl, &pConn->pTimer);
}
}
......
......@@ -139,7 +139,7 @@ char *tsError[] = {"success",
"unexpected response",
"invalid response type",
"no resource",
"invalid time stamp", // 15
"server-client date time unsynced", // 15
"mismatched meter ID",
"transcation not finished",
"not online",
......@@ -232,5 +232,6 @@ char *tsError[] = {"success",
"timestamp out of range",
"invalid query message",
"timestamp disordered in cache block",
"timestamp disordered in file block"
"timestamp disordered in file block",
"invalid commit log"
};
......@@ -48,9 +48,9 @@ int vnodeOpenCommitLog(int vnode, uint64_t firstV) {
dTrace("vid:%d, logfd:%d, open file:%s success", vnode, pVnode->logFd, fileName);
if (posix_fallocate64(pVnode->logFd, 0, pVnode->mappingSize) != 0) {
dError("vid:%d, logfd:%d, failed to alloc file size:%d", vnode, pVnode->logFd, pVnode->mappingSize);
dError("vid:%d, logfd:%d, failed to alloc file size:%d reason:%s", vnode, pVnode->logFd, pVnode->mappingSize, strerror(errno));
perror("fallocate failed");
return -1;
goto _err_log_open;
}
struct stat statbuf;
......@@ -60,13 +60,13 @@ int vnodeOpenCommitLog(int vnode, uint64_t firstV) {
if (length != pVnode->mappingSize) {
dError("vid:%d, logfd:%d, alloc file size:%ld not equal to mapping size:%ld", vnode, pVnode->logFd, length,
pVnode->mappingSize);
return -1;
goto _err_log_open;
}
pVnode->pMem = mmap(0, pVnode->mappingSize, PROT_WRITE | PROT_READ, MAP_SHARED, pVnode->logFd, 0);
if (pVnode->pMem == MAP_FAILED) {
dError("vid:%d, logfd:%d, failed to map file, reason:%s", vnode, pVnode->logFd, strerror(errno));
return -1;
goto _err_log_open;
}
pVnode->pWrite = pVnode->pMem;
......@@ -74,6 +74,12 @@ int vnodeOpenCommitLog(int vnode, uint64_t firstV) {
pVnode->pWrite += sizeof(firstV);
return pVnode->logFd;
_err_log_open:
close(pVnode->logFd);
remove(fileName);
pVnode->logFd = -1;
return -1;
}
int vnodeRenewCommitLog(int vnode) {
......@@ -244,9 +250,9 @@ int vnodeInitCommit(int vnode) {
void vnodeCleanUpCommit(int vnode) {
SVnodeObj *pVnode = vnodeList + vnode;
if (pVnode->logFd) tclose(pVnode->logFd);
if (VALIDFD(pVnode->logFd)) tclose(pVnode->logFd);
if (pVnode->cfg.commitLog && remove(pVnode->logFn) < 0) {
if (pVnode->cfg.commitLog && (pVnode->logFd > 0 && remove(pVnode->logFn) < 0)) {
dError("vid:%d, failed to remove:%s", vnode, pVnode->logFn);
taosLogError("vid:%d, failed to remove:%s", vnode, pVnode->logFn);
}
......
......@@ -881,6 +881,7 @@ int vnodeImportPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi
}
if ( pVnode->cfg.commitLog && source != TSDB_DATA_SOURCE_LOG) {
if (pVnode->logFd < 0) return TSDB_CODE_INVALID_COMMIT_LOG;
code = vnodeWriteToCommitLog(pObj, TSDB_ACTION_IMPORT, cont, contLen, sversion);
if (code != 0) return code;
}
......
......@@ -556,6 +556,7 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi
// FIXME: Here should be after the comparison of sversions.
if (pVnode->cfg.commitLog && source != TSDB_DATA_SOURCE_LOG) {
if (pVnode->logFd < 0) return TSDB_CODE_INVALID_COMMIT_LOG;
code = vnodeWriteToCommitLog(pObj, TSDB_ACTION_INSERT, cont, contLen, sversion);
if (code != 0) return code;
}
......
......@@ -46,7 +46,8 @@ typedef struct _cache_node_t {
char * key; /* null-terminated string */
struct _cache_node_t *prev;
struct _cache_node_t *next;
uint64_t time;
uint64_t addTime; // the time when this element is added or updated into cache
uint64_t time; // end time when this element should be remove from cache
uint64_t signature;
/*
......@@ -78,7 +79,7 @@ typedef struct {
* when the node in pTrash does not be referenced, it will be release at the expired time
*/
SDataNode *pTrash;
int numOfElemsInTrash; /* number of element in trash */
int numOfElemsInTrash; // number of element in trash
void *tmrCtrl;
void *pTimer;
......@@ -87,7 +88,7 @@ typedef struct {
_hashFunc hashFp;
/*
* pthread_rwlock_t have bugs on the windows platform
* pthread_rwlock_t will block ops on the windows platform, when refresh is called.
* so use pthread_mutex_t as an alternative
*/
#if defined LINUX
......@@ -125,7 +126,8 @@ static SDataNode *taosCreateHashNode(const char *key, uint32_t keyLen, const cha
memcpy(pNewNode->data, pData, dataSize);
pNewNode->time = taosGetTimestampMs() + lifespan;
pNewNode->addTime = (uint64_t) taosGetTimestampMs();
pNewNode->time = pNewNode->addTime + lifespan;
pNewNode->key = pNewNode->data + dataSize;
strcpy(pNewNode->key, key);
......@@ -146,7 +148,7 @@ static SDataNode *taosCreateHashNode(const char *key, uint32_t keyLen, const cha
static FORCE_INLINE int taosHashKey(int maxSessions, char *key, uint32_t len) {
uint32_t hash = MurmurHash3_32(key, len);
/* avoid the costly remainder operation */
// avoid the costly remainder operation
assert((maxSessions & (maxSessions - 1)) == 0);
hash = hash & (maxSessions - 1);
......@@ -485,11 +487,12 @@ void *taosAddDataIntoCache(void *handle, char *key, char *pData, int dataSize, i
if (pOldNode == NULL) { // do add to cache
pNode = taosAddToCacheImpl(pObj, key, keyLen, pData, dataSize, keepTime * 1000L);
pTrace("key:%s %p added into cache,slot:%d,expireTime:%lld,cache total:%d,size:%ldbytes,collision:%d", pNode->key,
pNode, pNode->hashVal, pNode->time, pObj->total, pObj->totalSize, pObj->statistics.numOfCollision);
pTrace("key:%s %p added into cache, slot:%d, addTime:%lld, expireTime:%lld, cache total:%d, "
"size:%lldbytes, collision:%d", pNode->key, pNode, pNode->hashVal, pNode->addTime, pNode->time, pObj->total,
pObj->totalSize, pObj->statistics.numOfCollision);
} else { // old data exists, update the node
pNode = taosUpdateCacheImpl(pObj, pOldNode, key, keyLen, pData, dataSize, keepTime * 1000L);
// pWarn("key:%s %p exist in cache,updated", key, pNode);
pTrace("key:%s %p exist in cache, updated", key, pNode);
}
#if defined LINUX
......@@ -507,7 +510,7 @@ void *taosAddDataIntoCache(void *handle, char *key, char *pData, int dataSize, i
* @param handle
* @param data
*/
void taosRemoveDataFromCache(void *handle, void **data, _Bool isForce) {
void taosRemoveDataFromCache(void *handle, void **data, bool remove) {
SCacheObj *pObj = (SCacheObj *)handle;
if (pObj == NULL || pObj->maxSessions == 0 || (*data) == NULL || (pObj->total + pObj->numOfElemsInTrash == 0)) return;
......@@ -532,7 +535,7 @@ void taosRemoveDataFromCache(void *handle, void **data, _Bool isForce) {
*data = NULL;
if (isForce) {
if (remove) {
#if defined LINUX
pthread_rwlock_wrlock(&pObj->lock);
#else
......@@ -540,6 +543,7 @@ void taosRemoveDataFromCache(void *handle, void **data, _Bool isForce) {
#endif
taosCacheMoveNodeToTrash(pObj, pNode);
#if defined LINUX
pthread_rwlock_unlock(&pObj->lock);
#else
......
......@@ -56,7 +56,7 @@ int64_t taosGetTimestamp(int32_t precision) {
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec) {
/* parse datatime string in with tz */
if (strnchr(timestr, 'T', len) != NULL) {
if (strnchr(timestr, 'T', len, false) != NULL) {
return parseTimeWithTz(timestr, time, timePrec);
} else {
return parseLocaltime(timestr, time, timePrec);
......
......@@ -119,27 +119,18 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
return split;
}
char *strnchr(char *haystack, char needle, int32_t len) {
char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
for (int32_t i = 0; i < len; ++i) {
if (haystack[i] == needle) {
return &haystack[i];
}
}
return NULL;
}
// skip the needle in quote, jump to the end of quoted string
if (skipquote && (haystack[i] == '\'' || haystack[i] == '"')) {
char quote = haystack[i++];
while(i < len && haystack[i++] != quote);
if (i >= len) {
return NULL;
}
}
char *strnchrNoquote(char *haystack, char needle, int32_t len) {
for (int32_t i = 0; i < len; ++i) {
if (haystack[i] == '\'' || haystack[i] == '"') {
char quote = haystack[i++];
while(i < len && haystack[i] != quote){++i;}
if (++i >= len) {
return NULL;
}
}
if (haystack[i] == needle) {
return &haystack[i];
}
......@@ -148,8 +139,7 @@ char *strnchrNoquote(char *haystack, char needle, int32_t len) {
return NULL;
}
void strtolower(char *z, char *dst) {
void strtolower(char *dst, const char *z) {
int quote = 0;
char *str = z;
if (dst == NULL) {
......@@ -169,6 +159,8 @@ void strtolower(char *z, char *dst) {
str++;
}
*dst = 0;
}
char *paGetToken(char *string, char **token, int32_t *tokenLen) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册