2021-10-21 03:06:52 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
|
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-28 06:15:44 +00:00
|
|
|
#ifndef _TD_UTIL_PAGEDBUF_H_
|
|
|
|
|
#define _TD_UTIL_PAGEDBUF_H_
|
|
|
|
|
|
|
|
|
|
#include "thash.h"
|
|
|
|
|
#include "tlist.h"
|
|
|
|
|
#include "tlockfree.h"
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-02-28 06:15:44 +00:00
|
|
|
typedef struct SPageInfo SPageInfo;
|
2022-02-08 02:21:00 +00:00
|
|
|
typedef struct SDiskbasedBuf SDiskbasedBuf;
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
typedef struct SFilePage {
|
2022-02-24 09:18:56 +00:00
|
|
|
int32_t num;
|
2021-10-21 03:06:52 +00:00
|
|
|
char data[];
|
|
|
|
|
} SFilePage;
|
|
|
|
|
|
2022-02-15 06:40:29 +00:00
|
|
|
typedef struct SDiskbasedBufStatis {
|
|
|
|
|
int64_t flushBytes;
|
|
|
|
|
int64_t loadBytes;
|
|
|
|
|
int32_t loadPages;
|
|
|
|
|
int32_t getPages;
|
|
|
|
|
int32_t releasePages;
|
|
|
|
|
int32_t flushPages;
|
|
|
|
|
} SDiskbasedBufStatis;
|
|
|
|
|
|
2021-10-21 03:06:52 +00:00
|
|
|
/**
|
|
|
|
|
* create disk-based result buffer
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @param rowSize
|
|
|
|
|
* @param pagesize
|
|
|
|
|
* @param inMemPages
|
|
|
|
|
* @param handle
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-10-13 03:09:43 +00:00
|
|
|
int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMemBufSize, const char* id,
|
|
|
|
|
const char* dir);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @param pageId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-08-29 10:47:46 +00:00
|
|
|
void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-11-25 14:54:54 +00:00
|
|
|
SArray* getDataBufPagesIdList(SDiskbasedBuf* pBuf);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the specified buffer page by id
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-23 07:10:15 +00:00
|
|
|
void* getBufPage(SDiskbasedBuf* pBuf, int32_t id);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* release the referenced buf pages
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @param page
|
|
|
|
|
*/
|
2022-02-10 08:31:23 +00:00
|
|
|
void releaseBufPage(SDiskbasedBuf* pBuf, void* page);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @param pi
|
|
|
|
|
*/
|
2022-02-10 08:31:23 +00:00
|
|
|
void releaseBufPageInfo(SDiskbasedBuf* pBuf, struct SPageInfo* pi);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the total buffer size in the format of disk file
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-10 08:31:23 +00:00
|
|
|
size_t getTotalBufSize(const SDiskbasedBuf* pBuf);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* destroy result buffer
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2021-10-21 03:06:52 +00:00
|
|
|
*/
|
2022-02-19 15:11:23 +00:00
|
|
|
void destroyDiskbasedBuf(SDiskbasedBuf* pBuf);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param pList
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-11-25 14:54:54 +00:00
|
|
|
SPageInfo* getLastPageInfo(SArray* pList);
|
2022-02-08 02:21:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param pPgInfo
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-08 07:40:13 +00:00
|
|
|
int32_t getPageId(const SPageInfo* pPgInfo);
|
2022-02-08 02:21:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the buffer page size.
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2022-02-08 02:21:00 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-10 08:31:23 +00:00
|
|
|
int32_t getBufPageSize(const SDiskbasedBuf* pBuf);
|
2022-02-08 02:21:00 +00:00
|
|
|
|
2022-02-23 11:39:43 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param pBuf
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-13 06:34:00 +00:00
|
|
|
int32_t getNumOfInMemBufPages(const SDiskbasedBuf* pBuf);
|
|
|
|
|
|
2022-02-08 02:21:00 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2022-02-10 08:31:23 +00:00
|
|
|
* @param pBuf
|
2022-02-08 02:21:00 +00:00
|
|
|
* @return
|
|
|
|
|
*/
|
2022-02-10 08:31:23 +00:00
|
|
|
bool isAllDataInMemBuf(const SDiskbasedBuf* pBuf);
|
2021-10-21 03:06:52 +00:00
|
|
|
|
2022-02-10 05:49:17 +00:00
|
|
|
/**
|
|
|
|
|
* Set the buffer page is dirty, and needs to be flushed to disk when swap out.
|
2022-02-23 11:39:43 +00:00
|
|
|
* @param pPage
|
2022-02-10 05:49:17 +00:00
|
|
|
* @param dirty
|
|
|
|
|
*/
|
2022-02-23 11:39:43 +00:00
|
|
|
void setBufPageDirty(void* pPage, bool dirty);
|
2022-02-10 08:31:23 +00:00
|
|
|
|
2022-02-23 07:54:59 +00:00
|
|
|
/**
|
|
|
|
|
* Set the compress/ no-compress flag for paged buffer, when flushing data in disk.
|
|
|
|
|
* @param pBuf
|
|
|
|
|
*/
|
|
|
|
|
void setBufPageCompressOnDisk(SDiskbasedBuf* pBuf, bool comp);
|
|
|
|
|
|
2022-02-23 11:39:43 +00:00
|
|
|
/**
|
|
|
|
|
* Set the pageId page buffer is not need
|
|
|
|
|
* @param pBuf
|
|
|
|
|
* @param pageId
|
|
|
|
|
*/
|
2024-07-25 06:49:47 +00:00
|
|
|
int32_t dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage);
|
2022-02-10 08:31:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print the statistics when closing this buffer
|
|
|
|
|
* @param pBuf
|
|
|
|
|
*/
|
2022-02-23 07:10:15 +00:00
|
|
|
void dBufSetPrintInfo(SDiskbasedBuf* pBuf);
|
2022-02-10 05:49:17 +00:00
|
|
|
|
2022-02-15 06:40:29 +00:00
|
|
|
/**
|
2022-02-23 07:10:15 +00:00
|
|
|
* Return buf statistics.
|
|
|
|
|
* @param pBuf
|
|
|
|
|
* @return
|
2022-02-15 06:40:29 +00:00
|
|
|
*/
|
|
|
|
|
SDiskbasedBufStatis getDBufStatis(const SDiskbasedBuf* pBuf);
|
|
|
|
|
|
2022-02-23 07:10:15 +00:00
|
|
|
/**
|
|
|
|
|
* Print the buffer statistics information
|
|
|
|
|
* @param pBuf
|
|
|
|
|
*/
|
|
|
|
|
void dBufPrintStatis(const SDiskbasedBuf* pBuf);
|
|
|
|
|
|
2022-06-06 05:23:04 +00:00
|
|
|
/**
|
|
|
|
|
* Set all of page buffer are not need
|
|
|
|
|
* @param pBuf
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
void clearDiskbasedBuf(SDiskbasedBuf* pBuf);
|
|
|
|
|
|
2021-10-21 03:06:52 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-02-28 06:15:44 +00:00
|
|
|
#endif // _TD_UTIL_PAGEDBUF_H_
|