merge trans
This commit is contained in:
parent
dbe325e118
commit
3a01542c5a
|
@ -135,6 +135,7 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||||
|
|
||||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||||
|
|
||||||
SRpcMsg rpcRsp = {.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = NULL};
|
SRpcMsg rpcRsp = {
|
||||||
|
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||||
rpcSendResponse(&rpcRsp);
|
rpcSendResponse(&rpcRsp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
static void *dmThreadRoutine(void *param) {
|
static void *dmThreadRoutine(void *param) {
|
||||||
SDnodeMgmt *pMgmt = param;
|
SDnodeMgmt *pMgmt = param;
|
||||||
SDnode *pDnode = pMgmt->pDnode;
|
SDnode * pDnode = pMgmt->pDnode;
|
||||||
int64_t lastStatusTime = taosGetTimestampMs();
|
int64_t lastStatusTime = taosGetTimestampMs();
|
||||||
int64_t lastMonitorTime = lastStatusTime;
|
int64_t lastMonitorTime = lastStatusTime;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ static void *dmThreadRoutine(void *param) {
|
||||||
static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||||
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
|
|
||||||
SDnode *pDnode = pMgmt->pDnode;
|
SDnode * pDnode = pMgmt->pDnode;
|
||||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
dTrace("msg:%p, will be processed in dnode queue", pMsg);
|
dTrace("msg:%p, will be processed in dnode queue", pMsg);
|
||||||
|
|
|
@ -183,7 +183,7 @@ typedef struct {
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
typedef enum { Normal, Quit, Release, Register } STransMsgType;
|
typedef enum { Normal, Quit, Release, Register } STransMsgType;
|
||||||
typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken } ConnStatus;
|
typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } ConnStatus;
|
||||||
|
|
||||||
#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member)))
|
#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member)))
|
||||||
#define RPC_RESERVE_SIZE (sizeof(STranConnCtx))
|
#define RPC_RESERVE_SIZE (sizeof(STranConnCtx))
|
||||||
|
|
|
@ -53,6 +53,7 @@ typedef struct SCliMsg {
|
||||||
queue q;
|
queue q;
|
||||||
uint64_t st;
|
uint64_t st;
|
||||||
STransMsgType type;
|
STransMsgType type;
|
||||||
|
int sent; //(0: no send, 1: alread sent)
|
||||||
} SCliMsg;
|
} SCliMsg;
|
||||||
|
|
||||||
typedef struct SCliThrdObj {
|
typedef struct SCliThrdObj {
|
||||||
|
@ -135,6 +136,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
||||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||||
do { \
|
do { \
|
||||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||||
|
uint64_t ahandle = head->ahandle; \
|
||||||
|
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \
|
||||||
conn->status = ConnRelease; \
|
conn->status = ConnRelease; \
|
||||||
transClearBuffer(&conn->readBuf); \
|
transClearBuffer(&conn->readBuf); \
|
||||||
transFreeMsg(transContFromHead((char*)head)); \
|
transFreeMsg(transContFromHead((char*)head)); \
|
||||||
|
@ -146,6 +149,7 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
||||||
SCliThrdObj* thrd = conn->hostThrd; \
|
SCliThrdObj* thrd = conn->hostThrd; \
|
||||||
addConnToPool(thrd->pool, conn); \
|
addConnToPool(thrd->pool, conn); \
|
||||||
} \
|
} \
|
||||||
|
destroyCmsg(pMsg); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -198,8 +202,18 @@ static void* cliWorkThread(void* arg);
|
||||||
|
|
||||||
bool cliMaySendCachedMsg(SCliConn* conn) {
|
bool cliMaySendCachedMsg(SCliConn* conn) {
|
||||||
if (!transQueueEmpty(&conn->cliMsgs)) {
|
if (!transQueueEmpty(&conn->cliMsgs)) {
|
||||||
|
SCliMsg* pCliMsg = NULL;
|
||||||
|
int i = 0;
|
||||||
|
do {
|
||||||
|
pCliMsg = transQueueGet(&conn->cliMsgs, i++);
|
||||||
|
if (pCliMsg && 0 == pCliMsg->sent) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (pCliMsg != NULL);
|
||||||
|
if (pCliMsg == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
cliSend(conn);
|
cliSend(conn);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -218,33 +232,27 @@ void cliHandleResp(SCliConn* conn) {
|
||||||
transMsg.msgType = pHead->msgType;
|
transMsg.msgType = pHead->msgType;
|
||||||
transMsg.ahandle = NULL;
|
transMsg.ahandle = NULL;
|
||||||
|
|
||||||
CONN_SHOULD_RELEASE(conn, pHead);
|
|
||||||
|
|
||||||
SCliMsg* pMsg = NULL;
|
SCliMsg* pMsg = NULL;
|
||||||
STransConnCtx* pCtx = NULL;
|
STransConnCtx* pCtx = NULL;
|
||||||
|
CONN_SHOULD_RELEASE(conn, pHead);
|
||||||
|
|
||||||
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
||||||
pMsg = transQueuePop(&conn->cliMsgs);
|
pMsg = transQueuePop(&conn->cliMsgs);
|
||||||
|
/// uint64_t ahandle = (uint64_t)pHead->ahandle;
|
||||||
|
// CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
||||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
pCtx = pMsg ? pMsg->ctx : NULL;
|
||||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) {
|
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||||
transMsg.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
tDebug("cli conn %p get ahandle %p, persist: 0", conn, transMsg.ahandle);
|
||||||
if (transMsg.ahandle == NULL) {
|
|
||||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
|
||||||
}
|
|
||||||
tDebug("cli conn %p construct ahandle %p, persist: 0", conn, transMsg.ahandle);
|
|
||||||
} else {
|
|
||||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
|
||||||
tDebug("cli conn %p get ahandle %p, persist: 0", conn, transMsg.ahandle);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
||||||
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
transMsg.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
transMsg.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
||||||
|
tDebug("cli conn %p construct ahandle %p by %d, persist: 1", conn, transMsg.ahandle, transMsg.msgType);
|
||||||
if (transMsg.ahandle == NULL) {
|
if (transMsg.ahandle == NULL) {
|
||||||
|
tDebug("cli conn %p construct ahandle %p due brokenlink, persist: 1", conn, transMsg.ahandle);
|
||||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
transMsg.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
||||||
}
|
}
|
||||||
tDebug("cli conn %p construct ahandle %p, persist: 1", conn, transMsg.ahandle);
|
|
||||||
} else {
|
} else {
|
||||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
pCtx = pMsg ? pMsg->ctx : NULL;
|
||||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||||
|
@ -419,7 +427,7 @@ static void addConnToPool(void* pool, SCliConn* conn) {
|
||||||
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||||
transCtxCleanup(&conn->ctx);
|
transCtxCleanup(&conn->ctx);
|
||||||
transQueueClear(&conn->cliMsgs);
|
transQueueClear(&conn->cliMsgs);
|
||||||
conn->status = ConnNormal;
|
conn->status = ConnInPool;
|
||||||
|
|
||||||
char key[128] = {0};
|
char key[128] = {0};
|
||||||
tstrncpy(key, conn->ip, strlen(conn->ip));
|
tstrncpy(key, conn->ip, strlen(conn->ip));
|
||||||
|
@ -546,7 +554,21 @@ void cliSend(SCliConn* pConn) {
|
||||||
|
|
||||||
// assert(taosArrayGetSize(pConn->cliMsgs) > 0);
|
// assert(taosArrayGetSize(pConn->cliMsgs) > 0);
|
||||||
assert(!transQueueEmpty(&pConn->cliMsgs));
|
assert(!transQueueEmpty(&pConn->cliMsgs));
|
||||||
SCliMsg* pCliMsg = transQueueGet(&pConn->cliMsgs, 0);
|
|
||||||
|
SCliMsg* pCliMsg = NULL;
|
||||||
|
int i = 0;
|
||||||
|
do {
|
||||||
|
pCliMsg = transQueueGet(&pConn->cliMsgs, i++);
|
||||||
|
if (pCliMsg && 0 == pCliMsg->sent) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (pCliMsg != NULL);
|
||||||
|
if (pCliMsg == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCliMsg->sent = 1;
|
||||||
|
|
||||||
STransConnCtx* pCtx = pCliMsg->ctx;
|
STransConnCtx* pCtx = pCliMsg->ctx;
|
||||||
|
|
||||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||||
|
@ -558,7 +580,7 @@ void cliSend(SCliConn* pConn) {
|
||||||
pMsg->contLen = 0;
|
pMsg->contLen = 0;
|
||||||
}
|
}
|
||||||
STransMsgHead* pHead = transHeadFromCont(pMsg->pCont);
|
STransMsgHead* pHead = transHeadFromCont(pMsg->pCont);
|
||||||
pHead->ahandle = (uint64_t)pCtx->ahandle;
|
pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0;
|
||||||
|
|
||||||
int msgLen = transMsgLenFromCont(pMsg->contLen);
|
int msgLen = transMsgLenFromCont(pMsg->contLen);
|
||||||
|
|
||||||
|
@ -868,6 +890,7 @@ void transReleaseCliHandle(void* handle) {
|
||||||
|
|
||||||
STransMsg tmsg = {.handle = handle};
|
STransMsg tmsg = {.handle = handle};
|
||||||
SCliMsg* cmsg = calloc(1, sizeof(SCliMsg));
|
SCliMsg* cmsg = calloc(1, sizeof(SCliMsg));
|
||||||
|
|
||||||
cmsg->msg = tmsg;
|
cmsg->msg = tmsg;
|
||||||
cmsg->type = Release;
|
cmsg->type = Release;
|
||||||
|
|
||||||
|
|
|
@ -93,25 +93,25 @@ typedef struct SServerObj {
|
||||||
|
|
||||||
static const char* notify = "a";
|
static const char* notify = "a";
|
||||||
|
|
||||||
#define CONN_SHOULD_RELEASE(conn, head) \
|
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||||
do { \
|
do { \
|
||||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||||
conn->status = ConnRelease; \
|
conn->status = ConnRelease; \
|
||||||
transClearBuffer(&conn->readBuf); \
|
transClearBuffer(&conn->readBuf); \
|
||||||
transFreeMsg(transContFromHead((char*)head)); \
|
transFreeMsg(transContFromHead((char*)head)); \
|
||||||
tTrace("server conn %p received release request", conn); \
|
tTrace("server conn %p received release request", conn); \
|
||||||
\
|
\
|
||||||
STransMsg tmsg = {.handle = (void*)conn, .code = 0}; \
|
STransMsg tmsg = {.code = 0, .handle = (void*)conn, .ahandle = NULL}; \
|
||||||
SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); \
|
SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg)); \
|
||||||
srvMsg->msg = tmsg; \
|
srvMsg->msg = tmsg; \
|
||||||
srvMsg->type = Release; \
|
srvMsg->type = Release; \
|
||||||
srvMsg->pConn = conn; \
|
srvMsg->pConn = conn; \
|
||||||
if (!transQueuePush(&conn->srvMsgs, srvMsg)) { \
|
if (!transQueuePush(&conn->srvMsgs, srvMsg)) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
uvStartSendRespInternal(srvMsg); \
|
uvStartSendRespInternal(srvMsg); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
static void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||||
|
@ -823,7 +823,7 @@ void transReleaseSrvHandle(void* handle) {
|
||||||
SSrvConn* pConn = handle;
|
SSrvConn* pConn = handle;
|
||||||
SWorkThrdObj* pThrd = pConn->hostThrd;
|
SWorkThrdObj* pThrd = pConn->hostThrd;
|
||||||
|
|
||||||
STransMsg tmsg = {.handle = handle, .code = 0};
|
STransMsg tmsg = {.code = 0, .handle = handle, .ahandle = NULL};
|
||||||
|
|
||||||
SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg));
|
SSrvMsg* srvMsg = calloc(1, sizeof(SSrvMsg));
|
||||||
srvMsg->msg = tmsg;
|
srvMsg->msg = tmsg;
|
||||||
|
|
Loading…
Reference in New Issue