tpagedfile.h 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * 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/>.
 */

#ifndef TDENGINE_TPAGEDFILE_H
#define TDENGINE_TPAGEDFILE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "tlist.h"
#include "thash.h"
#include "os.h"
#include "tlockfree.h"

typedef struct SArray* SIDList;
29 30
typedef struct SPageInfo SPageInfo;
typedef struct SDiskbasedBuf SDiskbasedBuf;
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

#define DEFAULT_INTERN_BUF_PAGE_SIZE  (1024L)                          // in bytes
#define PAGE_INFO_INITIALIZER         (SPageDiskInfo){-1, -1}
#define DEFAULT_PAGE_SIZE             (16384L)

typedef struct SFilePage {
  int64_t num;
  char    data[];
} SFilePage;

/**
 * create disk-based result buffer
 * @param pResultBuf
 * @param rowSize
 * @param pagesize
 * @param inMemPages
 * @param handle
 * @return
 */
50
int32_t createDiskbasedResultBuffer(SDiskbasedBuf** pResultBuf, int32_t pagesize, int32_t inMemBufSize, uint64_t qId, const char* dir);
51 52 53 54 55 56 57 58

/**
 *
 * @param pResultBuf
 * @param groupId
 * @param pageId
 * @return
 */
59
SFilePage* getNewDataBuf(SDiskbasedBuf* pResultBuf, int32_t groupId, int32_t* pageId);
60 61 62 63 64 65 66

/**
 *
 * @param pResultBuf
 * @param groupId
 * @return
 */
67
SIDList getDataBufPagesIdList(SDiskbasedBuf* pResultBuf, int32_t groupId);
68 69 70 71 72 73 74

/**
 * get the specified buffer page by id
 * @param pResultBuf
 * @param id
 * @return
 */
75
SFilePage* getResBufPage(SDiskbasedBuf* pResultBuf, int32_t id);
76 77 78 79 80 81

/**
 * release the referenced buf pages
 * @param pResultBuf
 * @param page
 */
82
void releaseResBufPage(SDiskbasedBuf* pResultBuf, void* page);
83 84 85 86 87 88

/**
 *
 * @param pResultBuf
 * @param pi
 */
89
void releaseResBufPageInfo(SDiskbasedBuf* pResultBuf, struct SPageInfo* pi);
90 91 92 93 94 95

/**
 * get the total buffer size in the format of disk file
 * @param pResultBuf
 * @return
 */
96
size_t getResBufSize(const SDiskbasedBuf* pResultBuf);
97 98 99 100 101 102

/**
 * get the number of groups in the result buffer
 * @param pResultBuf
 * @return
 */
103
size_t getNumOfResultBufGroupId(const SDiskbasedBuf* pResultBuf);
104 105 106 107 108

/**
 * destroy result buffer
 * @param pResultBuf
 */
109
void destroyResultBuf(SDiskbasedBuf* pResultBuf);
110 111 112 113 114 115

/**
 *
 * @param pList
 * @return
 */
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
struct SPageInfo* getLastPageInfo(SIDList pList);

/**
 *
 * @param pPgInfo
 * @return
 */
int32_t getPageId(const struct SPageInfo* pPgInfo);

/**
 * Return the buffer page size.
 * @param pResultBuf
 * @return
 */
int32_t getBufPageSize(const SDiskbasedBuf* pResultBuf);

/**
 *
 * @param pResultBuf
 * @return
 */
bool isAllDataInMemBuf(const SDiskbasedBuf* pResultBuf);
138 139 140 141 142 143

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TPAGEDFILE_H