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

taosdata / TDengine / #3647

13 Mar 2025 05:26AM UTC coverage: 25.9% (-2.5%) from 28.375%
#3647

push

travis-ci

web-flow
Merge pull request #30158 from taosdata/docs/anchor-caps-30

docs: lowercase anchors for 3.0

53974 of 285572 branches covered (18.9%)

Branch coverage included in aggregate %.

92870 of 281392 relevant lines covered (33.0%)

617448.64 hits per line

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

42.59
/source/util/src/mpDirect.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 "osMemPool.h"
18
#include "tmempoolInt.h"
19
#include "tlog.h"
20
#include "tutil.h"
21

22
void* mpDirectAlloc(SMemPool* pPool, SMPJob* pJob, int64_t size) {
1✔
23
  MP_CHECK_QUOTA(pPool, pJob, size);
1!
24
  
25
  return taosMemMalloc(size);
1✔
26
}
27

28

29
void* mpDirectAlignAlloc(SMemPool* pPool, SMPJob* pJob, uint32_t alignment, int64_t size) {
1✔
30
  MP_CHECK_QUOTA(pPool, pJob, size);
1!
31
  
32
  return taosMemMallocAlign(alignment, size);
1✔
33
}
34

35

36
void* mpDirectCalloc(SMemPool* pPool, SMPJob* pJob, int64_t num, int64_t size) {
1✔
37
  int64_t tSize = num * size;
1✔
38
  MP_CHECK_QUOTA(pPool, pJob, tSize);
1!
39

40
  return taosMemCalloc(num, size);
1✔
41
}
42

43
void mpDirectFree(SMemPool* pPool, SMPJob* pJob, void *ptr) {
1✔
44
  if (*pPool->cfg.jobQuota > 0) {
1!
45
    (void)atomic_sub_fetch_64(&pJob->job.allocMemSize, taosMemSize(ptr));
×
46
  }
47
  taosMemFree(ptr);
1✔
48
}
1✔
49

50

51
void* mpDirectRealloc(SMemPool* pPool, SMPJob* pJob, void* ptr, int64_t size) {
1✔
52
  int32_t code = TSDB_CODE_SUCCESS;
1✔
53

54
  if (NULL == ptr) {
1!
55
    return mpDirectAlloc(pPool, pJob, size);
×
56
  }
57

58
  if (0 == size) {
1!
59
    mpDirectFree(pPool, pJob, ptr);
×
60
    return NULL;
×
61
  }
62

63
  int64_t oSize = taosMemSize(ptr);
1✔
64

65
  MP_CHECK_QUOTA(pPool, pJob, size - oSize);
1!
66

67
  return taosMemRealloc(ptr, size);
1✔
68
}
69

70
void* mpDirectStrdup(SMemPool* pPool, SMPJob* pJob, const void* ptr) {
1✔
71
  if (NULL == ptr) {
1!
72
    return NULL;
×
73
  }
74
  
75
  int64_t oSize = strlen(ptr);
1✔
76
  MP_CHECK_QUOTA(pPool, pJob, oSize);
1!
77
  
78
  return taosStrdupi(ptr);
1✔
79
}
80

81
void* mpDirectStrndup(SMemPool* pPool, SMPJob* pJob, const void* ptr, int64_t size) {
1✔
82
  if (NULL == ptr) {
1!
83
    return NULL;
×
84
  }
85
  
86
  int64_t oSize = strlen(ptr);
1✔
87
  MP_CHECK_QUOTA(pPool, pJob, TMIN(oSize, size) + 1);
1!
88
  
89
  return taosStrndupi(ptr, size);
1✔
90
}
91

92

93

94

95
int64_t mpDirectGetMemSize(SMemPool* pPool, SMPSession* pSession, void *ptr) {
2✔
96
  return taosMemSize(ptr);
2✔
97
}
98

99
void mpDirectFullFree(SMemPool* pPool, SMPSession* pSession, void *ptr, int64_t* origSize) {
1✔
100
  int64_t oSize = taosMemSize(ptr);
1✔
101
  if (origSize) {
1!
102
    *origSize = oSize;
1✔
103
  }
104
  
105
  MP_LOCK(MP_READ, &pPool->cfgLock); // tmp test
1!
106

107
  taosMemFree(ptr);
1✔
108

109
  if (NULL != pSession) {
1!
110
    (void)atomic_sub_fetch_64(&pSession->allocMemSize, oSize);
1✔
111
    (void)atomic_sub_fetch_64(&pSession->pJob->job.allocMemSize, oSize);
1✔
112
  }
113
  
114
  (void)atomic_sub_fetch_64(&pPool->allocMemSize, oSize);
1✔
115

116
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
1!
117
}
1✔
118

119

120

121
int32_t mpDirectFullAlloc(SMemPool* pPool, SMPSession* pSession, int64_t* size, uint32_t alignment, void** ppRes) {
5✔
122
  int32_t code = TSDB_CODE_SUCCESS;
5✔
123
  void* res = NULL;
5✔
124
  int64_t nSize = *size;
5✔
125
  
126
  MP_LOCK(MP_READ, &pPool->cfgLock);
5!
127

128
  MP_ERR_JRET(mpChkFullQuota(pPool, pSession, *size));
5!
129
  
130
  res = alignment ? taosMemMallocAlign(alignment, *size) : taosMemMalloc(*size);
5✔
131
  if (NULL != res) {
5!
132
    nSize = taosMemSize(res);
5✔
133
    mpUpdateAllocSize(pPool, pSession, nSize, nSize - *size);
5✔
134
  } else {
135
    if (NULL != pSession) {
×
136
      (void)atomic_sub_fetch_64(&pSession->pJob->job.allocMemSize, *size);
×
137
    }
138
    
139
    (void)atomic_sub_fetch_64(&pPool->allocMemSize, *size);
×
140
    
141
    uError("malloc %" PRId64 " alignment %d failed, code: 0x%x", *size, alignment, terrno);
×
142

143
    code = terrno;
×
144
  }
145

146
_return:
5✔
147

148
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
5!
149
  
150
  *ppRes = res;
5✔
151
  *size = nSize;
5✔
152
  
153
  MP_RET(code);
5!
154
}
155

156
int32_t mpDirectFullRealloc(SMemPool* pPool, SMPSession* pSession, void **pPtr, int64_t* size, int64_t* origSize) {
1✔
157
  int32_t code = TSDB_CODE_SUCCESS;
1✔
158
  int64_t nSize = *size;
1✔
159

160
  MP_LOCK(MP_READ, &pPool->cfgLock);
1!
161

162
  MP_ERR_JRET(mpChkFullQuota(pPool, pSession, *size - *origSize));
1!
163
  
164
  *pPtr = taosMemRealloc(*pPtr, *size);
1✔
165
  if (NULL != *pPtr) {
1!
166
    nSize = taosMemSize(*pPtr);
1✔
167
    mpUpdateAllocSize(pPool, pSession, nSize - *origSize, nSize - *size + *origSize);
1✔
168
  } else {
169
    MP_ERR_JRET(terrno);
×
170
  }
171

172
_return:
1✔
173

174
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
1!
175

176
  if (code) {
1!
177
    mpDirectFullFree(pPool, pSession, *pPtr, origSize);
×
178
    *pPtr = NULL;
×
179
  }
180

181
  *size = nSize;
1✔
182
  
183
  return TSDB_CODE_SUCCESS;
1✔
184
}
185

186
int32_t mpDirectTrim(SMemPool* pPool, SMPSession* pSession, int32_t size, bool* trimed) {
2✔
187
  return taosMemTrim(size, trimed);
2✔
188
}
189

190

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