blob: 832795169cecbf80b4af594a363a978e6a38ec75 (
plain)
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
183
184
185
186
187
188
189
190
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2008-2010 WiredTiger, Inc.
* All rights reserved.
*
* $Id$
*/
#if defined(__cplusplus)
extern "C" {
#endif
/*******************************************
* WiredTiger public include file, and configuration control.
*******************************************/
#include "wiredtiger.h"
#include "wiredtiger_config.h"
/*******************************************
* WiredTiger system include files.
*******************************************/
#include <sys/stat.h>
#include <sys/uio.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*******************************************
* WiredTiger externally maintained include files.
*******************************************/
#include "queue.h"
#include "bitstring.h"
/*******************************************
* WiredTiger internal include files.
*******************************************/
#include "mutex.h"
#include "btree.h"
#include "cache.h"
#include "debug.h"
#include "fh.h"
#include "mem.h"
#include "misc.h"
#include "stat.h"
/*******************************************
* WT_TOC support.
*******************************************/
/*
* Set/clear the WT_TOC's generation number; done in the API level, as well as
* periodically by long-running operations.
*/
#define WT_TOC_GEN_CLR(toc) \
(toc)->gen = UINT32_MAX
#define WT_TOC_GEN_SET(toc) \
(toc)->gen = (toc)->env->ienv->api_gen
/*
* WT_DATA_UPDATE --
* A structure to accumulate database changes on a per-thread basis.
*/
struct __wt_data_update {
u_int32_t len; /* Buffer original size */
u_int8_t *first_free; /* Buffer's first free byte */
u_int32_t space_avail; /* Buffer's available memory */
u_int16_t in; /* Buffer chunks in use */
u_int16_t out; /* Buffer chunks not in use */
};
/*******************************************
* Cursor handle information that doesn't persist.
*******************************************/
struct __idbc {
DBC *dbc; /* Public object */
};
/*******************************************
* Database handle information that doesn't persist.
*******************************************/
struct __idb {
DB *db; /* Public object */
TAILQ_ENTRY(__idb) q; /* Linked list of databases */
char *name; /* Database name */
mode_t mode; /* Database file create mode */
u_int32_t file_id; /* In-memory file ID */
WT_FH *fh; /* Backing file handle */
u_int32_t root_addr; /* Root page addr */
u_int32_t root_size; /* Root page size */
/*
* The root page is pinned into memory when the database is opened
* and/or created; if the root_page isn't set, there's usually not
* much to do.
*/
#define WT_UNOPENED_DATABASE(idb) ((idb)->root_page == NULL ? 1 : 0)
WT_PAGE *root_page; /* Root page */
u_int32_t free_addr; /* Free page addr */
u_int32_t free_size; /* Free page size */
void *huffman_key; /* Key huffman encoding */
void *huffman_data; /* Data huffman encoding */
WT_STATS *stats; /* Database handle statistics */
WT_STATS *dstats; /* Database file statistics */
u_int32_t flags;
};
/*******************************************
* Environment handle information that doesn't persist.
*******************************************/
struct __ienv {
WT_MTX *mtx; /* Global mutex */
pthread_t workq_tid; /* workQ thread ID */
pthread_t cache_drain_tid; /* Cache drain server thread ID */
pthread_t cache_read_tid; /* Cache read server thread ID */
TAILQ_HEAD(
__wt_db_qh, __idb) dbqh; /* Locked: database list */
TAILQ_HEAD(
__wt_fh_qh, __wt_fh) fhqh; /* Locked: file list */
u_int next_file_id; /* Locked: file ID counter */
u_int32_t volatile api_gen; /* API generation number */
/*
* WiredTiger allocates space for 50 simultaneous threads of control by
* default. The Env.toc_max_set method tunes this if the application
* needs more. Growing the number of threads dynamically is possible,
* but tricky since the workQ is walking the array without locking it.
*
* There's an array of WT_TOC pointers that reference the allocated
* array; we do it that way because we want an easy way for the workQ
* code to avoid walking the entire array when only a few threads are
* running.
*/
WT_TOC **toc; /* TOC reference */
u_int32_t toc_cnt; /* TOC count */
void *toc_array; /* TOC array */
/*
* WiredTiger allocates space for 15 hazard references in each thread of
* control, by default. The Env.hazard_max_set method tunes this if an
* application needs more, but that shouldn't happen, there's no code
* path that requires more than 15 pages at a time (and if we find one,
* the right change is to increase the default). The method is there
* just in case an application starts failing in the field.
*
* The hazard array is separate from the WT_TOC array because we want to
* be able to easily copy and search it when draining the cache.
*/
WT_PAGE **hazard; /* Hazard references array */
WT_CACHE *cache; /* Page cache */
WT_STATS *stats; /* Environment handle statistics */
WT_STATS *method_stats; /* Environment method statistics */
#ifdef HAVE_DIAGNOSTIC
WT_MTRACK *mtrack; /* Memory tracking information */
#endif
char *sep; /* Display separator line */
char err_buf[32]; /* Last-ditch error buffer */
u_int32_t flags;
};
#include "serial.h"
#include "extern.h"
#if defined(__cplusplus)
}
#endif
|