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

taosdata / TDengine / #4688

26 Aug 2025 02:05PM UTC coverage: 56.997% (-0.9%) from 57.894%
#4688

push

travis-ci

web-flow
fix: modify the prompt language of the taos-shell (#32758)

* fix: modify prompt language

* fix: add shell test case

* fix: modify comments

* fix: modify test case for TDengine TSDB

130660 of 292423 branches covered (44.68%)

Branch coverage included in aggregate %.

16 of 17 new or added lines in 2 files covered. (94.12%)

9459 existing lines in 157 files now uncovered.

198294 of 284715 relevant lines covered (69.65%)

4532552.29 hits per line

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

18.52
/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) {
399,018,341✔
23
  MP_CHECK_QUOTA(pPool, pJob, size);
399,018,341!
24
  
25
  return taosMemMalloc(size);
398,715,756✔
26
}
27

28

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

35

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

40
  return taosMemCalloc(num, size);
455,861,112✔
41
}
42

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

50

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

54
  if (NULL == ptr) {
189,550,238✔
55
    return mpDirectAlloc(pPool, pJob, size);
150,895,806✔
56
  }
57

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

63
  int64_t oSize = taosMemSize(ptr);
38,654,432✔
64

65
  MP_CHECK_QUOTA(pPool, pJob, size - oSize);
38,815,034!
66

67
  return taosMemRealloc(ptr, size);
38,788,396✔
68
}
69

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

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

92

93

94

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

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

UNCOV
107
  taosMemFree(ptr);
×
108

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

UNCOV
116
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
×
UNCOV
117
}
×
118

119

120

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

UNCOV
128
  MP_ERR_JRET(mpChkFullQuota(pPool, pSession, *size));
×
129
  
UNCOV
130
  res = alignment ? taosMemMallocAlign(alignment, *size) : taosMemMalloc(*size);
×
UNCOV
131
  if (NULL != res) {
×
UNCOV
132
    nSize = taosMemSize(res);
×
UNCOV
133
    mpUpdateAllocSize(pPool, pSession, nSize, nSize - *size);
×
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

UNCOV
146
_return:
×
147

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

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

UNCOV
160
  MP_LOCK(MP_READ, &pPool->cfgLock);
×
161

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

UNCOV
172
_return:
×
173

UNCOV
174
  MP_UNLOCK(MP_READ, &pPool->cfgLock);
×
175

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

UNCOV
181
  *size = nSize;
×
182
  
UNCOV
183
  return TSDB_CODE_SUCCESS;
×
184
}
185

UNCOV
186
int32_t mpDirectTrim(SMemPool* pPool, SMPSession* pSession, int32_t size, bool* trimed) {
×
UNCOV
187
  return taosMemTrim(size, trimed);
×
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