syncIO.c 13.8 KB
Newer Older
M
Minghao Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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 "syncIO.h"
H
Haojun Liao 已提交
17
#include <tdatablock.h>
M
Minghao Li 已提交
18
#include "os.h"
M
Minghao Li 已提交
19
#include "syncMessage.h"
M
Minghao Li 已提交
20
#include "syncUtil.h"
M
Minghao Li 已提交
21 22 23 24
#include "tglobal.h"
#include "ttimer.h"
#include "tutil.h"

S
Shengliang Guan 已提交
25
bool     gRaftDetailLog = false;
M
Minghao Li 已提交
26 27
SSyncIO *gSyncIO = NULL;

M
Minghao Li 已提交
28
// local function ------------
M
sync io  
Minghao Li 已提交
29 30
static SSyncIO *syncIOCreate(char *host, uint16_t port);
static int32_t  syncIODestroy(SSyncIO *io);
M
Minghao Li 已提交
31 32
static int32_t  syncIOStartInternal(SSyncIO *io);
static int32_t  syncIOStopInternal(SSyncIO *io);
M
sync io  
Minghao Li 已提交
33

M
Minghao Li 已提交
34
static void   *syncIOConsumerFunc(void *param);
M
Minghao Li 已提交
35 36 37 38 39 40 41 42 43 44
static void    syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
static void    syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey);

static int32_t syncIOStartQ(SSyncIO *io);
static int32_t syncIOStopQ(SSyncIO *io);
static int32_t syncIOStartPing(SSyncIO *io);
static int32_t syncIOStopPing(SSyncIO *io);
static void    syncIOTickQ(void *param, void *tmrId);
static void    syncIOTickPing(void *param, void *tmrId);
M
Minghao Li 已提交
45 46
// ----------------------------

M
sync io  
Minghao Li 已提交
47 48
// public function ------------
int32_t syncIOStart(char *host, uint16_t port) {
M
Minghao Li 已提交
49
  int32_t ret = 0;
M
sync io  
Minghao Li 已提交
50
  gSyncIO = syncIOCreate(host, port);
M
Minghao Li 已提交
51
  ASSERT(gSyncIO != NULL);
M
Minghao Li 已提交
52

wafwerar's avatar
wafwerar 已提交
53
  taosSeedRand(taosGetTimestampSec());
M
Minghao Li 已提交
54
  ret = syncIOStartInternal(gSyncIO);
M
Minghao Li 已提交
55
  ASSERT(ret == 0);
M
Minghao Li 已提交
56

M
Minghao Li 已提交
57 58
  sTrace("syncIOStart ok, gSyncIO:%p", gSyncIO);
  return ret;
M
Minghao Li 已提交
59
}
M
Minghao Li 已提交
60

M
sync io  
Minghao Li 已提交
61 62
int32_t syncIOStop() {
  int32_t ret = syncIOStopInternal(gSyncIO);
M
Minghao Li 已提交
63
  ASSERT(ret == 0);
M
Minghao Li 已提交
64

M
sync io  
Minghao Li 已提交
65
  ret = syncIODestroy(gSyncIO);
M
Minghao Li 已提交
66
  ASSERT(ret == 0);
M
Minghao Li 已提交
67 68 69
  return ret;
}

S
Shengliang Guan 已提交
70
int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
M
Minghao Li 已提交
71 72
  ASSERT(pEpSet->inUse == 0);
  ASSERT(pEpSet->numOfEps == 1);
M
Minghao Li 已提交
73

M
Minghao Li 已提交
74
  int32_t ret = 0;
M
Minghao Li 已提交
75 76 77
  {
    syncUtilMsgNtoH(pMsg->pCont);

78
    char logBuf[256] = {0};
M
Minghao Li 已提交
79 80
    snprintf(logBuf, sizeof(logBuf), "==syncIOSendMsg== %s:%d msgType:%d", pEpSet->eps[0].fqdn, pEpSet->eps[0].port,
             pMsg->msgType);
M
Minghao Li 已提交
81 82 83 84
    syncRpcMsgLog2(logBuf, pMsg);

    syncUtilMsgHtoN(pMsg->pCont);
  }
