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

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

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23
#include "hash.h"
H
Haojun Liao 已提交
24 25
#include "os.h"
#include "qExtbuffer.h"
26

H
Haojun Liao 已提交
27
typedef struct SArray* SIDList;
28

29
typedef struct SDiskbasedResultBuf {
H
Haojun Liao 已提交
30 31 32 33 34 35
  int32_t   numOfRowsPerPage;
  int32_t   numOfPages;
  int64_t   totalBufSize;
  int32_t   fd;                  // data file fd
  int32_t   allocateId;          // allocated page id
  int32_t   incStep;             // minimum allocated pages
36
  void*     pBuf;                // mmap buffer pointer
H
Haojun Liao 已提交
37
  char*     path;                // file path
38 39
  int32_t   pageSize;            // current used page size
  int32_t   inMemPages;          // numOfPages that are allocated in memory
H
Haojun Liao 已提交
40 41
  SHashObj* idsTable;            // id hash table
  SIDList   list;                // for each id, there is a page id list
42 43 44

  void*     iBuf;                // inmemory buf
  void*     handle;              // for debug purpose
H
Haojun Liao 已提交
45
  void*     emptyDummyIdList;    // dummy id list
46
} SDiskbasedResultBuf;
47

48 49
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L)
#define DEFAULT_INMEM_BUF_PAGES       10
50

51 52 53 54 55 56 57
/**
 * create disk-based result buffer
 * @param pResultBuf
 * @param size
 * @param rowSize
 * @return
 */
58 59
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t numOfPages, int32_t rowSize, int32_t pagesize,
    int32_t inMemPages, void* handle);
60 61 62 63 64 65 66 67

/**
 *
 * @param pResultBuf
 * @param groupId
 * @param pageId
 * @return
 */
68
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
69 70 71 72 73 74

/**
 *
 * @param pResultBuf
 * @return
 */
75
int32_t getNumOfRowsPerPage(SDiskbasedResultBuf* pResultBuf);
76 77 78 79 80 81 82

/**
 *
 * @param pResultBuf
 * @param groupId
 * @return
 */
83
SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId);
84 85 86 87 88 89 90

/**
 * get the specified buffer page by id
 * @param pResultBuf
 * @param id
 * @return
 */
91 92
static FORCE_INLINE tFilePage* getResBufPage(SDiskbasedResultBuf* pResultBuf, int32_t id) {
  if (id < pResultBuf->inMemPages) {
H
Haojun Liao 已提交
93
    return (tFilePage*) ((char*) pResultBuf->iBuf + id * pResultBuf->pageSize);
94
  } else {
H
Haojun Liao 已提交
95
    return (tFilePage*) ((char*) pResultBuf->pBuf + (id - pResultBuf->inMemPages) * pResultBuf->pageSize);
96 97
  }
}
98 99 100 101 102
/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
103
int32_t getResBufSize(SDiskbasedResultBuf* pResultBuf);
104 105 106 107 108 109

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
110
int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf);
111 112 113 114 115

/**
 * destroy result buffer
 * @param pResultBuf
 */
H
hjxilinx 已提交
116
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle);
117 118 119 120 121 122

/**
 *
 * @param pList
 * @return
 */
H
Haojun Liao 已提交
123
int32_t getLastPageId(SIDList pList);
124 125 126 127 128 129

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_VNODEQUERYUTIL_H