• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4780

06 Oct 2025 08:05AM UTC coverage: 57.808% (-0.7%) from 58.554%
#4780

push

travis-ci

web-flow
Merge pull request #33175 from taosdata/docs/fix-download-url

fix: remove unnecessary jsonPath attribute and add  tdgpt download url

137100 of 302743 branches covered (45.29%)

Branch coverage included in aggregate %.

208096 of 294403 relevant lines covered (70.68%)

5550964.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

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

16
#define _DEFAULT_SOURCE
17
#include "mndTrans.h"
18
#include "mndDb.h"
19
#include "mndPrivilege.h"
20
#include "mndShow.h"
21
#include "mndStb.h"
22
#include "mndSubscribe.h"
23
#include "mndSync.h"
24
#include "mndUser.h"
25
#include "mndVgroup.h"
26
#include "osTime.h"
27

28
#define TRANS_VER1_NUMBER  1
29
#define TRANS_VER2_NUMBER  2
30
#define TRANS_VER3_NUMBER  3
31
#define TRANS_ARRAY_SIZE   8
32
#define TRANS_RESERVE_SIZE 39
33
#define TRANS_ACTION_TIMEOUT 1000 * 1000 * 60 * 15
34

35
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
36
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
37
static int32_t mndTransDelete(SSdb *pSdb, STrans *pTrans, bool callFunc);
38

39
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
40
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction);
41
static void    mndTransDropLogs(SArray *pArray);
42
static void    mndTransDropActions(SArray *pArray);
43

44
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray, bool topHalf, bool notSend);
45
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans, bool topHalf);
46
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans, bool topHalf);
47
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend);
48
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend);
49
static int32_t mndTransExecuteCommitActions(SMnode *pMnode, STrans *pTrans, bool topHalf);
50
static bool    mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
51
static bool    mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend);
52
static bool    mndTransPerformUndoLogStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
53
static bool    mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend);
54
static bool    mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
55
static bool    mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
56
static bool    mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
57
static bool    mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
58

59
static inline bool mndTransIsInSyncContext(bool topHalf) { return !topHalf; }
327,861✔
60

61
static bool mndCannotExecuteTrans(SMnode *pMnode, bool topHalf) {
312,831✔
62
  bool isLeader = mndIsLeader(pMnode);
312,831✔
63
  bool ret = (!pMnode->deploy && !isLeader) || mndTransIsInSyncContext(topHalf);
312,831✔
64
  if (ret) mDebug("cannot execute trans action, deploy:%d, isLeader:%d, topHalf:%d", pMnode->deploy, isLeader, topHalf);
312,831✔
65
  return ret;
312,831✔
66
}
67

68
static bool mndCannotExecuteTransWithInfo(SMnode *pMnode, bool topHalf, char *str, int32_t size) {
32,955✔
69
  bool isLeader = mndIsLeader(pMnode);
32,955✔
70
  bool ret = (!pMnode->deploy && !isLeader) || mndTransIsInSyncContext(topHalf);
32,955✔
71
  if (ret)
32,955✔
72
    tsnprintf(str, size, "deploy:%d, isLeader:%d, context:%s", pMnode->deploy, isLeader,
9,467✔
73
              topHalf ? "transContext" : "syncContext");
74
  return ret;
32,955✔
75
}
76

77
static inline char *mndStrExecutionContext(bool topHalf) { return topHalf ? "transContext" : "syncContext"; }
483,954✔
78

79
static void    mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans);
80
static int32_t mndProcessTransTimer(SRpcMsg *pReq);
81
static int32_t mndProcessTtl(SRpcMsg *pReq);
82
static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
83

84
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
85
static void    mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
86
static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
87
static int32_t tsMaxTransId = 0;
88

89
int32_t mndInitTrans(SMnode *pMnode) {
1,954✔
90
  SSdbTable table = {
1,954✔
91
      .sdbType = SDB_TRANS,
92
      .keyType = SDB_KEY_INT32,
93
      .encodeFp = (SdbEncodeFp)mndTransEncode,
94
      .decodeFp = (SdbDecodeFp)mndTransDecode,
95
      .insertFp = (SdbInsertFp)mndTransActionInsert,
96
      .updateFp = (SdbUpdateFp)mndTransActionUpdate,
97
      .deleteFp = (SdbDeleteFp)mndTransDelete,
98
  };
99

100
  mndSetMsgHandle(pMnode, TDMT_MND_TRANS_TIMER, mndProcessTransTimer);
1,954✔
101
  mndSetMsgHandle(pMnode, TDMT_MND_KILL_TRANS, mndProcessKillTransReq);
1,954✔
102

103
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans);
1,954✔
104
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans);
1,954✔
105
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANSACTION_DETAIL, mndRetrieveTransDetail);
1,954✔
106
  return sdbSetTable(pMnode->pSdb, table);
1,954✔
107
}
108

109
void mndCleanupTrans(SMnode *pMnode) {}
1,954✔
110

111
static int32_t mndTransGetActionsSize(SArray *pArray) {
620,412✔
112
  int32_t actionNum = taosArrayGetSize(pArray);
620,412✔
113
  int32_t rawDataLen = 0;
620,412✔
114

115
  for (int32_t i = 0; i < actionNum; ++i) {
1,826,893✔
116
    STransAction *pAction = taosArrayGet(pArray, i);
1,206,481✔
117
    if (pAction->actionType == TRANS_ACTION_RAW) {
1,206,481✔
118
      rawDataLen += (sizeof(STransAction) + sdbGetRawTotalSize(pAction->pRaw));
841,435✔
119
    } else if (pAction->actionType == TRANS_ACTION_MSG) {
365,046!
120
      rawDataLen += (sizeof(STransAction) + pAction->contLen);
365,046✔
121
    } else {
122
      // empty
123
    }
124
    rawDataLen += sizeof(int8_t);
1,206,481✔
125
  }
126

127
  return rawDataLen;
620,412✔
128
}
129

130
static int32_t mndTransEncodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionsNum,
620,412✔
131
                                    int32_t sver) {
132
  int32_t code = 0;
620,412✔
133
  int32_t lino = 0;
620,412✔
134
  int32_t dataPos = *offset;
620,412✔
135
  int8_t  unused = 0;
620,412✔
136
  int32_t ret = -1;
620,412✔
137

138
  for (int32_t i = 0; i < actionsNum; ++i) {
1,826,893✔
139
    STransAction *pAction = taosArrayGet(pActions, i);
1,206,481✔
140
    SDB_SET_INT32(pRaw, dataPos, pAction->id, _OVER)
1,206,481!
141
    SDB_SET_INT32(pRaw, dataPos, pAction->errCode, _OVER)
1,206,481!
142
    SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
1,206,481!
143
    SDB_SET_INT32(pRaw, dataPos, pAction->retryCode, _OVER)
1,206,481!
144
    SDB_SET_INT8(pRaw, dataPos, pAction->actionType, _OVER)
1,206,481!
145
    SDB_SET_INT8(pRaw, dataPos, pAction->stage, _OVER)
1,206,481!
146
    SDB_SET_INT8(pRaw, dataPos, pAction->reserved, _OVER)
1,206,481!
147
    if (sver > TRANS_VER2_NUMBER) {
1,206,481!
148
      SDB_SET_INT32(pRaw, dataPos, pAction->groupId, _OVER)
1,206,481!
149
    }
150
    if (pAction->actionType == TRANS_ACTION_RAW) {
1,206,481✔
151
      int32_t len = sdbGetRawTotalSize(pAction->pRaw);
841,435✔
152
      SDB_SET_INT8(pRaw, dataPos, unused /*pAction->rawWritten*/, _OVER)
841,435!
153
      SDB_SET_INT32(pRaw, dataPos, len, _OVER)
841,435!
154
      SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pRaw, len, _OVER)
841,435!
155
    } else if (pAction->actionType == TRANS_ACTION_MSG) {
365,046!
156
      SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
365,046!
157
      SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
365,046!
158
      SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgSent*/, _OVER)
365,046!
159
      SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgReceived*/, _OVER)
365,046!
160
      SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
365,046!
161
      SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
365,046!
162
    } else {
163
      // nothing
164
    }
165
  }
166
  ret = 0;
620,412✔
167

168
_OVER:
620,412✔
169
  *offset = dataPos;
620,412✔
170
  return ret;
620,412✔
171
}
172

173
SSdbRaw *mndTransEncode(STrans *pTrans) {
155,103✔
174
  int32_t code = 0;
155,103✔
175
  int32_t lino = 0;
155,103✔
176
  terrno = TSDB_CODE_INVALID_MSG;
155,103✔
177
  int8_t sver = TRANS_VER3_NUMBER;
155,103✔
178

179
  int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
155,103✔
180
  rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
155,103✔
181
  rawDataLen += mndTransGetActionsSize(pTrans->redoActions);
155,103✔
182
  rawDataLen += mndTransGetActionsSize(pTrans->undoActions);
155,103✔
183
  rawDataLen += mndTransGetActionsSize(pTrans->commitActions);
155,103✔
184

185
  SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, sver, rawDataLen);
155,103✔
186
  if (pRaw == NULL) {
155,103!
187
    mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
×
188
    return NULL;
×
189
  }
190

191
  int32_t dataPos = 0;
155,103✔
192
  SDB_SET_INT32(pRaw, dataPos, pTrans->id, _OVER)
155,103!
193
  SDB_SET_INT8(pRaw, dataPos, pTrans->stage, _OVER)
155,103!
194
  SDB_SET_INT8(pRaw, dataPos, pTrans->policy, _OVER)
155,103!
195
  SDB_SET_INT8(pRaw, dataPos, pTrans->conflict, _OVER)
155,103!
196
  SDB_SET_INT8(pRaw, dataPos, pTrans->exec, _OVER)
155,103!
197
  SDB_SET_INT8(pRaw, dataPos, pTrans->oper, _OVER)
155,103!
198
  SDB_SET_INT8(pRaw, dataPos, 0, _OVER)
155,103!
199
  SDB_SET_INT16(pRaw, dataPos, pTrans->originRpcType, _OVER)
155,103!
200
  SDB_SET_INT64(pRaw, dataPos, pTrans->createdTime, _OVER)
155,103!
201
  SDB_SET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_TABLE_FNAME_LEN, _OVER)
155,103!
202
  SDB_SET_BINARY(pRaw, dataPos, pTrans->stbname, TSDB_TABLE_FNAME_LEN, _OVER)
155,103!
203
  SDB_SET_INT32(pRaw, dataPos, pTrans->actionPos, _OVER)
155,103!
204

205
  int32_t prepareActionNum = taosArrayGetSize(pTrans->prepareActions);
155,103✔
206
  int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
155,103✔
207
  int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
155,103✔
208
  int32_t commitActionNum = taosArrayGetSize(pTrans->commitActions);
155,103✔
209

210
  if (sver > TRANS_VER1_NUMBER) {
155,103!
211
    SDB_SET_INT32(pRaw, dataPos, prepareActionNum, _OVER)
155,103!
212
  }
213
  SDB_SET_INT32(pRaw, dataPos, redoActionNum, _OVER)
155,103!
214
  SDB_SET_INT32(pRaw, dataPos, undoActionNum, _OVER)
155,103!
215
  SDB_SET_INT32(pRaw, dataPos, commitActionNum, _OVER)
155,103!
216

217
  if (mndTransEncodeAction(pRaw, &dataPos, pTrans->prepareActions, prepareActionNum, sver) < 0) goto _OVER;
155,103!
218
  if (mndTransEncodeAction(pRaw, &dataPos, pTrans->redoActions, redoActionNum, sver) < 0) goto _OVER;
155,103!
219
  if (mndTransEncodeAction(pRaw, &dataPos, pTrans->undoActions, undoActionNum, sver) < 0) goto _OVER;
155,103!
220
  if (mndTransEncodeAction(pRaw, &dataPos, pTrans->commitActions, commitActionNum, sver) < 0) goto _OVER;
155,103!
221

222
  SDB_SET_INT32(pRaw, dataPos, pTrans->startFunc, _OVER)
155,103!
223
  SDB_SET_INT32(pRaw, dataPos, pTrans->stopFunc, _OVER)
155,103!
224
  SDB_SET_INT32(pRaw, dataPos, pTrans->paramLen, _OVER)
155,103!
225
  if (pTrans->param != NULL) {
155,103!
226
    SDB_SET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, _OVER)
×
227
  }
228

229
  SDB_SET_BINARY(pRaw, dataPos, pTrans->opername, TSDB_TRANS_OPER_LEN, _OVER)
155,103!
230

231
  int32_t arbGroupNum = taosHashGetSize(pTrans->arbGroupIds);
155,103✔
232
  SDB_SET_INT32(pRaw, dataPos, arbGroupNum, _OVER)
155,103!
233
  void *pIter = NULL;
155,103✔
234
  pIter = taosHashIterate(pTrans->arbGroupIds, NULL);
155,103✔
235
  while (pIter) {
155,199✔
236
    int32_t arbGroupId = *(int32_t *)pIter;
96✔
237
    SDB_SET_INT32(pRaw, dataPos, arbGroupId, _OVER)
96!
238
    pIter = taosHashIterate(pTrans->arbGroupIds, pIter);
96✔
239
  }
240

241
  if (sver > TRANS_VER1_NUMBER) {
155,103!
242
    SDB_SET_INT8(pRaw, dataPos, pTrans->ableToBeKilled, _OVER)
155,103!
243
    SDB_SET_INT32(pRaw, dataPos, pTrans->killMode, _OVER)
155,103!
244
  }
245

246
  if (sver > TRANS_VER2_NUMBER) {
155,103!
247
    int32_t groupNum = taosHashGetSize(pTrans->groupActionPos);
155,103✔
248
    SDB_SET_INT32(pRaw, dataPos, groupNum, _OVER)
155,103!
249
    void *pIter = NULL;
155,103✔
250
    pIter = taosHashIterate(pTrans->groupActionPos, NULL);
155,103✔
251
    while (pIter) {
159,989✔
252
      size_t   keysize = 0;
4,886✔
253
      int32_t *groupId = taosHashGetKey(pIter, &keysize);
4,886✔
254
      int32_t  groupPos = *(int32_t *)pIter;
4,886✔
255
      SDB_SET_INT32(pRaw, dataPos, *groupId, _OVER)
4,886!
256
      SDB_SET_INT32(pRaw, dataPos, groupPos, _OVER)
4,886!
257
      pIter = taosHashIterate(pTrans->groupActionPos, pIter);
4,886✔
258
    }
259
  }
260
  SDB_SET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
155,103!
261
  SDB_SET_DATALEN(pRaw, dataPos, _OVER)
155,103!
262

263
  terrno = 0;
155,103✔
264

265
_OVER:
155,103✔
266
  if (terrno != 0) {
155,103!
267
    mError("trans:%d, failed to encode to raw:%p maxlen:%d len:%d since %s", pTrans->id, pRaw, sdbGetRawTotalSize(pRaw),
×
268
           dataPos, terrstr());
269
    sdbFreeRaw(pRaw);
×
270
    return NULL;
×
271
  }
272

273
  mTrace("trans:%d, encode to raw:%p, row:%p len:%d", pTrans->id, pRaw, pTrans, dataPos);
155,103✔
274
  return pRaw;
155,103✔
275
}
276

277
static int32_t mndTransDecodeGroupRedoAction(SHashObj *redoGroupActions, STransAction *pAction) {
47,469✔
278
  if (pAction->groupId < 0) return 0;
47,469✔
279
  SArray **redoAction = taosHashGet(redoGroupActions, &pAction->groupId, sizeof(int32_t));
45,714✔
280
  if (redoAction == NULL) {
45,714✔
281
    SArray *array = taosArrayInit(4, sizeof(STransAction *));
9,752✔
282
    if (array != NULL) {
9,752!
283
      if (taosHashPut(redoGroupActions, &pAction->groupId, sizeof(int32_t), &array, sizeof(SArray *)) < 0) {
9,752!
284
        mInfo("failed put action into redo group actions");
×
285
        return TSDB_CODE_INTERNAL_ERROR;
×
286
      }
287
    }
288
    redoAction = taosHashGet(redoGroupActions, &pAction->groupId, sizeof(int32_t));
9,752✔
289
  }
290
  if (redoAction != NULL) {
45,714!
291
    if (taosArrayPush(*redoAction, &pAction) == NULL) return TSDB_CODE_INTERNAL_ERROR;
91,428!
292
  }
293
  return 0;
45,714✔
294
}
295

296
static int32_t mndTransDecodeActionWithGroup(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum,
3,275✔
297
                                             SHashObj *redoGroupActions, int32_t sver) {
298
  int32_t      code = 0;
3,275✔
299
  int32_t      lino = 0;
3,275✔
300
  STransAction action = {0};
3,275✔
301
  int32_t      dataPos = *offset;
3,275✔
302
  int8_t       unused = 0;
3,275✔
303
  int8_t       stage = 0;
3,275✔
304
  int8_t       actionType = 0;
3,275✔
305
  int32_t      dataLen = 0;
3,275✔
306
  int32_t      ret = -1;
3,275✔
307
  terrno = 0;
3,275✔
308

309
  for (int32_t i = 0; i < actionNum; ++i) {
50,744✔
310
    memset(&action, 0, sizeof(action));
47,469✔
311
    SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
47,469!
312
    SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
47,469!
313
    SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
47,469!
314
    SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
47,469!
315
    SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
47,469!
316
    action.actionType = actionType;
47,469✔
317
    SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
47,469!
318
    action.stage = stage;
47,469✔
319
    SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
47,469!
320
    if (sver > TRANS_VER2_NUMBER) {
47,469!
321
      SDB_GET_INT32(pRaw, dataPos, &action.groupId, _OVER)
47,469!
322
    }
323
    if (action.actionType == TRANS_ACTION_RAW) {
47,469✔
324
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
8,413!
325
      SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
8,413!
326
      action.pRaw = taosMemoryMalloc(dataLen);
8,413!
327
      if (action.pRaw == NULL) goto _OVER;
8,413!
328
      mTrace("raw:%p, is created", action.pRaw);
8,413!
329
      SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
8,413!
330
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
8,413!
331
      STransAction *pAction = taosArrayGet(pActions, taosArrayGetSize(pActions) - 1);
8,413✔
332
      if (mndTransDecodeGroupRedoAction(redoGroupActions, pAction) != 0) goto _OVER;
8,413!
333
      action.pRaw = NULL;
8,413✔
334
    } else if (action.actionType == TRANS_ACTION_MSG) {
39,056!
335
      SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
39,056!
336
      tmsgUpdateDnodeEpSet(&action.epSet);
39,056✔
337
      SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
39,056!
338
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
39,056!
339
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
39,056!
340
      SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
39,056!
341
      action.pCont = taosMemoryMalloc(action.contLen);
39,056!
342
      if (action.pCont == NULL) goto _OVER;
39,056!
343
      SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
39,056!
344
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
39,056!
345
      STransAction *pAction = taosArrayGet(pActions, taosArrayGetSize(pActions) - 1);
39,056✔
346
      if (mndTransDecodeGroupRedoAction(redoGroupActions, pAction) != 0) goto _OVER;
39,056!
347
      action.pCont = NULL;
39,056✔
348
    } else {
349
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
×
350
    }
351
  }
352
  ret = 0;
3,275✔
353

354
_OVER:
3,275✔
355
  if (terrno != 0) mError("failed to decode action with group at line:%d, since %s", lino, terrstr());
3,275!
356
  *offset = dataPos;
3,275✔
357
  taosMemoryFreeClear(action.pCont);
3,275!
358
  return ret;
3,275✔
359
}
360

361
static int32_t mndTransDecodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum, int32_t sver) {
1,167,749✔
362
  int32_t      code = 0;
1,167,749✔
363
  int32_t      lino = 0;
1,167,749✔
364
  STransAction action = {0};
1,167,749✔
365
  int32_t      dataPos = *offset;
1,167,749✔
366
  int8_t       unused = 0;
1,167,749✔
367
  int8_t       stage = 0;
1,167,749✔
368
  int8_t       actionType = 0;
1,167,749✔
369
  int32_t      dataLen = 0;
1,167,749✔
370
  int32_t      ret = -1;
1,167,749✔
371
  terrno = 0;
1,167,749✔
372

373
  for (int32_t i = 0; i < actionNum; ++i) {
3,358,741✔
374
    memset(&action, 0, sizeof(action));
2,190,992✔
375
    SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
2,190,992!
376
    SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
2,190,992!
377
    SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
2,190,992!
378
    SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
2,190,992!
379
    SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
2,190,992!
380
    action.actionType = actionType;
2,190,992✔
381
    SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
2,190,992!
382
    action.stage = stage;
2,190,992✔
383
    SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
2,190,992!
384
    if (sver > TRANS_VER2_NUMBER) {
2,190,992!
385
      SDB_GET_INT32(pRaw, dataPos, &action.groupId, _OVER)
2,190,992!
386
    }
387
    if (action.actionType == TRANS_ACTION_RAW) {
2,190,992✔
388
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
1,502,879!
389
      SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
1,502,879!
390
      action.pRaw = taosMemoryMalloc(dataLen);
1,502,879!
391
      if (action.pRaw == NULL) goto _OVER;
1,502,879!
392
      mTrace("raw:%p, is created", action.pRaw);
1,502,879✔
393
      SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
1,502,879!
394
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
1,502,879!
395
      action.pRaw = NULL;
1,502,879✔
396
    } else if (action.actionType == TRANS_ACTION_MSG) {
688,113!
397
      SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
688,113!
398
      tmsgUpdateDnodeEpSet(&action.epSet);
688,113✔
399
      SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
688,113!
400
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
688,113!
401
      SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
688,113!
402
      SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
688,113!
403
      action.pCont = taosMemoryMalloc(action.contLen);
688,113!
404
      if (action.pCont == NULL) goto _OVER;
688,113!
405
      SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
688,113!
406
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
688,113!
407
      action.pCont = NULL;
688,113✔
408
    } else {
409
      if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
×
410
    }
411
  }
412
  ret = 0;
1,167,749✔
413

414
_OVER:
1,167,749✔
415
  if (terrno != 0) mError("failed to decode action at line:%d, since %s", lino, terrstr());
1,167,749!
416
  *offset = dataPos;
1,167,749✔
417
  taosMemoryFreeClear(action.pCont);
1,167,749!
418
  return ret;
1,167,749✔
419
}
420