M
Minghao Li 已提交
85

S
Shengliang Guan 已提交
86 87
  pMsg->info.handle = NULL;
  pMsg->info.noResp = 1;
S
Shengliang Guan 已提交
88
  rpcSendRequest(gSyncIO->clientRpc, pEpSet, pMsg, NULL);
M
Minghao Li 已提交
89
  return ret;
M
Minghao Li 已提交
90 91
}

S
Shengliang Guan 已提交
92
int32_t syncIOEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
M
Minghao Li 已提交
93
  int32_t ret = 0;
M
Minghao Li 已提交
94 95 96 97

  char logBuf[256] = {0};
  snprintf(logBuf, sizeof(logBuf), "==syncIOEqMsg== msgType:%d", pMsg->msgType);
  syncRpcMsgLog2(logBuf, pMsg);
M
Minghao Li 已提交
98

M
Minghao Li 已提交
99
  SRpcMsg *pTemp;
100
  pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM);
M
Minghao Li 已提交
101 102
  memcpy(pTemp, pMsg, sizeof(SRpcMsg));

S
Shengliang Guan 已提交
103
  STaosQueue *pMsgQ = gSyncIO->pMsgQ;
M
Minghao Li 已提交
104 105
  taosWriteQitem(pMsgQ, pTemp);

M
Minghao Li 已提交
106 107 108 109 110
  return ret;
}

int32_t syncIOQTimerStart() {
  int32_t ret = syncIOStartQ(gSyncIO);
M
Minghao Li 已提交
111
  ASSERT(ret == 0);
M
Minghao Li 已提交
112 113 114 115 116
  return ret;
}

int32_t syncIOQTimerStop() {
  int32_t ret = syncIOStopQ(gSyncIO);
M
Minghao Li 已提交
117
  ASSERT(ret == 0);
M
Minghao Li 已提交
118 119 120 121 122
  return ret;
}

int32_t syncIOPingTimerStart() {
  int32_t ret = syncIOStartPing(gSyncIO);
M
Minghao Li 已提交
123
  ASSERT(ret == 0);
M
Minghao Li 已提交
124 125 126 127 128
  return ret;
}

int32_t syncIOPingTimerStop() {
  int32_t ret = syncIOStopPing(gSyncIO);
M
Minghao Li 已提交
129
  ASSERT(ret == 0);
M
Minghao Li 已提交
130
  return ret;
M
Minghao Li 已提交
131 132
}

M
sync io  
Minghao Li 已提交
133
// local function ------------
M
Minghao Li 已提交
134
static SSyncIO *syncIOCreate(char *host, uint16_t port) {
wafwerar's avatar
wafwerar 已提交
135
  SSyncIO *io = (SSyncIO *)taosMemoryMalloc(sizeof(SSyncIO));
M
Minghao Li 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
  memset(io, 0, sizeof(*io));

  io->pMsgQ = taosOpenQueue();
  io->pQset = taosOpenQset();
  taosAddIntoQset(io->pQset, io->pMsgQ, NULL);

  io->myAddr.inUse = 0;
  io->myAddr.numOfEps = 0;
  addEpIntoEpSet(&io->myAddr, host, port);

  io->qTimerMS = TICK_Q_TIMER_MS;
  io->pingTimerMS = TICK_Ping_TIMER_MS;

  return io;
}

static int32_t syncIODestroy(SSyncIO *io) {
  int32_t ret = 0;
  int8_t  start = atomic_load_8(&io->isStart);
M
Minghao Li 已提交
155
  ASSERT(start == 0);
M
Minghao Li 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

  if (io->serverRpc != NULL) {
    rpcClose(io->serverRpc);
    io->serverRpc = NULL;
  }

  if (io->clientRpc != NULL) {
    rpcClose(io->clientRpc);
    io->clientRpc = NULL;
  }

  taosCloseQueue(io->pMsgQ);
  taosCloseQset(io->pQset);

  return ret;
}

