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

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

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

0.0
/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) {
×
23
  MP_CHECK_QUOTA(pPool, pJob, size);
×
24
  
25
  return taosMemMalloc(size);
×
26
}
27

28

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

35

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

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

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

50

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

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

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

63
  int64_t oSize = taosMemSize(ptr);
×
64

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

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

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

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

92

93

94

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

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

107
  taosMemFree(ptr);
×
108

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

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

119

120

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

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

146
_return:
×
147

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

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

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

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

172
_return:
×
173

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

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

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

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