421
SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
292,756✔
422
  terrno = TSDB_CODE_INVALID_MSG;
292,756✔
423
  int32_t  code = 0;
292,756✔
424
  int32_t  lino = 0;
292,756✔
425
  SSdbRow *pRow = NULL;
292,756✔
426
  STrans  *pTrans = NULL;
292,756✔
427
  char    *pData = NULL;
292,756✔
428
  int32_t  dataLen = 0;
292,756✔
429
  int8_t   sver = 0;
292,756✔
430
  int32_t  prepareActionNum = 0;
292,756✔
431
  int32_t  redoActionNum = 0;
292,756✔
432
  int32_t  undoActionNum = 0;
292,756✔
433
  int32_t  commitActionNum = 0;
292,756✔
434
  int32_t  dataPos = 0;
292,756✔
435
  int32_t  arbgroupIdNum = 0;
292,756✔
436

437
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
292,756!
438

439
  if (sver > TRANS_VER3_NUMBER) {
292,756!
440
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
441
    goto _OVER;
×
442
  }
443

444
  pRow = sdbAllocRow(sizeof(STrans));
292,756✔
445
  if (pRow == NULL) goto _OVER;
292,756!
446

447
  pTrans = sdbGetRowObj(pRow);
292,756✔
448
  if (pTrans == NULL) goto _OVER;
292,756!
449

450
  SDB_GET_INT32(pRaw, dataPos, &pTrans->id, _OVER)
292,756!
451

452
  int8_t stage = 0;
292,756✔
453
  int8_t policy = 0;
292,756✔
454
  int8_t conflict = 0;
292,756✔
455
  int8_t exec = 0;
292,756✔
456
  int8_t oper = 0;
292,756✔
457
  int8_t reserved = 0;
292,756✔
458
  int8_t actionType = 0;
292,756✔
459
  SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
292,756!
460
  SDB_GET_INT8(pRaw, dataPos, &policy, _OVER)
292,756!
461
  SDB_GET_INT8(pRaw, dataPos, &conflict, _OVER)
292,756!
462
  SDB_GET_INT8(pRaw, dataPos, &exec, _OVER)
292,756!
463
  SDB_GET_INT8(pRaw, dataPos, &oper, _OVER)
292,756!
464
  SDB_GET_INT8(pRaw, dataPos, &reserved, _OVER)
292,756!
465
  pTrans->stage = stage;
292,756✔
466
  pTrans->policy = policy;
292,756✔
467
  pTrans->conflict = conflict;
292,756✔
468
  pTrans->exec = exec;
292,756✔
469
  pTrans->oper = oper;
292,756✔
470
  SDB_GET_INT16(pRaw, dataPos, &pTrans->originRpcType, _OVER)
292,756!
471
  SDB_GET_INT64(pRaw, dataPos, &pTrans->createdTime, _OVER)
292,756!
472
  SDB_GET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_TABLE_FNAME_LEN, _OVER)
292,756!
473
  SDB_GET_BINARY(pRaw, dataPos, pTrans->stbname, TSDB_TABLE_FNAME_LEN, _OVER)
292,756!
474
  SDB_GET_INT32(pRaw, dataPos, &pTrans->actionPos, _OVER)
292,756!
475

476
  if (sver > TRANS_VER1_NUMBER) {
292,756!
477
    SDB_GET_INT32(pRaw, dataPos, &prepareActionNum, _OVER)
292,756!
478
  }
479
  SDB_GET_INT32(pRaw, dataPos, &redoActionNum, _OVER)
292,756!
480
  SDB_GET_INT32(pRaw, dataPos, &undoActionNum, _OVER)
292,756!
481
  SDB_GET_INT32(pRaw, dataPos, &commitActionNum, _OVER)
292,756!
482

483
  pTrans->prepareActions = taosArrayInit(prepareActionNum, sizeof(STransAction));
292,756✔
484
  pTrans->redoActions = taosArrayInit(redoActionNum, sizeof(STransAction));
292,756✔
485
  pTrans->undoActions = taosArrayInit(undoActionNum, sizeof(STransAction));
292,756✔
486
  pTrans->commitActions = taosArrayInit(commitActionNum, sizeof(STransAction));
292,756✔
487
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL) {
292,756✔
488
    pTrans->redoGroupActions = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
3,275✔
489
    pTrans->groupActionPos = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
3,275✔
490
  }
491

492
  if (pTrans->prepareActions == NULL) goto _OVER;
292,756!
493
  if (pTrans->redoActions == NULL) goto _OVER;
292,756!
494
  if (pTrans->undoActions == NULL) goto _OVER;
292,756!
495
  if (pTrans->commitActions == NULL) goto _OVER;
292,756!
496

497
  if (mndTransDecodeAction(pRaw, &dataPos, pTrans->prepareActions, prepareActionNum, sver) < 0) goto _OVER;
292,756!
498
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL) {
292,756✔
499
    if (mndTransDecodeActionWithGroup(pRaw, &dataPos, pTrans->redoActions, redoActionNum, pTrans->redoGroupActions,
3,275!
500
                                      sver) < 0)
501
      goto _OVER;
×
502
  } else {
503
    if (mndTransDecodeAction(pRaw, &dataPos, pTrans->redoActions, redoActionNum, sver) < 0) goto _OVER;
289,481!
504
  }
505
  if (mndTransDecodeAction(pRaw, &dataPos, pTrans->undoActions, undoActionNum, sver) < 0) goto _OVER;
292,756!
506
  if (mndTransDecodeAction(pRaw, &dataPos, pTrans->commitActions, commitActionNum, sver) < 0) goto _OVER;
292,756!
507

508
  SDB_GET_INT32(pRaw, dataPos, &pTrans->startFunc, _OVER)
292,756!
509
  SDB_GET_INT32(pRaw, dataPos, &pTrans->stopFunc, _OVER)
292,756!
510
  SDB_GET_INT32(pRaw, dataPos, &pTrans->paramLen, _OVER)
292,756!
511
  if (pTrans->paramLen != 0) {
292,756!
512
    pTrans->param = taosMemoryMalloc(pTrans->paramLen);
×
513
    if (pTrans->param == NULL) goto _OVER;
×
514
    SDB_GET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, _OVER);
×
515
  }
516

517
  SDB_GET_BINARY(pRaw, dataPos, pTrans->opername, TSDB_TRANS_OPER_LEN, _OVER);
292,756!
518

519
  SDB_GET_INT32(pRaw, dataPos, &arbgroupIdNum, _OVER)
292,756!
520
  if (arbgroupIdNum > 0) {
292,756✔
521
    pTrans->arbGroupIds = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
150✔
522
    if (pTrans->arbGroupIds == NULL) goto _OVER;
150!
523
    for (int32_t i = 0; i < arbgroupIdNum; ++i) {
310✔
524
      int32_t arbGroupId = 0;
160✔
525
      SDB_GET_INT32(pRaw, dataPos, &arbGroupId, _OVER)
160!
526
      if ((terrno = taosHashPut(pTrans->arbGroupIds, &arbGroupId, sizeof(int32_t), NULL, 0)) != 0) goto _OVER;
160!
527
    }
528
  }
529

530
  int8_t ableKill = 0;
292,756✔
531
  int32_t killMode = 0;
292,756✔
532
  if (sver > TRANS_VER1_NUMBER) {
292,756!
533
    SDB_GET_INT8(pRaw, dataPos, &ableKill, _OVER)
292,756!
534
    SDB_GET_INT32(pRaw, dataPos, &killMode, _OVER)
292,756!
535
  }
536
  pTrans->ableToBeKilled = ableKill;
292,756✔
537
  pTrans->killMode = (int8_t)killMode;
292,756✔
538

539
  if (sver > TRANS_VER2_NUMBER) {
292,756!
540
    int32_t groupNum = -1;
292,756✔
541
    SDB_GET_INT32(pRaw, dataPos, &groupNum, _OVER)
292,756!
542
    for (int32_t i = 0; i < groupNum; ++i) {
302,508✔
543
      int32_t groupId = -1;
9,752✔
544
      int32_t groupPos = -1;
9,752✔
545
      SDB_GET_INT32(pRaw, dataPos, &groupId, _OVER)
9,752!
546
      SDB_GET_INT32(pRaw, dataPos, &groupPos, _OVER)
9,752!
547
      if ((terrno = taosHashPut(pTrans->groupActionPos, &groupId, sizeof(int32_t), &groupPos, sizeof(int32_t))) != 0)
9,752!
548
        goto _OVER;
×
549
    }
550
  }
551

552
  SDB_GET_RESERVE(pRaw, dataPos, TRANS_RESERVE_SIZE, _OVER)
292,756!
553

554
  terrno = 0;
292,756✔
555

556
_OVER:
292,756✔
557
  if (terrno != 0 && pTrans != NULL) {
292,756!
558
    mError("trans:%d, failed to parse from raw:%p at line:%d dataPos:%d dataLen:%d since %s", pTrans->id, pRaw, lino,
×
559
           dataPos, pRaw->dataLen, terrstr());
560
    mndTransDropData(pTrans);
×
561
    taosMemoryFreeClear(pRow);
×
562
    return NULL;
×
563
  }
564

565
  if (pTrans != NULL) {
292,756!
566
    mTrace("trans:%d, decode from raw:%p, row:%p", pTrans->id, pRaw, pTrans);
292,756✔
567
  }
568
  return pRow;
292,756✔
569
}
570

571
static const char *mndTransStr(ETrnStage stage) {
2,065,234✔
572
  switch (stage) {
2,065,234!
573
    case TRN_STAGE_PREPARE:
156,662✔
574
      return "prepare";
156,662✔
575
    case TRN_STAGE_REDO_ACTION:
687,044✔
576
      return "redoAction";
687,044✔
577
    case TRN_STAGE_ROLLBACK:
10✔
578
      return "rollback";
10✔
579
    case TRN_STAGE_UNDO_ACTION:
40,841✔
580
      return "undoAction";
40,841✔
581
    case TRN_STAGE_COMMIT:
249,780✔
582
      return "commit";
249,780✔
583
    case TRN_STAGE_COMMIT_ACTION:
556,643✔
584
      return "commitAction";
556,643✔
585
    case TRN_STAGE_FINISH:
374,244✔
586
      return "finished";
374,244✔
587
    case TRN_STAGE_PRE_FINISH:
10✔
588
      return "pre-finish";
10✔
589
    default:
×
590
      return "invalid";
×
591
  }
592
}
593

594
static const char *mndTransTypeStr(ETrnAct actionType) {
×
595
  switch (actionType) {
×
596
    case TRANS_ACTION_MSG:
×
597
      return "msg";
×
598
    case TRANS_ACTION_RAW:
×
599
      return "sdb";
×
600
    default:
×
601
      return "invalid";
×
602
  }
603
}
604

605
static void mndSetTransLastAction(STrans *pTrans, STransAction *pAction) {
596,328✔
606
  if (pAction != NULL) {
596,328✔
607
    if (pAction->errCode != TSDB_CODE_ACTION_IN_PROGRESS) {
470,707✔
608
      pTrans->lastAction = pAction->id;
348,615✔
609
      pTrans->lastMsgType = pAction->msgType;
348,615✔
610
      pTrans->lastEpset = pAction->epSet;
348,615✔
611
      pTrans->lastErrorNo = pAction->errCode;
348,615✔
612
    }
613
  } else {
614
    pTrans->lastAction = 0;
125,621✔
615
    pTrans->lastMsgType = 0;
125,621✔
616
    memset(&pTrans->lastEpset, 0, sizeof(pTrans->lastEpset));
125,621✔
617
    pTrans->lastErrorNo = 0;
125,621✔
618
  }
619
}
596,328✔
620

621
static void mndTransTestStartFunc(SMnode *pMnode, void *param, int32_t paramLen) {
×
622
  mInfo("test trans start, param:%s, len:%d", (char *)param, paramLen);
×
623
}
×
624

625
static void mndTransTestStopFunc(SMnode *pMnode, void *param, int32_t paramLen) {
×
626
  mInfo("test trans stop, param:%s, len:%d", (char *)param, paramLen);
×
627
}
×
628

629
static TransCbFp mndTransGetCbFp(ETrnFunc ftype) {
1,508✔
630
  switch (ftype) {
1,508!
631
    case TRANS_START_FUNC_TEST:
×
632
      return mndTransTestStartFunc;
×
633
    case TRANS_STOP_FUNC_TEST:
×
634
      return mndTransTestStopFunc;
×
635
    case TRANS_START_FUNC_MQ_REB:
754✔
636
      return mndRebCntInc;
754✔
637
    case TRANS_STOP_FUNC_MQ_REB:
754✔
638
      return mndRebCntDec;
754✔
639
    default:
×
640
      return NULL;
×
641
  }
642
}
643

644
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
55,581✔
645
  mInfo("trans:%d, perform insert action, row:%p stage:%s, callfunc:1, startFunc:%d", pTrans->id, pTrans,
55,581!
646
        mndTransStr(pTrans->stage), pTrans->startFunc);
647

648
  (void)taosThreadMutexInit(&pTrans->mutex, NULL);
55,581✔
649

650
  if (pTrans->startFunc > 0) {
55,581✔
651
    TransCbFp fp = mndTransGetCbFp(pTrans->startFunc);
754✔
652
    if (fp) {
754!
653
      (*fp)(pSdb->pMnode, pTrans->param, pTrans->paramLen);
754✔
654
    }
655
    // pTrans->startFunc = 0;
656
  }
657

658
  if (pTrans->stage == TRN_STAGE_COMMIT) {
55,581✔
659
    pTrans->stage = TRN_STAGE_COMMIT_ACTION;
2✔
660
    mInfo("trans:%d, stage from commit to commitAction since perform update action", pTrans->id);
2!
661
  }
662

663
  if (pTrans->stage == TRN_STAGE_ROLLBACK) {
55,581!
664
    pTrans->stage = TRN_STAGE_UNDO_ACTION;
×
665
    mInfo("trans:%d, stage from rollback to undoAction since perform update action", pTrans->id);
×
666
  }
667

668
  if (pTrans->stage == TRN_STAGE_PRE_FINISH) {
55,581!
669
    pTrans->stage = TRN_STAGE_FINISH;
×
670
    mInfo("trans:%d, stage from pre-finish to finished since perform update action", pTrans->id);
×
671
  }
672

673
  return 0;
55,581✔
674
}
675

676
void mndTransDropData(STrans *pTrans) {
339,527✔
677
  if (pTrans->prepareActions != NULL) {
339,527!
678
    mndTransDropActions(pTrans->prepareActions);
339,527✔
679
    pTrans->prepareActions = NULL;
339,527✔
680
  }
681
  if (pTrans->redoActions != NULL) {
339,527!
682
    mndTransDropActions(pTrans->redoActions);
339,527✔
683
    pTrans->redoActions = NULL;
339,527✔
684
  }
685
  if (pTrans->undoActions != NULL) {
339,527!
686
    mndTransDropActions(pTrans->undoActions);
339,527✔
687
    pTrans->undoActions = NULL;
339,527✔
688
  }
689
  if (pTrans->commitActions != NULL) {
339,527!
690
    mndTransDropActions(pTrans->commitActions);
339,527✔
691
    pTrans->commitActions = NULL;
339,527✔
692
  }
693
  if (pTrans->redoGroupActions != NULL) {
339,527✔
694
    void *pIter = taosHashIterate(pTrans->redoGroupActions, NULL);
50,046✔
695
    while (pIter) {
60,298✔
696
      SArray **redoActions = pIter;
10,252✔
697
      taosArrayDestroy(*redoActions);
10,252✔
698
      pIter = taosHashIterate(pTrans->redoGroupActions, pIter);
10,252✔
699
    }
700

701
    taosHashCleanup(pTrans->redoGroupActions);
50,046✔
702
    pTrans->redoGroupActions = NULL;
50,046✔
703
  }
704
  if (pTrans->groupActionPos != NULL) {
339,527✔
705
    taosHashCleanup(pTrans->groupActionPos);
50,046✔
706
    pTrans->groupActionPos = NULL;
50,046✔
707
  }
708
  if (pTrans->arbGroupIds != NULL) {
339,527✔
709
    taosHashCleanup(pTrans->arbGroupIds);
46,921✔
710
  }
711
  if (pTrans->pRpcArray != NULL) {
339,527✔
712
    taosArrayDestroy(pTrans->pRpcArray);
46,771✔
713
    pTrans->pRpcArray = NULL;
46,771✔
714
  }
715
  if (pTrans->rpcRsp != NULL) {
339,527✔
716
    taosMemoryFree(pTrans->rpcRsp);
17,515!
717
    pTrans->rpcRsp = NULL;
17,515✔
718
    pTrans->rpcRspLen = 0;
17,515✔
719
  }
720
  if (pTrans->param != NULL) {
339,527!
721
    taosMemoryFree(pTrans->param);
×
722
    pTrans->param = NULL;
×
723
    pTrans->paramLen = 0;
×
724
  }
725
  (void)taosThreadMutexDestroy(&pTrans->mutex);
339,527✔
726
}
339,527✔
727

728
static int32_t mndTransDelete(SSdb *pSdb, STrans *pTrans, bool callFunc) {
174,154✔
729
  mInfo("trans:%d, perform delete action, row:%p stage:%s callfunc:%d, stopFunc:%d", pTrans->id, pTrans,
174,154!
730
        mndTransStr(pTrans->stage), callFunc, pTrans->stopFunc);
731

732
  if (pTrans->stopFunc > 0 && callFunc) {
174,154✔
733
    TransCbFp fp = mndTransGetCbFp(pTrans->stopFunc);
754✔
734
    if (fp) {
754!
735
      (*fp)(pSdb->pMnode, pTrans->param, pTrans->paramLen);
754✔
736
    }
737
    // pTrans->stopFunc = 0;
738
  }
739

740
  mndTransDropData(pTrans);
174,154✔
741
  return 0;
174,154✔
742
}
743

744
static void mndTransUpdateActions(SArray *pOldArray, SArray *pNewArray) {
252,472✔
745
  for (int32_t i = 0; i < taosArrayGetSize(pOldArray); ++i) {
783,670✔
746
    STransAction *pOldAction = taosArrayGet(pOldArray, i);
531,198✔
747
    STransAction *pNewAction = taosArrayGet(pNewArray, i);
531,198✔
748
    pOldAction->rawWritten = pNewAction->rawWritten;
531,198✔
749
    pOldAction->msgSent = pNewAction->msgSent;
531,198✔
750
    pOldAction->msgReceived = pNewAction->msgReceived;
531,198✔
751
    pOldAction->errCode = pNewAction->errCode;
531,198✔
752
  }
753
}
252,472✔
754

755
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
63,118✔
756
  mInfo("trans:%d, perform update action, old row:%p stage:%s create:%" PRId64 ", new row:%p stage:%s create:%" PRId64,
63,118!
757
        pOld->id, pOld, mndTransStr(pOld->stage), pOld->createdTime, pNew, mndTransStr(pNew->stage), pNew->createdTime);
758

759
  if (pOld->createdTime != pNew->createdTime) {
63,118!
760
    mError("trans:%d, failed to perform update action since createTime not match, old row:%p stage:%s create:%" PRId64
×
761
           ", new row:%p stage:%s create:%" PRId64,
762
           pOld->id, pOld, mndTransStr(pOld->stage), pOld->createdTime, pNew, mndTransStr(pNew->stage),
763
           pNew->createdTime);
764
    // only occured while sync timeout
765
    TAOS_RETURN(TSDB_CODE_MND_TRANS_SYNC_TIMEOUT);
×
766
  }
767

768
  mndTransUpdateActions(pOld->prepareActions, pNew->prepareActions);
63,118✔
769
  mndTransUpdateActions(pOld->redoActions, pNew->redoActions);