M
sync io  
Minghao Li 已提交
173
static int32_t syncIOStartInternal(SSyncIO *io) {
M
Minghao Li 已提交
174
  int32_t ret = 0;
M
Minghao Li 已提交
175 176
  taosBlockSIGPIPE();

M
sync io  
Minghao Li 已提交
177
  rpcInit();
M
Minghao Li 已提交
178 179 180 181 182 183 184 185

  // cient rpc init
  {
    SRpcInit rpcInit;
    memset(&rpcInit, 0, sizeof(rpcInit));
    rpcInit.localPort = 0;
    rpcInit.label = "SYNC-IO-CLIENT";
    rpcInit.numOfThreads = 1;
M
sync io  
Minghao Li 已提交
186
    rpcInit.cfp = syncIOProcessReply;
M
Minghao Li 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    rpcInit.sessions = 100;
    rpcInit.idleTime = 100;
    rpcInit.user = "sync-io";
    rpcInit.connType = TAOS_CONN_CLIENT;

    io->clientRpc = rpcOpen(&rpcInit);
    if (io->clientRpc == NULL) {
      sError("failed to initialize RPC");
      return -1;
    }
  }

  // server rpc init
  {
    SRpcInit rpcInit;
    memset(&rpcInit, 0, sizeof(rpcInit));
M
Minghao Li 已提交
203
    snprintf(rpcInit.localFqdn, sizeof(rpcInit.localFqdn), "%s", "127.0.0.1");
M
sync io  
Minghao Li 已提交
204
    rpcInit.localPort = io->myAddr.eps[0].port;
M
Minghao Li 已提交
205 206
    rpcInit.label = "SYNC-IO-SERVER";
    rpcInit.numOfThreads = 1;
M
sync io  
Minghao Li 已提交
207
    rpcInit.cfp = syncIOProcessRequest;
M
Minghao Li 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221
    rpcInit.sessions = 1000;
    rpcInit.idleTime = 2 * 1500;
    rpcInit.parent = io;
    rpcInit.connType = TAOS_CONN_SERVER;

    void *pRpc = rpcOpen(&rpcInit);
    if (pRpc == NULL) {
      sError("failed to start RPC server");
      return -1;
    }
  }

  // start consumer thread
  {
wafwerar's avatar
wafwerar 已提交
222
    if (taosThreadCreate(&io->consumerTid, NULL, syncIOConsumerFunc, io) != 0) {
M
Minghao Li 已提交
223 224 225 226 227 228 229
      sError("failed to create sync consumer thread since %s", strerror(errno));
      terrno = TAOS_SYSTEM_ERROR(errno);
      return -1;
    }
  }

  // start tmr thread
M
Minghao Li 已提交
230
  io->timerMgr = taosTmrInit(1000, 50, 10000, "SYNC-IO");
M
Minghao Li 已提交
231

M
Minghao Li 已提交
232 233
  atomic_store_8(&io->isStart, 1);
  return ret;
M
Minghao Li 已提交
234 235
}

M
sync io  
Minghao Li 已提交
236
static int32_t syncIOStopInternal(SSyncIO *io) {
M
Minghao Li 已提交
237
  int32_t ret = 0;
M
Minghao Li 已提交
238
  atomic_store_8(&io->isStart, 0);
wafwerar's avatar
wafwerar 已提交
239
  taosThreadJoin(io->consumerTid, NULL);
240
  taosThreadClear(&io->consumerTid);
M
Minghao Li 已提交
241 242
  taosTmrCleanUp(io->timerMgr);
  return ret;
M
sync io  
Minghao Li 已提交
243 244 245
}

