qResultbuf.h 3.6 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 37 38 39 40
  int32_t length;
} SPageDiskInfo;

typedef struct SPageInfo {
  int32_t       pageId;
  SPageDiskInfo info;
  void*         pData;
  T_REF_DECLARE();
41 42
} SPageInfo;

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

48
typedef struct SDiskbasedResultBuf {
H
Haojun Liao 已提交
49 50 51
  int32_t   numOfRowsPerPage;
  int32_t   numOfPages;
  int64_t   totalBufSize;
H
Haojun Liao 已提交
52 53
//  int32_t   fd;
  FILE*     file;
H
Haojun Liao 已提交
54
  int32_t   allocateId;          // allocated page id
H
Haojun Liao 已提交
55
//  int32_t   incStep;             // minimum allocated pages
56
  void*     pBuf;                // mmap buffer pointer
H
Haojun Liao 已提交
57
  char*     path;                // file path
58 59
  int32_t   pageSize;            // current used page size
  int32_t   inMemPages;          // numOfPages that are allocated in memory
H
Haojun Liao 已提交
60
  SHashObj* idsTable;            // id hash table
H
Haojun Liao 已提交
61 62
  SHashObj* all;
  SList*    pPageList;
63
  void*     handle;              // for debug purpose
H
Haojun Liao 已提交
64
  void*     emptyDummyIdList;    // dummy id list
65
  bool      comp;
H
Haojun Liao 已提交
66 67
  SArray*   pFree;               // free area in file
  int32_t   nextPos;             // next page flush position
68
} SDiskbasedResultBuf;
69

70 71
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L)
#define DEFAULT_INMEM_BUF_PAGES       10
H
Haojun Liao 已提交
72
#define PAGE_INFO_INITIALIZER         (SPageDiskInfo){-1, -1}
73

74 75 76 77 78 79 80
/**
 * create disk-based result buffer
 * @param pResultBuf
 * @param size
 * @param rowSize
 * @return
 */
81
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t numOfPages, int32_t rowSize, int32_t pagesize,
H
Haojun Liao 已提交
82
                                    int32_t inMemPages, const void* handle);
83 84 85 86 87 88 89 90

/**
 *
 * @param pResultBuf
 * @param groupId
 * @param pageId
 * @return
 */
91
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
92 93 94 95 96 97

/**
 *
 * @param pResultBuf
 * @return
 */
98
int32_t getNumOfRowsPerPage(SDiskbasedResultBuf* pResultBuf);
99 100 101 102 103 104 105

/**
 *
 * @param pResultBuf
 * @param groupId
 * @return
 */
106
SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId);
107 108 109 110 111 112 113

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

void releaseResBufPage(SDiskbasedResultBuf* pResultBuf, void* page);

118 119 120 121 122
/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
123
int32_t getResBufSize(SDiskbasedResultBuf* pResultBuf);
124 125 126 127 128 129

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
130
int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf);
131 132 133 134 135

/**
 * destroy result buffer
 * @param pResultBuf
 */
H
hjxilinx 已提交
136
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle);
137 138 139 140 141 142

/**
 *
 * @param pList
 * @return
 */
H
Haojun Liao 已提交
143
int32_t getLastPageId(SIDList pList);
144 145 146 147 148

#ifdef __cplusplus
}
#endif

149
#endif  // TDENGINE_QRESULTBUF_H