63,118✔
770
  mndTransUpdateActions(pOld->undoActions, pNew->undoActions);
63,118✔
771
  mndTransUpdateActions(pOld->commitActions, pNew->commitActions);
63,118✔
772
  pOld->stage = pNew->stage;
63,118✔
773
  pOld->actionPos = pNew->actionPos;
63,118✔
774

775
  void *pIter = taosHashIterate(pNew->groupActionPos, NULL);
63,118✔
776
  while (pIter != NULL) {
67,219✔
777
    int32_t newActionPos = *(int32_t *)pIter;
4,101✔
778

779
    size_t   keylen = 0;
4,101✔
780
    int32_t *groupId = taosHashGetKey(pIter, &keylen);
4,101✔
781

782
    int32_t *oldActionPos = taosHashGet(pOld->groupActionPos, groupId, sizeof(int32_t));
4,101✔
783
    if (oldActionPos != NULL) {
4,101!
784
      *oldActionPos = newActionPos;
4,101✔
785
    } else
786
      taosHashPut(pOld->groupActionPos, groupId, sizeof(int32_t), &newActionPos, sizeof(int32_t));
×
787

788
    pIter = taosHashIterate(pNew->groupActionPos, pIter);
4,101✔
789
  }
790

791
  if (pOld->stage == TRN_STAGE_COMMIT) {
63,118✔
792
    pOld->stage = TRN_STAGE_COMMIT_ACTION;
55,451✔
793
    mInfo("trans:%d, stage from commit to commitAction since perform update action", pNew->id);
55,451!
794
  }
795

796
  if (pOld->stage == TRN_STAGE_ROLLBACK) {
63,118✔
797
    pOld->stage = TRN_STAGE_UNDO_ACTION;
2✔
798
    mInfo("trans:%d, stage from rollback to undoAction since perform update action", pNew->id);
2!
799
  }
800

801
  if (pOld->stage == TRN_STAGE_PRE_FINISH) {
63,118✔
802
    pOld->stage = TRN_STAGE_FINISH;
2✔
803
    mInfo("trans:%d, stage from pre-finish to finished since perform update action", pNew->id);
2!
804
  }
805

806
  return 0;
63,118✔
807
}
808

809
STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
226,364✔
810
  STrans *pTrans = sdbAcquire(pMnode->pSdb, SDB_TRANS, &transId);
226,364✔
811
  if (pTrans == NULL) {
226,364!
812
    terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
×
813
  }
814
  return pTrans;
226,364✔
815
}
816

817
void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
226,365✔
818
  SSdb *pSdb = pMnode->pSdb;
226,365✔
819
  if (pTrans != NULL) mInfo("vgId:1, trans:%d, release transaction", pTrans->id);
226,365!
820
  sdbRelease(pSdb, pTrans);
226,365✔
821
}
226,365✔
822

823
STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict, const SRpcMsg *pReq,
46,771✔
824
                       const char *opername) {
825
  STrans *pTrans = taosMemoryCalloc(1, sizeof(STrans));
46,771!
826
  if (pTrans == NULL) {
46,771!
827
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
828
    mError("failed to create transaction since %s", terrstr());
×
829
    return NULL;
×
830
  }
831

832
  if (opername != NULL) {
46,771!
833
    tstrncpy(pTrans->opername, opername, TSDB_TRANS_OPER_LEN);
46,771✔
834
  }
835

836
  int32_t sdbMaxId = sdbGetMaxId(pMnode->pSdb, SDB_TRANS);
46,771✔
837
  sdbReadLock(pMnode->pSdb, SDB_TRANS);
46,771✔
838
  pTrans->id = TMAX(sdbMaxId, tsMaxTransId + 1);
46,771✔
839
  sdbUnLock(pMnode->pSdb, SDB_TRANS);
46,771✔
840
  pTrans->stage = TRN_STAGE_PREPARE;
46,771✔
841
  pTrans->policy = policy;
46,771✔
842
  pTrans->conflict = conflict;
46,771✔
843
  pTrans->exec = TRN_EXEC_PARALLEL;
46,771✔
844
  pTrans->ableToBeKilled = false;
46,771✔
845
  pTrans->createdTime = taosGetTimestampMs();
46,771✔
846
  pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
46,771✔
847
  pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
46,771✔
848
  pTrans->undoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
46,771✔
849
  pTrans->commitActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
46,771✔
850
  pTrans->redoGroupActions = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
46,771✔
851
  pTrans->groupActionPos = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
46,771✔
852
  pTrans->arbGroupIds = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
46,771✔
853
  pTrans->pRpcArray = taosArrayInit(1, sizeof(SRpcHandleInfo));
46,771✔
854
  pTrans->mTraceId = pReq ? TRACE_GET_ROOTID(&pReq->info.traceId) : tGenIdPI64();
46,771✔
855
  taosInitRWLatch(&pTrans->lockRpcArray);
46,771✔
856
  (void)taosThreadMutexInit(&pTrans->mutex, NULL);
46,771✔
857

858
  if (pTrans->redoActions == NULL || pTrans->undoActions == NULL || pTrans->commitActions == NULL ||
46,771!
859
      pTrans->pRpcArray == NULL) {
46,771!
860
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
861
    mError("failed to create transaction since %s", terrstr());
×
862
    mndTransDrop(pTrans);
×
863
    return NULL;
×
864
  }
865

866
  if (pReq != NULL) {
46,771✔
867
    if (taosArrayPush(pTrans->pRpcArray, &pReq->info) == NULL) {
62,812!
868
      terrno = TSDB_CODE_OUT_OF_MEMORY;
×
869
      return NULL;
×
870
    }
871
    pTrans->originRpcType = pReq->msgType;
31,406✔
872
  }
873

874
  mInfo("trans:%d, create transaction:%s, origin:%s", pTrans->id, pTrans->opername, opername);
46,771!
875

876
  mTrace("trans:%d, local object is created, data:%p", pTrans->id, pTrans);
46,771✔
877
  return pTrans;
46,771✔
878
}
879

880
static void mndTransDropActions(SArray *pArray) {
1,358,108✔
881
  int32_t size = taosArrayGetSize(pArray);
1,358,108✔
882
  for (int32_t i = 0; i < size; ++i) {
3,936,215✔
883
    STransAction *pAction = taosArrayGet(pArray, i);
2,578,107✔
884
    if (pAction->actionType == TRANS_ACTION_RAW) {
2,578,107✔
885
      taosMemoryFreeClear(pAction->pRaw);
1,768,983!
886
    } else if (pAction->actionType == TRANS_ACTION_MSG) {
809,124!
887
      taosMemoryFreeClear(pAction->pCont);
809,124!
888
    } else {
889
      // nothing
890
    }
891
  }
892

893
  taosArrayDestroy(pArray);
1,358,108✔
894
}
1,358,108✔
895

896
void mndTransDrop(STrans *pTrans) {
47,084✔
897
  if (pTrans != NULL) {
47,084✔
898
    mndTransDropData(pTrans);
46,771✔
899
    mTrace("trans:%d, local object is freed, data:%p", pTrans->id, pTrans);
46,771✔
900
    taosMemoryFreeClear(pTrans);
46,771!
901
  }
902
}
47,084✔
903

904
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) {
339,646✔
905
  pAction->id = taosArrayGetSize(pArray);
339,646✔
906

907
  void *ptr = taosArrayPush(pArray, pAction);
339,646✔
908
  if (ptr == NULL) {
339,646!
909
    TAOS_RETURN(terrno);
×
910
  }
911

912
  return 0;
339,646✔
913
}
914

915
static int32_t mndTransAddActionToGroup(STrans *pTrans, STransAction *pAction) {
17,069✔
916
  if (pTrans->exec != TRN_EXEC_GROUP_PARALLEL) return 0;
17,069✔
917

918
  SArray **redoAction = taosHashGet(pTrans->redoGroupActions, &pAction->groupId, sizeof(int32_t));
1,061✔
919
  if (redoAction == NULL) {
1,061✔
920
    SArray *array = taosArrayInit(4, sizeof(STransAction *));
500✔
921
    if (array != NULL) {
500!
922
      if (taosHashPut(pTrans->redoGroupActions, &pAction->groupId, sizeof(int32_t), &array, sizeof(SArray *)) < 0) {
500!
923
        mInfo("failed put action into redo group actions");
×
924
        return TSDB_CODE_INTERNAL_ERROR;
×
925
      }
926
      redoAction = taosHashGet(pTrans->redoGroupActions, &pAction->groupId, sizeof(int32_t));
500✔
927
    }
928
  }
929
  if (redoAction != NULL) {
1,061!
930
    mInfo("trans:%d, append action into group %d, msgType:%s", pTrans->id, pAction->groupId,
1,061!
931
          TMSG_INFO(pAction->msgType));
932
    void *ptr = taosArrayPush(*redoAction, &pAction);
1,061✔
933
    if (ptr == NULL) {
1,061!
934
      TAOS_RETURN(terrno);
×
935
    }
936
  }
937

938
  int32_t *actionPos = taosHashGet(pTrans->groupActionPos, &pAction->groupId, sizeof(int32_t));
1,061✔
939
  if (actionPos == NULL) {
1,061✔
940
    int32_t pos = 0;
500✔
941
    if (taosHashPut(pTrans->groupActionPos, &pAction->groupId, sizeof(int32_t), &pos, sizeof(int32_t)) < 0) {
500!
942
      mInfo("failed put action into group action pos");
×
943
      return TSDB_CODE_INTERNAL_ERROR;
×
944
    }
945
  }
946

947
  return 0;
1,061✔
948
}
949

950
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
1,299✔
951
  STransAction action = {
1,299✔
952
      .stage = TRN_STAGE_REDO_ACTION, .actionType = TRANS_ACTION_RAW, .pRaw = pRaw, .mTraceId = pTrans->mTraceId};
1,299✔
953
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && action.groupId == 0) return TSDB_CODE_INTERNAL_ERROR;
1,299!
954
  return mndTransAppendAction(pTrans->redoActions, &action);
1,299✔
955
}
956

957
int32_t mndTransAppendGroupRedolog(STrans *pTrans, SSdbRaw *pRaw, int32_t groupId) {
974✔
958
  STransAction action = {.stage = TRN_STAGE_REDO_ACTION,
974✔
959
                         .actionType = TRANS_ACTION_RAW,
960
                         .pRaw = pRaw,
961
                         .mTraceId = pTrans->mTraceId,
974✔
962
                         .groupId = groupId};
963
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && action.groupId == 0) {
974!
964
    mError("trans:%d, groupid cannot be 0 in TRN_EXEC_GROUP_PARALLEL", pTrans->id);
×
965
    return TSDB_CODE_INTERNAL_ERROR;
×
966
  }
967
  if (groupId > 0) TAOS_CHECK_RETURN(mndTransAddActionToGroup(pTrans, &action));
974!
968
  return mndTransAppendAction(pTrans->redoActions, &action);
974✔
969
}
970

971
int32_t mndTransAppendNullLog(STrans *pTrans) {
×
972
  STransAction action = {.stage = TRN_STAGE_REDO_ACTION, .actionType = TRANS_ACTION_NULL};
×
973
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && action.groupId == 0) {
×
974
    mError("trans:%d, groupid cannot be 0 in TRN_EXEC_GROUP_PARALLEL", pTrans->id);
×
975
    return TSDB_CODE_INTERNAL_ERROR;
×
976
  }
977
  return mndTransAppendAction(pTrans->redoActions, &action);
×
978
}
979

980
int32_t mndTransAppendGroupNullLog(STrans *pTrans, int32_t groupId) {
×
981
  STransAction action = {.stage = TRN_STAGE_REDO_ACTION, .actionType = TRANS_ACTION_NULL, .groupId = groupId};
×
982
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && action.groupId == 0) {
×
983
    mError("trans:%d, groupid cannot be 0 in TRN_EXEC_GROUP_PARALLEL", pTrans->id);
×
984
    return TSDB_CODE_INTERNAL_ERROR;
×
985
  }
986
  if (groupId > 0) TAOS_CHECK_RETURN(mndTransAddActionToGroup(pTrans, &action));
×
987
  return mndTransAppendAction(pTrans->redoActions, &action);
×
988
}
989

990
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
13,508✔
991
  STransAction action = {.stage = TRN_STAGE_UNDO_ACTION, .actionType = TRANS_ACTION_RAW, .pRaw = pRaw};
13,508✔
992
  return mndTransAppendAction(pTrans->undoActions, &action);
13,508✔
993
}
994

995
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
216,991✔
996
  STransAction action = {.stage = TRN_STAGE_COMMIT_ACTION, .actionType = TRANS_ACTION_RAW, .pRaw = pRaw};
216,991✔
997
  return mndTransAppendAction(pTrans->commitActions, &action);
216,991✔
998
}
999

1000
int32_t mndTransAppendPrepareLog(STrans *pTrans, SSdbRaw *pRaw) {
24,919✔
1001
  STransAction action = {
24,919✔
1002
      .pRaw = pRaw, .stage = TRN_STAGE_PREPARE, .actionType = TRANS_ACTION_RAW, .mTraceId = pTrans->mTraceId};
24,919✔
1003
  return mndTransAppendAction(pTrans->prepareActions, &action);
24,919✔
1004
}
1005

1006
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction) {
54,711✔
1007
  pAction->stage = TRN_STAGE_REDO_ACTION;
54,711✔
1008
  pAction->actionType = TRANS_ACTION_MSG;
54,711✔
1009
  pAction->mTraceId = pTrans->mTraceId;
54,711✔
1010
  if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && pAction->groupId == 0) {
54,711✔
1011
    mError("trans:%d, groupid cannot be 0 in TRN_EXEC_GROUP_PARALLEL", pTrans->id);
3!
1012
    return TSDB_CODE_INTERNAL_ERROR;
3✔
1013
  }
1014
  if (pAction->groupId > 0) TAOS_CHECK_RETURN(mndTransAddActionToGroup(pTrans, pAction));
54,708!
1015
  return mndTransAppendAction(pTrans->redoActions, pAction);
54,708✔
1016
}
1017

1018
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction) {
27,247✔
1019
  pAction->stage = TRN_STAGE_UNDO_ACTION;
27,247✔
1020
  pAction->actionType = TRANS_ACTION_MSG;
27,247✔
1021
  return mndTransAppendAction(pTrans->undoActions, pAction);
27,247✔
1022
}
1023

1024
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen) {
17,515✔
1025
  pTrans->rpcRsp = pCont;
17,515✔
1026
  pTrans->rpcRspLen = contLen;
17,515✔
1027
}
17,515✔
1028

1029
void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, void *param, int32_t paramLen) {
742✔
1030
  pTrans->startFunc = startFunc;
742✔
1031
  pTrans->stopFunc = stopFunc;
742✔
1032
  pTrans->param = param;
742✔
1033
  pTrans->paramLen = paramLen;
742✔
1034
}
742✔
1035

1036
int32_t mndSetRpcInfoForDbTrans(SMnode *pMnode, SRpcMsg *pMsg, EOperType oper, const char *dbname) {
×
1037
  STrans *pTrans = NULL;
×
1038
  void   *pIter = NULL;
×
1039
  int32_t code = -1;
×
1040

1041
  while (1) {
1042
    pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
×
1043
    if (pIter == NULL) break;
×
1044

1045
    if (pTrans->oper == oper) {
×
1046
      if (taosStrcasecmp(dbname, pTrans->dbname) == 0) {
×
1047
        mInfo("trans:%d, db:%s oper:%d matched with input", pTrans->id, dbname, oper);
×
1048
        taosWLockLatch(&pTrans->lockRpcArray);
×
1049
        if (pTrans->pRpcArray == NULL) {
×
1050
          pTrans->pRpcArray = taosArrayInit(4, sizeof(SRpcHandleInfo));
×
1051
        }
1052
        if (pTrans->pRpcArray != NULL && taosArrayPush(pTrans->pRpcArray, &pMsg->info) != NULL) {
×
1053
          code = 0;
×
1054
        }
1055
        taosWUnLockLatch(&pTrans->lockRpcArray);
×
1056

1057
        sdbRelease(pMnode->pSdb, pTrans);
×
1058
        break;
×
1059
      }
1060
    }
1061

1062
    sdbRelease(pMnode->pSdb, pTrans);
×
1063
  }
1064
  return code;
×
1065
}
1066

1067
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname) {
25,969✔
1068
  if (dbname != NULL) {
25,969!
1069
    tstrncpy(pTrans->dbname, dbname, TSDB_DB_FNAME_LEN);
25,969✔
1070
  }
1071
  if (stbname != NULL) {
25,969✔
1072
    tstrncpy(pTrans->stbname, stbname, TSDB_TABLE_FNAME_LEN);
18,857✔
1073
  }
1074
}
25,969✔
1075

1076
void mndTransAddArbGroupId(STrans *pTrans, int32_t groupId) {
75✔
1077
  if (taosHashPut(pTrans->arbGroupIds, &groupId, sizeof(int32_t), NULL, 0) != 0) {
75!
1078
    mError("trans:%d, failed to put groupid into hash, groupId:%d", pTrans->id, groupId);
×
1079
  }
1080
}
75✔
1081

1082
void mndTransSetSerial(STrans *pTrans) {
1,274✔
1083
  mInfo("trans:%d, set Serial", pTrans->id);
1,274!
1084
  pTrans->exec = TRN_EXEC_SERIAL;
1,274✔
1085
}
1,274✔
1086

1087
void mndTransSetGroupParallel(STrans *pTrans) {
202✔
1088
  mInfo("trans:%d, set Group Parallel", pTrans->id);
202!
1089
  pTrans->exec = TRN_EXEC_GROUP_PARALLEL;
202✔
1090
}
202✔
1091

1092
void mndTransSetParallel(STrans *pTrans) {
×
1093
  mInfo("trans:%d, set Parallel", pTrans->id);
×
1094
  pTrans->exec = TRN_EXEC_PARALLEL;
×
1095
}
×
1096

1097
void mndTransSetBeKilled(STrans *pTrans, bool ableToBeKilled) { pTrans->ableToBeKilled = ableToBeKilled; }
×
1098

1099
void mndTransSetKillMode(STrans *pTrans, ETrnKillMode killMode) {
29✔
1100
  pTrans->ableToBeKilled = true; 
29✔
1101
  pTrans->killMode = killMode; 
29✔
1102
}
29✔
1103

1104
void mndTransSetChangeless(STrans *pTrans) { pTrans->changeless = true; }
39✔
1105

1106
void mndTransSetOper(STrans *pTrans, EOperType oper) { pTrans->oper = oper; }
4,056✔
1107

1108
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
99,473✔
1109
  int32_t  code = 0;
99,473✔
1110
  SSdbRaw *pRaw = mndTransEncode(pTrans);
99,473✔
1111
  if (pRaw == NULL) {
99,473!
1112
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1113
    if (terrno != 0) code = terrno;
×
1114
    mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, tstrerror(code));
×
1115
    TAOS_RETURN(code);
×
1116
  }
1117
  TAOS_CHECK_RETURN(sdbSetRawStatus(pRaw, SDB_STATUS_READY));
99,473!
1118

1119
  mInfo("trans:%d, sync to other mnodes, stage:%s createTime:%" PRId64, pTrans->id, mndTransStr(pTrans->stage),
99,473!
1120
        pTrans->createdTime);
1121
  code = mndSyncPropose(pMnode, pRaw, pTrans->id);
99,473✔
1122
  if (code != 0) {
99,473✔
1123
    mError("trans:%d, failed to sync, errno:%s code:0x%x createTime:%" PRId64 " saved trans:%d", pTrans->id,
6!
1124
           tstrerror(code), code, pTrans->createdTime, pMnode->syncMgmt.transId);
1125
    sdbFreeRaw(pRaw);
6✔
1126
    TAOS_RETURN(code);
6✔
1127
  }
1128

1129
  sdbFreeRaw(pRaw);
99,467✔
1130
  mInfo("trans:%d, sync to other mnodes finished, createTime:%" PRId64, pTrans->id, pTrans->createdTime);
99,467!
1131
  TAOS_RETURN(code);
99,467✔
1132
}
1133

1134
static bool mndCheckDbConflict(const char *conflict, STrans *pTrans) {
1,398✔
1135
  if (conflict[0] == 0) return false;
1,398!
1136
  if (taosStrcasecmp(conflict, pTrans->dbname) == 0) return true;
1,398✔
1137
  return false;
1,193✔
1138
}
1139

1140
static bool mndCheckStbConflict(const char *conflict, STrans *pTrans) {
17,752✔
1141
  if (conflict[0] == 0) return false;
17,752✔
1142
  if (taosStrcasecmp(conflict, pTrans->stbname) == 0) return true;
16,616✔
1143
  return false;
16,501✔
1144
}
1145

