refine heartbeat interface

This commit is contained in:
Liu Jicong 2022-01-06 19:53:14 +08:00
parent 5d3f439a5b
commit 5c73c1ffd8
2 changed files with 78 additions and 78 deletions

View File

@ -20,6 +20,8 @@
typedef enum {
mq = 0,
// type can be added here
//
HEARTBEAT_TYPE_MAX
} EHbType;
@ -30,6 +32,60 @@ typedef struct SKlv {
void* value;
} SKlv;
typedef struct SClientHbKey {
int32_t connId;
int32_t hbType;
} SClientHbKey;
typedef struct SClientHbReq {
SClientHbKey hbKey;
SHashObj* info; // hash<Slv.key, Sklv>
} SClientHbReq;
typedef struct SClientHbBatchReq {
int64_t reqId;
SArray* reqs; // SArray<SClientHbReq>
} SClientHbBatchReq;
typedef struct SClientHbHandleResult {
} SClientHbHandleResult;
typedef struct SClientHbRsp {
int32_t connId;
int32_t hbType;
} SClientHbRsp;
typedef struct SClientHbBatchRsp {
int64_t reqId;
int64_t rspId;
SArray* rsps; // SArray<SClientHbRsp>
} SClientHbBatchRsp;
typedef int32_t (*FHbRspHandle)(SClientHbRsp* pReq);
typedef int32_t (*FGetConnInfo)(SClientHbKey connKey, void* param);
typedef struct SClientHbMgr {
int8_t inited;
int32_t reportInterval; // unit ms
int32_t stats;
SRWLatch lock;
SHashObj* activeInfo; // hash<SClientHbKey, SClientHbReq>
SHashObj* getInfoFuncs; // hash<SClientHbKey, FGetConnInfo>
FHbRspHandle handle[HEARTBEAT_TYPE_MAX];
// input queue
} SClientHbMgr;
static SClientHbMgr clientHbMgr = {0};
int hbMgrInit();
void hbMgrCleanUp();
int hbHandleRsp(void* hbMsg);
int hbRegisterConn(SClientHbKey connKey, FGetConnInfo func);
int hbAddConnInfo(SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen);
static FORCE_INLINE int taosEncodeSKlv(void** buf, const SKlv* pKlv) {
int tlen = 0;
tlen += taosEncodeFixedI32(buf, pKlv->keyLen);
@ -47,11 +103,6 @@ static FORCE_INLINE void* taosDecodeSKlv(void* buf, SKlv* pKlv) {
return buf;
}
typedef struct SClientHbKey {
int32_t connId;
int32_t hbType;
} SClientHbKey;
static FORCE_INLINE int taosEncodeSClientHbKey(void** buf, const SClientHbKey* pKey) {
int tlen = 0;
tlen += taosEncodeFixedI32(buf, pKey->connId);
@ -65,11 +116,6 @@ static FORCE_INLINE void* taosDecodeSClientHbKey(void* buf, SClientHbKey* pKey)
return buf;
}
typedef struct SClientHbReq {
SClientHbKey hbKey;
SHashObj* info; // hash<Sklv>
} SClientHbReq;
static FORCE_INLINE int tSerializeSClientHbReq(void** buf, const SClientHbReq* pReq) {
int tlen = 0;
tlen += taosEncodeSClientHbKey(buf, &pReq->hbKey);
@ -93,8 +139,8 @@ static FORCE_INLINE void* tDeserializeClientHbReq(void* buf, SClientHbReq* pReq)
ASSERT(pReq->info != NULL);
buf = taosDecodeSClientHbKey(buf, &pReq->hbKey);
//TODO: error handling
if(pReq->info == NULL) {
// TODO: error handling
if (pReq->info == NULL) {
pReq->info = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
}
SKlv klv;
@ -103,46 +149,3 @@ static FORCE_INLINE void* tDeserializeClientHbReq(void* buf, SClientHbReq* pReq)
return buf;
}
typedef struct SClientHbBatchReq {
int64_t reqId;
SArray* reqs; // SArray<SClientHbReq>
} SClientHbBatchReq;
typedef struct SClientHbHandleResult {
} SClientHbHandleResult;
typedef struct SClientHbRsp {
int32_t connId;
int32_t hbType;
} SClientHbRsp;
typedef struct SClientHbBatchRsp {
int64_t reqId;
int64_t rspId;
SArray* rsps; // SArray<SClientHbRsp>
} SClientHbBatchRsp;
typedef int32_t (*FHbRspHandle)(SClientHbReq* pReq);
typedef int32_t (*FGetConnInfo)(int32_t conn, void* self);
typedef struct SClientHbMgr {
int8_t inited;
int32_t reportInterval; // unit ms
int32_t stats;
SRWLatch lock;
SHashObj* info; //hash<SClientHbKey, SClientHbReq>
FHbRspHandle handle[HEARTBEAT_TYPE_MAX];
// input queue
} SClientHbMgr;
static SClientHbMgr clientHbMgr = {0};
int hbMgrInit();
void hbMgrCleanUp();
int registerConn(int32_t connId, FGetConnInfo func, FHbRspHandle rspHandle);
int registerHbRspHandle(int32_t connId, int32_t hbType, FHbRspHandle rspHandle);
int HbAddConnInfo(int32_t connId, void* key, void* value, int32_t keyLen, int32_t valueLen);

View File

@ -15,7 +15,7 @@
#include "clientHb.h"
static int32_t mqHbRspHandle(SClientHbReq* pReq) {
static int32_t mqHbRspHandle(SClientHbRsp* pReq) {
return 0;
}
@ -42,15 +42,12 @@ void hbMgrCleanUp() {
}
int registerConn(int32_t connId, FGetConnInfo func, FHbRspHandle rspHandle) {
int hbRegisterConn(SClientHbKey connKey, FGetConnInfo func) {
return 0;
}
int registerHbRspHandle(int32_t connId, int32_t hbType, FHbRspHandle rspHandle) {
return 0;
}
int HbAddConnInfo(int32_t connId, void* key, void* value, int32_t keyLen, int32_t valueLen) {
int hbAddConnInfo(SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen) {
//lock
//find req by connection id