qResultbuf.h 4.2 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/>.
 */

16 17
#ifndef TDENGINE_QRESULTBUF_H
#define TDENGINE_QRESULTBUF_H
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23
#include <tlist.h>
H
Haojun Liao 已提交
24
#include "hash.h"
H
Haojun Liao 已提交
25 26
#include "os.h"
#include "qExtbuffer.h"
H
Haojun Liao 已提交
27
#include "tlockfree.h"
28

H
Haojun Liao 已提交
29
typedef struct SArray* SIDList;
30

H
Haojun Liao 已提交
31
typedef struct SPageDiskInfo {
32
  int32_t offset;
H
Haojun Liao 已提交
33 34 35 36
  int32_t length;
} SPageDiskInfo;

typedef struct SPageInfo {
H
Haojun Liao 已提交
37
  SListNode*    pn;       // point to list node
H
Haojun Liao 已提交
38 39 40
  int32_t       pageId;
  SPageDiskInfo info;
  void*         pData;
H
Haojun Liao 已提交
41
  bool          used;     // set current page is in used
42 43
} SPageInfo;

H
Haojun Liao 已提交
44 45 46 47 48
typedef struct SFreeListItem {
  int32_t offset;
  int32_t len;
} SFreeListItem;

H
Haojun Liao 已提交
49 50 51 52 53 54 55 56 57
typedef struct SResultBufStatis {
  int32_t flushBytes;
  int32_t loadBytes;
  int32_t getPages;
  int32_t releasePages;
  int32_t flushPages;
  int32_t fileSize;
} SResultBufStatis;

58
typedef struct SDiskbasedResultBuf {
H
Haojun Liao 已提交
59 60 61
  int32_t   numOfRowsPerPage;
  int32_t   numOfPages;
  int64_t   totalBufSize;
H
Haojun Liao 已提交
62
  int64_t   diskFileSize;        // disk file size
H
Haojun Liao 已提交
63
  FILE*     file;
H
Haojun Liao 已提交
64 65
  int32_t   allocateId;          // allocated page id
  char*     path;                // file path
66 67
  int32_t   pageSize;            // current used page size
  int32_t   inMemPages;          // numOfPages that are allocated in memory
H
Haojun Liao 已提交
68
  SHashObj* groupSet;            // id hash table
H
Haojun Liao 已提交
69
  SHashObj* all;
H
Haojun Liao 已提交
70
  SList*    lruList;
71
  void*     handle;              // for debug purpose
H
Haojun Liao 已提交
72
  void*     emptyDummyIdList;    // dummy id list
H
Haojun Liao 已提交
73 74
  bool      comp;                // compressed before flushed to disk
  void*     assistBuf;           // assistant buffer for compress data
H
Haojun Liao 已提交
75 76
  SArray*   pFree;               // free area in file
  int32_t   nextPos;             // next page flush position
H
Haojun Liao 已提交
77 78

  SResultBufStatis statis;
79
} SDiskbasedResultBuf;
80

81 82
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L)
#define DEFAULT_INMEM_BUF_PAGES       10
H
Haojun Liao 已提交
83
#define PAGE_INFO_INITIALIZER         (SPageDiskInfo){-1, -1}
84

85 86 87 88 89 90 91
/**
 * create disk-based result buffer
 * @param pResultBuf
 * @param size
 * @param rowSize
 * @return
 */
92
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t numOfPages, int32_t rowSize, int32_t pagesize,
H
Haojun Liao 已提交
93
                                    int32_t inMemPages, const void* handle);
94 95 96 97 98 99 100 101

/**
 *
 * @param pResultBuf
 * @param groupId
 * @param pageId
 * @return
 */
102
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
103 104 105 106 107 108

/**
 *
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
109
size_t getNumOfRowsPerPage(const SDiskbasedResultBuf* pResultBuf);
110 111 112 113 114 115 116

/**
 *
 * @param pResultBuf
 * @param groupId
 * @return
 */
117
SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId);
118 119 120 121 122 123 124

/**
 * get the specified buffer page by id
 * @param pResultBuf
 * @param id
 * @return
 */
H
Haojun Liao 已提交
125 126
tFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id);

H
Haojun Liao 已提交
127 128 129 130 131
/**
 * release the referenced buf pages
 * @param pResultBuf
 * @param page
 */
H
Haojun Liao 已提交
132 133
void releaseResBufPage(SDiskbasedResultBuf* pResultBuf, void* page);

H
Haojun Liao 已提交
134 135 136 137 138 139 140 141 142 143
void releaseResBufPageInfo(SDiskbasedResultBuf* pResultBuf, SPageInfo* pi);

/**
 *
 * @param pResultBuf
 * @param id
 * @return
 */
//tFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id);

144 145 146 147 148
/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
149
size_t getResBufSize(const SDiskbasedResultBuf* pResultBuf);
150 151 152 153 154 155

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
156
size_t getNumOfResultBufGroupId(const SDiskbasedResultBuf* pResultBuf);
157 158 159 160 161

/**
 * destroy result buffer
 * @param pResultBuf
 */
H
hjxilinx 已提交
162
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle);
163 164 165 166 167 168

/**
 *
 * @param pList
 * @return
 */
H
Haojun Liao 已提交
169
SPageInfo* getLastPageInfo(SIDList pList);
170 171 172 173 174

#ifdef __cplusplus
}
#endif

175
#endif  // TDENGINE_QRESULTBUF_H