chore: remove asserts of mempool

This commit is contained in:
kailixu 2024-12-13 15:56:49 +08:00
parent b58620cedf
commit 1509df2e91
4 changed files with 243 additions and 264 deletions

View File

@ -505,7 +505,7 @@ pipeline {
}
}
stage('linux test') {
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63"}
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
options { skipDefaultCheckout() }
when {
changeRequest()

View File

@ -21,9 +21,9 @@ extern "C" {
#endif
#include "os.h"
#include "tlockfree.h"
#include "thash.h"
#include "tglobal.h"
#include "thash.h"
#include "tlockfree.h"
#define MP_CHUNK_CACHE_ALLOC_BATCH_SIZE 1000
#define MP_NSCHUNK_CACHE_ALLOC_BATCH_SIZE 500
@ -36,7 +36,6 @@ extern "C" {
#define MP_MIN_MEM_CHK_INTERVAL_MS 1
#define MP_MEMORY_TRIM_INTERVAL_TIMES 500
#define MP_RETIRE_HIGH_THRESHOLD_PERCENT (0.95)
#define MP_RETIRE_MID_THRESHOLD_PERCENT (0.9)
#define MP_RETIRE_LOW_THRESHOLD_PERCENT (0.85)
@ -48,12 +47,10 @@ extern "C" {
#define MP_MIN_FREE_SIZE_AFTER_RESERVE (4 * 1024 * 1048576L)
#define MP_MIN_MEM_POOL_SIZE (5 * 1024 * 1048576L)
// FLAGS AREA
#define MP_CHUNK_FLAG_IN_USE (1 << 0)
#define MP_CHUNK_FLAG_NS_CHUNK (1 << 1)
// STAT FLAGS
#define MP_LOG_FLAG_ALL_MEM (1 << 0)
#define MP_LOG_FLAG_ALL_CHUNK (1 << 1)
@ -69,7 +66,6 @@ extern "C" {
#define MP_STAT_FLAG_LOG_ALL (0xFFFFFFFFFFFFFFFF)
// STAT PROCESURE FLAGS
#define MP_STAT_PROC_FLAG_EXEC (1 << 0)
#define MP_STAT_PROC_FLAG_INPUT_ERR (1 << 1)
@ -82,7 +78,6 @@ extern "C" {
#define MP_CTRL_FLAG_LOCK_DBG (1 << 2)
#define MP_CTRL_FLAG_LOG_MAXSIZE (1 << 3)
typedef enum EMPStatLogItem {
E_MP_STAT_LOG_MEM_MALLOC = 1,
E_MP_STAT_LOG_MEM_CALLOC,
@ -102,8 +97,8 @@ typedef enum EMPStatLogItem {
#define MP_MEM_HEADER_FLAG_NS_CHUNK (1 << 0)
typedef struct SMPMemHeader {
uint64_t flags:24;
uint64_t size:40;
uint64_t flags : 24;
uint64_t size : 40;
} SMPMemHeader;
typedef struct SMPMemTailer {
@ -111,12 +106,12 @@ typedef struct SMPMemTailer {
} SMPMemTailer;
typedef struct SMPListNode {
void *pNext;
void* pNext;
} SMPListNode;
typedef struct SMPChunk {
SMPListNode list;
char *pMemStart;
char* pMemStart;
int32_t flags;
/* KEEP ABOVE SAME WITH SMPNSChunk */
@ -125,7 +120,7 @@ typedef struct SMPChunk {
typedef struct SMPNSChunk {
SMPListNode list;
char *pMemStart;
char* pMemStart;
int32_t flags;
/* KEEP ABOVE SAME WITH SMPChunk */
@ -133,11 +128,10 @@ typedef struct SMPNSChunk {
uint64_t memBytes;
} SMPNSChunk;
typedef struct SMPCacheGroup {
int32_t nodesNum;
int32_t idleOffset;
void *pNodes;
void* pNodes;
void* pNext;
} SMPCacheGroup;
@ -151,7 +145,6 @@ typedef struct SMPStatInput {
void* pOrigMem;
} SMPStatInput;
typedef struct SMPCtrlInfo {
int64_t statFlags;
int64_t funcFlags;
@ -166,7 +159,7 @@ typedef struct SMPStatSession {
typedef struct SMPAllocStat {
int64_t allocTimes;
int64_t allocBytes;
//int64_t freeIDs[]; // TODO
// int64_t freeIDs[]; // TODO
} SMPAllocStat;
typedef struct SMPFreeStat {
@ -200,7 +193,6 @@ typedef struct SMPStatInfo {
SMPStatPos posStat;
} SMPStatInfo;
typedef struct SMPJob {
SMemPoolJob job; // KEEP IT FIRST
SMPStatInfo stat;
@ -212,25 +204,25 @@ typedef struct SMPSessionChunk {
int64_t reUseChunkNum;
int32_t srcChunkNum;
SMPChunk *srcChunkHead;
SMPChunk *srcChunkTail;
SMPChunk* srcChunkHead;
SMPChunk* srcChunkTail;
int32_t inUseChunkNum;
SMPChunk *inUseChunkHead;
SMPChunk *inUseChunkTail;
SMPChunk* inUseChunkHead;
SMPChunk* inUseChunkTail;
SMPNSChunk *inUseNSChunkHead;
SMPNSChunk *inUseNSChunkTail;
SMPNSChunk* inUseNSChunkHead;
SMPNSChunk* inUseNSChunkTail;
SMPChunk *reUseChunkHead;
SMPChunk *reUseChunkTail;
SMPChunk* reUseChunkHead;
SMPChunk* reUseChunkTail;
SMPNSChunk *reUseNSChunkHead;
SMPNSChunk *reUseNSChunkTail;
SMPNSChunk* reUseNSChunkHead;
SMPNSChunk* reUseNSChunkTail;
} SMPSessionChunk;
typedef struct SMPSession {
//SMPListNode list;
// SMPListNode list;
char* sessionId;
SMPJob* pJob;
@ -238,7 +230,7 @@ typedef struct SMPSession {
int64_t allocMemSize;
int64_t maxAllocMemSize;
//SMPSessionChunk chunk;
// SMPSessionChunk chunk;
SMPStatInfo stat;
} SMPSession;
@ -247,8 +239,8 @@ typedef struct SMPCacheGroupInfo {
int16_t nodeSize;
int64_t allocNum;
int32_t groupNum;
SMPCacheGroup *pGrpHead;
void *pIdleList;
SMPCacheGroup* pGrpHead;
void* pIdleList;
} SMPCacheGroupInfo;
typedef struct SMPChunkMgmt {
@ -268,21 +260,20 @@ typedef struct SMPChunkMgmt {
int32_t readyChunkLowNum;
int32_t readyChunkGotNum;
SRWLatch readyChunkLock;
SMPChunk *readyChunkHead;
SMPChunk *readyChunkTail;
SMPChunk* readyChunkHead;
SMPChunk* readyChunkTail;
int64_t readyNSChunkNum;
SMPChunk *readyNSChunkHead;
SMPChunk *readyNSChunkTail;
SMPChunk* readyNSChunkHead;
SMPChunk* readyNSChunkTail;
} SMPChunkMgmt;
typedef struct SMemPool {
char *name;
char* name;
int16_t slotId;
SRWLatch cfgLock;
SMemPoolCfg cfg;
//int64_t retireThreshold[3];
// int64_t retireThreshold[3];
int64_t retireUnit;
int64_t maxAllocMemSize;
@ -322,11 +313,10 @@ typedef struct SMemPoolMgmt {
extern SMemPoolMgmt gMPMgmt;
typedef int32_t (*mpAllocFunc)(SMemPool*, SMPSession*, int64_t*, uint32_t, void**);
typedef void (*mpFreeFunc)(SMemPool*, SMPSession*, void *, int64_t*);
typedef void (*mpFreeFunc)(SMemPool*, SMPSession*, void*, int64_t*);
typedef int64_t (*mpGetSizeFunc)(SMemPool*, SMPSession*, void*);
typedef int32_t (*mpReallocFunc)(SMemPool*, SMPSession*, void **, int64_t*, int64_t*);
typedef int32_t (*mpReallocFunc)(SMemPool*, SMPSession*, void**, int64_t*, int64_t*);
typedef int32_t (*mpInitSessionFunc)(SMemPool*, SMPSession*);
typedef int32_t (*mpInitFunc)(SMemPool*, char*, SMemPoolCfg*);
typedef int32_t (*mpUpdateCfgFunc)(SMemPool*);
@ -353,10 +343,13 @@ enum {
};
#define MP_STAT_FORMAT "%-8s => inErr:%10" PRId64 ", exec:%12" PRId64 ", succ:%12" PRId64 ", fail:%12" PRId64
#define MP_STAT_ORIG_FORMAT "%-8s => inErr:%10" PRId64 ", exec:%12" PRId64 ", succ:%12" PRId64 ", fail:%12" PRId64 ", oExec:%12" PRId64 ", oSucc:%12" PRId64 ", oFail:%12" PRId64
#define MP_STAT_ORIG_FORMAT \
"%-8s => inErr:%10" PRId64 ", exec:%12" PRId64 ", succ:%12" PRId64 ", fail:%12" PRId64 ", oExec:%12" PRId64 \
", oSucc:%12" PRId64 ", oFail:%12" PRId64
#define MP_STAT_VALUE(_name, _item) _name, (_item).inErr, (_item).exec, (_item).succ, (_item).fail
#define MP_STAT_ORIG_VALUE(_name, _item) _name, (_item).inErr, (_item).exec, (_item).succ, (_item).fail, (_item).origExec, (_item).origSucc, (_item).origFail
#define MP_STAT_ORIG_VALUE(_name, _item) \
_name, (_item).inErr, (_item).exec, (_item).succ, (_item).fail, (_item).origExec, (_item).origSucc, (_item).origFail
#define MP_INIT_MEM_HEADER(_header, _size, _nsChunk) \
do { \
@ -384,49 +377,42 @@ enum {
do { \
if (MP_READ == (type)) { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before try read lock"); \
uDebug("MP TRY RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
(_res) = taosRTryLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP TRY RLOCK%p:%d %s, %s:%d E", (_lock), atomic_load_32(_lock), (_res) ? "failed" : "succeed", __FILE__, __LINE__); \
ASSERTS((_res) ? atomic_load_32((_lock)) >= 0 : atomic_load_32((_lock)) > 0, "invalid lock value after try read lock"); \
uDebug("MP TRY RLOCK%p:%d %s, %s:%d E", (_lock), atomic_load_32(_lock), (_res) ? "failed" : "succeed", \
__FILE__, __LINE__); \
} \
} else { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before try write lock"); \
uDebug("MP TRY WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
(_res) = taosWTryLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP TRY WLOCK%p:%d %s, %s:%d E", (_lock), atomic_load_32(_lock), (_res) ? "failed" : "succeed", __FILE__, __LINE__); \
ASSERTS((_res) ? atomic_load_32((_lock)) >= 0 : atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value after try write lock"); \
uDebug("MP TRY WLOCK%p:%d %s, %s:%d E", (_lock), atomic_load_32(_lock), (_res) ? "failed" : "succeed", \
__FILE__, __LINE__); \
} \
} \
} while (0)
#define MP_LOCK(type, _lock) \
do { \
if (MP_READ == (type)) { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before read lock"); \
uDebug("MP RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
taosRLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value after read lock"); \
} \
} else { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before write lock"); \
uDebug("MP WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
taosWLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value after write lock"); \
} \
} \
} while (0)
@ -435,28 +421,23 @@ enum {
do { \
if (MP_READ == (type)) { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value before read unlock"); \
uDebug("MP RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
taosRUnLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after read unlock"); \
} \
} else { \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value before write unlock"); \
uDebug("MP WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
} \
taosWUnLockLatch(_lock); \
if (MP_GET_FLAG(gMPMgmt.ctrl.funcFlags, MP_CTRL_FLAG_LOCK_DBG)) { \
uDebug("MP WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after write unlock"); \
} \
} \
} while (0)
#define MP_ERR_RET(c) \
do { \
int32_t _code = c; \
@ -484,21 +465,24 @@ enum {
} \
} while (0)
#define MP_CHECK_QUOTA(_pool, _job, _size) do { \
#define MP_CHECK_QUOTA(_pool, _job, _size) \
do { \
if (*(_pool)->cfg.jobQuota > 0) { \
int64_t cAllocSize = atomic_add_fetch_64(&(_job)->job.allocMemSize, (_size)); \
if (cAllocSize > (*(_pool)->cfg.jobQuota * 1048576L)) { \
uWarn("job 0x%" PRIx64 " remainSession:%d allocSize %" PRId64 " is over than quota %dMB", (_job)->job.jobId, (_job)->job.remainSession, cAllocSize, *(_pool)->cfg.jobQuota); \
uWarn("job 0x%" PRIx64 " remainSession:%d allocSize %" PRId64 " is over than quota %dMB", (_job)->job.jobId, \
(_job)->job.remainSession, cAllocSize, *(_pool)->cfg.jobQuota); \
(_pool)->cfg.cb.reachFp(pJob->job.jobId, (_job)->job.clientId, TSDB_CODE_QRY_REACH_QMEM_THRESHOLD); \
mpSchedTrim(NULL); \
terrno = TSDB_CODE_QRY_REACH_QMEM_THRESHOLD; \
return NULL; \
} else { \
uDebug("job 0x%" PRIx64 " remainSession:%d allocSize %" PRId64 " is lower than quota %dMB", (_job)->job.jobId, (_job)->job.remainSession, cAllocSize, *(_pool)->cfg.jobQuota); \
uDebug("job 0x%" PRIx64 " remainSession:%d allocSize %" PRId64 " is lower than quota %dMB", (_job)->job.jobId, \
(_job)->job.remainSession, cAllocSize, *(_pool)->cfg.jobQuota); \
} \
} \
if (atomic_load_64(&tsCurrentAvailMemorySize) <= ((_pool)->cfg.reserveSize + (_size))) { \
uWarn("%s pool sysAvailMemSize %" PRId64 " can't alloc %" PRId64" while keeping reserveSize %" PRId64 " bytes", \
uWarn("%s pool sysAvailMemSize %" PRId64 " can't alloc %" PRId64 " while keeping reserveSize %" PRId64 " bytes", \
(_pool)->name, atomic_load_64(&tsCurrentAvailMemorySize), (_size), (_pool)->cfg.reserveSize); \
(_pool)->cfg.cb.reachFp((_job)->job.jobId, (_job)->job.clientId, TSDB_CODE_QRY_QUERY_MEM_EXHAUSTED); \
mpSchedTrim(NULL); \
@ -507,32 +491,30 @@ enum {
} \
} while (0)
// direct
void* mpDirectAlloc(SMemPool* pPool, SMPJob* pJob, int64_t size);
void* mpDirectAlignAlloc(SMemPool* pPool, SMPJob* pJob, uint32_t alignment, int64_t size);
void* mpDirectCalloc(SMemPool* pPool, SMPJob* pJob, int64_t num, int64_t size);
void mpDirectFree(SMemPool* pPool, SMPJob* pJob, void *ptr);
void mpDirectFree(SMemPool* pPool, SMPJob* pJob, void* ptr);
void* mpDirectRealloc(SMemPool* pPool, SMPJob* pJob, void* ptr, int64_t size);
void* mpDirectStrdup(SMemPool* pPool, SMPJob* pJob, const void* ptr);
void* mpDirectStrndup(SMemPool* pPool, SMPJob* pJob, const void* ptr, int64_t size);
int32_t mpDirectFullAlloc(SMemPool* pPool, SMPSession* pSession, int64_t* size, uint32_t alignment, void** ppRes);
int64_t mpDirectGetMemSize(SMemPool* pPool, SMPSession* pSession, void *ptr);
void mpDirectFullFree(SMemPool* pPool, SMPSession* pSession, void *ptr, int64_t* origSize);
int32_t mpDirectFullRealloc(SMemPool* pPool, SMPSession* pSession, void **pPtr, int64_t* size, int64_t* origSize);
int64_t mpDirectGetMemSize(SMemPool* pPool, SMPSession* pSession, void* ptr);
void mpDirectFullFree(SMemPool* pPool, SMPSession* pSession, void* ptr, int64_t* origSize);
int32_t mpDirectFullRealloc(SMemPool* pPool, SMPSession* pSession, void** pPtr, int64_t* size, int64_t* origSize);
int32_t mpDirectTrim(SMemPool* pPool, SMPSession* pSession, int32_t size, bool* trimed);
// chunk
int32_t mpChunkInit(SMemPool* pPool, char* poolName, SMemPoolCfg* cfg);
int64_t mpChunkGetMemSize(SMemPool* pPool, SMPSession* pSession, void *ptr);
int64_t mpChunkGetMemSize(SMemPool* pPool, SMPSession* pSession, void* ptr);
int32_t mpChunkAlloc(SMemPool* pPool, SMPSession* pSession, int64_t* size, uint32_t alignment, void** ppRes);
void mpChunkFree(SMemPool* pPool, SMPSession* pSession, void *ptr, int64_t* origSize);
int32_t mpChunkRealloc(SMemPool* pPool, SMPSession* pSession, void **pPtr, int64_t* size, int64_t* origSize);
void mpChunkFree(SMemPool* pPool, SMPSession* pSession, void* ptr, int64_t* origSize);
int32_t mpChunkRealloc(SMemPool* pPool, SMPSession* pSession, void** pPtr, int64_t* size, int64_t* origSize);
int32_t mpChunkInitSession(SMemPool* pPool, SMPSession* pSession);
int32_t mpChunkUpdateCfg(SMemPool* pPool);
int32_t mpPopIdleNode(SMemPool* pPool, SMPCacheGroupInfo* pInfo, void** ppRes);
int32_t mpChkFullQuota(SMemPool* pPool, SMPSession* pSession, int64_t size);
void mpUpdateAllocSize(SMemPool* pPool, SMPSession* pSession, int64_t size, int64_t addSize);
@ -540,8 +522,6 @@ int32_t mpAddCacheGroup(SMemPool* pPool, SMPCacheGroupInfo* pInfo, SMPCacheGroup
int32_t mpMalloc(SMemPool* pPool, SMPSession* pSession, int64_t* size, uint32_t alignment, void** ppRes);
void mpSchedTrim(int64_t* loopTimes);
#ifdef __cplusplus
}
#endif

View File

@ -808,7 +808,7 @@ void mpLogPosStat(SMPStatPos* pStat, EMPStatLogItem item, SMPStatInput* pInput,
MP_ERR_JRET(code);
}
ASSERT((pInput->pOrigMem && pInput->origSize > 0) || (NULL == pInput->pOrigMem && pInput->origSize == 0));
// ASSSRT((pInput->pOrigMem && pInput->origSize > 0) || (NULL == pInput->pOrigMem && pInput->origSize == 0));
if (pInput->pOrigMem && pInput->origSize > 0) {
code = taosHashRemove(pStat->remainHash, &pInput->pOrigMem, POINTER_BYTES);

View File

@ -186,8 +186,7 @@ class TDTestCase:
raise Exception(repr(e))
finally:
if infoFile:
infoFile.flush()
# close()
infoFile.close()
def s3_check_show_grants_granted(self):
tdLog.printNoPrefix("======== test show grants granted: ")