This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
storage.h
94 lines (77 loc) · 2.47 KB
/
storage.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef __STORAGE_H__
#define __STORAGE_H__
#include "postgres.h"
#include "access/htup.h"
#include "storage/bufpage.h"
#include "compression.h"
#define STORAGE_VERSION 1
#define CRYO_META_PAGE 0
/*
* XXX probably it makes sense to make page size configurable for each table
* but that would require more complex solution for cache
*/
#define CRYO_BLCKSZ (1 << 20) /* 1Mb */
/*
* PageHeaderData clone with only difference that it doesn't have flexible
* array member `pd_linp` which allows to add it as a member to other structs.
* It has the same length and the same structure as PageHeaderData so they are
* mutually convertable.
*/
typedef struct
{
PageXLogRecPtr pd_lsn;
uint16 pd_checksum;
uint16 pd_flags;
LocationIndex pd_lower;
LocationIndex pd_upper;
LocationIndex pd_special;
uint16 pd_pagesize_version;
TransactionId pd_prune_xid;
} PageHeaderClone;
typedef struct
{
PageHeaderClone base; /* to keep PageIsVerified quiet */
uint16 version; /* storage version */
uint64 ntuples; /* total number of tuples in relation */
} CryoMetaPage;
/*
* Compressed cryo page maps to several postgres blocks. Each block has
* a simple header containing block number relative to the starting one.
*/
typedef struct
{
PageHeaderClone base; /* we don't use it, but it is required by
* GenericXLogFinish() */
BlockNumber first;
BlockNumber next;
} CryoPageHeader;
/*
* First cryo page also contains additional metadata on compressed cryo block.
*/
typedef struct
{
CryoPageHeader cryo_base;
TransactionId created_xid; /* transaction performed insertion */
CompressionMethod compression_method;
uint32 compressed_size;
uint16 npages; /* number of pages for this cryo block */
} CryoFirstPageHeader;
#define CryoPageHeaderSize(page, block) \
((page)->first == block ? sizeof(CryoFirstPageHeader) : sizeof(CryoPageHeader))
/* */
typedef struct
{
uint32 off;
uint32 len;
} CryoItemId;
typedef struct
{
uint32 lower;
uint32 upper;
char data[];
} CryoDataHeader;
#define CryoDataHeaderSize offsetof(CryoDataHeader, data)
void cryo_init_page(CryoDataHeader *hdr);
int cryo_storage_insert(CryoDataHeader *d, HeapTuple tuple);
HeapTuple cryo_storage_fetch(CryoDataHeader *d, int pos, HeapTuple tuple);
#endif /* __STORAGE_H__ */