summaryrefslogtreecommitdiff
path: root/include/wt_internal.in
blob: baea94548a963f05ad26cae86f90d3bc2fe74a5b (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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2008-2011 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"
#include "walk.h"

/*******************************************
 * WT_TOC support.
 *******************************************/
/*
 * WT_TOC_UPDATE --
 *	A structure to accumulate database changes on a per-thread basis.
 */
struct __wt_toc_update {
	uint32_t len;				/* Buffer original size */
	uint32_t space_avail;			/* Buffer's available memory */
	uint8_t *first_free;			/* Buffer's first free byte */

	uint16_t in;				/* Buffer chunks in use */
	uint16_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 */

	uint32_t file_id;		/* In-memory file ID */
	WT_FH	 *fh;			/* Backing file handle */

	/* Pages in the tree are WT_CHILD/WT_OFF pairs -- here's the root. */
	WT_REF	root_page;		/* Root page */
	WT_OFF	root_off;

	WT_WALK evict_walk;		/* Eviction thread's walk state */

	/*
	 * When a database is opened and/or created a hazard reference is taken
	 * on its root page, and the root page brought into memory.  If no root
	 * page has been acquired, there's usually not much work to do.
	 */
#define	WT_UNOPENED_DATABASE(idb)	((idb)->root_page.page == NULL ? 1 : 0)

	uint32_t free_addr;		/* Free page addr */
	uint32_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 */

	uint32_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_evict_tid;	/* Cache eviction server thread ID */
	pthread_t cache_read_tid;	/* Cache read server thread ID */

	TAILQ_HEAD(
	    __wt_db_qh, __idb) dbqh;	/* Locked: database list */
	u_int dbqcnt;			/* Locked: database list count */

	TAILQ_HEAD(
	    __wt_fh_qh, __wt_fh) fhqh;	/* Locked: file list */
	u_int next_file_id;		/* Locked: file ID counter */

	uint32_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 */
	uint32_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 must be
	 * able to easily copy and search it when evicting pages from 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 */

	uint32_t flags;
};

#include "serial.h"
#include "extern.h"

#if defined(__cplusplus)
}
#endif