qResultbuf.h 3.7 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
  int64_t   diskFileSize;        // disk file size
H
Haojun Liao 已提交
53
  FILE*     file;
H
Haojun Liao 已提交
54 55
  int32_t   allocateId;          // allocated page id
  char*     path;                // file path
56 57
  int32_t   pageSize;            // current used page size
  int32_t   inMemPages;          // numOfPages that are allocated in memory
H
Haojun Liao 已提交
58
  SHashObj* groupSet;            // id hash table
H
Haojun Liao 已提交
59
  SHashObj* all;
H
Haojun Liao 已提交
60
  SList*    lruList;
61
  void*     handle;              // for debug purpose
H
Haojun Liao 已提交
62
  void*     emptyDummyIdList;    // dummy id list
H
Haojun Liao 已提交
63 64
  bool      comp;                // compressed before flushed to disk
  void*     assistBuf;           // assistant buffer for compress data
H
Haojun Liao 已提交
65 66
  SArray*   pFree;               // free area in file
  int32_t   nextPos;             // next page flush position
67
} SDiskbasedResultBuf;
68

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

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

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

/**
 *
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
97
size_t getNumOfRowsPerPage(const SDiskbasedResultBuf* pResultBuf);
98 99 100 101 102 103 104

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

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

H
Haojun Liao 已提交
115 116 117 118 119
/**
 * release the referenced buf pages
 * @param pResultBuf
 * @param page
 */
H
Haojun Liao 已提交
120 121
void releaseResBufPage(SDiskbasedResultBuf* pResultBuf, void* page);

122 123 124 125 126
/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
127
size_t getResBufSize(const SDiskbasedResultBuf* pResultBuf);
128 129 130 131 132 133

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
H
Haojun Liao 已提交
134
size_t getNumOfResultBufGroupId(const SDiskbasedResultBuf* pResultBuf);
135 136 137 138 139

/**
 * destroy result buffer
 * @param pResultBuf
 */
H
hjxilinx 已提交
140
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle);
141 142 143 144 145 146

/**
 *
 * @param pList
 * @return
 */
H
Haojun Liao 已提交
147
int32_t getLastPageId(SIDList pList);
148 149 150 151 152

#ifdef __cplusplus
}
#endif

153
#endif  // TDENGINE_QRESULTBUF_H