dmMgmt.h 5.1 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16 17
#ifndef _TD_DND_IMP_H_
#define _TD_DND_IMP_H_
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19 20 21
// tobe deleted
#include "uv.h"

S
Shengliang Guan 已提交
22
#include "dmInt.h"
S
Shengliang Guan 已提交
23 24 25 26 27

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
28 29
typedef struct SMgmtWrapper SMgmtWrapper;

30 31 32 33 34 35 36 37 38
#define SINGLE_PROC               0
#define CHILD_PROC                1
#define PARENT_PROC               2
#define TEST_PROC                 3
#define OnlyInSingleProc(wrapper) ((wrapper)->proc.ptype == SINGLE_PROC)
#define OnlyInChildProc(wrapper)  ((wrapper)->proc.ptype == CHILD_PROC)
#define OnlyInParentProc(wrapper) ((wrapper)->proc.ptype == PARENT_PROC)
#define InChildProc(wrapper)      ((wrapper)->proc.ptype & CHILD_PROC)
#define InParentProc(wrapper)     ((wrapper)->proc.ptype & PARENT_PROC)
S
Shengliang Guan 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

typedef struct {
  int32_t       head;
  int32_t       tail;
  int32_t       total;
  int32_t       avail;
  int32_t       items;
  char          name[8];
  TdThreadMutex mutex;
  tsem_t        sem;
  char          pBuffer[];
} SProcQueue;

typedef struct {
  SMgmtWrapper *wrapper;
  const char   *name;
  SHashObj     *hash;
  SProcQueue   *pqueue;
  SProcQueue   *cqueue;
  TdThread      pthread;
  TdThread      cthread;
  SShm          shm;
  int32_t       pid;
62
  EDndProcType  ptype;
S
Shengliang Guan 已提交
63 64 65
  bool          stop;
} SProc;

S
Shengliang Guan 已提交
66
typedef struct SMgmtWrapper {
67
  SMgmtFunc      func;
68
  struct SDnode *pDnode;
69 70 71 72 73 74 75 76 77 78
  void          *pMgmt;
  const char    *name;
  char          *path;
  int32_t        refCount;
  SRWLatch       latch;
  EDndNodeType   ntype;
  bool           deployed;
  bool           required;
  SProc          proc;
  NodeMsgFp      msgFps[TDMT_MAX];
S
Shengliang Guan 已提交
79 80 81 82 83
} SMgmtWrapper;

typedef struct {
  EDndNodeType defaultNtype;
  bool         needCheckVgId;
84
} SDnodeHandle;
S
Shengliang Guan 已提交
85 86

typedef struct {
87 88 89
  void        *serverRpc;
  void        *clientRpc;
  SDnodeHandle msgHandles[TDMT_MAX];
S
Shengliang Guan 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
} SDnodeTrans;

typedef struct {
  char name[TSDB_STEP_NAME_LEN];
  char desc[TSDB_STEP_DESC_LEN];
} SStartupInfo;

typedef struct SUdfdData {
  bool         startCalled;
  bool         needCleanUp;
  uv_loop_t    loop;
  uv_thread_t  thread;
  uv_barrier_t barrier;
  uv_process_t process;
  int          spawnErr;
  uv_pipe_t    ctrlPipe;
  uv_async_t   stopAsync;
  int32_t      stopCalled;
  int32_t      dnodeId;
} SUdfdData;

typedef struct SDnode {
112 113
  int8_t        once;
  bool          stop;
114
  EDndProcType  ptype;
S
Shengliang Guan 已提交
115
  EDndNodeType  rtype;
S
Shengliang Guan 已提交
116 117 118 119 120 121
  EDndRunStatus status;
  SStartupInfo  startup;
  SDnodeTrans   trans;
  SUdfdData     udfdData;
  TdThreadMutex mutex;
  TdFilePtr     lockfile;
S
Shengliang Guan 已提交
122
  SDnodeData    data;
S
Shengliang Guan 已提交
123 124 125
  SMgmtWrapper  wrappers[NODE_END];
} SDnode;

126 127 128
// dmEnv.c
SDnode *dmInstance();
void    dmReportStartup(const char *pName, const char *pDesc);
S
Shengliang Guan 已提交
129

130 131 132
// dmMgmt.c
int32_t       dmInitDnode(SDnode *pDnode, EDndNodeType rtype);
void          dmCleanupDnode(SDnode *pDnode);
S
Shengliang Guan 已提交
133 134 135
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
int32_t       dmMarkWrapper(SMgmtWrapper *pWrapper);
void          dmReleaseWrapper(SMgmtWrapper *pWrapper);
S
Shengliang Guan 已提交
136
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
S
Shengliang Guan 已提交
137 138

void dmSetStatus(SDnode *pDnode, EDndRunStatus stype);
S
Shengliang Guan 已提交
139 140
void dmProcessServerStartupStatus(SDnode *pDnode, SRpcMsg *pMsg);
void dmProcessNetTestReq(SDnode *pDnode, SRpcMsg *pMsg);
S
Shengliang Guan 已提交
141

142 143
// dmNodes.c
int32_t dmOpenNode(SMgmtWrapper *pWrapper);
144 145
int32_t dmStartNode(SMgmtWrapper *pWrapper);
void    dmStopNode(SMgmtWrapper *pWrapper);
146 147 148
void    dmCloseNode(SMgmtWrapper *pWrapper);
int32_t dmRunDnode(SDnode *pDnode);

S
Shengliang Guan 已提交
149 150 151 152 153 154 155 156 157 158 159 160
// dmProc.c
int32_t dmInitProc(struct SMgmtWrapper *pWrapper);
void    dmCleanupProc(struct SMgmtWrapper *pWrapper);
int32_t dmRunProc(SProc *proc);
void    dmStopProc(SProc *proc);
int64_t dmRemoveProcRpcHandle(SProc *proc, void *handle);
void    dmCloseProcRpcHandles(SProc *proc);
int32_t dmPutToProcCQueue(SProc *proc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
                          void *handle, int64_t handleRef, EProcFuncType ftype);
void    dmPutToProcPQueue(SProc *proc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
                          EProcFuncType ftype);

S
Shengliang Guan 已提交
161
// dmTransport.c
S
Shengliang Guan 已提交
162 163 164 165
int32_t dmInitServer(SDnode *pDnode);
void    dmCleanupServer(SDnode *pDnode);
int32_t dmInitClient(SDnode *pDnode);
void    dmCleanupClient(SDnode *pDnode);
166
SMsgCb  dmGetMsgcb(SDnode *pDnode);
S
Shengliang Guan 已提交
167
int32_t dmInitMsgHandle(SDnode *pDnode);
S
Shengliang Guan 已提交
168
int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
S
Shengliang Guan 已提交
169

S
Shengliang Guan 已提交
170
// mgmt nodes
S
Shengliang Guan 已提交
171 172 173 174 175 176
SMgmtFunc dmGetMgmtFunc();
SMgmtFunc bmGetMgmtFunc();
SMgmtFunc qmGetMgmtFunc();
SMgmtFunc smGetMgmtFunc();
SMgmtFunc vmGetMgmtFunc();
SMgmtFunc mmGetMgmtFunc();
S
Shengliang Guan 已提交
177

S
Shengliang Guan 已提交
178 179 180 181
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
182
#endif /*_TD_DND_IMP_H_*/