1146
static void mndTransLogConflict(STrans *pNew, STrans *pTrans, bool conflict, bool *globalConflict) {
19,150✔
1147
  if (conflict) {
19,150✔
1148
    mError("trans:%d, opername:%s db:%s stb:%s type:%d, can't execute since conflict with trans:%d, opername:%s db:%s "
320!
1149
      "stb:%s type:%d", 
1150
      pNew->id, pNew->opername, pNew->dbname, pNew->stbname, pNew->conflict, pTrans->id, pTrans->opername, 
1151
      pTrans->dbname, pTrans->stbname, pTrans->conflict);
1152
    *globalConflict = true;
320✔
1153
  } else {
1154
    mInfo("trans:%d, opername:%s db:%s stb:%s type:%d, not conflict with trans:%d, opername:%s db:%s stb:%s type:%d", 
18,830!
1155
      pNew->id, pNew->opername, pNew->dbname, pNew->stbname, pNew->conflict, pTrans->id, pTrans->opername, 
1156
      pTrans->dbname, pTrans->stbname, pTrans->conflict);
1157
  }
1158
}
19,150✔
1159

1160
static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) {
128,326✔
1161
  STrans *pTrans = NULL;
128,326✔
1162
  void   *pIter = NULL;
128,326✔
1163
  bool    conflict = false;
128,326✔
1164

1165
  if (pNew->conflict == TRN_CONFLICT_NOTHING) return conflict;
128,326✔
1166

1167
  int32_t size = sdbGetSize(pMnode->pSdb, SDB_TRANS);
91,164✔
1168
  mInfo("trans:%d, trans hash size %d", pNew->id, size);
91,164!
1169

1170
  while (1) {
1171
    pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
108,996✔
1172
    if (pIter == NULL) break;
108,996✔
1173

1174
    if (pNew->conflict == TRN_CONFLICT_GLOBAL) conflict = true;
17,832✔
1175

1176
    if (pNew->conflict == TRN_CONFLICT_DB) {
17,832✔
1177
      if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true;
1,139✔
1178
      if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
1,139✔
1179
        mndTransLogConflict(pNew, pTrans, mndCheckDbConflict(pNew->dbname, pTrans), &conflict);
1,136✔
1180
        mndTransLogConflict(pNew, pTrans, mndCheckStbConflict(pNew->stbname, pTrans), &conflict);
1,136✔
1181
      }
1182
    }
1183

1184
    if (pNew->conflict == TRN_CONFLICT_DB_INSIDE) {
17,832✔
1185
      if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true;
16,629✔
1186
      if (pTrans->conflict == TRN_CONFLICT_DB) {
16,629✔
1187
        mndTransLogConflict(pNew, pTrans, mndCheckDbConflict(pNew->dbname, pTrans), &conflict);
262✔
1188
        mndTransLogConflict(pNew, pTrans, mndCheckStbConflict(pNew->stbname, pTrans), &conflict);
262✔
1189
      }
1190
      if (pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
16,629✔
1191
        mndTransLogConflict(pNew, pTrans, mndCheckStbConflict(pNew->stbname, pTrans), &conflict);  // for stb
16,354✔
1192
      }
1193
    }
1194

1195
    if (pNew->conflict == TRN_CONFLICT_ARBGROUP) {
17,832✔
1196
      if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true;
43!
1197
      if (pTrans->conflict == TRN_CONFLICT_ARBGROUP) {
43!
1198
        void *pGidIter = taosHashIterate(pNew->arbGroupIds, NULL);
×
1199
        while (pGidIter != NULL) {
×
1200
          int32_t groupId = *(int32_t *)pGidIter;
×
1201
          if (taosHashGet(pTrans->arbGroupIds, &groupId, sizeof(int32_t)) != NULL) {
×
1202
            taosHashCancelIterate(pNew->arbGroupIds, pGidIter);
×
1203
            mndTransLogConflict(pNew, pTrans, true, &conflict);
×
1204
            break;
×
1205
          } else {
1206
            mndTransLogConflict(pNew, pTrans, false, &conflict);
×
1207
          }
1208
          pGidIter = taosHashIterate(pNew->arbGroupIds, pGidIter);
×
1209
        }
1210
      }
1211
    }
1212

1213
    if (pNew->conflict == TRN_CONFLICT_TSMA) {
17,832!
1214
      if (pTrans->conflict == TRN_CONFLICT_GLOBAL || pTrans->conflict == TRN_CONFLICT_TSMA) {
×
1215
        mndTransLogConflict(pNew, pTrans, true, &conflict);
×
1216
      } else {
1217
        mndTransLogConflict(pNew, pTrans, false, &conflict);
×
1218
      }
1219
    }
1220

1221
    sdbRelease(pMnode->pSdb, pTrans);
17,832✔
1222
  }
1223

1224
  return conflict;
91,164✔
1225
}
1226

1227
int32_t mndTransCheckConflict(SMnode *pMnode, STrans *pTrans) {
128,326✔
1228
  int32_t code = 0;
128,326✔
1229
  if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
128,326✔
1230
    if (strlen(pTrans->dbname) == 0 && strlen(pTrans->stbname) == 0) {
82,324!
1231
      code = TSDB_CODE_MND_TRANS_CONFLICT;
×
1232
      mError("trans:%d, failed to check tran conflict since db not set", pTrans->id);
×
1233
      TAOS_RETURN(code);
×
1234
    }
1235
  }
1236

1237
  if (mndCheckTransConflict(pMnode, pTrans)) {
128,326✔
1238
    code = TSDB_CODE_MND_TRANS_CONFLICT;
398✔
1239
    mError("trans:%d, failed to check tran conflict since %s", pTrans->id, tstrerror(code));
398!
1240
    TAOS_RETURN(code);
398✔
1241
  }
1242

1243
  TAOS_RETURN(code);
127,928✔
1244
}
1245

1246
int32_t mndTransCheckConflictWithCompact(SMnode *pMnode, STrans *pTrans) {
303✔
1247
  int32_t      code = 0;
303✔
1248
  void        *pIter = NULL;
303✔
1249
  bool         conflict = false;
303✔
1250
  SCompactObj *pCompact = NULL;
303✔
1251

1252
  while (1) {
4✔
1253
    bool thisConflict = false;
307✔
1254
    pIter = sdbFetch(pMnode->pSdb, SDB_COMPACT, pIter, (void **)&pCompact);
307✔
1255
    if (pIter == NULL) break;
307✔
1256

1257
    if (pTrans->conflict == TRN_CONFLICT_GLOBAL) {
4✔
1258
      thisConflict = true;
2✔
1259
    }
1260
    if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
4!
1261
      if (taosStrcasecmp(pTrans->dbname, pCompact->dbname) == 0) thisConflict = true;
2!
1262
    }
1263

1264
    if (thisConflict) {
4!
1265
      mError("trans:%d, db:%s stb:%s type:%d, can't execute since conflict with compact:%d db:%s", pTrans->id,
4!
1266
             pTrans->dbname, pTrans->stbname, pTrans->conflict, pCompact->compactId, pCompact->dbname);
1267
      conflict = true;
4✔
1268
    } else {
1269
      mInfo("trans:%d, db:%s stb:%s type:%d, not conflict with compact:%d db:%s", pTrans->id, pTrans->dbname,
×
1270
            pTrans->stbname, pTrans->conflict, pCompact->compactId, pCompact->dbname);
1271
    }
1272
    sdbRelease(pMnode->pSdb, pCompact);
4✔
1273
  }
1274

1275
  if (conflict) {
303✔
1276
    code = TSDB_CODE_MND_TRANS_CONFLICT_COMPACT;
4✔
1277
    mError("trans:%d, failed to check tran conflict with compact since %s", pTrans->id, tstrerror(code));
4!
1278
    TAOS_RETURN(code);
4✔
1279
  }
1280

1281
  TAOS_RETURN(code);
299✔
1282
}
1283

1284
static bool mndTransActionsOfSameType(SArray *pActions) {
108,496✔
1285
  int32_t size = taosArrayGetSize(pActions);
108,496✔
1286
  ETrnAct lastActType = TRANS_ACTION_NULL;
108,496✔
1287
  bool    same = true;
108,496✔
1288
  for (int32_t i = 0; i < size; ++i) {
391,507✔
1289
    STransAction *pAction = taosArrayGet(pActions, i);
283,011✔
1290
    if (i > 0) {
283,011✔
1291
      if (lastActType != pAction->actionType) {
206,075!
1292
        same = false;
×
1293
        break;
×
1294
      }
1295
    }
1296
    lastActType = pAction->actionType;
283,011✔
1297
  }
1298
  return same;
108,496✔
1299
}
1300

1301
static int32_t mndTransCheckParallelActions(SMnode *pMnode, STrans *pTrans) {
46,294✔
1302
  int32_t code = 0;
46,294✔
1303
  if (pTrans->exec == TRN_EXEC_PARALLEL) {
46,294✔
1304
    if (mndTransActionsOfSameType(pTrans->redoActions) == false) {
44,859!
1305
      code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
×
1306
      mError("trans:%d, types of parallel redo actions are not the same", pTrans->id);
×
1307
      TAOS_RETURN(code);
×
1308
    }
1309

1310
    if (pTrans->policy == TRN_POLICY_ROLLBACK) {
44,859✔
1311
      if (mndTransActionsOfSameType(pTrans->undoActions) == false) {
17,343!
1312
        code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
×
1313
        mError("trans:%d, types of parallel undo actions are not the same", pTrans->id);
×
1314
        TAOS_RETURN(code);
×
1315
      }
1316
    }
1317
  }
1318

1319
  TAOS_RETURN(code);
46,294✔
1320
}
1321

1322
static int32_t mndTransCheckCommitActions(SMnode *pMnode, STrans *pTrans) {
46,294✔
1323
  int32_t code = 0;
46,294✔
1324
  if (!pTrans->changeless && taosArrayGetSize(pTrans->commitActions) <= 0) {
46,294!
1325
    code = TSDB_CODE_MND_TRANS_CLOG_IS_NULL;
×
1326
    mError("trans:%d, commit actions of non-changeless trans are empty", pTrans->id);
×
1327
    TAOS_RETURN(code);
×
1328
  }
1329
  if (mndTransActionsOfSameType(pTrans->commitActions) == false) {
46,294!
1330
    code = TSDB_CODE_MND_TRANS_INVALID_STAGE;
×
1331
    mError("trans:%d, types of commit actions are not the same", pTrans->id);
×
1332
    TAOS_RETURN(code);
×
1333
  }
1334

1335
  TAOS_RETURN(code);
46,294✔
1336
}
1337

1338
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
46,304✔
1339
  int32_t code = 0;
46,304✔
1340
  if (pTrans == NULL) {
46,304!
1341
    return TSDB_CODE_INVALID_PARA;
×
1342
  }
1343

1344
  mInfo("trans:%d, action list:", pTrans->id);
46,304!
1345
  int32_t index = 0;
46,304✔
1346
  for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
71,193✔
1347
    STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
24,889✔
1348
    mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index, mndTransStr(pAction->stage),
24,889!
1349
          pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1350
  }
1351

1352
  for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
102,938✔
1353
    STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
56,634✔
1354
    if (pAction->actionType == TRANS_ACTION_MSG) {
56,634✔
1355
      mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index, mndTransStr(pAction->stage), pAction->id,
54,453!
1356
            TMSG_INFO(pAction->msgType));
1357
      ;
1358
    } else {
1359
      mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index, mndTransStr(pAction->stage),
2,181!
1360
            pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1361
    }
1362
  }
1363

1364
  for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
263,116✔
1365
    STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
216,812✔
1366
    mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index, mndTransStr(pAction->stage), i,
216,812!
1367
          sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1368
  }
1369

1370
  for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
87,059✔
1371
    STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
40,755✔
1372
    if (pAction->actionType == TRANS_ACTION_MSG) {
40,755✔
1373
      mInfo("trans:%d, action:%d, %s:%d msgType:%s", pTrans->id, index, mndTransStr(pAction->stage), pAction->id,
27,247!
1374
            TMSG_INFO(pAction->msgType));
1375
      ;
1376
    } else {
1377
      mInfo("trans:%d, action:%d, %s:%d sdbType:%s, sdbStatus:%s", pTrans->id, index, mndTransStr(pAction->stage),
13,508!
1378
            pAction->id, sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1379
    }
1380
  }
1381

1382
  TAOS_CHECK_RETURN(mndTransCheckConflict(pMnode, pTrans));
46,304✔
1383

1384
  TAOS_CHECK_RETURN(mndTransCheckParallelActions(pMnode, pTrans));
46,294!
1385

1386
  TAOS_CHECK_RETURN(mndTransCheckCommitActions(pMnode, pTrans));
46,294!
1387

1388
  mInfo("trans:%d, prepare transaction", pTrans->id);
46,294!
1389
  if ((code = mndTransSync(pMnode, pTrans)) != 0) {
46,294!
1390
    mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
×
1391
    sdbWriteLock(pMnode->pSdb, SDB_TRANS);
×
1392
    tsMaxTransId = TMAX(pTrans->id, tsMaxTransId);
×
1393
    sdbUnLock(pMnode->pSdb, SDB_TRANS);
×
1394
    TAOS_RETURN(code);
×
1395
  }
1396
  mInfo("trans:%d, prepare finished", pTrans->id);
46,294!
1397

1398
  STrans *pNew = mndAcquireTrans(pMnode, pTrans->id);
46,294✔
1399
  if (pNew == NULL) {
46,294!
1400
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1401
    if (terrno != 0) code = terrno;
×
1402
    mError("trans:%d, failed to read from sdb since %s", pTrans->id, tstrerror(code));
×
1403
    TAOS_RETURN(code);
×
1404
  }
1405

1406
  pNew->pRpcArray = pTrans->pRpcArray;
46,294✔
1407
  pNew->rpcRsp = pTrans->rpcRsp;
46,294✔
1408
  pNew->rpcRspLen = pTrans->rpcRspLen;
46,294✔
1409
  pNew->mTraceId = pTrans->mTraceId;
46,294✔
1410
  pTrans->pRpcArray = NULL;
46,294✔
1411
  pTrans->rpcRsp = NULL;
46,294✔
1412
  pTrans->rpcRspLen = 0;
46,294✔
1413

1414
  mInfo("trans:%d, execute transaction in prepare", pTrans->id);
46,294!
1415
  mndTransExecute(pMnode, pNew, false);
46,294✔
1416
  mndReleaseTrans(pMnode, pNew);
46,294✔
1417
  // TDOD change to TAOS_RETURN(code);
1418
  return 0;
46,294✔
1419
}
1420

1421
static int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
46,292✔
1422
  int32_t code = 0;
46,292✔
1423
  mInfo("trans:%d, commit transaction", pTrans->id);
46,292!
1424
  if ((code = mndTransSync(pMnode, pTrans)) != 0) {
46,292✔
1425
    mError("trans:%d, failed to commit since %s", pTrans->id, tstrerror(code));
6!
1426
    TAOS_RETURN(code);
6✔
1427
  }
1428
  mInfo("trans:%d, commit finished", pTrans->id);
46,286!
1429
  TAOS_RETURN(code);
46,286✔
1430
}
1431

1432
static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
2✔
1433
  int32_t code = 0;
2✔
1434
  mInfo("trans:%d, rollback transaction", pTrans->id);
2!
1435
  if ((code = mndTransSync(pMnode, pTrans)) != 0) {
2!
1436
    mError("trans:%d, failed to rollback since %s", pTrans->id, tstrerror(code));
×
1437
    TAOS_RETURN(code);
×
1438
  }
1439
  mInfo("trans:%d, rollback finished", pTrans->id);
2!
1440
  TAOS_RETURN(code);
2✔
1441
}
1442

1443
static int32_t mndTransPreFinish(SMnode *pMnode, STrans *pTrans) {
2✔
1444
  int32_t code = 0;
2✔
1445
  mInfo("trans:%d, pre-finish transaction", pTrans->id);
2!
1446
  if ((code = mndTransSync(pMnode, pTrans)) != 0) {
2!
1447
    mError("trans:%d, failed to pre-finish since %s", pTrans->id, tstrerror(code));
×
1448
    TAOS_RETURN(code);
×
1449
  }
1450
  mInfo("trans:%d, pre-finish finished", pTrans->id);
2!
1451
  TAOS_RETURN(code);
2✔
1452
}
1453

1454
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
226,364✔
1455
  bool    sendRsp = false;
226,364✔
1456
  int32_t code = pTrans->code;
226,364✔
1457

1458
  if (pTrans->stage == TRN_STAGE_FINISH) {
226,364✔
1459
    sendRsp = true;
101,745✔
1460
  }
1461

1462
  if (pTrans->policy == TRN_POLICY_ROLLBACK) {
226,364✔
1463
    if (pTrans->stage == TRN_STAGE_UNDO_ACTION || pTrans->stage == TRN_STAGE_ROLLBACK) {
81,720!
1464
      if (code == 0) code = TSDB_CODE_MND_TRANS_UNKNOW_ERROR;
12!
1465
      sendRsp = true;
12✔
1466
    }
1467
  } else {
1468
    if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
144,644✔
1469
      if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_APP_IS_STARTING ||
83,035!
1470
          code == TSDB_CODE_SYN_PROPOSE_NOT_READY) {
1471
        if (pTrans->failedTimes > 60) sendRsp = true;
×
1472
      } else {
1473
        if (pTrans->failedTimes > 6) sendRsp = true;
83,035!
1474
      }
1475
      if (code == 0) code = TSDB_CODE_MND_TRANS_UNKNOW_ERROR;
83,035✔
1476
    }
1477
  }
1478

1479
  if (!sendRsp) {
226,364✔
1480
    return;
124,607✔
1481
  } else {
1482
    mInfo("vgId:1, trans:%d, start to send rsp, stage:%s failedTimes:%d code:0x%x", pTrans->id,
101,757!
1483
          mndTransStr(pTrans->stage), pTrans->failedTimes, code);
1484
  }
1485

1486
  mInfo("vgId:1, trans:%d, start to lock rpc array", pTrans->id);
101,757!
1487
  taosWLockLatch(&pTrans->lockRpcArray);
101,757✔
1488
  int32_t size = taosArrayGetSize(pTrans->pRpcArray);
101,757✔
1489
  if (size <= 0) {
101,757✔
1490
    taosWUnLockLatch(&pTrans->lockRpcArray);
70,798✔
1491
    return;
70,798✔
1492
  }
1493

1494
  for (int32_t i = 0; i < size; ++i) {
61,918✔
1495
    SRpcHandleInfo *pInfo = taosArrayGet(pTrans->pRpcArray, i);
30,959✔
1496
    if (pInfo->handle != NULL) {
30,959✔
1497
      if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
29,925!
1498
        code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
×
1499
      }
1500
      if (code == TSDB_CODE_SYN_TIMEOUT) {
29,925!
1501
        code = TSDB_CODE_MND_TRANS_SYNC_TIMEOUT;
×
1502
      }
1503

1504
      if (i != 0 && code == 0) {
29,925!
1505
        code = TSDB_CODE_MNODE_NOT_FOUND;
×
1506
      }
1507
      mInfo("vgId:1, trans:%d, client:%d start to send rsp, code:0x%x stage:%s app:%p", pTrans->id, i, code,
29,925!
1508
            mndTransStr(pTrans->stage), pInfo->ahandle);
1509

1510
      SRpcMsg rspMsg = {.code = code, .info = *pInfo};
29,925✔
1511

1512
      if (pTrans->originRpcType == TDMT_MND_CREATE_DB) {
29,925✔
1513
        mInfo("trans:%d, origin msgtype:%s", pTrans->id, TMSG_INFO(pTrans->originRpcType));
4,030!
1514
        SDbObj *pDb = mndAcquireDb(pMnode, pTrans->dbname);
4,030✔
1515
        if (pDb != NULL) {
4,030!
1516
          for (int32_t j = 0; j < 12; j++) {
4,843✔
1517
            bool ready = mndIsDbReady(pMnode, pDb);
4,841✔
1518
            if (!ready) {
4,841✔
1519
              mInfo("trans:%d, db:%s not ready yet, wait %d times", pTrans->id, pTrans->dbname, j);
813!
1520
              taosMsleep(1000);
813✔
1521
            } else {
1522
              break;
4,028✔
1523
            }
1524
          }
1525
        }
1526
        mndReleaseDb(pMnode, pDb);
4,030✔
1527
      } else if (pTrans->originRpcType == TDMT_MND_CREATE_STB) {
25,895✔
1528
        void   *pCont = NULL;
6,792✔
1529
        int32_t contLen = 0;
6,792✔
1530
        if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen)) {
6,792✔
1531
          mndTransSetRpcRsp(pTrans, pCont, contLen);
6,790✔
1532
        }
1533
      } else if (pTrans->originRpcType == TDMT_MND_CREATE_INDEX) {
19,103✔
1534
        void   *pCont = NULL;
10✔
1535
        int32_t contLen = 0;
10✔
1536
        if (0 == mndBuildSMCreateStbRsp(pMnode, pTrans->dbname, pTrans->stbname, &pCont, &contLen)) {
10!
1537
          mndTransSetRpcRsp(pTrans, pCont, contLen);
10✔
1538
        }
1539
      } else if (pTrans->originRpcType == TDMT_MND_DROP_DNODE) {
19,093✔
1540
        int32_t code = mndRefreshUserIpWhiteList(pMnode);
23✔
1541
        if (code != 0) {
23!
1542
          mWarn("failed to refresh user ip white list since %s", tstrerror(code));
×
1543
        }
1544
      }
