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

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

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

68.71
/source/libs/sync/src/syncEnv.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 "syncEnv.h"
18
#include "syncUtil.h"
19
#include "tref.h"
20

21
static SSyncEnv gSyncEnv = {0};
22
static int32_t  gNodeRefId = -1;
23
static int32_t  gHbDataRefId = -1;
24

25
SSyncEnv *syncEnv() { return &gSyncEnv; }
617,847✔
26

27
bool syncIsInit() { return atomic_load_8(&gSyncEnv.isStart); }
6,824,021✔
28

29
int32_t syncInit() {
3,361✔
30
  if (syncIsInit()) return 0;
3,361✔
31

32
  uint32_t seed = (uint32_t)(taosGetTimestampNs() & 0x00000000FFFFFFFF);
1,880✔
33
  taosSeedRand(seed);
1,880✔
34

35
  (void)memset(&gSyncEnv, 0, sizeof(SSyncEnv));
1,880✔
36
  gSyncEnv.pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV");
1,880✔
37

38
  gNodeRefId = taosOpenRef(200, (RefFp)syncNodeClose);
1,880✔
39
  if (gNodeRefId < 0) {
1,880!
40
    sError("failed to init node rset");
×
41
    syncCleanUp();
×
42
    return TSDB_CODE_SYN_WRONG_REF;
×
43
  }
44
  sDebug("sync node rset is open, rsetId:%d", gNodeRefId);
1,880✔
45

46
  gHbDataRefId = taosOpenRef(200, (RefFp)syncHbTimerDataFree);
1,880✔
47
  if (gHbDataRefId < 0) {
1,880!
48
    sError("failed to init hbdata rset");
×
49
    syncCleanUp();
×
50
    return TSDB_CODE_SYN_WRONG_REF;
×
51
  }
52

53
  sDebug("sync hbdata rset is open, rsetId:%d", gHbDataRefId);
1,880✔
54

55
  atomic_store_8(&gSyncEnv.isStart, 1);
1,880✔
56
  return 0;
1,880✔
57
}
58

59
void syncCleanUp() {
1,879✔
60
  atomic_store_8(&gSyncEnv.isStart, 0);
1,879✔
61
  taosTmrCleanUp(gSyncEnv.pTimerManager);
1,879✔
62
  (void)memset(&gSyncEnv, 0, sizeof(SSyncEnv));
1,879✔
63

64
  if (gNodeRefId != -1) {
1,879!
65
    sDebug("sync node rset is closed, rsetId:%d", gNodeRefId);
1,879✔
66
    taosCloseRef(gNodeRefId);
1,879✔
67
    gNodeRefId = -1;
1,879✔
68
  }
69

70
  if (gHbDataRefId != -1) {
1,879!
71
    sDebug("sync hbdata rset is closed, rsetId:%d", gHbDataRefId);
1,879✔
72
    taosCloseRef(gHbDataRefId);
1,879✔
73
    gHbDataRefId = -1;
1,879✔
74
  }
75
}
1,879✔
76

77
int64_t syncNodeAdd(SSyncNode *pNode) {
11,662✔
78
  pNode->rid = taosAddRef(gNodeRefId, pNode);
11,662✔
79
  if (pNode->rid < 0) {
11,662!
80
    return terrno = TSDB_CODE_SYN_WRONG_REF;
×
81
  }
82

83
  sDebug("vgId:%d, sync node refId:%" PRId64 " is added to rsetId:%d", pNode->vgId, pNode->rid, gNodeRefId);
11,662✔
84
  return pNode->rid;
11,662✔
85
}
86

87
void syncNodeRemove(int64_t rid) {
11,661✔
88
  sDebug("sync node refId:%" PRId64 " is removed from rsetId:%d", rid, gNodeRefId);
11,661✔
89
  if (rid > 0) {
11,661!
90
    int32_t code = 0;
11,661✔
91
    if ((code = taosRemoveRef(gNodeRefId, rid)) != 0)
11,661!
92
      sError("failed to remove sync node from refId:%" PRId64 ", rsetId:%d, since %s", rid, gNodeRefId,
×
93
             tstrerror(code));
94
  }
95
}
11,661✔
96

97
SSyncNode *syncNodeAcquire(int64_t rid) {
21,120,216✔
98
  SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid);
21,120,216✔
99
  if (pNode == NULL) {
21,123,074!
UNCOV
100
    sError("failed to acquire sync node from refId:%" PRId64 ", rsetId:%d", rid, gNodeRefId);
×
UNCOV
101
    terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
×
102
  }
103

104
  return pNode;
21,123,317✔
105
}
106

107
void syncNodeRelease(SSyncNode *pNode) {
21,121,012✔
108
  if (pNode) {
21,121,012!
109
    int32_t code = 0;
21,121,778✔
110
    if ((code = taosReleaseRef(gNodeRefId, pNode->rid)) != 0)
21,121,778!
111
      sError("failed to release sync node from refId:%" PRId64 ", rsetId:%d, since %s", pNode->rid, gNodeRefId,
×
112
             tstrerror(code));
113
  }
114
}
21,121,045✔
115

116
int64_t syncHbTimerDataAdd(SSyncHbTimerData *pData) {
1,934✔
117
  pData->rid = taosAddRef(gHbDataRefId, pData);
1,934✔
118
  if (pData->rid < 0) {
1,934!
119
    return terrno = TSDB_CODE_SYN_WRONG_REF;
×
120
  }
121

122
  return pData->rid;
1,934✔
123
}
124

125
void syncHbTimerDataRemove(int64_t rid) {
19,865✔
126
  if (rid > 0) {
19,865✔
127
    int32_t code = 0;
1,930✔
128
    if ((code = taosRemoveRef(gHbDataRefId, rid)) != 0)
1,930!
129
      sError("failed to remove hbdata from refId:%" PRId64 ", rsetId:%d, since %s", rid, gHbDataRefId, tstrerror(code));
×
130
  }
131
}
19,865✔
132

133
SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) {
33,743✔
134
  SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid);
33,743✔
135
  if (pData == NULL && rid > 0) {
33,743!
136
    sInfo("failed to acquire hbdata from refId:%" PRId64 ", rsetId:%d", rid, gHbDataRefId);
×
137
    terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
×
138
  }
139

140
  return pData;
33,743✔
141
}
142

143
void syncHbTimerDataRelease(SSyncHbTimerData *pData) {
31,809✔
144
  if (pData) {
31,809!
145
    int32_t code = 0;
31,809✔
146
    if ((code = taosReleaseRef(gHbDataRefId, pData->rid)) != 0) {
31,809!
147
      sError("failed to release hbdata from refId:%" PRId64 ", rsetId:%d, since %s", pData->rid, gHbDataRefId,
×
148
             tstrerror(code));
149
    }
150
  }
151
}
31,809✔
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