static void *syncIOConsumerFunc(void *param) {
M
Minghao Li 已提交
246
  SSyncIO   *io = param;
247
  STaosQall *qall = taosAllocateQall();
M
Minghao Li 已提交
248
  SRpcMsg   *pRpcMsg, rpcMsg;
249
  SQueueInfo qinfo = {0};
M
sync io  
Minghao Li 已提交
250 251

  while (1) {
252
    int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, &qinfo);
M
sync io  
Minghao Li 已提交
253
    sTrace("syncIOConsumerFunc %d msgs are received", numOfMsgs);
M
Minghao Li 已提交
254 255 256
    if (numOfMsgs <= 0) {
      break;
    }
M
sync io  
Minghao Li 已提交
257 258 259

    for (int i = 0; i < numOfMsgs; ++i) {
      taosGetQitem(qall, (void **)&pRpcMsg);
M
Minghao Li 已提交
260
      char logBuf[128];
M
Minghao Li 已提交
261
      snprintf(logBuf, sizeof(logBuf), "==syncIOConsumMsg== msgType:%d", pRpcMsg->msgType);
M
Minghao Li 已提交
262
      syncRpcMsgLog2(logBuf, pRpcMsg);
M
Minghao Li 已提交
263

M
Minghao Li 已提交
264
      // use switch case instead of if else
265
      if (pRpcMsg->msgType == TDMT_SYNC_PING) {
M
sync io  
Minghao Li 已提交
266
        if (io->FpOnSyncPing != NULL) {
M
Minghao Li 已提交
267
          SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
268
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
269 270
          io->FpOnSyncPing(io->pSyncNode, pSyncMsg);
          syncPingDestroy(pSyncMsg);
M
sync io  
Minghao Li 已提交
271
        }
M
Minghao Li 已提交
272

273
      } else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) {
M
Minghao Li 已提交
274
        if (io->FpOnSyncPingReply != NULL) {
M
Minghao Li 已提交
275
          SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
276
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
277
          io->FpOnSyncPingReply(io->pSyncNode, pSyncMsg);
M
Minghao Li 已提交
278
          syncPingReplyDestroy(pSyncMsg);
M
Minghao Li 已提交
279
        }
M
Minghao Li 已提交
280

281
      } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
M
Minghao Li 已提交
282
        if (io->FpOnSyncClientRequest != NULL) {
283
          io->FpOnSyncClientRequest(io->pSyncNode, pRpcMsg, NULL);
M
Minghao Li 已提交
284 285
        }

286
      } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
M
Minghao Li 已提交
287
        if (io->FpOnSyncRequestVote != NULL) {
M
Minghao Li 已提交
288
          SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
289
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
290 291 292 293
          io->FpOnSyncRequestVote(io->pSyncNode, pSyncMsg);
          syncRequestVoteDestroy(pSyncMsg);
        }

294
      } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
M
Minghao Li 已提交
295
        if (io->FpOnSyncRequestVoteReply != NULL) {
M
Minghao Li 已提交
296
          SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
297
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
298 299 300 301
          io->FpOnSyncRequestVoteReply(io->pSyncNode, pSyncMsg);
          syncRequestVoteReplyDestroy(pSyncMsg);
        }

302
      } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
M
Minghao Li 已提交
303
        if (io->FpOnSyncAppendEntries != NULL) {
M
Minghao Li 已提交
304
          SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
305
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
306 307 308 309
          io->FpOnSyncAppendEntries(io->pSyncNode, pSyncMsg);
          syncAppendEntriesDestroy(pSyncMsg);
        }

310
      } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
M
Minghao Li 已提交
311
        if (io->FpOnSyncAppendEntriesReply != NULL) {
M
Minghao Li 已提交
312
          SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
313
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
314 315 316 317
          io->FpOnSyncAppendEntriesReply(io->pSyncNode, pSyncMsg);
          syncAppendEntriesReplyDestroy(pSyncMsg);
        }

