support disk usage
This commit is contained in:
parent
af80d0a6bf
commit
a6436882a2
|
@ -1748,6 +1748,18 @@ typedef struct {
|
|||
int32_t learnerProgress; // use one reservered
|
||||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t numOfTables;
|
||||
int64_t memSize;
|
||||
int64_t l1Size;
|
||||
int64_t l2Size;
|
||||
int64_t l3Size;
|
||||
int64_t cacheSize;
|
||||
int64_t walSize;
|
||||
int64_t metaSize;
|
||||
} SDbSizeStatisInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t nTimeSeries;
|
||||
|
|
|
@ -279,7 +279,7 @@ typedef struct SStoreMeta {
|
|||
int32_t (*getNumOfChildTables)(void* pVnode, int64_t uid, int64_t* numOfTables, int32_t* numOfCols);
|
||||
void (*getBasicInfo)(void* pVnode, const char** dbname, int32_t* vgId, int64_t* numOfTables,
|
||||
int64_t* numOfNormalTables);
|
||||
int32_t (*getDBSize)(void* pVnode, int64_t* dataSize, int64_t* walSize, int64_t* metaSize);
|
||||
int32_t (*getDBSize)(void* pVnode, SDbSizeStatisInfo* pInfo);
|
||||
|
||||
SMCtbCursor* (*openCtbCursor)(void* pVnode, tb_uid_t uid, int lock);
|
||||
int32_t (*resumeCtbCursor)(SMCtbCursor* pCtbCur, int8_t first);
|
||||
|
|
|
@ -100,6 +100,7 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry);
|
|||
char *taosGetDirEntryName(TdDirEntryPtr pDirEntry);
|
||||
int32_t taosCloseDir(TdDirPtr *ppDir);
|
||||
|
||||
int taosGetDirSize(const char *path, int64_t *size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -80,7 +80,7 @@ int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list);
|
|||
int32_t vnodeIsCatchUp(SVnode *pVnode);
|
||||
ESyncRole vnodeGetRole(SVnode *pVnode);
|
||||
int32_t vnodeGetArbToken(SVnode *pVnode, char *outToken);
|
||||
int32_t vnodeGetDBSize(void *pVnode, int64_t *dataSize, int64_t *walSize, int64_t *metaSize);
|
||||
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo);
|
||||
|
||||
int32_t vnodeUpdateArbTerm(SVnode *pVnode, int64_t arbTerm);
|
||||
|
||||
|
|
|
@ -94,6 +94,8 @@ typedef struct SQueryNode SQueryNode;
|
|||
#define VNODE_RSMA1_DIR "rsma1"
|
||||
#define VNODE_RSMA2_DIR "rsma2"
|
||||
#define VNODE_TQ_STREAM "stream"
|
||||
#define VNODE_CACHE_DIR "cache.rdb"
|
||||
#define VNODE_TSDB_CACHE_DIR VNODE_TSDB_DIR TD_DIRSEP VNODE_CACHE_DIR
|
||||
|
||||
#if SUSPEND_RESUME_TEST // only for test purpose
|
||||
#define VNODE_BUFPOOL_SEGMENTS 1
|
||||
|
|
|
@ -870,7 +870,7 @@ int32_t vnodeGetTableSchema(void *pVnode, int64_t uid, STSchema **pSchema, int64
|
|||
return tsdbGetTableSchema(((SVnode *)pVnode)->pMeta, uid, pSchema, suid);
|
||||
}
|
||||
|
||||
int32_t vnodeGetDBSize(void *pVnode, int64_t *dataSize, int64_t *walSize, int64_t *metaSize) {
|
||||
int32_t vnodeGetDBSize(void *pVnode, SDbSizeStatisInfo *pInfo) {
|
||||
SVnode *pVnodeObj = pVnode;
|
||||
if (pVnodeObj == NULL) {
|
||||
return TSDB_CODE_VND_NOT_EXIST;
|
||||
|
@ -878,26 +878,27 @@ int32_t vnodeGetDBSize(void *pVnode, int64_t *dataSize, int64_t *walSize, int64_
|
|||
int32_t code = 0;
|
||||
char path[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
char *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR};
|
||||
int64_t dirSize[3];
|
||||
char *dirName[] = {VNODE_TSDB_DIR, VNODE_WAL_DIR, VNODE_META_DIR, VNODE_TSDB_CACHE_DIR};
|
||||
int64_t dirSize[4];
|
||||
|
||||
vnodeGetPrimaryDir(pVnodeObj->path, pVnodeObj->diskPrimary, pVnodeObj->pTfs, path, TSDB_FILENAME_LEN);
|
||||
int32_t offset = strlen(path);
|
||||
|
||||
for (int i = 0; i < sizeof(dirName) / sizeof(dirName[0]); i++) {
|
||||
SDiskSize size = {0};
|
||||
int64_t size = {0};
|
||||
(void)snprintf(path + offset, TSDB_FILENAME_LEN, "%s%s", TD_DIRSEP, dirName[i]);
|
||||
code = taosGetDiskSize(path, &size);
|
||||
code = taosGetDirSize(path, &size);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
path[offset] = 0;
|
||||
dirSize[i] = size.used;
|
||||
dirSize[i] = size;
|
||||
}
|
||||
|
||||
*dataSize = dirSize[0];
|
||||
*walSize = dirSize[1];
|
||||
*metaSize = dirSize[2];
|
||||
pInfo->l1Size = dirSize[0];
|
||||
pInfo->walSize = dirSize[1];
|
||||
pInfo->metaSize = dirSize[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2030,7 +2030,7 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
|
||||
setOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
// return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
}
|
||||
if (pInfo->pCur == NULL) {
|
||||
pInfo->pCur = pAPI->metaFn.openTableMetaCursor(pInfo->readHandle.vnode);
|
||||
|
@ -2048,12 +2048,20 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
int32_t numOfCols = 0;
|
||||
int32_t vgId = 0;
|
||||
int64_t dbSize = 0;
|
||||
int64_t memSize = 0;
|
||||
int64_t l1Size = 0;
|
||||
int64_t l2Size = 0;
|
||||
int64_t l3Size = 0;
|
||||
int64_t walSize = 0;
|
||||
int64_t metaSize = 0;
|
||||
int64_t s3Size = 0;
|
||||
|
||||
pAPI->metaFn.getBasicInfo(pInfo->readHandle.vnode, &db, &vgId, NULL, NULL);
|
||||
|
||||
code = pAPI->metaFn.getDBSize(pInfo->readHandle.vnode, &dbSize, &walSize, &metaSize);
|
||||
SDbSizeStatisInfo info = {0};
|
||||
info.vgId = vgId;
|
||||
|
||||
code = pAPI->metaFn.getDBSize(pInfo->readHandle.vnode, &info);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
SName sn = {0};
|
||||
|
@ -2072,8 +2080,6 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
code = blockDataEnsureCapacity(p, pOperator->resultInfo.capacity);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, dbname, false);
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
@ -2089,30 +2095,30 @@ static SSDataBlock* sysTableBuildVgUsage(SOperatorInfo* pOperator) {
|
|||
totalSize += walSize;
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&walSize, false); // memtable
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&memSize, false); // memtable
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
totalSize += walSize;
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&walSize, false); // l1_size
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&l1Size, false); // l1_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
totalSize += walSize;
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&walSize, false); // l2_size
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&l2Size, false); // l2_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
|
||||
totalSize += walSize;
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&walSize, false); // l3_size
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&l3Size, false); // l3_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
totalSize += walSize;
|
||||
|
||||
pColInfoData = taosArrayGet(p->pDataBlock, numOfCols++);
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&walSize, false); // s3_size
|
||||
code = colDataSetVal(pColInfoData, numOfRows, (char*)&s3Size, false); // s3_size
|
||||
QUERY_CHECK_CODE(code, lino, _end);
|
||||
totalSize += walSize;
|
||||
|
||||
|
|
|
@ -220,7 +220,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
#endif
|
||||
|
||||
if (taosDirExist(temp)) {
|
||||
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
if (checkAccess &&
|
||||
taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -274,7 +275,8 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
|||
}
|
||||
|
||||
if (code < 0 && errno == EEXIST) {
|
||||
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
if (checkAccess &&
|
||||
taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -567,3 +569,46 @@ void taosGetCwd(char *buf, int32_t len) {
|
|||
tstrncpy(buf, "not implemented on windows", len);
|
||||
#endif
|
||||
}
|
||||
|
||||
int taosGetDirSize(const char *path, int64_t *size) {
|
||||
int32_t code;
|
||||
TdDirPtr pDir = taosOpenDir(path);
|
||||
if (pDir == NULL) {
|
||||
return code = terrno;
|
||||
}
|
||||
int32_t nBytes = 0;
|
||||
char fullPath[512] = {0};
|
||||
|
||||
int64_t totalSize = 0;
|
||||
TdDirEntryPtr de = NULL;
|
||||
while ((de = taosReadDir(pDir)) != NULL) {
|
||||
char *name = taosGetDirEntryName(de);
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
|
||||
continue;
|
||||
}
|
||||
nBytes = snprintf(fullPath, sizeof(fullPath), "%s%s%s", path, TD_DIRSEP, name);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(fullPath)) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
if (taosIsDir(fullPath)) {
|
||||
code = taosGetDirSize(fullPath, &totalSize);
|
||||
if (code != 0) {
|
||||
taosCloseDir(&pDir);
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
int64_t fileSize = 0;
|
||||
code = taosStatFile(fullPath, &fileSize, NULL, NULL);
|
||||
if (code != 0) {
|
||||
taosCloseDir(&pDir);
|
||||
return code;
|
||||
}
|
||||
totalSize += fileSize;
|
||||
}
|
||||
fullPath[0] = 0;
|
||||
}
|
||||
*size = totalSize;
|
||||
TAOS_UNUSED(taosCloseDir(&pDir));
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue