tpagedbuf.h 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

S
Shengliang Guan 已提交
16 17 18 19 20 21
#ifndef _TD_UTIL_PAGEDBUF_H_
#define _TD_UTIL_PAGEDBUF_H_

#include "thash.h"
#include "tlist.h"
#include "tlockfree.h"
22 23 24 25 26

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
27 28
typedef struct SArray*       SIDList;
typedef struct SPageInfo     SPageInfo;
29
typedef struct SDiskbasedBuf SDiskbasedBuf;
30

S
Shengliang Guan 已提交
31
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L)  // in bytes
32 33

typedef struct SFilePage {
H
Haojun Liao 已提交
34
  int32_t num;
35 36 37
  char    data[];
} SFilePage;

H
Haojun Liao 已提交
38 39 40 41 42 43 44 45 46
typedef struct SDiskbasedBufStatis {
  int64_t flushBytes;
  int64_t loadBytes;
  int32_t loadPages;
  int32_t getPages;
  int32_t releasePages;
  int32_t flushPages;
} SDiskbasedBufStatis;

47 48
/**
 * create disk-based result buffer
H
Haojun Liao 已提交
49
 * @param pBuf
50 51 52 53 54 55
 * @param rowSize
 * @param pagesize
 * @param inMemPages
 * @param handle
 * @return
 */
H
Haojun Liao 已提交
56
int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMemBufSize, const char* id, const char* dir);
57 58 59

/**
 *
H
Haojun Liao 已提交
60
 * @param pBuf
61 62 63 64
 * @param groupId
 * @param pageId
 * @return
 */
H
Haojun Liao 已提交
65
void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId);
66 67 68

/**
 *
H
Haojun Liao 已提交
69
 * @param pBuf
70 71 72
 * @param groupId
 * @return
 */
H
Haojun Liao 已提交
73
SIDList getDataBufPagesIdList(SDiskbasedBuf* pBuf, int32_t groupId);
74 75 76

/**
 * get the specified buffer page by id
H
Haojun Liao 已提交
77
 * @param pBuf
78 79 80
 * @param id
 * @return
 */
H
Haojun Liao 已提交
81
void* getBufPage(SDiskbasedBuf* pBuf, int32_t id);
82 83 84

/**
 * release the referenced buf pages
H
Haojun Liao 已提交
85
 * @param pBuf
86 87
 * @param page
 */
H
Haojun Liao 已提交
88
void releaseBufPage(SDiskbasedBuf* pBuf, void* page);
89 90 91

/**
 *
H
Haojun Liao 已提交
92
 * @param pBuf
93 94
 * @param pi
 */
H
Haojun Liao 已提交
95
void releaseBufPageInfo(SDiskbasedBuf* pBuf, struct SPageInfo* pi);
96 97 98

/**
 * get the total buffer size in the format of disk file
H
Haojun Liao 已提交
99
 * @param pBuf
100 101
 * @return
 */
H
Haojun Liao 已提交
102
size_t getTotalBufSize(const SDiskbasedBuf* pBuf);
103 104 105

/**
 * get the number of groups in the result buffer
H
Haojun Liao 已提交
106
 * @param pBuf
107 108
 * @return
 */
H
Haojun Liao 已提交
109
size_t getNumOfBufGroupId(const SDiskbasedBuf* pBuf);
110 111 112

/**
 * destroy result buffer
H
Haojun Liao 已提交
113
 * @param pBuf
114
 */
H
Haojun Liao 已提交
115
void destroyDiskbasedBuf(SDiskbasedBuf* pBuf);
116 117 118 119 120 121

/**
 *
 * @param pList
 * @return
 */
122
SPageInfo* getLastPageInfo(SIDList pList);
123 124 125 126 127 128

/**
 *
 * @param pPgInfo
 * @return
 */
129
int32_t getPageId(const SPageInfo* pPgInfo);
130 131 132

/**
 * Return the buffer page size.
H
Haojun Liao 已提交
133
 * @param pBuf
134 135
 * @return
 */
H
Haojun Liao 已提交
136
int32_t getBufPageSize(const SDiskbasedBuf* pBuf);
137

H
Haojun Liao 已提交
138 139 140 141 142
/**
 *
 * @param pBuf
 * @return
 */
H
Haojun Liao 已提交
143 144
int32_t getNumOfInMemBufPages(const SDiskbasedBuf* pBuf);

145 146
/**
 *
H
Haojun Liao 已提交
147
 * @param pBuf
148 149
 * @return
 */
H
Haojun Liao 已提交
150
bool isAllDataInMemBuf(const SDiskbasedBuf* pBuf);
151

152 153
/**
 * Set the buffer page is dirty, and needs to be flushed to disk when swap out.
H
Haojun Liao 已提交
154
 * @param pPage
155 156
 * @param dirty
 */
H
Haojun Liao 已提交
157
void setBufPageDirty(void* pPage, bool dirty);
H
Haojun Liao 已提交
158

159 160 161 162 163 164
/**
 * Set the compress/ no-compress flag for paged buffer, when flushing data in disk.
 * @param pBuf
 */
void setBufPageCompressOnDisk(SDiskbasedBuf* pBuf, bool comp);

H
Haojun Liao 已提交
165 166 167 168 169 170
/**
 * Set the pageId page buffer is not need
 * @param pBuf
 * @param pageId
 */
void dBufSetBufPageRecycled(SDiskbasedBuf *pBuf, void* pPage);
H
Haojun Liao 已提交
171 172 173 174 175

/**
 * Print the statistics when closing this buffer
 * @param pBuf
 */
H
Haojun Liao 已提交
176
void dBufSetPrintInfo(SDiskbasedBuf* pBuf);
177

H
Haojun Liao 已提交
178
/**
H
Haojun Liao 已提交
179 180 181
 * Return buf statistics.
 * @param pBuf
 * @return
H
Haojun Liao 已提交
182 183 184
 */
SDiskbasedBufStatis getDBufStatis(const SDiskbasedBuf* pBuf);

H
Haojun Liao 已提交
185 186 187 188 189 190
/**
 * Print the buffer statistics information
 * @param pBuf
 */
void dBufPrintStatis(const SDiskbasedBuf* pBuf);

5
54liuyao 已提交
191 192 193 194 195 196 197
/**
 * Set all of page buffer are not need
 * @param pBuf
 * @return
 */
void clearDiskbasedBuf(SDiskbasedBuf* pBuf);

198 199 200 201
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
202
#endif  // _TD_UTIL_PAGEDBUF_H_