318
      } else if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) {
M
Minghao Li 已提交
319
        if (io->FpOnSyncTimeout != NULL) {
M
Minghao Li 已提交
320
          SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
321
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
322 323 324
          io->FpOnSyncTimeout(io->pSyncNode, pSyncMsg);
          syncTimeoutDestroy(pSyncMsg);
        }
M
Minghao Li 已提交
325

326
      } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
M
Minghao Li 已提交
327
        if (io->FpOnSyncSnapshot != NULL) {
M
Minghao Li 已提交
328
          SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
329
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
330
          io->FpOnSyncSnapshot(io->pSyncNode, pSyncMsg);
M
Minghao Li 已提交
331 332 333
          syncSnapshotSendDestroy(pSyncMsg);
        }

334
      } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
M
Minghao Li 已提交
335
        if (io->FpOnSyncSnapshotReply != NULL) {
M
Minghao Li 已提交
336
          SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pRpcMsg);
M
Minghao Li 已提交
337
          ASSERT(pSyncMsg != NULL);
M
Minghao Li 已提交
338
          io->FpOnSyncSnapshotReply(io->pSyncNode, pSyncMsg);
M
Minghao Li 已提交
339 340 341
          syncSnapshotRspDestroy(pSyncMsg);
        }

M
Minghao Li 已提交
342
      } else {
M
Minghao Li 已提交
343
        sTrace("unknown msgType:%d, no operator", pRpcMsg->msgType);
M
sync io  
Minghao Li 已提交
344 345 346 347 348 349 350 351
      }
    }

    taosResetQitems(qall);
    for (int i = 0; i < numOfMsgs; ++i) {
      taosGetQitem(qall, (void **)&pRpcMsg);
      rpcFreeCont(pRpcMsg->pCont);

M
Minghao Li 已提交
352 353 354 355 356 357 358 359 360 361 362
      /*
            if (pRpcMsg->handle != NULL) {
              int msgSize = 32;
              memset(&rpcMsg, 0, sizeof(rpcMsg));
              rpcMsg.msgType = SYNC_RESPONSE;
              rpcMsg.pCont = rpcMallocCont(msgSize);
              rpcMsg.contLen = msgSize;
              snprintf(rpcMsg.pCont, rpcMsg.contLen, "%s", "give a reply");
              rpcMsg.handle = pRpcMsg->handle;
              rpcMsg.code = 0;

M
Minghao Li 已提交
363
              syncRpcMsgLog2((char *)"syncIOConsumerFunc rpcSendResponse --> ", &rpcMsg);
M
Minghao Li 已提交
364 365 366
              rpcSendResponse(&rpcMsg);
            }
      */
M
sync io  
Minghao Li 已提交
367 368 369

      taosFreeQitem(pRpcMsg);
    }
370 371

    taosUpdateItemSize(qinfo.queue, numOfMsgs);
M
Minghao Li 已提交
372 373
  }

M
sync io  
Minghao Li 已提交
374 375 376 377 378
  taosFreeQall(qall);
  return NULL;
}

static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
M
Minghao Li 已提交
379 380 381
  syncUtilMsgNtoH(pMsg->pCont);

  syncRpcMsgLog2((char *)"==syncIOProcessRequest==", pMsg);
M
sync io  
Minghao Li 已提交
382 383
  SSyncIO *io = pParent;
  SRpcMsg *pTemp;
384
  pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM);
M
sync io  
Minghao Li 已提交
385 386 387 388 389
  memcpy(pTemp, pMsg, sizeof(SRpcMsg));
  taosWriteQitem(io->pMsgQ, pTemp);
}

static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
390
  if (pMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) {
M
Minghao Li 已提交
391 392
    sTrace("==syncIOProcessReply==");
  } else {
M
Minghao Li 已提交
393
    syncRpcMsgLog2((char *)"==syncIOProcessReply==", pMsg);
M
Minghao Li 已提交
394
  }
