syncInt.h 2.2 KB
Newer Older
L
lichuang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (c) 2019 TAOS Data, Inc. <cli@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/>.
 */

#ifndef _TD_LIBS_SYNC_INT_H
#define _TD_LIBS_SYNC_INT_H

#include "thash.h"
#include "os.h"
#include "sync.h"
22
#include "sync_type.h"
L
lichuang 已提交
23 24 25 26 27 28 29 30 31 32 33
#include "raft.h"
#include "tlog.h"

#define TAOS_SYNC_MAX_WORKER 3

typedef struct SSyncWorker {
  pthread_t thread;
} SSyncWorker;

struct SSyncNode {
  pthread_mutex_t   mutex;
34
  int32_t      refCount;
L
lichuang 已提交
35 36
  SyncGroupId   vgId;
  SSyncRaft raft;
37
  void* syncTimer;
L
lichuang 已提交
38 39 40 41 42
};

typedef struct SSyncManager {
  pthread_mutex_t   mutex;

43 44 45 46 47 48 49 50
  // sync server rpc
  void* serverRpc;
  // rpc server hash table base on FQDN:port key
  SHashObj* rpcServerTable;

  // sync client rpc
  void* clientRpc;

L
lichuang 已提交
51 52 53 54 55 56
  // worker threads
  SSyncWorker worker[TAOS_SYNC_MAX_WORKER];

  // vgroup hash table
  SHashObj* vgroupTable;

57 58 59
  // timer manager
  void* syncTimerManager;

L
lichuang 已提交
60 61 62 63 64 65 66 67 68 69 70 71
} SSyncManager;

extern SSyncManager* gSyncManager;

#define syncFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYNC FATAL ", 255, __VA_ARGS__); }}     while(0)
#define syncError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYNC ERROR ", 255, __VA_ARGS__); }}     while(0)
#define syncWarn(...)  do { if (sDebugFlag & DEBUG_WARN)  { taosPrintLog("SYNC WARN ", 255, __VA_ARGS__); }}      while(0)
#define syncInfo(...)  do { if (sDebugFlag & DEBUG_INFO)  { taosPrintLog("SYNC ", 255, __VA_ARGS__); }}           while(0)
#define syncDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYNC ", sDebugFlag, __VA_ARGS__); }} while(0)
#define syncTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYNC ", sDebugFlag, __VA_ARGS__); }} while(0)

#endif  /* _TD_LIBS_SYNC_INT_H */