qResultbuf.h 3.3 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
45
} SDiskbasedResultBuf;
46

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

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

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

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

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

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

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

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

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

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_VNODEQUERYUTIL_H