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

taosdata / TDengine / #3660

15 Mar 2025 09:06AM UTC coverage: 62.039% (-1.3%) from 63.314%
#3660

push

travis-ci

web-flow
feat(stream): support stream processing for virtual tables (#30144)

* enh: add client processing

* enh: add mnode vtables processing

* enh: add mnode vtable processing

* enh: add normal child vtable support

* fix: compile issues

* fix: compile issues

* fix: create stream issues

* fix: multi stream scan issue

* fix: remove debug info

* fix: agg task and task level issues

* fix: correct task output type

* fix: split vtablescan from agg

* fix: memory leak issues

* fix: add limitations

* Update 09-error-code.md

* Update 09-error-code.md

* fix: remove usless case

* feat(stream): extract original table data in source scan task

Implemented functionality in the source task to extract data
corresponding to the virtual table from the original table using WAL.
The extracted data is then sent to the downstream merge task for further
processing.

* feat(stream): multi-way merge using loser tree in virtual merge task

Implemented multi-way merge in the merge task using a loser tree to
combine data from multiple original table into a single virtual table.
The merged virtual table data is then pushed downstream for further
processing.  Introduced memory limit handling during the merge process
with configurable behavior when the memory limit is reached.

* fix(test): remove useless cases

---------

Co-authored-by: dapan1121 <wpan@taosdata.com>
Co-authored-by: Pan Wei <72057773+dapan1121@users.noreply.github.com>

154078 of 317582 branches covered (48.52%)

Branch coverage included in aggregate %.

313 of 2391 new or added lines in 34 files covered. (13.09%)

26134 existing lines in 205 files now uncovered.

240261 of 318051 relevant lines covered (75.54%)

16655189.27 hits per line

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

63.89
/source/libs/sync/src/syncAppendEntriesReply.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 "syncAppendEntriesReply.h"
18
#include "syncCommit.h"
19
#include "syncIndexMgr.h"
20
#include "syncPipeline.h"
21
#include "syncMessage.h"
22
#include "syncRaftEntry.h"
23
#include "syncRaftStore.h"
24
#include "syncReplication.h"
25
#include "syncSnapshot.h"
26
#include "syncUtil.h"
27

28
// TLA+ Spec
29
// HandleAppendEntriesResponse(i, j, m) ==
30
//    /\ m.mterm = currentTerm[i]
31
//    /\ \/ /\ m.msuccess \* successful
32
//          /\ nextIndex'  = [nextIndex  EXCEPT ![i][j] = m.mmatchIndex + 1]
33
//          /\ matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
34
//       \/ /\ \lnot m.msuccess \* not successful
35
//          /\ nextIndex' = [nextIndex EXCEPT ![i][j] =
36
//                               Max({nextIndex[i][j] - 1, 1})]
37
//          /\ UNCHANGED <<matchIndex>>
38
//    /\ Discard(m)
39
//    /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
40
//
41

42
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
896,254✔
43
  int32_t                 code = 0;
896,254✔
44
  SyncAppendEntriesReply* pMsg = (SyncAppendEntriesReply*)pRpcMsg->pCont;
896,254✔
45
  int32_t ret = 0;
896,254✔
46
  const STraceId*         trace = &pRpcMsg->info.traceId;
896,254✔
47
  char                    tbuf[40] = {0};
896,254✔
48

49
  // if already drop replica, do not process
50
  if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
896,254!
51
    syncLogRecvAppendEntriesReply(ths, pMsg, "not in my config");
×
52
    return 0;
×
53
  }
54

55
  // drop stale response
56
  if (pMsg->term < raftStoreGetTerm(ths)) {
896,252!
57
    syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
×
58
    return 0;
×
59
  }
60

61
  if (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
896,255!
62
    if (pMsg->term != raftStoreGetTerm(ths)) {
896,253!
63
      syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
×
64
      syncNodeStepDown(ths, pMsg->term, pMsg->srcId);
×
UNCOV
65
      return TSDB_CODE_SYN_WRONG_TERM;
×
66
    }
67

68
    sGTrace("vgId:%d, received append entries reply. srcId:0x%016" PRIx64 ",  term:%" PRId64 ", matchIndex:%" PRId64 "",
896,251!
69
            pMsg->vgId, pMsg->srcId.addr, pMsg->term, pMsg->matchIndex);
70

71
    if (pMsg->success) {
896,251✔
72
      SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
692,961✔
73
      if (pMsg->matchIndex > oldMatchIndex) {
692,961✔
74
        syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
625,249✔
75
      }
76

77
      // commit if needed
78
      SyncIndex indexLikely = TMIN(pMsg->matchIndex, ths->pLogBuf->matchIndex);
692,959✔
79
      SyncIndex commitIndex = syncNodeCheckCommitIndex(ths, indexLikely);
692,959✔
80
      if (ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
692,958!
81
        if (commitIndex >= ths->assignedCommitIndex) {
×
82
          syncNodeStepDown(ths, pMsg->term, pMsg->destId);
×
83
        }
84
      } else {
85
        TAOS_CHECK_RETURN(syncLogBufferCommit(ths->pLogBuf, ths, commitIndex));
692,958✔
86
      }
87
    }
88

89
    // replicate log
90
    SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(ths, &pMsg->srcId);
896,252✔
91
    if (pMgr == NULL) {
896,249✔
92
      code = TSDB_CODE_MND_RETURN_VALUE_NULL;
2✔
93
      if (terrno != 0) code = terrno;
2!
94
      sError("vgId:%d, failed to get log repl mgr for src addr: 0x%016" PRIx64, ths->vgId, pMsg->srcId.addr);
2!
95
      TAOS_RETURN(code);
2✔
96
    }
97
    TAOS_CHECK_RETURN(syncLogReplProcessReply(pMgr, ths, pMsg));
896,247!
98
  }
99
  TAOS_RETURN(code);
896,249✔
100
}
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