syncTimeout.c 1.7 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 "syncTimeout.h"
M
Minghao Li 已提交
17
#include "syncElection.h"
M
Minghao Li 已提交
18
#include "syncReplication.h"
M
Minghao Li 已提交
19

M
Minghao Li 已提交
20 21 22 23 24
int32_t syncNodeTimerRoutine(SSyncNode* ths) {
  syncNodeEventLog(ths, "timer routines ... ");
  return 0;
}

M
Minghao Li 已提交
25 26
int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
  int32_t ret = 0;
M
Minghao Li 已提交
27
  syncTimeoutLog2("==syncNodeOnTimeoutCb==", pMsg);
M
Minghao Li 已提交
28 29 30 31

  if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
    if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
      ++(ths->pingTimerCounter);
M
Minghao Li 已提交
32

M
Minghao Li 已提交
33
      // syncNodePingAll(ths);
M
Minghao Li 已提交
34 35 36
      // syncNodePingPeers(ths);

      syncNodeTimerRoutine(ths);
M
Minghao Li 已提交
37 38 39 40 41 42 43 44 45 46 47
    }

  } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
    if (atomic_load_64(&ths->electTimerLogicClockUser) <= pMsg->logicClock) {
      ++(ths->electTimerCounter);
      syncNodeElect(ths);
    }

  } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) {
    if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) {
      ++(ths->heartbeatTimerCounter);
M
Minghao Li 已提交
48
      syncNodeReplicate(ths);
M
Minghao Li 已提交
49 50
    }
  } else {
M
Minghao Li 已提交
51
    sError("vgId:%d, unknown timeout-type:%d", ths->vgId, pMsg->timeoutType);
M
Minghao Li 已提交
52 53 54 55
  }

  return ret;
}