1545

1546
      if (pTrans->rpcRspLen != 0) {
29,925✔
1547
        void *rpcCont = rpcMallocCont(pTrans->rpcRspLen);
17,515✔
1548
        if (rpcCont != NULL) {
17,515!
1549
          memcpy(rpcCont, pTrans->rpcRsp, pTrans->rpcRspLen);
17,515✔
1550
          rspMsg.pCont = rpcCont;
17,515✔
1551
          rspMsg.contLen = pTrans->rpcRspLen;
17,515✔
1552
        }
1553
      }
1554

1555
      tmsgSendRsp(&rspMsg);
29,925✔
1556

1557
      mInfo("vgId:1, trans:%d, client:%d send rsp finished, code:0x%x stage:%s app:%p", pTrans->id, i, code,
29,925!
1558
            mndTransStr(pTrans->stage), pInfo->ahandle);
1559
    }
1560
  }
1561
  taosArrayClear(pTrans->pRpcArray);
30,959✔
1562
  taosWUnLockLatch(&pTrans->lockRpcArray);
30,959✔
1563
}
1564

1565
int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
58,628✔
1566
  int32_t code = 0;
58,628✔
1567
  SMnode *pMnode = pRsp->info.node;
58,628✔
1568
#ifndef TD_ASTRA_32
1569
  int64_t signature = (int64_t)(pRsp->info.ahandle);
58,628✔
1570
  int32_t transId = (int32_t)(signature >> 32);
58,628✔
1571
  int32_t action = (int32_t)((signature << 32) >> 32);
58,628✔
1572
#else
1573
  int32_t transId = (int32_t)(pRsp->info.ahandle);
1574
  int32_t action = (int32_t)(pRsp->info.ahandleEx);
1575
#endif
1576
  STraceId* trace = &(pRsp->info.traceId);
58,628✔
1577
  STrans *pTrans = mndAcquireTrans(pMnode, transId);
58,628✔
1578
  if (pTrans == NULL) {
58,628!
1579
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
1580
    if (terrno != 0) code = terrno;
×
1581
    mError("trans:%d, failed to get transId from vnode rsp since %s", transId, tstrerror(code));
×
1582
    goto _OVER;
×
1583
  }
1584

1585
  SArray *pArray = NULL;
58,628✔
1586
  if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
58,628✔
1587
    pArray = pTrans->redoActions;
58,620✔
1588
  } else if (pTrans->stage == TRN_STAGE_UNDO_ACTION) {
8!
1589
    pArray = pTrans->undoActions;
8✔
1590
  } else {
1591
    mError("trans:%d, invalid trans stage:%d while recv action rsp", pTrans->id, pTrans->stage);
×
1592
    goto _OVER;
×
1593
  }
1594

1595
  if (pArray == NULL) {
58,628!
1596
    mError("trans:%d, invalid trans stage:%d", transId, pTrans->stage);
×
1597
    goto _OVER;
×
1598
  }
1599

1600
  int32_t actionNum = taosArrayGetSize(pArray);
58,628✔
1601
  if (action < 0 || action >= actionNum) {
58,628!
1602
    mError("trans:%d, invalid action:%d", transId, action);
×
1603
    goto _OVER;
×
1604
  }
1605

1606
  STransAction *pAction = taosArrayGet(pArray, action);
58,628✔
1607
  if (pAction != NULL) {
58,628!
1608
    if (pAction->msgSent) {
58,628!
1609
      pAction->msgReceived = 1;
58,628✔
1610
      pAction->errCode = pRsp->code;
58,628✔
1611
      pAction->endTime = taosGetTimestampMs();
58,628✔
1612

1613
      // pTrans->lastErrorNo = pRsp->code;
1614
      mndSetTransLastAction(pTrans, pAction);
58,628✔
1615

1616
      mInfo("trans:%d, %s:%d response is received, msgType:%s, QID:0x%" PRIx64 ":0x%" PRIx64 ", received code:0x%x(%s), accept:0x%x(%s) retry:0x%x(%s)", transId,
58,628!
1617
            mndTransStr(pAction->stage), action, TMSG_INFO(pAction->msgType), trace ? trace->rootId : 0, 
1618
              trace ? trace->msgId : 0, pRsp->code, tstrerror(pRsp->code), pAction->acceptableCode,
1619
            tstrerror(pAction->acceptableCode), pAction->retryCode, tstrerror(pAction->retryCode));
1620
    } else {
1621
      mWarn("trans:%d, %s:%d response is received, but msgSent is false, code:0x%x(%s), accept:0x%x(%s) retry:0x%x", 
×
1622
            transId, mndTransStr(pAction->stage), action, pRsp->code, tstrerror(pRsp->code),
1623
            pAction->acceptableCode, tstrerror(pAction->acceptableCode), pAction->retryCode);
1624
    }
1625

1626
  } else {
1627
    mInfo("trans:%d, invalid action, index:%d, code:0x%x", transId, action, pRsp->code);
×
1628
  }
1629

1630
  mInfo("trans:%d, execute transaction in process response", pTrans->id);
58,628!
1631
  mndTransExecute(pMnode, pTrans, true);
58,628✔
1632

1633
_OVER:
58,628✔
1634
  mndReleaseTrans(pMnode, pTrans);
58,628✔
1635
  TAOS_RETURN(code);
58,628✔
1636
}
1637

1638
static void mndTransResetAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
4,274✔
1639
  pAction->rawWritten = 0;
4,274✔
1640
  pAction->msgSent = 0;
4,274✔
1641
  pAction->msgReceived = 0;
4,274✔
1642
  if (pAction->errCode == TSDB_CODE_SYN_NEW_CONFIG_ERROR || pAction->errCode == TSDB_CODE_SYN_INTERNAL_ERROR ||
4,274!
1643
      pAction->errCode == TSDB_CODE_SYN_NOT_LEADER) {
4,274✔
1644
    pAction->epSet.inUse = (pAction->epSet.inUse + 1) % pAction->epSet.numOfEps;
4✔
1645
    mInfo("trans:%d, %s:%d execute status is reset and set epset inuse:%d", pTrans->id, mndTransStr(pAction->stage),
4!
1646
          pAction->id, pAction->epSet.inUse);
1647
  } else {
1648
    mInfo("trans:%d, %s:%d execute status is reset", pTrans->id, mndTransStr(pAction->stage), pAction->id);
4,270!
1649
  }
1650
  //  pAction->errCode = 0;
1651
}
4,274✔
1652

1653
static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) {
2✔
1654
  int32_t numOfActions = taosArrayGetSize(pArray);
2✔
1655

1656
  for (int32_t action = 0; action < numOfActions; ++action) {
10✔
1657
    STransAction *pAction = taosArrayGet(pArray, action);
8✔
1658
    if (pAction->msgSent && pAction->msgReceived &&
8!
1659
        (pAction->errCode == 0 || pAction->errCode == pAction->acceptableCode))
8!
1660
      continue;
6✔
1661
    if (pAction->msgSent && !pAction->msgReceived) {
2!
1662
      int64_t timestamp = taosGetTimestampMs();
×
1663
      if (timestamp - pAction->startTime <= TRANS_ACTION_TIMEOUT) continue;
×
1664
    }
1665

1666
    if (pAction->rawWritten && (pAction->errCode == 0 || pAction->errCode == pAction->acceptableCode)) continue;
2!
1667

1668
    mndTransResetAction(pMnode, pTrans, pAction);
2✔
1669
    mInfo("trans:%d, %s:%d reset, errCode:%d, startTime:%" PRId64, pTrans->id, mndTransStr(pAction->stage), pAction->id,
2!
1670
          pAction->errCode, pAction->startTime);
1671
  }
1672
}
2✔
1673

1674
// execute in sync context
1675
static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
489,519✔
1676
  if (pAction->rawWritten) return 0;
489,519✔
1677
  if (topHalf) {
270,608✔
1678
    TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
13✔
1679
  }
1680

1681
  if (pAction->pRaw->type >= SDB_MAX) {
270,595!
1682
    pAction->rawWritten = true;
×
1683
    pAction->errCode = 0;
×
1684
    mndSetTransLastAction(pTrans, pAction);
×
1685
    mInfo("skip sdb raw type:%d since it is not supported", pAction->pRaw->type);
×
1686
    TAOS_RETURN(TSDB_CODE_SUCCESS);
×
1687
  }
1688

1689
  int32_t code = sdbWriteWithoutFree(pMnode->pSdb, pAction->pRaw);
270,595✔
1690
  if (code == 0 || terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
270,595!
1691
    pAction->rawWritten = true;
270,595✔
1692
    pAction->errCode = 0;
270,595✔
1693
    code = 0;
270,595✔
1694
    mInfo("trans:%d, %s:%d write to sdb, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), pAction->id,
270,595!
1695
          sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1696

1697
    mndSetTransLastAction(pTrans, pAction);
270,595✔
1698
  } else {
1699
    pAction->errCode = (terrno != 0) ? terrno : code;
×
1700
    mError("trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage),
×
1701
           pAction->id, tstrerror(code), sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
1702
    mndSetTransLastAction(pTrans, pAction);
×
1703
  }
1704

1705
  TAOS_RETURN(code);
270,595✔
1706
}
1707

1708
// execute in trans context
1709
static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf,
259,708✔
1710
                                     bool notSend) {
1711
  if (pAction->msgSent) return 0;
259,708✔
1712
  if (mndCannotExecuteTrans(pMnode, topHalf)) {
95,624✔
1713
    TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
36,982✔
1714
  }
1715

1716
  if (notSend) {
58,642✔
1717
    mInfo("trans:%d, action:%d skip to execute msg action", pTrans->id, pAction->id);
11!
1718
    return 0;
11✔
1719
  }
1720

1721
#ifndef TD_ASTRA_32
1722
  int64_t signature = pTrans->id;
58,631✔
1723
  signature = (signature << 32);
58,631✔
1724
  signature += pAction->id;
58,631✔
1725

1726
  SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .info.ahandle = (void *)signature};
58,631✔
1727
#else
1728
  SRpcMsg rpcMsg = {.msgType = pAction->msgType,
1729
                    .contLen = pAction->contLen,
1730
                    .info.ahandle = (void *)pTrans->id,
1731
                    .info.ahandleEx = (void *)pAction->id};
1732
#endif
1733
  rpcMsg.pCont = rpcMallocCont(pAction->contLen);
58,631✔
1734
  if (rpcMsg.pCont == NULL) {
58,631!
1735
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
1736
    return -1;
×
1737
  }
1738
  rpcMsg.info.traceId.rootId = pTrans->mTraceId;
58,631✔
1739
  TRACE_SET_MSGID(&(rpcMsg.info.traceId), tGenIdPI64());
58,631✔
1740
  rpcMsg.info.notFreeAhandle = 1;
58,631✔
1741
  STraceId* trace = &(rpcMsg.info.traceId);
58,631✔
1742

1743
  memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen);
58,631✔
1744

1745
  char    detail[1024] = {0};
58,631✔
1746
  int32_t len = tsnprintf(detail, sizeof(detail), "msgType:%s numOfEps:%d inUse:%d", TMSG_INFO(pAction->msgType),
58,631!
1747
                          pAction->epSet.numOfEps, pAction->epSet.inUse);
58,631✔
1748
  for (int32_t i = 0; i < pAction->epSet.numOfEps; ++i) {
125,028✔
1749
    len += tsnprintf(detail + len, sizeof(detail) - len, " ep:%d-%s:%u", i, pAction->epSet.eps[i].fqdn,
66,397✔
1750
                     pAction->epSet.eps[i].port);
66,397✔
1751
  }
1752

1753
  int32_t code = tmsgSendReq(&pAction->epSet, &rpcMsg);
58,631✔
1754
  if (code == 0) {
58,631✔
1755
    pAction->msgSent = 1;
58,630✔
1756
    // pAction->msgReceived = 0;
1757
    pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
58,630✔
1758
    pAction->startTime = taosGetTimestampMs();
58,630✔
1759
    pAction->endTime = 0;
58,630✔
1760
    mInfo("trans:%d, %s:%d is sent, QID:0x%" PRIx64 ":0x%" PRIx64 ", %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, trace ? trace->rootId : 0, 
58,630!
1761
              trace ? trace->msgId : 0, detail);
1762

1763
    mndSetTransLastAction(pTrans, pAction);
58,630✔
1764
  } else {
1765
    pAction->msgSent = 0;
1✔
1766
    pAction->msgReceived = 0;
1✔
1767
    pAction->errCode = (terrno != 0) ? terrno : code;
1!
1768
    mError("trans:%d, %s:%d not send since %s, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr(),
1!
1769
           detail);
1770

1771
    mndSetTransLastAction(pTrans, pAction);
1✔
1772
  }
1773

1774
  TAOS_RETURN(code);
58,631✔
1775
}
1776

1777
static int32_t mndTransExecNullMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
×
1778
  if (!topHalf) return TSDB_CODE_MND_TRANS_CTX_SWITCH;
×
1779
  pAction->rawWritten = 0;
×
1780
  pAction->errCode = 0;
×
1781
  mInfo("trans:%d, %s:%d confirm action executed", pTrans->id, mndTransStr(pAction->stage), pAction->id);
×
1782

1783
  mndSetTransLastAction(pTrans, pAction);
×
1784
  return 0;
×
1785
}
1786

1787
static int32_t mndTransExecSingleAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf,
749,227✔
1788
                                        bool notSend) {
1789
  if (pAction->actionType == TRANS_ACTION_RAW) {
749,227✔
1790
    return mndTransWriteSingleLog(pMnode, pTrans, pAction, topHalf);
489,519✔
1791
  } else if (pAction->actionType == TRANS_ACTION_MSG) {
259,708!
1792
    return mndTransSendSingleMsg(pMnode, pTrans, pAction, topHalf, notSend);
259,708✔
1793
  } else {
1794
    return mndTransExecNullMsg(pMnode, pTrans, pAction, topHalf);
×
1795
  }
1796
}
1797

1798
static int32_t mndTransExecSingleActions(SMnode *pMnode, STrans *pTrans, SArray *pArray, bool topHalf, bool notSend) {
205,518✔
1799
  int32_t numOfActions = taosArrayGetSize(pArray);
205,518✔
1800
  int32_t code = 0;
205,518✔
1801

1802
  for (int32_t action = 0; action < numOfActions; ++action) {
861,794✔
1803
    STransAction *pAction = taosArrayGet(pArray, action);
686,275✔
1804
    code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf, notSend);
686,275✔
1805
    if (code != 0) {
686,275✔
1806
      mInfo("trans:%d, action:%d not executed since %s. numOfActions:%d", pTrans->id, action, tstrerror(code),
29,999!
1807
            numOfActions);
1808
      break;
29,999✔
1809
    }
1810
  }
1811

1812
  return code;
205,518✔
1813
}
1814

1815
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray, bool topHalf, bool notSend) {
250,295✔
1816
  int32_t numOfActions = taosArrayGetSize(pArray);
250,295✔
1817
  int32_t code = 0;
250,295✔
1818
  if (numOfActions == 0) return 0;
250,295✔
1819

1820
  if ((code = mndTransExecSingleActions(pMnode, pTrans, pArray, topHalf, notSend)) != 0) {
205,518✔
1821
    return code;
29,999✔
1822
  }
1823

1824
  int32_t       numOfExecuted = 0;
175,519✔
1825
  int32_t       errCode = 0;
175,519✔
1826
  STransAction *pErrAction = NULL;
175,519✔
1827
  for (int32_t action = 0; action < numOfActions; ++action) {
831,795✔
1828
    STransAction *pAction = taosArrayGet(pArray, action);
656,276✔
1829
    if (pAction->msgReceived || pAction->rawWritten) {
656,276✔
1830
      numOfExecuted++;
555,343✔
1831
      if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
555,343✔
1832
        errCode = pAction->errCode;
3✔
1833
        pErrAction = pAction;
3✔
1834
      }
1835
    } else {
1836
      pErrAction = pAction;
100,933✔
1837
    }
1838
  }
1839

1840
  mndSetTransLastAction(pTrans, pErrAction);
175,519✔
1841

1842
  if (numOfExecuted == numOfActions) {
175,519✔
1843
    if (errCode == 0) {
125,623✔
1844
      mInfo("trans:%d, all %d actions execute successfully", pTrans->id, numOfActions);
125,621!
1845
      return 0;
125,621✔
1846
    } else {
1847
      mError("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errCode & 0XFFFF);
2!
1848
      mndTransResetActions(pMnode, pTrans, pArray);
2✔
1849
      terrno = errCode;
2✔
1850
      return errCode;
2✔
1851
    }
1852
  } else {
1853
    mInfo("trans:%d, %d of %d actions executed", pTrans->id, numOfExecuted, numOfActions);
49,896!
1854

1855
    for (int32_t action = 0; action < numOfActions; ++action) {
201,661✔
1856
      STransAction *pAction = taosArrayGet(pArray, action);
151,765✔
1857
      mDebug("trans:%d, %s:%d Sent:%d, Received:%d, errCode:0x%x, acceptableCode:0x%x, retryCode:0x%x", pTrans->id,
151,765✔
1858
             mndTransStr(pAction->stage), pAction->id, pAction->msgSent, pAction->msgReceived, pAction->errCode,
1859
             pAction->acceptableCode, pAction->retryCode);
1860
      if (pAction->msgSent) {
151,765✔
1861
        bool reset = false;
151,754✔
1862
        if (pAction->msgReceived) {
151,754✔
1863
          if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) reset = true;
50,832✔
1864
        } else {
1865
          int64_t timestamp = taosGetTimestampMs();
100,922✔
1866
          if (timestamp - pAction->startTime > TRANS_ACTION_TIMEOUT) reset = true;
100,922!
1867
        }
1868
        if (reset) {
151,754✔
1869
          mndTransResetAction(pMnode, pTrans, pAction);
1✔
1870
          mInfo("trans:%d, %s:%d reset, errCode:%d, startTime:%" PRId64, pTrans->id, mndTransStr(pAction->stage),
1!
1871
                pAction->id, pAction->errCode, pAction->startTime);
1872
        }
1873
      }
1874
    }
1875
    return TSDB_CODE_ACTION_IN_PROGRESS;
49,896✔
1876
  }
1877
}
1878

1879
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
148,542✔
1880
  int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions, topHalf, notSend);
148,542✔
1881
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
148,542✔
1882
    mError("trans:%d, failed to execute redoActions since:%s, code:0x%x, in %s", pTrans->id, terrstr(), terrno,
2!
1883
           mndStrExecutionContext(topHalf));
1884
  }
1885
  return code;
148,542✔
1886
}
1887

1888
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
14✔
1889
  int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions, topHalf, notSend);
14✔
1890
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
14!
1891
    mError("trans:%d, failed to execute undoActions since %s. in %s", pTrans->id, terrstr(),
×
1892
           mndStrExecutionContext(topHalf));
1893
  }
1894
  return code;
14✔
1895
}
1896

1897
static int32_t mndTransExecuteCommitActions(SMnode *pMnode, STrans *pTrans, bool topHalf) {
101,739✔
1898
  int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->commitActions, topHalf, true);
101,739✔
1899
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
101,739!
1900
    mError("trans:%d, failed to execute commitActions since %s. in %s", pTrans->id, terrstr(),
×
1901
           mndStrExecutionContext(topHalf));
1902
  }
1903
  return code;
101,739✔
1904
}
1905

1906
static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArray *pActions, bool topHalf) {
19,464✔
1907
  int32_t code = 0;
19,464✔
1908
  int32_t numOfActions = taosArrayGetSize(pActions);
19,464✔
1909
  if (numOfActions == 0) return code;
19,464✔
1910

1911
  if (pTrans->actionPos >= numOfActions) {
19,460✔
1912
    return code;
1,486✔
1913
  }
1914

1915
  mInfo("trans:%d, execute %d actions serial, begin at action:%d, stage:%s", pTrans->id, numOfActions,
17,974!
1916
        pTrans->actionPos, mndTransStr(pTrans->stage));
1917

1918
  for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
28,033✔
1919
    STransAction *pAction = taosArrayGet(pActions, action);
26,788✔
1920

1921
    if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL && pAction->groupId > 0) {
26,788✔
1922
      code = TSDB_CODE_ACTION_IN_PROGRESS;
15✔
1923
      break;
16,729✔
1924
    }
1925

1926
    mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d", pTrans->id,
26,773!
1927
          pTrans->actionPos, mndTransStr(pAction->stage), pAction->actionType, pAction->msgSent, pAction->msgReceived);
1928

1929
    code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf, false);
