-
Notifications
You must be signed in to change notification settings - Fork 11
/
db.h
182 lines (151 loc) · 4.32 KB
/
db.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once
#ifndef _WIN32
#include <pthread.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
extern bool Btree1_stats, debug;
// general object pointer
typedef union {
uint64_t bits;
uint64_t addr:48; // address part of struct below
uint64_t verNo:48; // document version number
struct {
uint32_t off; // 16 byte offset in segment
uint16_t seg; // slot index in arena segment array
union {
uint8_t step:8;
uint16_t xtra[1]; // xtra bits
uint8_t latch[1];
struct {
uint8_t mutex :1; // mutex bit
uint8_t kill :1; // kill entry
uint8_t type :6; // object type
union {
uint8_t nbyte; // number of bytes in a span node
uint8_t nslot; // number of frame slots in use
uint8_t maxidx; // maximum slot index in use
uint8_t firstx; // first array inUse to chk
uint8_t ttype; // index transaction type
uint8_t docIdx; // document key index no
int8_t rbcmp; // red/black comparison
};
};
};
};
} DbAddr, ObjId, DocId;
#define TYPE_SHIFT (6*8 + 2) // number of bits to shift type left and zero all bits
#define BYTE_SHIFT (2) // number of bits to shift type left and zero latch
#define MUTEX_BIT 0x01
#define KILL_BIT 0x02
#define TYPE_BITS 0xFC
#define ADDR_MUTEX_SET 0x0001000000000000ULL
#define ADDR_KILL_SET 0x0002000000000000ULL
#define ADDR_BITS 0x0000ffffffffffffULL
/*
typedef union {
struct {
uint32_t idx; // record ID in the segment
uint16_t seg; // arena segment number
union {
uint8_t step :8;
uint16_t xtra[1]; // xtra bits
};
};
uint64_t addr:48; // address part of struct above
uint64_t bits;
} ObjId;
*/
#define MAX_key 1024
// string /./content
typedef struct {
uint16_t len;
uint8_t str[];
} DbString;
typedef struct SkipHead_ SkipHead;
typedef struct DbMap_ DbMap;
// param slots
typedef enum {
Size = 0, // total Params structure size (int)
OnDisk, // Arena resides on disk (bool)
InitSize, // initial arena size (int)
ObjIdSize, // size of arena ObjId array element (int)
ClntSize, // Handle client area size (DbCursor, Iterator) (int)
XtraSize, // Handle client extra storage (leaf page buffer) (int)
ArenaXtra, // extra bytes in arena (DbIndex, DocStore) (int)
RecordType = 10,// arena document record type: 0=raw, 1=mvcc
MvccBlkSize, // initial mvcc document size
IdxKeyUnique = 15, // index keys uniqueness constraint (bool)
IdxKeyDeferred, // uniqueness constraints deferred to commit (bool)
IdxKeyAddr, // index key definition address
IdxKeySparse,
IdxKeyPartial, // offset of partial document
IdxKeyFlds, // store field lengths in keys (bool)
IdxType, // 0 for artree, 1 & 2 for btree (int)
IdxNoDocs, // stand-alone index file (bool)
Btree1Bits = 25, // Btree1 page size in bits (int)
Btree1Xtra, // leaf page extra bits (int)
Btree2Bits = 28, // Btree2 page size in bits (int)
Btree2Xtra, // leaf page extra bits (int)
CursorDeDup = 30, // de-duplicate cursor results (bool)
Concurrency,
ResultSetSize, // # cursor keys or # iterator docs returned (int)
UserParams = 40,
MaxParam = 64 // count of param slots defined
} ParamSlot;
typedef union {
uint64_t intVal;
uint32_t offset;
double dblVal;
uint32_t wordVal;
char charVal;
bool boolVal;
DbAddr addr;
void *obj;
} Params;
// cursor move/positioning operations
typedef enum {
OpLeft = 'l',
OpRight = 'r',
OpNext = 'n',
OpPrev = 'p',
OpFind = 'f',
OpOne = 'o',
OpBefore = 'b',
OpAfter = 'a'
} CursorOp;
// user's DbHandle
// contains the Handle ObjId bits
typedef union {
ObjId hndlId;
uint64_t hndlBits;
} DbHandle;
// DbVector definition
typedef struct {
uint8_t latch[1];
uint8_t type;
uint16_t vecLen;
uint16_t vecMax;
DbAddr next, vector[1];
} DbVector;
uint32_t vectorPush(DbMap*, DbVector *, DbAddr);
DbAddr *vectorFind(DbMap*, DbVector *, uint32_t);
#define HandleAddr(id) fetchIdSlot(hndlMap, id)
#define MapAddr(handle) (DbMap *)(db_memObj(handle->mapAddr))
#define ClntAddr(handle) getObj(hndlMap, handle->clientAddr)
DbMap *hndlMap;
// document header in docStore
#include "db_arena.h"
#include "db_index.h"
#include "db_cursor.h"
#include "db_map.h"
#include "db_error.h"
#include "db_frame.h"
#include "db_api.h"
#include "db_malloc.h"
#include "db_error.h"
#include "db_handle.h"
#include "db_object.h"
#include "db_object.h"
#include "db_handle.h"