diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 9406a2fdce90713d784758d479e953aa18aacdb9..799a0b051433d8af06d52d29b6c8e7b41cd3183d 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -38,6 +38,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; void *ahandle; int num; // number of continuous streams @@ -73,6 +74,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { strcpy(pContext->user, pCfg->user); strcpy(pContext->pass, pCfg->pass); + strcpy(pContext->db, pCfg->db); pContext->vgId = pCfg->vgId; pContext->cqWrite = pCfg->cqWrite; pContext->ahandle = ahandle; @@ -207,9 +209,8 @@ void cqDrop(void *handle) { } static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { - if (pContext->dbConn == NULL) { - pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, NULL, 0); + pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, pContext->db, 0); if (pContext->dbConn == NULL) { cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno)); } @@ -217,6 +218,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { } int64_t lastKey = 0; + pObj->pContext = pContext; pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, lastKey, pObj, NULL); if (pObj->pStream) { pContext->num++; diff --git a/src/dnode/inc/dnodeModule.h b/src/dnode/inc/dnodeModule.h index 8618de324446ca3f2504d15a6422bcca3a4b51b0..fb529ee67c31c40d1ad2dded48319a602645f65a 100644 --- a/src/dnode/inc/dnodeModule.h +++ b/src/dnode/inc/dnodeModule.h @@ -22,7 +22,8 @@ extern "C" { int32_t dnodeInitModules(); void dnodeStartModules(); -void dnodeCleanupModules(); +void dnodeStartStream(); +void dnodeCleanUpModules(); void dnodeProcessModuleStatus(uint32_t moduleStatus); #ifdef __cplusplus diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 7683843371ab4ba0a0bfb6d3b119fbbeca031b8d..73bc2923b25f6d0d4b433a6247cc531a1d98325f 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -124,6 +124,7 @@ int32_t dnodeInitSystem() { dnodeStartModules(); dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_RUNING); + dnodeStartStream(); dPrint("TDengine is initialized successfully"); diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 7c457defca9dd822b018221deeeb4646ed919988..a29f99dda6a263f459e0da8c66d7a8331a0c1a59 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -260,11 +260,27 @@ static int32_t dnodeOpenVnodes() { } free(vnodeList); - dPrint("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, numOfVnodes-failed, failed); return TSDB_CODE_SUCCESS; } +void dnodeStartStream() { + int32_t vnodeList[TSDB_MAX_VNODES]; + int32_t numOfVnodes = 0; + int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes); + + if (status != TSDB_CODE_SUCCESS) { + dPrint("Get dnode list failed"); + return; + } + + for (int32_t i = 0; i < numOfVnodes; ++i) { + vnodeStartStream(vnodeList[i]); + } + + dPrint("streams started"); +} + static void dnodeCloseVnodes() { int32_t *vnodeList = (int32_t *)malloc(sizeof(int32_t) * TSDB_MAX_VNODES); int32_t numOfVnodes; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index e025afaa0ae428b9545b5a23308830f8aa455002..ba198ab66e05f4c954a002c2a81862aa23851fe3 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -27,6 +27,7 @@ typedef struct { int vgId; char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_NAME_LEN]; FCqWrite cqWrite; } SCqCfg; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 2dc9b977b46449602381606ade0508035ab01a26..d3ec96acf60c2d01473c16c055d963fe1cd662f2 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -118,6 +118,7 @@ int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg); TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid); +void tsdbStartStream(TsdbRepoT *repo); uint32_t tsdbGetFileInfo(TsdbRepoT *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size); diff --git a/src/inc/vnode.h b/src/inc/vnode.h index f4fb8060feabc12e0f6bfcb933572ed4090ebb6e..e507c55942bc6b4db682fd25739a9da34ce668fb 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -38,6 +38,7 @@ typedef struct { int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeDrop(int32_t vgId); int32_t vnodeOpen(int32_t vgId, char *rootDir); +int32_t vnodeStartStream(int32_t vgId); int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeClose(int32_t vgId); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 0efb477e7393fa4cfd7d824224f7e59db557d99c..632c1dd34e221ae0ea958b2fc24e5b2b959f8615 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -474,6 +474,18 @@ TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, uint64_t uid) { return TSDB_GET_TABLE_LAST_KEY(pTable); } +void tsdbStartStream(TsdbRepoT *repo) { + STsdbRepo *pRepo = (STsdbRepo *)repo; + STsdbMeta *pMeta = pRepo->tsdbMeta; + + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pMeta->tables[i]; + if (pTable && pTable->type == TSDB_STREAM_TABLE) { + pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, pTable->tableId.tid, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); + } + } +} + STableInfo *tsdbGetTableInfo(TsdbRepoT *pRepo, STableId tableId) { // TODO return NULL; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 9f1e507d548c0284d3f5bf4398e3e43348e449d8..bf5fac4e45dc9cec086c88b69d5c9c39f7af63bc 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -150,7 +150,6 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) { void tsdbOrgMeta(void *pHandle) { STsdbMeta *pMeta = (STsdbMeta *)pHandle; - STsdbRepo *pRepo = (STsdbRepo *)pMeta->pRepo; for (int i = 1; i < pMeta->maxTables; i++) { STable *pTable = pMeta->tables[i]; @@ -158,13 +157,6 @@ void tsdbOrgMeta(void *pHandle) { tsdbAddTableIntoIndex(pMeta, pTable); } } - - for (int i = 0; i < pMeta->maxTables; i++) { - STable *pTable = pMeta->tables[i]; - if (pTable && pTable->type == TSDB_STREAM_TABLE) { - pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, i, pTable->sql, tsdbGetTableSchema(pMeta, pTable)); - } - } } /** diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 3d8cf67d02e46ae4dfbe69132c2a6ccdc598db5f..037dadb8fdf22070e85241af156ff0c48e5b3a54 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -208,8 +208,9 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { } SCqCfg cqCfg = {0}; - sprintf(cqCfg.user, "root"); + sprintf(cqCfg.user, "_root"); strcpy(cqCfg.pass, tsInternalPass); + strcpy(cqCfg.db, "s1_db0"); // TODO: replace hard coded db name cqCfg.vgId = vnode; cqCfg.cqWrite = vnodeWriteToQueue; pVnode->cq = cqOpen(pVnode, &cqCfg); @@ -277,6 +278,15 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { return TSDB_CODE_SUCCESS; } +int32_t vnodeStartStream(int32_t vnode) { + SVnodeObj* pVnode = vnodeAccquireVnode(vnode); + if (pVnode != NULL) { + tsdbStartStream(pVnode->tsdb); + vnodeRelease(pVnode); + } + return TSDB_CODE_SUCCESS; +} + int32_t vnodeClose(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) return 0;