26,773✔
1930
    if (code == 0) {
26,773✔
1931
      if (pAction->msgSent) {
22,325✔
1932
        bool reset = false;
18,077✔
1933
        if (pAction->msgReceived) {
18,077✔
1934
          if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
8,067!
1935
            code = pAction->errCode;
4,193✔
1936
            reset = true;
4,193✔
1937
          } else {
1938
            mInfo("trans:%d, %s:%d execute successfully", pTrans->id, mndTransStr(pAction->stage), pAction->id);
3,874!
1939
          }
1940
        } else {
1941
          int64_t timestamp = taosGetTimestampMs();
10,010✔
1942
          if (timestamp - pAction->startTime > TRANS_ACTION_TIMEOUT) reset = true;
10,010!
1943
          code = TSDB_CODE_ACTION_IN_PROGRESS;
10,010✔
1944
        }
1945
        if (reset) {
18,077✔
1946
          mndTransResetAction(pMnode, pTrans, pAction);
4,193✔
1947
          mInfo("trans:%d, %s:%d reset, errCode:%d, startTime:%" PRId64, pTrans->id, mndTransStr(pAction->stage),
4,193!
1948
                pAction->id, pAction->errCode, pAction->startTime);
1949
        }
1950
      } else if (pAction->rawWritten) {
4,248!
1951
        if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
4,248!
1952
          code = pAction->errCode;
×
1953
        } else {
1954
          mInfo("trans:%d, %s:%d was already written", pTrans->id, mndTransStr(pAction->stage), pAction->id);
4,248!
1955
        }
1956
      } else {
1957
      }
1958
    }
1959

1960
    if (code == 0) {
26,773✔
1961
      pTrans->failedTimes = 0;
8,122✔
1962
    }
1963
    mndSetTransLastAction(pTrans, pAction);
26,773✔
1964
    if (code == TSDB_CODE_MND_TRANS_CTX_SWITCH || code == TSDB_CODE_ACTION_IN_PROGRESS) {
26,773✔
1965
      mInfo(
14,457!
1966
          "trans:%d, not able to execute current action:%d since %s, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, "
1967
          "msgReceived:%d",
1968
          pTrans->id, pTrans->actionPos, tstrerror(code), mndTransStr(pAction->stage), pAction->actionType,
1969
          pAction->msgSent, pAction->msgReceived);
1970
    } else if (code != 0) {
12,316✔
1971
      mError(
4,194!
1972
          "trans:%d, failed to execute current action:%d since %s, stage:%s, actionType(1:msg,2:log):%d, msgSent:%d, "
1973
          "msgReceived:%d",
1974
          pTrans->id, pTrans->actionPos, tstrerror(code), mndTransStr(pAction->stage), pAction->actionType,
1975
          pAction->msgSent, pAction->msgReceived);
1976
    }
1977

1978
    char str[200] = {0};
26,773✔
1979
    if (mndCannotExecuteTransWithInfo(pMnode, topHalf, str, 200)) {
26,773✔
1980
      pTrans->lastErrorNo = code;
6,702✔
1981
      pTrans->code = code;
6,702✔
1982
      mInfo("trans:%d, %s:%d cannot execute next action, stop execution, %s", pTrans->id, mndTransStr(pAction->stage),
6,702!
1983
            action, str);
1984
      break;
6,702✔
1985
    }
1986

1987
    if (code == 0) {
20,071✔
1988
      pTrans->code = 0;
5,867✔
1989
      pTrans->actionPos++;
5,867✔
1990
      mInfo("trans:%d, %s:%d is executed and need sync to other mnodes", pTrans->id, mndTransStr(pAction->stage),
5,867!
1991
            pAction->id);
1992
      (void)taosThreadMutexUnlock(&pTrans->mutex);
5,867✔
1993
      code = mndTransSync(pMnode, pTrans);
5,867✔
1994
      (void)taosThreadMutexLock(&pTrans->mutex);
5,867✔
1995
      if (code != 0) {
5,867!
1996
        pTrans->actionPos--;
×
1997
        pTrans->code = terrno;
×
1998
        mError("trans:%d, %s:%d is executed and failed to sync to other mnodes since %s", pTrans->id,
×
1999
               mndTransStr(pAction->stage), pAction->id, terrstr());
2000
        break;
×
2001
      }
2002
    } else if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
14,204✔
2003
      mInfo("trans:%d, %s:%d is in progress and wait it finish", pTrans->id, mndTransStr(pAction->stage), pAction->id);
10,010!
2004
      break;
10,010✔
2005
    } else if (code == pAction->retryCode || code == TSDB_CODE_SYN_PROPOSE_NOT_READY ||
4,194!
2006
               code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_SYN_NOT_LEADER) {
6✔
2007
      mInfo("trans:%d, %s:%d receive code:0x%x(%s) and retry", pTrans->id, mndTransStr(pAction->stage), pAction->id,
4,192!
2008
            code, tstrerror(code));
2009
      pTrans->lastErrorNo = code;
4,192✔
2010
      taosMsleep(300);
4,192✔
2011
      action--;
4,192✔
2012
      continue;
4,192✔
2013
    } else {
2014
      terrno = code;
2✔
2015
      pTrans->lastErrorNo = code;
2✔
2016
      pTrans->code = code;
2✔
2017
      mInfo("trans:%d, %s:%d receive code:0x%x(%s) and wait another schedule, failedTimes:%d", pTrans->id,
2!
2018
            mndTransStr(pAction->stage), pAction->id, code, tstrerror(code), pTrans->failedTimes);
2019
      break;
2✔
2020
    }
2021
  }
2022

2023
  return code;
17,974✔
2024
}
2025

2026
static int32_t mndTransExecuteActionsSerialGroup(SMnode *pMnode, STrans *pTrans, SArray *pActions, bool topHalf,
8,073✔
2027
                                                 int32_t groupId, int32_t currentGroup, int32_t groupCount,
2028
                                                 bool notSend, SHashObj *pHash) {
2029
  int32_t code = 0;
8,073✔
2030
  int32_t numOfActions = taosArrayGetSize(pActions);
8,073✔
2031
  if (numOfActions == 0) return code;
8,073!
2032

2033
  if (groupId <= 0) {
8,073!
2034
    mError("trans:%d, failed to execute action in serail group, %d", pTrans->id, groupId);
×
2035
    return TSDB_CODE_INTERNAL_ERROR;
×
2036
  }
2037

2038
  int32_t *actionPos = taosHashGet(pTrans->groupActionPos, &groupId, sizeof(int32_t));
8,073✔
2039
  if (actionPos == NULL) {
8,073!
2040
    mError("trans:%d, failed to execute action in serail group, actionPos is null at group %d", pTrans->id, groupId);
×
2041
    return TSDB_CODE_INTERNAL_ERROR;
×
2042
  }
2043

2044
  if (*actionPos >= numOfActions) {
8,073✔
2045
    mError("trans:%d, failed to execute action in serail group, actionPos:%d >= numOfActions:%d at group %d",
1,567!
2046
           pTrans->id, *actionPos, numOfActions, groupId);
2047
    return TSDB_CODE_INTERNAL_ERROR;
1,567✔
2048
  }
2049

2050
  for (int32_t action = *actionPos; action < numOfActions; ++action) {
7,600✔
2051
    STransAction **ppAction = taosArrayGet(pActions, action);
7,105✔
2052
    STransAction  *pAction = *ppAction;
7,105✔
2053

2054
    if (notSend && !pAction->msgSent) {
7,105✔
2055
      mInfo(
923!
2056
          "trans:%d, %s:%d (%d/%d at group %d) skip to execute, curent state(actionType(1:msg,2:log):%d, "
2057
          "msgSent:%d, msgReceived:%d), transaction(action pos:%d)",
2058
          pTrans->id, mndTransStr(pTrans->stage), pAction->id, action, numOfActions, groupId, pAction->actionType,
2059
          pAction->msgSent, pAction->msgReceived, pTrans->actionPos);
2060
      code = TSDB_CODE_ACTION_IN_PROGRESS;
923✔
2061
      break;
6,011✔
2062
    }
2063

2064
    mInfo(
6,182!
2065
        "trans:%d, %s:%d (%d/%d at group %d) begin to execute, curent state(actionType(1:msg,2:log):%d, "
2066
        "msgSent:%d, msgReceived:%d), transaction(action pos:%d)",
2067
        pTrans->id, mndTransStr(pTrans->stage), pAction->id, action, numOfActions, groupId, pAction->actionType,
2068
        pAction->msgSent, pAction->msgReceived, pTrans->actionPos);
2069

2070
    code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf, false);
6,182✔
2071
    if (code == 0) {
6,182✔
2072
      if (pAction->msgSent) {
3,633✔
2073
        if (pAction->msgReceived) {
3,306✔
2074
          if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
983!
2075
            code = pAction->errCode;
78✔
2076
            mndTransResetAction(pMnode, pTrans, pAction);
78✔
2077
          } else {
2078
            mInfo("trans:%d, %s:%d (%d/%d at group %d) suceed to exeute", pTrans->id, mndTransStr(pAction->stage),
905!
2079
                  pAction->id, action, numOfActions, groupId);
2080
          }
2081
        } else {
2082
          code = TSDB_CODE_ACTION_IN_PROGRESS;
2,323✔
2083
        }
2084
        int8_t *msgSent = taosHashGet(pHash, &pAction->id, sizeof(int32_t));
3,306✔
2085
        if (msgSent != NULL) {
3,306!
2086
          *msgSent = pAction->msgSent;
3,306✔
2087
          mInfo("trans:%d, action:%d, set tmp msgSent:%d", pTrans->id, pAction->id, pAction->msgSent);
3,306!
2088
        } else {
2089
          mWarn("trans:%d, action:%d, failed set tmp msgSent:%d", pTrans->id, pAction->id, pAction->msgSent);
×
2090
        }
2091
      } else if (pAction->rawWritten) {
327!
2092
        if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
327!
2093
          code = pAction->errCode;
×
2094
        } else {
2095
          mInfo("trans:%d, %s:%d was already written", pTrans->id, mndTransStr(pAction->stage), pAction->id);
327!
2096
        }
2097
      } else {
2098
      }
2099
    }
2100

2101
    if (code == 0) {
6,182✔
2102
      pTrans->failedTimes = 0;
1,232✔
2103
    }
2104
    mndSetTransLastAction(pTrans, pAction);
6,182✔
2105

2106
    char str[200] = {0};
6,182✔
2107
    if (mndCannotExecuteTransWithInfo(pMnode, topHalf, str, 200)) {
6,182✔
2108
      pTrans->lastErrorNo = code;
2,765✔
2109
      pTrans->code = code;
2,765✔
2110
      if (code == TSDB_CODE_MND_TRANS_CTX_SWITCH) {
2,765✔
2111
        mInfo(
2,549!
2112
            "trans:%d, %s:%d (%d/%d at group %d) not able to execute since %s, current state("
2113
            "actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d)",
2114
            pTrans->id, mndTransStr(pAction->stage), pAction->id, action, numOfActions, groupId, tstrerror(code),
2115
            pAction->actionType, pAction->msgSent, pAction->msgReceived);
2116
      } else if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
216!
2117
        mError(
×
2118
            "trans:%d, %s:%d (%d/%d at group %d) failed to execute since %s, current action("
2119
            "actionType(1:msg,2:log):%d, msgSent:%d, msgReceived:%d)",
2120
            pTrans->id, mndTransStr(pAction->stage), pAction->id, action, numOfActions, groupId, tstrerror(code),
2121
            pAction->actionType, pAction->msgSent, pAction->msgReceived);
2122
      }
2123
      mInfo("trans:%d, %s:%d (%d/%d at group %d) cannot execute next action, stop this group execution, %s", pTrans->id,
2,765!
2124
            mndTransStr(pAction->stage), pAction->id, action, numOfActions, groupId, str);
2125
      break;
2,765✔
2126
    }
2127

2128
    if (code == 0) {
3,417✔
2129
      pTrans->code = 0;
1,016✔
2130
      pTrans->actionPos++;
1,016✔
2131
      (*actionPos)++;
1,016✔
2132
      mInfo("trans:%d, %s:%d is finished and need sync to other mnodes", pTrans->id, mndTransStr(pAction->stage),
1,016!
2133
            pAction->id);
2134
      (void)taosThreadMutexUnlock(&pTrans->mutex);
1,016✔
2135
      code = mndTransSync(pMnode, pTrans);
1,016✔
2136
      (void)taosThreadMutexLock(&pTrans->mutex);
1,016✔
2137
      mInfo("trans:%d, try to reset all action msgSent except:%d", pTrans->id, pAction->id);
1,016!
2138
      for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i) {
20,768✔
2139
        STransAction *pTmpAction = taosArrayGet(pTrans->redoActions, i);
19,752✔
2140
        int8_t       *msgSent = taosHashGet(pHash, &pTmpAction->id, sizeof(int32_t));
19,752✔
2141
        if (pTmpAction->id != pAction->id && pTmpAction->msgSent != *msgSent) {
19,752✔
2142
          pTmpAction->msgSent = *msgSent;
1,156✔
2143
          mInfo("trans:%d, action:%d, reset msgSent:%d", pTrans->id, pTmpAction->id, *msgSent);
1,156!
2144
        }
2145
      }
2146
      if (code != 0) {
1,016!
2147
        pTrans->actionPos--;
×
2148
        (*actionPos)--;
×
2149
        pTrans->code = terrno;
×
2150
        mError("trans:%d, %s:%d is executed and failed to sync to other mnodes since %s", pTrans->id,
×
2151
               mndTransStr(pAction->stage), pAction->id, terrstr());
2152
        break;
×
2153
      }
2154
    } else if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
2,401✔
2155
      mInfo("trans:%d, %s:%d is executed and still in progress and wait it finish", pTrans->id,
2,323!
2156
            mndTransStr(pAction->stage), pAction->id);
2157
      break;
2,323✔
2158
    } else if (code == pAction->retryCode || code == TSDB_CODE_SYN_PROPOSE_NOT_READY ||
78!
2159
               code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_SYN_NOT_LEADER) {
×
2160
      mInfo("trans:%d, %s:%d receive code:0x%x(%s) and retry", pTrans->id, mndTransStr(pAction->stage), pAction->id,
78!
2161
            code, tstrerror(code));
2162
      pTrans->lastErrorNo = code;
78✔
2163
      taosMsleep(300);
78✔
2164
      action--;
78✔
2165
      continue;
78✔
2166
    } else {
2167
      terrno = code;
×
2168
      pTrans->lastErrorNo = code;
×
2169
      pTrans->code = code;
×
2170
      mInfo("trans:%d, %s:%d receive code:0x%x(%s) and wait another schedule, failedTimes:%d", pTrans->id,
×
2171
            mndTransStr(pAction->stage), pAction->id, code, tstrerror(code), pTrans->failedTimes);
2172
      break;
×
2173
    }
2174
  }
2175

2176
  return code;
6,506✔
2177
}
2178

2179
static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans, bool topHalf) {
19,341✔
2180
  int32_t code = TSDB_CODE_ACTION_IN_PROGRESS;
19,341✔
2181
  (void)taosThreadMutexLock(&pTrans->mutex);
19,341✔
2182
  if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
19,341!
2183
    code = mndTransExecuteActionsSerial(pMnode, pTrans, pTrans->redoActions, topHalf);
19,341✔
2184
  }
2185
  (void)taosThreadMutexUnlock(&pTrans->mutex);
19,341✔
2186
  return code;
19,341✔
2187
}
2188

2189
static int32_t mndTransExecuteRedoActionGroup(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
2,512✔
2190
  int32_t total_code = TSDB_CODE_ACTION_IN_PROGRESS;
2,512✔
2191
  int32_t code = 0;
2,512✔
2192
  int32_t successCount = 0;
2,512✔
2193
  int32_t groupCount = taosHashGetSize(pTrans->redoGroupActions);
2,512✔
2194

2195
  SHashObj *pHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
2,512✔
2196
  if(pHash == NULL){
2,512!
2197
    mError("trans:%d, failed to init hash since %s", pTrans->id, terrstr());
×
2198
    return -1;
×
2199
  }
2200
  for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i) {
50,264✔
2201
    STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
47,752✔
2202
    int32_t       code = taosHashPut(pHash, &pAction->id, sizeof(int32_t), &pAction->msgSent, sizeof(int8_t));
47,752✔
2203
    if (code != 0) mError("trans:%d, failed to put hash since %s", pTrans->id, tstrerror(code));
47,752!
2204
  }
2205
  mTrace("trans:%d, temp save all action msgSent", pTrans->id);
2,512!
2206

2207
  mInfo("trans:%d, redo action group begin to execute, total group count:%d", pTrans->id, groupCount);
2,512!
2208
  void   *pIter = taosHashIterate(pTrans->redoGroupActions, NULL);
2,512✔
2209
  int32_t currentGroup = 1;
2,512✔
2210
  while (pIter) {
10,585✔
2211
    SArray **redoActions = pIter;
8,073✔
2212
    size_t   keyLen = 0;
8,073✔
2213
    int32_t *key = taosHashGetKey(pIter, &keyLen);
8,073✔
2214
    int32_t  actionCount = taosArrayGetSize(*redoActions);
8,073✔
2215
    mInfo("trans:%d, group:%d/%d(%d) begin to execute, current group(action count:%d) transaction(action pos:%d)",
8,073!
2216
          pTrans->id, currentGroup, groupCount, *key, actionCount, pTrans->actionPos);
2217
    code = mndTransExecuteActionsSerialGroup(pMnode, pTrans, *redoActions, topHalf, *key, currentGroup, groupCount,
8,073✔
2218
                                             notSend, pHash);
2219
    if (code == TSDB_CODE_MND_TRANS_CTX_SWITCH) {
8,073✔
2220
      mInfo("trans:%d, group:%d/%d(%d) not able to execute, code:%s", pTrans->id, currentGroup, groupCount, *key,
2,549!
2221
            tstrerror(code));
2222
    } else if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
5,524✔
2223
      mInfo("trans:%d, group:%d/%d(%d) is executed and still in progress", pTrans->id, currentGroup, groupCount, *key);
3,246!
2224
    } else if (code != 0) {
2,278✔
2225
      mError("trans:%d, group:%d/%d(%d) failed to execute, code:%s", pTrans->id, currentGroup, groupCount, *key,
1,567!
2226
             tstrerror(code));
2227
    } else {
2228
      successCount++;
711✔
2229
      mInfo("trans:%d, group:%d/%d(%d) is finished", pTrans->id, currentGroup, groupCount, *key);
711!
2230
    }
2231
    currentGroup++;
8,073✔
2232
    pIter = taosHashIterate(pTrans->redoGroupActions, pIter);
8,073✔
2233
  }
2234

2235
  taosHashCleanup(pHash);
2,512✔
2236

2237
  if (successCount == groupCount) {
2,512✔
2238
    total_code = 0;
46✔
2239
  } else {
2240
    mInfo("trans:%d, redo action group is executed, %d of %d groups is executed", pTrans->id, successCount, groupCount);
2,466!
2241
  }
2242

2243
  return total_code;
2,512✔
2244
}
2245

2246
static int32_t mndTransExecuteRedoActionsParallel(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
3,014✔
2247
  int32_t code = TSDB_CODE_ACTION_IN_PROGRESS;
3,014✔
2248
  (void)taosThreadMutexLock(&pTrans->mutex);
3,014✔
2249

2250
  if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
3,014!
2251
    int32_t numOfActions = taosArrayGetSize(pTrans->redoActions);
3,014✔
2252
    if (numOfActions == 0 || pTrans->actionPos >= numOfActions) {
3,014!
2253
      code = 0;
379✔
2254
    } else {
2255
      STransAction *pAction = taosArrayGet(pTrans->redoActions, pTrans->actionPos);
2,635✔
2256
      if (pAction != NULL && pAction->groupId == -1) {
2,635!
2257
        code = mndTransExecuteActionsSerial(pMnode, pTrans, pTrans->redoActions, topHalf);
123✔
2258
      } else {
2259
        code = mndTransExecuteRedoActionGroup(pMnode, pTrans, topHalf, notSend);
2,512✔
2260
        if (code == 0) {
2,512✔
2261
          if (pTrans->actionPos < numOfActions) {
46✔
2262
            code = TSDB_CODE_ACTION_IN_PROGRESS;
34✔
2263
          }
2264
        }
2265
      }
2266
    }
2267
  }
2268

2269
  (void)taosThreadMutexUnlock(&pTrans->mutex);
3,014✔
2270

2271
  return code;
3,014✔
2272
}
2273

2274
static int32_t mndTransExecuteUndoActionsSerial(SMnode *pMnode, STrans *pTrans, bool topHalf) {
×
2275
  int32_t code = TSDB_CODE_ACTION_IN_PROGRESS;
×
2276
  (void)taosThreadMutexLock(&pTrans->mutex);
×
2277
  if (pTrans->stage == TRN_STAGE_UNDO_ACTION) {
×
2278
    code = mndTransExecuteActionsSerial(pMnode, pTrans, pTrans->undoActions, topHalf);
×
2279
  }
2280
  (void)taosThreadMutexUnlock(&pTrans->mutex);
×
2281
  return code;
×
2282
}
2283

2284
bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
55,482✔
2285
  bool    continueExec = true;
