TBASE-1427
This commit is contained in:
parent
3537de849a
commit
44536fdcf7
|
@ -3543,18 +3543,20 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
||||||
|
|
||||||
tscSetResultPointer(pCmd, pRes);
|
tscSetResultPointer(pCmd, pRes);
|
||||||
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, pCmd->fieldsInfo.numOfOutputCols - 1);
|
if (pSql->pSubscription != NULL) {
|
||||||
int16_t offset = tscFieldInfoGetOffset(pCmd, pCmd->fieldsInfo.numOfOutputCols - 1);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pCmd, pCmd->fieldsInfo.numOfOutputCols - 1);
|
||||||
char* p = pRes->data + (pField->bytes + offset) * pRes->numOfRows;
|
int16_t offset = tscFieldInfoGetOffset(pCmd, pCmd->fieldsInfo.numOfOutputCols - 1);
|
||||||
|
char* p = pRes->data + (pField->bytes + offset) * pRes->numOfRows;
|
||||||
|
|
||||||
int32_t numOfMeters = htonl(*(int32_t*)p);
|
int32_t numOfMeters = htonl(*(int32_t*)p);
|
||||||
p += sizeof(int32_t);
|
p += sizeof(int32_t);
|
||||||
for (int i = 0; i < numOfMeters; i++) {
|
for (int i = 0; i < numOfMeters; i++) {
|
||||||
int64_t uid = htobe64(*(int64_t*)p);
|
int64_t uid = htobe64(*(int64_t*)p);
|
||||||
p += sizeof(int64_t);
|
p += sizeof(int64_t);
|
||||||
TSKEY key = htobe64(*(TSKEY*)p);
|
TSKEY key = htobe64(*(TSKEY*)p);
|
||||||
p += sizeof(TSKEY);
|
p += sizeof(TSKEY);
|
||||||
tscUpdateSubscriptionProgress(pSql, uid, key);
|
tscUpdateSubscriptionProgress(pSql, uid, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pRes->row = 0;
|
pRes->row = 0;
|
||||||
|
|
|
@ -32,6 +32,7 @@ typedef struct SSubscriptionProgress {
|
||||||
} SSubscriptionProgress;
|
} SSubscriptionProgress;
|
||||||
|
|
||||||
typedef struct SSub {
|
typedef struct SSub {
|
||||||
|
int64_t lastSyncTime;
|
||||||
void * signature;
|
void * signature;
|
||||||
TAOS * taos;
|
TAOS * taos;
|
||||||
void * pTimer;
|
void * pTimer;
|
||||||
|
@ -152,6 +153,57 @@ static void tscProcessSubscribeTimer(void *handle, void *tmrId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
||||||
|
int code = (uint8_t)tsParseSql(pSub->pSql, pObj->acctId, pObj->db, false);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
taos_unsubscribe(pSub);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int numOfMeters = 0;
|
||||||
|
SSubscriptionProgress* progress = NULL;
|
||||||
|
|
||||||
|
// ??? if there's more than one vnode
|
||||||
|
SSqlCmd* pCmd = &pSub->pSql->cmd;
|
||||||
|
|
||||||
|
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
||||||
|
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
|
||||||
|
numOfMeters = 1;
|
||||||
|
progress = calloc(1, sizeof(SSubscriptionProgress));
|
||||||
|
int64_t uid = pMeterMetaInfo->pMeterMeta->uid;
|
||||||
|
progress[0].uid = uid;
|
||||||
|
progress[0].key = tscGetSubscriptionProgress(pSub->pSql, uid);
|
||||||
|
} else {
|
||||||
|
SMetricMeta* pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
||||||
|
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex);
|
||||||
|
numOfMeters = pVnodeSidList->numOfSids;
|
||||||
|
progress = calloc(numOfMeters, sizeof(SSubscriptionProgress));
|
||||||
|
for (int32_t i = 0; i < numOfMeters; ++i) {
|
||||||
|
SMeterSidExtInfo *pMeterInfo = tscGetMeterSidInfo(pVnodeSidList, i);
|
||||||
|
int64_t uid = pMeterInfo->uid;
|
||||||
|
progress[i].uid = uid;
|
||||||
|
progress[i].key = tscGetSubscriptionProgress(pSub->pSql, uid);
|
||||||
|
}
|
||||||
|
qsort(progress, numOfMeters, sizeof(SSubscriptionProgress), tscCompareSubscriptionProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pSub->progress);
|
||||||
|
pSub->numOfMeters = numOfMeters;
|
||||||
|
pSub->progress = progress;
|
||||||
|
|
||||||
|
// timestamp must in the output column
|
||||||
|
SFieldInfo* pFieldInfo = &pCmd->fieldsInfo;
|
||||||
|
tscFieldInfoSetValue(pFieldInfo, pFieldInfo->numOfOutputCols, TSDB_DATA_TYPE_TIMESTAMP, "_c0", TSDB_KEYSIZE);
|
||||||
|
tscSqlExprInsertEmpty(pCmd, pFieldInfo->numOfOutputCols - 1, TSDB_FUNC_PRJ);
|
||||||
|
tscFieldInfoUpdateVisible(pFieldInfo, pFieldInfo->numOfOutputCols - 1, false);
|
||||||
|
tscFieldInfoCalOffset(pCmd);
|
||||||
|
|
||||||
|
pSub->lastSyncTime = taosGetTimestampMs();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TAOS_SUB *taos_subscribe(TAOS *taos, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) {
|
TAOS_SUB *taos_subscribe(TAOS *taos, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) {
|
||||||
STscObj* pObj = (STscObj*)taos;
|
STscObj* pObj = (STscObj*)taos;
|
||||||
if (pObj == NULL || pObj->signature != pObj) {
|
if (pObj == NULL || pObj->signature != pObj) {
|
||||||
|
@ -164,40 +216,12 @@ TAOS_SUB *taos_subscribe(TAOS *taos, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp
|
||||||
if (pSub == NULL) {
|
if (pSub == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pSub->taos = taos;
|
||||||
|
|
||||||
int code = (uint8_t)tsParseSql(pSub->pSql, pObj->acctId, pObj->db, false);
|
if (!tscUpdateSubscription(pObj, pSub)) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
taos_unsubscribe(pSub);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ??? if there's more than one vnode
|
|
||||||
SSqlCmd* pCmd = &pSub->pSql->cmd;
|
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
|
|
||||||
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
|
|
||||||
pSub->numOfMeters = 1;
|
|
||||||
pSub->progress = calloc(1, sizeof(SSubscriptionProgress));
|
|
||||||
pSub->progress[0].uid = pMeterMetaInfo->pMeterMeta->uid;
|
|
||||||
} else {
|
|
||||||
SMetricMeta* pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
|
||||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, pMeterMetaInfo->vnodeIndex);
|
|
||||||
pSub->numOfMeters = pVnodeSidList->numOfSids;
|
|
||||||
pSub->progress = calloc(pSub->numOfMeters, sizeof(SSubscriptionProgress));
|
|
||||||
for (int32_t i = 0; i < pSub->numOfMeters; ++i) {
|
|
||||||
SMeterSidExtInfo *pMeterInfo = tscGetMeterSidInfo(pVnodeSidList, i);
|
|
||||||
pSub->progress[i].uid = pMeterInfo->uid;
|
|
||||||
}
|
|
||||||
qsort(pSub->progress, pSub->numOfMeters, sizeof(SSubscriptionProgress), tscCompareSubscriptionProgress);
|
|
||||||
}
|
|
||||||
|
|
||||||
// timestamp must in the output column
|
|
||||||
SFieldInfo* pFieldInfo = &pCmd->fieldsInfo;
|
|
||||||
tscFieldInfoSetValue(pFieldInfo, pFieldInfo->numOfOutputCols, TSDB_DATA_TYPE_TIMESTAMP, "_c0", TSDB_KEYSIZE);
|
|
||||||
tscSqlExprInsertEmpty(pCmd, pFieldInfo->numOfOutputCols - 1, TSDB_FUNC_PRJ);
|
|
||||||
tscFieldInfoUpdateVisible(pFieldInfo, pFieldInfo->numOfOutputCols - 1, false);
|
|
||||||
tscFieldInfoCalOffset(pCmd);
|
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
pSub->fp = fp;
|
pSub->fp = fp;
|
||||||
pSub->interval = interval;
|
pSub->interval = interval;
|
||||||
|
@ -212,6 +236,12 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
||||||
SSub *pSub = (SSub *)tsub;
|
SSub *pSub = (SSub *)tsub;
|
||||||
if (pSub == NULL) return NULL;
|
if (pSub == NULL) return NULL;
|
||||||
|
|
||||||
|
if (taosGetTimestampMs() - pSub->lastSyncTime > 30 * 10 * 1000) {
|
||||||
|
taos_query(pSub->taos, "reset query cache;");
|
||||||
|
// TODO: clear memory
|
||||||
|
if (!tscUpdateSubscription(pSub->taos, pSub)) return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SSqlObj* pSql = pSub->pSql;
|
SSqlObj* pSql = pSub->pSql;
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
|
|
|
@ -1105,6 +1105,7 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
|
||||||
pSids[0] = (SMeterSidExtInfo *)pMsg;
|
pSids[0] = (SMeterSidExtInfo *)pMsg;
|
||||||
pSids[0]->sid = htonl(pSids[0]->sid);
|
pSids[0]->sid = htonl(pSids[0]->sid);
|
||||||
pSids[0]->uid = htobe64(pSids[0]->uid);
|
pSids[0]->uid = htobe64(pSids[0]->uid);
|
||||||
|
pSids[0]->key = htobe64(pSids[0]->key);
|
||||||
|
|
||||||
for (int32_t j = 1; j < pQueryMsg->numOfSids; ++j) {
|
for (int32_t j = 1; j < pQueryMsg->numOfSids; ++j) {
|
||||||
pSids[j] = (SMeterSidExtInfo *)((char *)pSids[j - 1] + sizeof(SMeterSidExtInfo) + pQueryMsg->tagLength);
|
pSids[j] = (SMeterSidExtInfo *)((char *)pSids[j - 1] + sizeof(SMeterSidExtInfo) + pQueryMsg->tagLength);
|
||||||
|
|
|
@ -441,7 +441,9 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
|
||||||
|
|
||||||
// buffer size for progress information, including meter count,
|
// buffer size for progress information, including meter count,
|
||||||
// and for each meter, including 'uid' and 'TSKEY'.
|
// and for each meter, including 'uid' and 'TSKEY'.
|
||||||
int progressSize = pQInfo->pMeterQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t);
|
int progressSize = 0;
|
||||||
|
if (pQInfo->pMeterQuerySupporter != NULL)
|
||||||
|
progressSize = pQInfo->pMeterQuerySupporter->numOfMeters * (sizeof(int64_t) + sizeof(TSKEY)) + sizeof(int32_t);
|
||||||
|
|
||||||
pStart = taosBuildRspMsgWithSize(pObj->thandle, TSDB_MSG_TYPE_RETRIEVE_RSP, progressSize + size + 100);
|
pStart = taosBuildRspMsgWithSize(pObj->thandle, TSDB_MSG_TYPE_RETRIEVE_RSP, progressSize + size + 100);
|
||||||
if (pStart == NULL) {
|
if (pStart == NULL) {
|
||||||
|
@ -476,13 +478,15 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
|
||||||
|
|
||||||
// write the progress information of each meter to response
|
// write the progress information of each meter to response
|
||||||
// this is required by subscriptions
|
// this is required by subscriptions
|
||||||
*((int32_t*)pMsg) = htonl(pQInfo->pMeterQuerySupporter->numOfMeters);
|
if (progressSize > 0) {
|
||||||
pMsg += sizeof(int32_t);
|
*((int32_t*)pMsg) = htonl(pQInfo->pMeterQuerySupporter->numOfMeters);
|
||||||
for (int32_t i = 0; i < pQInfo->pMeterQuerySupporter->numOfMeters; i++) {
|
pMsg += sizeof(int32_t);
|
||||||
*((int64_t*)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->uid);
|
for (int32_t i = 0; i < pQInfo->pMeterQuerySupporter->numOfMeters; i++) {
|
||||||
pMsg += sizeof(int64_t);
|
*((int64_t*)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->uid);
|
||||||
*((TSKEY*)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->key);
|
pMsg += sizeof(int64_t);
|
||||||
pMsg += sizeof(TSKEY);
|
*((TSKEY*)pMsg) = htobe64(pQInfo->pMeterQuerySupporter->pMeterSidExtInfo[i]->key);
|
||||||
|
pMsg += sizeof(TSKEY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msgLen = pMsg - pStart;
|
msgLen = pMsg - pStart;
|
||||||
|
|
Loading…
Reference in New Issue