tpagedbuf.h 3.4 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/>.
 */

H
Haojun Liao 已提交
16 17
#ifndef TDENGINE_TPAGEDBUF_H
#define TDENGINE_TPAGEDBUF_H
18 19 20 21 22 23 24 25 26 27 28

#ifdef __cplusplus
extern "C" {
#endif

#include "tlist.h"
#include "thash.h"
#include "os.h"
#include "tlockfree.h"

typedef struct SArray* SIDList;
29 30
typedef struct SPageInfo SPageInfo;
typedef struct SDiskbasedBuf SDiskbasedBuf;
31 32 33 34 35 36 37 38 39

#define DEFAULT_INTERN_BUF_PAGE_SIZE  (1024L)                          // in bytes
#define DEFAULT_PAGE_SIZE             (16384L)

typedef struct SFilePage {
  int64_t num;
  char    data[];
} SFilePage;

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

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

/**
 *
H
Haojun Liao 已提交
62
 * @param pBuf
63 64 65 66
 * @param groupId
 * @param pageId
 * @return
 */
H
Haojun Liao 已提交
67
SFilePage* getNewDataBuf(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId);
68 69 70

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

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

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

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

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

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

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

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

/**
 *
 * @param pPgInfo
 * @return
 */
131
int32_t getPageId(const SPageInfo* pPgInfo);
132 133 134

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

H
Haojun Liao 已提交
140 141
int32_t getNumOfInMemBufPages(const SDiskbasedBuf* pBuf);

142 143
/**
 *
H
Haojun Liao 已提交
144
 * @param pBuf
145 146
 * @return
 */
H
Haojun Liao 已提交
147
bool isAllDataInMemBuf(const SDiskbasedBuf* pBuf);
148

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

/**
 * Print the statistics when closing this buffer
 * @param pBuf
 */
void printStatisBeforeClose(SDiskbasedBuf* pBuf);
161

H
Haojun Liao 已提交
162 163 164 165 166
/**
 * return buf statistics.
 */
SDiskbasedBufStatis getDBufStatis(const SDiskbasedBuf* pBuf);

167 168 169 170
#ifdef __cplusplus
}
#endif

H
Haojun Liao 已提交
171
#endif  // TDENGINE_TPAGEDBUF_H