55,482✔
2286
  int32_t code = 0;
55,482✔
2287
  terrno = 0;
55,482✔
2288

2289
  int32_t numOfActions = taosArrayGetSize(pTrans->prepareActions);
55,482✔
2290
  if (numOfActions == 0) goto _OVER;
55,482✔
2291

2292
  mInfo("trans:%d, execute %d prepare actions.", pTrans->id, numOfActions);
20,551!
2293

2294
  for (int32_t action = 0; action < numOfActions; ++action) {
50,548✔
2295
    STransAction *pAction = taosArrayGet(pTrans->prepareActions, action);
29,997✔
2296
    code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf, true);
29,997✔
2297
    if (code != 0) {
29,997!
2298
      terrno = code;
×
2299
      mError("trans:%d, failed to execute prepare action:%d, numOfActions:%d, since %s", pTrans->id, action,
×
2300
             numOfActions, tstrerror(code));
2301
      return false;
×
2302
    }
2303
  }
2304

2305
_OVER:
20,551✔
2306
  pTrans->stage = TRN_STAGE_REDO_ACTION;
55,482✔
2307
  mInfo("trans:%d, stage from prepare to redoAction", pTrans->id);
55,482!
2308
  return continueExec;
55,482✔
2309
}
2310

2311
static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
170,897✔
2312
  bool    continueExec = true;
170,897✔
2313
  int32_t code = 0;
170,897✔
2314
  terrno = 0;
170,897✔
2315

2316
  if (pTrans->exec == TRN_EXEC_SERIAL) {
170,897✔
2317
    code = mndTransExecuteRedoActionsSerial(pMnode, pTrans, topHalf);
19,341✔
2318
  } else if (pTrans->exec == TRN_EXEC_PARALLEL) {
151,556✔
2319
    code = mndTransExecuteRedoActions(pMnode, pTrans, topHalf, notSend);
148,542✔
2320
  } else if (pTrans->exec == TRN_EXEC_GROUP_PARALLEL) {
3,014!
2321
    code = mndTransExecuteRedoActionsParallel(pMnode, pTrans, topHalf, notSend);
3,014✔
2322
  } else {
2323
    code = TSDB_CODE_INTERNAL_ERROR;
×
2324
  }
2325

2326
  if (code != 0 && code != TSDB_CODE_MND_TRANS_CTX_SWITCH && code != TSDB_CODE_ACTION_IN_PROGRESS &&
170,901!
2327
      mndTransIsInSyncContext(topHalf)) {
4✔
2328
    pTrans->lastErrorNo = code;
×
2329
    pTrans->code = code;
×
2330
    mInfo(
×
2331
        "trans:%d, failed to execute, will retry redo action stage in 100 ms , in %s, "
2332
        "continueExec:%d, code:%s",
2333
        pTrans->id, mndStrExecutionContext(topHalf), continueExec, tstrerror(code));
2334
    taosMsleep(100);
×
2335
    return true;
×
2336
  } else {
2337
    if (mndCannotExecuteTrans(pMnode, topHalf)) {
170,897✔
2338
      mInfo("trans:%d, cannot continue to execute redo action stage in %s, continueExec:%d, code:%s", pTrans->id,
63,263!
2339
            mndStrExecutionContext(topHalf), continueExec, tstrerror(code));
2340
      return false;
63,263✔
2341
    }
2342
  }
2343
  terrno = code;
107,634✔
2344

2345
  if (code == 0) {
107,634✔
2346
    pTrans->code = 0;
46,292✔
2347
    pTrans->stage = TRN_STAGE_COMMIT;
46,292✔
2348
    mInfo("trans:%d, stage from redoAction to commit", pTrans->id);
46,292!
2349
    continueExec = true;
46,292✔
2350
  } else if (code == TSDB_CODE_ACTION_IN_PROGRESS || code == TSDB_CODE_MND_TRANS_CTX_SWITCH) {
61,342!
2351
    mInfo("trans:%d, stage keep on redoAction since %s", pTrans->id, tstrerror(code));
61,338!
2352
    continueExec = false;
61,338✔
2353
  } else {
2354
    pTrans->failedTimes++;
4✔
2355
    pTrans->code = terrno;
4✔
2356
    if (pTrans->policy == TRN_POLICY_ROLLBACK) {
4✔
2357
      if (pTrans->lastAction != 0) {
2!
2358
        STransAction *pAction = taosArrayGet(pTrans->redoActions, pTrans->lastAction);
2✔
2359
        if (pAction->retryCode != 0 && pAction->retryCode == pAction->errCode) {
2!
2360
          if (pTrans->failedTimes < 6) {
×
2361
            mError("trans:%d, stage keep on redoAction since action:%d code:0x%x not 0x%x, failedTimes:%d", pTrans->id,
×
2362
                   pTrans->lastAction, pTrans->code, pAction->retryCode, pTrans->failedTimes);
2363
            taosMsleep(1000);
×
2364
            continueExec = true;
×
2365
            return true;
×
2366
          }
2367
        }
2368
      }
2369

2370
      pTrans->stage = TRN_STAGE_ROLLBACK;
2✔
2371
      pTrans->actionPos = 0;
2✔
2372
      mError("trans:%d, stage from redoAction to rollback since %s, and set actionPos to %d", pTrans->id, terrstr(),
2!
2373
             pTrans->actionPos);
2374
      continueExec = true;
2✔
2375
    } else {
2376
      mError("trans:%d, stage keep on redoAction since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
2!
2377
      continueExec = false;
2✔
2378
    }
2379
  }
2380

2381
  return continueExec;
107,634✔
2382
}
2383

2384
// execute in trans context
2385
static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
46,292✔
2386
  if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
46,292!
2387

2388
  bool    continueExec = true;
46,292✔
2389
  int32_t code = mndTransCommit(pMnode, pTrans);
46,292✔
2390

2391
  if (code == 0) {
46,292✔
2392
    pTrans->code = 0;
46,286✔
2393
    pTrans->stage = TRN_STAGE_COMMIT_ACTION;
46,286✔
2394
    mInfo("trans:%d, stage from commit to commitAction", pTrans->id);
46,286!
2395
    continueExec = true;
46,286✔
2396
  } else {
2397
    pTrans->code = terrno;
6✔
2398
    pTrans->failedTimes++;
6✔
2399
    mError("trans:%d, stage keep on commit since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
6!
2400
    continueExec = false;
6✔
2401
  }
2402

2403
  return continueExec;
46,292✔
2404
}
2405

2406
static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
101,739✔
2407
  bool    continueExec = true;
101,739✔
2408
  int32_t code = mndTransExecuteCommitActions(pMnode, pTrans, topHalf);
101,739✔
2409

2410
  if (code == 0) {
101,739!
2411
    pTrans->code = 0;
101,739✔
2412
    pTrans->stage = TRN_STAGE_FINISH;  // TRN_STAGE_PRE_FINISH is not necessary
101,739✔
2413
    mInfo("trans:%d, stage from commitAction to finished", pTrans->id);
101,739!
2414
    continueExec = true;
101,739✔
2415
  } else if (code == TSDB_CODE_MND_TRANS_CTX_SWITCH && topHalf) {
×
2416
    pTrans->code = 0;
×
2417
    pTrans->stage = TRN_STAGE_COMMIT;
×
2418
    mInfo("trans:%d, back to commit stage", pTrans->id);
×
2419
    continueExec = true;
×
2420
  } else {
2421
    pTrans->code = terrno;
×
2422
    pTrans->failedTimes++;
×
2423
    mError("trans:%d, stage keep on commitAction since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
×
2424
    continueExec = false;
×
2425
  }
2426

2427
  return continueExec;
101,739✔
2428
}
2429

2430
static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
14✔
2431
  bool    continueExec = true;
14✔
2432
  int32_t code = 0;
14✔
2433

2434
  if (pTrans->exec == TRN_EXEC_SERIAL) {
14!
2435
    code = mndTransExecuteUndoActionsSerial(pMnode, pTrans, topHalf);
×
2436
  } else {
2437
    code = mndTransExecuteUndoActions(pMnode, pTrans, topHalf, notSend);
14✔
2438
  }
2439

2440
  if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
14✔
2441
  terrno = code;
12✔
2442

2443
  if (code == 0) {
12✔
2444
    pTrans->stage = TRN_STAGE_PRE_FINISH;
2✔
2445
    mInfo("trans:%d, stage from undoAction to pre-finish", pTrans->id);
2!
2446
    continueExec = true;
2✔
2447
  } else if (code == TSDB_CODE_ACTION_IN_PROGRESS || code == TSDB_CODE_MND_TRANS_CTX_SWITCH) {
10!
2448
    mInfo("trans:%d, stage keep on undoAction since %s", pTrans->id, tstrerror(code));
10!
2449
    continueExec = false;
10✔
2450
  } else {
2451
    pTrans->failedTimes++;
×
2452
    mError("trans:%d, stage keep on undoAction since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
×
2453
    continueExec = false;
×
2454
  }
2455

2456
  return continueExec;
12✔
2457
}
2458

2459
// in trans context
2460
static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
2✔
2461
  if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
2!
2462

2463
  bool    continueExec = true;
2✔
2464
  int32_t code = mndTransRollback(pMnode, pTrans);
2✔
2465

2466
  if (code == 0) {
2!
2467
    pTrans->stage = TRN_STAGE_UNDO_ACTION;
2✔
2468
    continueExec = true;
2✔
2469
  } else {
2470
    pTrans->failedTimes++;
×
2471
    mError("trans:%d, stage keep on rollback since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
×
2472
    continueExec = false;
×
2473
  }
2474

2475
  return continueExec;
2✔
2476
}
2477

2478
// excute in trans context
2479
static bool mndTransPerformPreFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
2✔
2480
  if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
2!
2481

2482
  bool    continueExec = true;
2✔
2483
  int32_t code = mndTransPreFinish(pMnode, pTrans);
2✔
2484

2485
  if (code == 0) {
2!
2486
    pTrans->stage = TRN_STAGE_FINISH;
2✔
2487
    mInfo("trans:%d, stage from pre-finish to finish", pTrans->id);
2!
2488
    continueExec = true;
2✔
2489
  } else {
2490
    pTrans->failedTimes++;
×
2491
    mError("trans:%d, stage keep on pre-finish since %s, failedTimes:%d", pTrans->id, terrstr(), pTrans->failedTimes);
×
2492
    continueExec = false;
×
2493
  }
2494

2495
  return continueExec;
2✔
2496
}
2497

2498
static bool mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
101,743✔
2499
  bool continueExec = false;
101,743✔
2500
  if (topHalf) return continueExec;
101,743✔
2501

2502
  SSdbRaw *pRaw = mndTransEncode(pTrans);
55,455✔
2503
  if (pRaw == NULL) {
55,455!
2504
    mError("trans:%d, failed to encode while finish trans since %s", pTrans->id, terrstr());
×
2505
    return false;
×
2506
  }
2507
  TAOS_CHECK_RETURN(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED));
55,455!
2508

2509
  int32_t code = sdbWrite(pMnode->pSdb, pRaw);
55,455✔
2510
  if (code != 0) {
55,455!
2511
    mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr());
×
2512
  }
2513

2514
  mInfo("trans:%d, execute finished, code:0x%x, failedTimes:%d createTime:%" PRId64, pTrans->id, pTrans->code,
55,455!
2515
        pTrans->failedTimes, pTrans->createdTime);
2516
  return continueExec;
55,455✔
2517
}
2518

2519
void mndTransExecuteImp(SMnode *pMnode, STrans *pTrans, bool topHalf, bool notSend) {
226,364✔
2520
  bool continueExec = true;
226,364✔
2521

2522
  while (continueExec) {
647,053✔
2523
    mInfo("trans:%d, continue to execute stage:%s in %s, createTime:%" PRId64, pTrans->id,
420,689!
2524
          mndTransStr(pTrans->stage), mndStrExecutionContext(topHalf), pTrans->createdTime);
2525
    pTrans->lastExecTime = taosGetTimestampMs();
420,689✔
2526
    switch (pTrans->stage) {
420,689!
2527
      case TRN_STAGE_PREPARE:
×
2528
        continueExec = mndTransPerformPrepareStage(pMnode, pTrans, topHalf);
×
2529
        break;
×
2530
      case TRN_STAGE_REDO_ACTION:
170,897✔
2531
        continueExec = mndTransPerformRedoActionStage(pMnode, pTrans, topHalf, notSend);
170,897✔
2532
        break;
170,897✔
2533
      case TRN_STAGE_COMMIT:
46,292✔
2534
        continueExec = mndTransPerformCommitStage(pMnode, pTrans, topHalf);
46,292✔
2535
        break;
46,292✔
2536
      case TRN_STAGE_COMMIT_ACTION:
101,739✔
2537
        continueExec = mndTransPerformCommitActionStage(pMnode, pTrans, topHalf);
101,739✔
2538
        break;
101,739✔
2539
      case TRN_STAGE_ROLLBACK:
2✔
2540
        continueExec = mndTransPerformRollbackStage(pMnode, pTrans, topHalf);
2✔
2541
        break;
2✔
2542
      case TRN_STAGE_UNDO_ACTION:
14✔
2543
        continueExec = mndTransPerformUndoActionStage(pMnode, pTrans, topHalf, notSend);
14✔
2544
        break;
14✔
2545
      case TRN_STAGE_PRE_FINISH:
2✔
2546
        continueExec = mndTransPerformPreFinishStage(pMnode, pTrans, topHalf);
2✔
2547
        break;
2✔
2548
      case TRN_STAGE_FINISH:
101,743✔
2549
        continueExec = mndTransPerformFinishStage(pMnode, pTrans, topHalf);
101,743✔
2550
        break;
101,743✔
2551
      default:
×
2552
        continueExec = false;
×
2553
        break;
×
2554
    }
2555
  }
2556

2557
  mndTransSendRpcRsp(pMnode, pTrans);
226,364✔
2558
}
226,364✔
2559

2560
// start trans, pullup, receive rsp, kill
2561
void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool notSend) {
107,762✔
2562
  bool topHalf = true;
107,762✔
2563
  mndTransExecuteImp(pMnode, pTrans, topHalf, notSend);
107,762✔
2564
}
107,762✔
2565

2566
// update trans
2567
void mndTransRefresh(SMnode *pMnode, STrans *pTrans) {
118,602✔
2568
  bool topHalf = false;
118,602✔
2569
  mndTransExecuteImp(pMnode, pTrans, topHalf, false);
118,602✔
2570
}
118,602✔
2571

2572
static int32_t mndProcessTransTimer(SRpcMsg *pReq) {
30,717✔
2573
  mTrace("start to process trans timer");
30,717✔
2574
  mndTransPullup(pReq->info.node);
30,717✔
2575
  return 0;
30,717✔
2576
}
2577

2578
int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
×
2579
  SArray *pArray = NULL;
×
2580
  if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
×
2581
    pArray = pTrans->redoActions;
×
2582
  } else if (pTrans->stage == TRN_STAGE_UNDO_ACTION) {
×
2583
    pArray = pTrans->undoActions;
×
2584
  } else {
2585
    TAOS_RETURN(TSDB_CODE_MND_TRANS_INVALID_STAGE);
×
2586
  }
2587

2588
  if(!tsForceKillTrans){
×
2589
    if(pTrans->ableToBeKilled == false){
×
2590
      return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
×
2591
    }
2592
  }
2593
  
2594
  if(pTrans->killMode == TRN_KILL_MODE_SKIP){
×
2595
    for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
×
2596
      STransAction *pAction = taosArrayGet(pArray, i);
×
2597
      mInfo("trans:%d, %s:%d set processed for kill msg received, errCode from %s to success", pTrans->id,
×
2598
            mndTransStr(pAction->stage), i, tstrerror(pAction->errCode));
2599
      pAction->msgSent = 1;
×
2600
      pAction->msgReceived = 1;
×
2601
      pAction->errCode = 0;
×
2602
    }
2603
  }
2604
  else if(pTrans->killMode == TRN_KILL_MODE_INTERUPT){
×
2605
    pTrans->stage = TRN_STAGE_PRE_FINISH;
×
2606
  }
2607
  else{
2608
    return TSDB_CODE_MND_TRANS_NOT_ABLE_TO_kILLED;
×
2609
  }
2610

2611
  mInfo("trans:%d, execute transaction in kill trans", pTrans->id);
×
2612
  mndTransExecute(pMnode, pTrans, true);
×
2613
  return 0;
×
2614
}
2615

2616
static int32_t mndProcessKillTransReq(SRpcMsg *pReq) {
1✔
2617
  SMnode       *pMnode = pReq->info.node;
1✔
2618
  SKillTransReq killReq = {0};
1✔
2619
  int32_t       code = -1;
1✔
2620
  STrans       *pTrans = NULL;
1✔
2621

2622
  if (tDeserializeSKillTransReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
1!
2623
    code = TSDB_CODE_INVALID_MSG;
×
2624
    goto _OVER;
×
2625
  }
2626

2627
  mInfo("trans:%d, start to kill, force:%d", killReq.transId, tsForceKillTrans);
1!
2628
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_TRANS)) != 0) {
1!
2629
    goto _OVER;
1✔
2630
  }
2631

2632
  pTrans = mndAcquireTrans(pMnode, killReq.transId);
×
2633
  if (pTrans == NULL) {
×
2634
    code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
2635
    if (terrno != 0) code = terrno;
×
2636
    goto _OVER;
×
2637
  }
2638

2639
  code = mndKillTrans(pMnode, pTrans);
×
2640

2641
_OVER:
1✔
2642
  if (code != 0) {
1!
2643
    mError("trans:%d, failed to kill since %s", killReq.transId, terrstr());
1!
2644
  }
2645

2646
  mndReleaseTrans(pMnode, pTrans);
1✔
2647
  TAOS_RETURN(code);
1✔
2648
}
2649

2650
static int32_t mndCompareTransId(int32_t *pTransId1, int32_t *pTransId2) { return *pTransId1 >= *pTransId2 ? 1 : 0; }
55✔
2651

2652
void mndTransPullup(SMnode *pMnode) {
31,222✔
2653
  SSdb   *pSdb = pMnode->pSdb;
31,222✔
2654
  SArray *pArray = taosArrayInit(sdbGetSize(pSdb, SDB_TRANS), sizeof(int32_t));
31,222✔
2655
  if (pArray == NULL) return;
31,222!
2656

2657
  void *pIter = NULL;
31,222✔
2658
  while (1) {
2,840✔
2659
    STrans *pTrans = NULL;
34,062✔
2660
    pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
34,062✔
2661
    if (pIter == NULL) break;
34,062✔
2662
    if (taosArrayPush(pArray, &pTrans->id) == NULL) {
5,680!
2663
      mError("failed to put trans into array, trans:%d, but pull up will continute", pTrans->id);
×
2664
    }
2665
    sdbRelease(pSdb, pTrans);
2,840✔
2666
  }
2667

2668
  taosArraySort(pArray, (__compar_fn_t)mndCompareTransId);
31,222✔
2669

2670
  for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
34,062✔
2671
    int32_t *pTransId = taosArrayGet(pArray, i);
2,840✔
2672
    STrans  *pTrans = mndAcquireTrans(pMnode, *pTransId);
2,840✔
2673
    if (pTrans != NULL) {
2,840!
2674
      mInfo("trans:%d, execute transaction in trans pullup", pTrans->id);
2,840!
2675
      mndTransExecute(pMnode, pTrans, false);
2,840✔
2676
    }
2677
    mndReleaseTrans(pMnode, pTrans);
2,840✔
2678
  }
2679
  taosArrayDestroy(pArray);
31,222✔
2680
}
2681

2682
static char *formatTimestamp(char *buf, int64_t val, int precision) {
40,716✔
2683
  time_t tt;
2684
  if (precision == TSDB_TIME_PRECISION_MICRO) {
40,716!
2685
    tt = (time_t)(val / 1000000);
×
2686
  }
2687
  if (precision == TSDB_TIME_PRECISION_NANO) {
40,716!
2688
    tt = (time_t)(val / 1000000000);
×
2689
  } else {
2690
    tt = (time_t)(val / 1000);
40,716✔
2691
  }
2692

2693
  struct tm tm;
2694
  if (taosLocalTime(&tt, &tm, NULL, 0, NULL) == NULL) {
40,716!
2695
    mError("failed to get local time");
×
2696
    return NULL;
×
2697
  }
2698
  size_t pos = taosStrfTime(buf, 32, "%Y-%m-%d %H:%M:%S", &tm);
40,716✔
2699

2700
  if (precision == TSDB_TIME_PRECISION_MICRO) {
40,716!
2701
    sprintf(buf + pos, ".%06d", (int)(val % 1000000));
×
2702
  } else if (precision == TSDB_TIME_PRECISION_NANO) {
40,716!
2703
    sprintf(buf + pos, ".%09d", (int)(val % 1000000000));
×
2704
  } else {
2705
    sprintf(buf + pos, ".%03d", (int)(val % 1000));
40,716✔
2706
  }
2707

2708
  return buf;
40,716✔
2709
}
2710

