clientHb.h 2.3 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "os.h"
#include "tarray.h"
#include "thash.h"
#include "tmsg.h"

L
Liu Jicong 已提交
21
#define HEARTBEAT_INTERVAL 1500  // ms
L
Liu Jicong 已提交
22

L
Liu Jicong 已提交
23
typedef enum {
L
Liu Jicong 已提交
24 25
  HEARTBEAT_TYPE_MQ = 0,
  // types can be added here
L
Liu Jicong 已提交
26
  //
L
Liu Jicong 已提交
27 28 29
  HEARTBEAT_TYPE_MAX
} EHbType;

L
Liu Jicong 已提交
30
typedef int32_t (*FHbRspHandle)(SClientHbRsp* pReq);
L
Liu Jicong 已提交
31

L
Liu Jicong 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
typedef struct SAppHbMgr {
  // statistics
  int32_t reportCnt;
  int32_t connKeyCnt;
  int64_t reportBytes;  // not implemented
  int64_t startTime;
  // ctl
  SRWLatch lock;  // lock is used in serialization
  // connection
  void*  transporter;
  SEpSet epSet;
  // info
  SHashObj* activeInfo;    // hash<SClientHbKey, SClientHbReq>
  SHashObj* getInfoFuncs;  // hash<SClientHbKey, FGetConnInfo>
} SAppHbMgr;

typedef struct SClientHbMgr {
  int8_t inited;
  // ctl
  int8_t          threadStop;
  pthread_t       thread;
  pthread_mutex_t lock;       // used when app init and cleanup
  SArray*         appHbMgrs;  // SArray<SAppHbMgr*> one for each cluster
  FHbRspHandle    handle[HEARTBEAT_TYPE_MAX];
} SClientHbMgr;

// TODO: embed param into function
// return type: SArray<Skv>
L
Liu Jicong 已提交
60
typedef SArray* (*FGetConnInfo)(SClientHbKey connKey, void* param);
L
Liu Jicong 已提交
61

L
Liu Jicong 已提交
62 63
// global, called by mgmt
int  hbMgrInit();
L
Liu Jicong 已提交
64
void hbMgrCleanUp();
L
Liu Jicong 已提交
65
int  hbHandleRsp(SClientHbBatchRsp* hbRsp);
L
Liu Jicong 已提交
66

L
Liu Jicong 已提交
67 68 69 70 71 72 73
// cluster level
SAppHbMgr* appHbMgrInit(void* transporter, SEpSet epSet);
void appHbMgrCleanup(SAppHbMgr* pAppHbMgr);

// conn level
int  hbRegisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, FGetConnInfo func);
void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey);
L
Liu Jicong 已提交
74

L
Liu Jicong 已提交
75
int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen);
L
Liu Jicong 已提交
76

L
Liu Jicong 已提交
77 78
// mq
void hbMgrInitMqHbRspHandle();