M
sync io  
Minghao Li 已提交
395 396 397
  rpcFreeCont(pMsg->pCont);
}

M
Minghao Li 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey) {
  // app shall retrieve the auth info based on meterID from DB or a data file
  // demo code here only for simple demo
  int32_t ret = 0;
  return ret;
}

static int32_t syncIOStartQ(SSyncIO *io) {
  int32_t ret = 0;
  taosTmrReset(syncIOTickQ, io->qTimerMS, io, io->timerMgr, &io->qTimer);
  return ret;
}

static int32_t syncIOStopQ(SSyncIO *io) {
  int32_t ret = 0;
  taosTmrStop(io->qTimer);
  io->qTimer = NULL;
  return ret;
}

static int32_t syncIOStartPing(SSyncIO *io) {
  int32_t ret = 0;
  taosTmrReset(syncIOTickPing, io->pingTimerMS, io, io->timerMgr, &io->pingTimer);
  return ret;
}

static int32_t syncIOStopPing(SSyncIO *io) {
  int32_t ret = 0;
  taosTmrStop(io->pingTimer);
  io->pingTimer = NULL;
  return ret;
M
Minghao Li 已提交
429
}
M
sync io  
Minghao Li 已提交
430

M
Minghao Li 已提交
431
static void syncIOTickQ(void *param, void *tmrId) {
M
sync io  
Minghao Li 已提交
432 433
  SSyncIO *io = (SSyncIO *)param;

M
Minghao Li 已提交
434 435 436 437 438
  SRaftId srcId, destId;
  srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
  srcId.vgId = -1;
  destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
  destId.vgId = -1;
M
Minghao Li 已提交
439
  SyncPingReply *pMsg = syncPingReplyBuild2(&srcId, &destId, -1, "syncIOTickQ");
M
sync io  
Minghao Li 已提交
440

M
Minghao Li 已提交
441 442
  SRpcMsg rpcMsg;
  syncPingReply2RpcMsg(pMsg, &rpcMsg);
M
sync io  
Minghao Li 已提交
443
  SRpcMsg *pTemp;
444
  pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM);
M
sync io  
Minghao Li 已提交
445
  memcpy(pTemp, &rpcMsg, sizeof(SRpcMsg));
M
Minghao Li 已提交
446
  syncRpcMsgLog2((char *)"==syncIOTickQ==", &rpcMsg);
M
sync io  
Minghao Li 已提交
447
  taosWriteQitem(io->pMsgQ, pTemp);
M
Minghao Li 已提交
448 449 450
  syncPingReplyDestroy(pMsg);

  taosTmrReset(syncIOTickQ, io->qTimerMS, io, io->timerMgr, &io->qTimer);
M
sync io  
Minghao Li 已提交
451 452
}

M
Minghao Li 已提交
453 454 455 456 457 458 459 460
static void syncIOTickPing(void *param, void *tmrId) {
  SSyncIO *io = (SSyncIO *)param;

  SRaftId srcId, destId;
  srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
  srcId.vgId = -1;
  destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
  destId.vgId = -1;
M
Minghao Li 已提交
461
  SyncPing *pMsg = syncPingBuild2(&srcId, &destId, -1, "syncIOTickPing");
M
Minghao Li 已提交
462 463 464 465
  // SyncPing *pMsg = syncPingBuild3(&srcId, &destId);

  SRpcMsg rpcMsg;
  syncPing2RpcMsg(pMsg, &rpcMsg);
M
Minghao Li 已提交
466
  syncRpcMsgLog2((char *)"==syncIOTickPing==", &rpcMsg);
M
Minghao Li 已提交
467 468 469 470
  rpcSendRequest(io->clientRpc, &io->myAddr, &rpcMsg, NULL);
  syncPingDestroy(pMsg);

  taosTmrReset(syncIOTickPing, io->pingTimerMS, io, io->timerMgr, &io->pingTimer);
dengyihao's avatar
dengyihao 已提交
471
}