2711
static void mndTransLogAction(STrans *pTrans) {
841✔
2712
  char    detail[512] = {0};
841✔
2713
  int32_t len = 0;
841✔
2714
  int32_t index = 0;
841✔
2715

2716
  if (pTrans->stage == TRN_STAGE_PREPARE) {
841!
2717
    for (int32_t i = 0; i < taosArrayGetSize(pTrans->prepareActions); ++i, ++index) {
×
2718
      len = 0;
×
2719
      STransAction *pAction = taosArrayGet(pTrans->prepareActions, i);
×
2720
      len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
×
2721
                      mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
×
2722
                      sdbStatusName(pAction->pRaw->status));
×
2723
      mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
×
2724
    }
2725
  }
2726

2727
  if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
841!
2728
    for (int32_t i = 0; i < taosArrayGetSize(pTrans->redoActions); ++i, ++index) {
27,533✔
2729
      len = 0;
26,692✔
2730
      STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
26,692✔
2731
      if (pAction->actionType == TRANS_ACTION_MSG) {
26,692✔
2732
        char bufStart[40] = {0};
20,358✔
2733
        (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
20,358✔
2734

2735
        char endStart[40] = {0};
20,358✔
2736
        (void)formatTimestamp(endStart, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
20,358✔
2737
        len += snprintf(detail + len, sizeof(detail) - len,
40,716!
2738
                        "action:%d, %s:%d msgType:%s,"
2739
                        "sent:%d, received:%d, startTime:%s, endTime:%s, ",
2740
                        index, mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType), pAction->msgSent,
20,358✔
2741
                        pAction->msgReceived, bufStart, endStart);
20,358✔
2742

2743
        SEpSet epset = pAction->epSet;
20,358✔
2744
        if (epset.numOfEps > 0) {
20,358!
2745
          len += snprintf(detail + len, sizeof(detail) - len, "numOfEps:%d inUse:%d ", epset.numOfEps, epset.inUse);
20,358✔
2746
          for (int32_t i = 0; i < epset.numOfEps; ++i) {
45,744✔
2747
            len +=
25,386✔
2748
                snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
25,386✔
2749
          }
2750
        }
2751

2752
        len += snprintf(detail + len, sizeof(detail) - len, ", errCode:0x%x(%s)\n", pAction->errCode & 0xFFFF,
20,358✔
2753
                        tstrerror(pAction->errCode));
2754
      } else {
2755
        len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s, written:%d\n",
6,334✔
2756
                        index, mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
6,334✔
2757
                        sdbStatusName(pAction->pRaw->status), pAction->rawWritten);
6,334✔
2758
      }
2759
      mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
26,692!
2760
    }
2761
  }
2762

2763
  if (pTrans->stage == TRN_STAGE_COMMIT_ACTION) {
841!
2764
    for (int32_t i = 0; i < taosArrayGetSize(pTrans->commitActions); ++i, ++index) {
×
2765
      len = 0;
×
2766
      STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
×
2767
      len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
×
2768
                      mndTransStr(pAction->stage), i, sdbTableName(pAction->pRaw->type),
×
2769
                      sdbStatusName(pAction->pRaw->status));
×
2770
      mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
×
2771
    }
2772

2773
    for (int32_t i = 0; i < taosArrayGetSize(pTrans->undoActions); ++i, ++index) {
×
2774
      len = 0;
×
2775
      STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
×
2776
      if (pAction->actionType == TRANS_ACTION_MSG) {
×
2777
        len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d msgType:%s\n", index,
×
2778
                        mndTransStr(pAction->stage), pAction->id, TMSG_INFO(pAction->msgType));
×
2779
        ;
2780
      } else {
2781
        len += snprintf(detail + len, sizeof(detail) - len, "action:%d, %s:%d sdbType:%s, sdbStatus:%s\n", index,
×
2782
                        mndTransStr(pAction->stage), pAction->id, sdbTableName(pAction->pRaw->type),
×
2783
                        sdbStatusName(pAction->pRaw->status));
×
2784
      }
2785
      mDebug("trans:%d, show tran action, detail:%s", pTrans->id, detail);
×
2786
    }
2787
  }
2788
}
841✔
2789

2790
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
889✔
2791
  SMnode *pMnode = pReq->info.node;
889✔
2792
  SSdb   *pSdb = pMnode->pSdb;
889✔
2793
  int32_t numOfRows = 0;
889✔
2794
  STrans *pTrans = NULL;
889✔
2795
  int32_t cols = 0;
889✔
2796
  int32_t code = 0;
889✔
2797
  int32_t lino = 0;
889✔
2798

2799
  while (numOfRows < rows) {
1,730!
2800
    pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans);
1,730✔
2801
    if (pShow->pIter == NULL) break;
1,730✔
2802

2803
    cols = 0;
841✔
2804

2805
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2806
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->id, false), pTrans, &lino, _OVER);
841!
2807

2808
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2809
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->createdTime, false), pTrans, &lino,
841!
2810
                        _OVER);
2811

2812
    char stage[TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE] = {0};
841✔
2813
    STR_WITH_MAXSIZE_TO_VARSTR(stage, mndTransStr(pTrans->stage), pShow->pMeta->pSchemas[cols].bytes);
841✔
2814
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2815
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stage, false), pTrans, &lino, _OVER);
841!
2816

2817
    char opername[TSDB_TRANS_OPER_LEN + VARSTR_HEADER_SIZE] = {0};
841✔
2818
    STR_WITH_MAXSIZE_TO_VARSTR(opername, pTrans->opername, pShow->pMeta->pSchemas[cols].bytes);
841✔
2819
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2820
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)opername, false), pTrans, &lino, _OVER);
841!
2821

2822
    char dbname[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
841✔
2823
    STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndGetDbStr(pTrans->dbname), pShow->pMeta->pSchemas[cols].bytes);
841✔
2824
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2825
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)dbname, false), pTrans, &lino, _OVER);
841!
2826

2827
    char stbname[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
841✔
2828
    STR_WITH_MAXSIZE_TO_VARSTR(stbname, mndGetDbStr(pTrans->stbname), pShow->pMeta->pSchemas[cols].bytes);
841✔
2829
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2830
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)stbname, false), pTrans, &lino, _OVER);
841!
2831

2832
    const char *killableStr = pTrans->ableToBeKilled ? "yes" : "no";
841✔
2833
    char        killableVstr[10 + VARSTR_HEADER_SIZE] = {0};
841✔
2834
    STR_WITH_MAXSIZE_TO_VARSTR(killableVstr, killableStr, 10 + VARSTR_HEADER_SIZE);
841✔
2835
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2836
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killableVstr, false), pTrans, &lino, _OVER);
841!
2837

2838
    /*
2839
    const char *killModeStr = pTrans->killMode == TRN_KILL_MODE_SKIP ? "skip" : "interrupt";
2840
    char        killModeVstr[10 + VARSTR_HEADER_SIZE] = {0};
2841
    STR_WITH_MAXSIZE_TO_VARSTR(killModeVstr, killModeStr, 24);
2842
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
2843
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)killModeVstr, false), pTrans, &lino, _OVER);
2844
    */
2845

2846
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2847
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->failedTimes, false), pTrans, &lino,
841!
2848
                        _OVER);
2849

2850
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2851
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false), pTrans, &lino,
841!
2852
                        _OVER);
2853

2854
    char    lastInfo[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0};
841✔
2855
    char    detail[TSDB_TRANS_ERROR_LEN + 1] = {0};
841✔
2856
    int32_t len = tsnprintf(detail, sizeof(detail), "action:%d code:0x%x(%s) ", pTrans->lastAction,
2,523✔
2857
                            pTrans->lastErrorNo & 0xFFFF, tstrerror(pTrans->lastErrorNo));
841✔
2858
    SEpSet  epset = pTrans->lastEpset;
841✔
2859
    if (epset.numOfEps > 0) {
841✔
2860
      len += tsnprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
1,660!
2861
                       TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
1,660✔
2862
      for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
2,375✔
2863
        len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
1,545✔
2864
      }
2865
    }
2866
    STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
841✔
2867
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
841✔
2868
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)lastInfo, false), pTrans, &lino, _OVER);
841!
2869

2870
    mndTransLogAction(pTrans);
841✔
2871

2872
    numOfRows++;
841✔
2873
    sdbRelease(pSdb, pTrans);
841✔
2874
  }
2875

2876
_OVER:
×
2877
  if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
889!
2878
  pShow->numOfRows += numOfRows;
889✔
2879
  return numOfRows;
889✔
2880
}
2881

2882
static int32_t mndShowTransCommonColumns(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction,
×
2883
                                         int32_t transactionId, int32_t curActionId, int32_t numOfRows, int32_t *cols) {
2884
  int32_t code = 0;
×
2885
  int32_t lino = 0;
×
2886
  int32_t len = 0;
×
2887

2888
  SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
×
2889
  TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)&transactionId, false), &lino, _OVER);
×
2890

2891
  char action[30 + 1] = {0};
×
2892
  if (curActionId == pAction->id) {
×
2893
    len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)<-last", mndTransStr(pAction->stage), pAction->id,
×
2894
                    mndTransTypeStr(pAction->actionType));
2895
  } else {
2896
    len += snprintf(action + len, sizeof(action) - len, "%s:%d(%s)", mndTransStr(pAction->stage), pAction->id,
×
2897
                    mndTransTypeStr(pAction->actionType));
2898
  }
2899
  char actionVStr[30 + VARSTR_HEADER_SIZE] = {0};
×
2900
  STR_WITH_MAXSIZE_TO_VARSTR(actionVStr, action, pShow->pMeta->pSchemas[*cols].bytes);
×
2901
  pColInfo = taosArrayGet(pBlock->pDataBlock, (*cols)++);
×
2902
  TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)actionVStr, false), &lino, _OVER);
×
2903
_OVER:
×
2904
  if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
×
2905
  return code;
×
2906
}
2907

2908
static void mndShowTransAction(SShowObj *pShow, SSDataBlock *pBlock, STransAction *pAction, int32_t transactionId,
×
2909
                               int32_t curActionId, int32_t rows, int32_t numOfRows) {
2910
  int32_t code = 0;
×
2911
  int32_t lino = 0;
×
2912
  int32_t len = 0;
×
2913
  int32_t cols = 0;
×
2914

2915
  cols = 0;
×
2916

2917
  if (mndShowTransCommonColumns(pShow, pBlock, pAction, transactionId, curActionId, numOfRows, &cols) != 0) return;
×
2918

2919
  if (pAction->actionType == TRANS_ACTION_MSG) {
×
2920
    int32_t len = 0;
×
2921

2922
    char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
×
2923
    len += snprintf(objType + len, sizeof(objType) - len, "%s(s:%d,r:%d)", TMSG_INFO(pAction->msgType),
×
2924
                    pAction->msgSent, pAction->msgReceived);
×
2925
    char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
×
2926
    STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
×
2927
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2928
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
×
2929

2930
    char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
×
2931
    len = 0;
×
2932
    len += snprintf(result + len, sizeof(result) - len, "errCode:0x%x(%s)", pAction->errCode & 0xFFFF,
×
2933
                    tstrerror(pAction->errCode));
2934
    char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
×
2935
    STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
×
2936
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2937
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
×
2938

2939
    char target[TSDB_TRANS_TARGET_LEN] = {0};
×
2940
    len = 0;
×
2941
    SEpSet epset = pAction->epSet;
×
2942
    if (epset.numOfEps > 0) {
×
2943
      for (int32_t i = 0; i < epset.numOfEps; ++i) {
×
2944
        len += snprintf(target + len, sizeof(target) - len, "ep:%d-%s:%u,", i, epset.eps[i].fqdn, epset.eps[i].port);
×
2945
      }
2946
      len += snprintf(target + len, sizeof(target) - len, "(%d:%d) ", epset.numOfEps, epset.inUse);
×
2947
    }
2948
    char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
×
2949
    STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
×
2950
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2951
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
×
2952

2953
    char detail[TSDB_TRANS_DETAIL_LEN] = {0};
×
2954
    len = 0;
×
2955
    char bufStart[40] = {0};
×
2956
    if (pAction->startTime > 0) (void)formatTimestamp(bufStart, pAction->startTime, TSDB_TIME_PRECISION_MILLI);
×
2957
    char bufEnd[40] = {0};
×
2958
    if (pAction->endTime > 0) (void)formatTimestamp(bufEnd, pAction->endTime, TSDB_TIME_PRECISION_MILLI);
×
2959
    len += snprintf(detail + len, sizeof(detail) - len, "startTime:%s, endTime:%s, ", bufStart, bufEnd);
×
2960
    char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
×
2961
    STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
×
2962
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2963
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
×
2964

2965
  } else {
2966
    int32_t len = 0;
×
2967

2968
    char objType[TSDB_TRANS_OBJTYPE_LEN + 1] = {0};
×
2969
    if (pAction->pRaw->type == SDB_VGROUP) {
×
2970
      SSdbRow *pRow = mndVgroupActionDecode(pAction->pRaw);
×
2971
      SVgObj  *pVgroup = sdbGetRowObj(pRow);
×
2972
      len += snprintf(objType + len, sizeof(objType) - len, "%s(%d)", sdbTableName(pAction->pRaw->type), pVgroup->vgId);
×
2973
      taosMemoryFreeClear(pRow);
×
2974
    } else {
2975
      strcpy(objType, sdbTableName(pAction->pRaw->type));
×
2976
    }
2977
    char objTypeVStr[TSDB_TRANS_OBJTYPE_LEN + VARSTR_HEADER_SIZE] = {0};
×
2978
    STR_WITH_MAXSIZE_TO_VARSTR(objTypeVStr, objType, pShow->pMeta->pSchemas[cols].bytes);
×
2979
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2980
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)objTypeVStr, false), &lino, _OVER);
×
2981

2982
    char result[TSDB_TRANS_RESULT_LEN + 1] = {0};
×
2983
    len = 0;
×
2984
    len += snprintf(result + len, sizeof(result) - len, "rawWritten:%d", pAction->rawWritten);
×
2985
    char resultVStr[TSDB_TRANS_RESULT_LEN + VARSTR_HEADER_SIZE] = {0};
×
2986
    STR_WITH_MAXSIZE_TO_VARSTR(resultVStr, result, pShow->pMeta->pSchemas[cols].bytes);
×
2987
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2988
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)resultVStr, false), &lino, _OVER);
×
2989

2990
    char target[TSDB_TRANS_TARGET_LEN] = "";
×
2991
    char targetVStr[TSDB_TRANS_TARGET_LEN + VARSTR_HEADER_SIZE] = {0};
×
2992
    STR_WITH_MAXSIZE_TO_VARSTR(targetVStr, target, pShow->pMeta->pSchemas[cols].bytes);
×
2993
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
2994
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)targetVStr, false), &lino, _OVER);
×
2995

2996
    char detail[TSDB_TRANS_DETAIL_LEN] = {0};
×
2997
    len = 0;
×
2998
    len += snprintf(detail + len, sizeof(detail) - len, "sdbStatus:%s", sdbStatusName(pAction->pRaw->status));
×
2999
    char detailVStr[TSDB_TRANS_DETAIL_LEN + VARSTR_HEADER_SIZE] = {0};
×
3000
    STR_WITH_MAXSIZE_TO_VARSTR(detailVStr, detail, pShow->pMeta->pSchemas[cols].bytes);
×
3001
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
×
3002
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)detailVStr, false), &lino, _OVER);
×
3003
  }
3004

3005
_OVER:
×
3006
  if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
×
3007
}
3008

3009
static SArray *mndTransGetAction(STrans *pTrans, ETrnStage stage) {
×
3010
  if (stage == TRN_STAGE_PREPARE) {
×
3011
    return pTrans->prepareActions;
×
3012
  }
3013
  if (stage == TRN_STAGE_REDO_ACTION) {
×
3014
    return pTrans->redoActions;
×
3015
  }
3016
  if (stage == TRN_STAGE_COMMIT_ACTION) {
×
3017
    return pTrans->commitActions;
×
3018
  }
3019
  if (stage == TRN_STAGE_UNDO_ACTION) {
×
3020
    return pTrans->undoActions;
×
3021
  }
3022
  return NULL;
×
3023
}
3024

3025
typedef struct STransDetailIter {
3026
  void     *pIter;
3027
  STrans   *pTrans;
3028
  ETrnStage stage;
3029
  int32_t   num;
3030
} STransDetailIter;
3031

3032
static void mndTransShowActions(SSdb *pSdb, STransDetailIter *pShowIter, SShowObj *pShow, SSDataBlock *pBlock,
×
3033
                                int32_t rows, int32_t *numOfRows, SArray *pActions, int32_t end, int32_t start) {
3034
  int32_t actionNum = taosArrayGetSize(pActions);
×
3035
  mInfo("stage:%s, Actions num:%d", mndTransStr(pShowIter->stage), actionNum);
×
3036

3037
  for (int32_t i = start; i < actionNum; ++i) {
×
3038
    STransAction *pAction = taosArrayGet(pShowIter->pTrans->redoActions, i);
×
3039
    mndShowTransAction(pShow, pBlock, pAction, pShowIter->pTrans->id, pShowIter->pTrans->lastAction, rows, *numOfRows);
×
3040
    (*numOfRows)++;
×
3041
    if (*numOfRows >= rows) break;
×
3042
  }
3043

3044
  if (*numOfRows == end) {
×
3045
    sdbRelease(pSdb, pShowIter->pTrans);
×
3046
    pShowIter->pTrans = NULL;
×
3047
    pShowIter->num = 0;
×
3048
  } else {
3049
    pShowIter->pTrans = pShowIter->pTrans;
×
3050
    pShowIter->stage = pShowIter->pTrans->stage;
×
3051
    pShowIter->num += (*numOfRows);
×
3052
  }
3053
}
×
3054

3055
static int32_t mndRetrieveTransDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
×
3056
  SMnode *pMnode = pReq->info.node;
×
3057
  SSdb   *pSdb = pMnode->pSdb;
×
3058
  int32_t numOfRows = 0;
×
3059

3060
  int32_t code = 0;
×
3061
  int32_t lino = 0;
×
3062

3063
  mInfo("start to mndRetrieveTransDetail, rows:%d, pShow->numOfRows:%d, pShow->pIter:%p", rows, pShow->numOfRows,
×
3064
        pShow->pIter);
3065

3066
  if (pShow->pIter == NULL) {
×
3067
    pShow->pIter = taosMemoryMalloc(sizeof(STransDetailIter));
×
3068
    if (pShow->pIter == NULL) {
×
3069
      mError("failed to malloc for pShow->pIter");
×
3070
      return 0;
×
3071
    }
3072
    memset(pShow->pIter, 0, sizeof(STransDetailIter));
×
3073
  }
3074

3075
  STransDetailIter *pShowIter = (STransDetailIter *)pShow->pIter;
×
3076

3077
  while (numOfRows < rows) {
×
3078
    if (pShowIter->pTrans == NULL) {
×
3079
      pShowIter->pIter = sdbFetch(pSdb, SDB_TRANS, pShowIter->pIter, (void **)&(pShowIter->pTrans));
×
3080
      mDebug("retrieve trans detail from fetch, pShow->pIter:%p, pTrans:%p", pShowIter->pIter, pShowIter->pTrans);
×
3081
      if (pShowIter->pIter == NULL) break;
×
3082
      mInfo("retrieve trans detail from fetch, id:%d, trans stage:%d, IterNum:%d", pShowIter->pTrans->id,
×
3083
            pShowIter->pTrans->stage, pShowIter->num);
3084

3085
      SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->pTrans->stage);
×
3086

3087
      mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions, taosArrayGetSize(pActions), 0);
×
3088
      break;
×
3089
    } else {
3090
      mInfo("retrieve trans detail from iter, id:%d, iterStage:%d, IterNum:%d", pShowIter->pTrans->id, pShowIter->stage,
×
3091
            pShowIter->num);
3092
      SArray *pActions = mndTransGetAction(pShowIter->pTrans, pShowIter->stage);
×
3093

3094
      mndTransShowActions(pSdb, pShowIter, pShow, pBlock, rows, &numOfRows, pActions,
×
3095
                          taosArrayGetSize(pActions) - pShowIter->num, pShowIter->num);
×
3096
      break;
×
3097
    }
3098
  }
3099

3100
_OVER:
×
3101
  pShow->numOfRows += numOfRows;
×
3102

3103
  if (code != 0) {
×
3104
    mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code));
×
3105
  } else {
3106
    mInfo("retrieve trans detail, numOfRows:%d, pShow->numOfRows:%d", numOfRows, pShow->numOfRows)
×
3107
  }
3108
  if (numOfRows == 0) {
×
3109
    taosMemoryFree(pShow->pIter);
×
3110
    pShow->pIter = NULL;
×
3111
  }
3112
  return numOfRows;
×
3113
}
3114

3115
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter) {
×
3116
  SSdb *pSdb = pMnode->pSdb;
×
3117
  sdbCancelFetchByType(pSdb, pIter, SDB_TRANS);
×
3118
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc