1 a0d146ed 2005-07-12 devnull typedef struct Config Config;
2 a0d146ed 2005-07-12 devnull typedef struct AMap AMap;
3 a0d146ed 2005-07-12 devnull typedef struct AMapN AMapN;
4 a0d146ed 2005-07-12 devnull typedef struct Arena Arena;
5 a0d146ed 2005-07-12 devnull typedef struct AState AState;
6 a0d146ed 2005-07-12 devnull typedef struct ArenaHead ArenaHead;
7 a0d146ed 2005-07-12 devnull typedef struct ArenaPart ArenaPart;
8 a0d146ed 2005-07-12 devnull typedef struct ArenaTail ArenaTail;
9 a0d146ed 2005-07-12 devnull typedef struct ATailStats ATailStats;
10 a0d146ed 2005-07-12 devnull typedef struct CIBlock CIBlock;
11 a0d146ed 2005-07-12 devnull typedef struct Clump Clump;
12 a0d146ed 2005-07-12 devnull typedef struct ClumpInfo ClumpInfo;
13 a0d146ed 2005-07-12 devnull typedef struct Graph Graph;
14 a0d146ed 2005-07-12 devnull typedef struct IAddr IAddr;
15 a0d146ed 2005-07-12 devnull typedef struct IBucket IBucket;
16 a0d146ed 2005-07-12 devnull typedef struct IEStream IEStream;
17 a0d146ed 2005-07-12 devnull typedef struct IEntry IEntry;
18 a0d146ed 2005-07-12 devnull typedef struct IFile IFile;
19 a0d146ed 2005-07-12 devnull typedef struct ISect ISect;
20 a0d146ed 2005-07-12 devnull typedef struct Index Index;
21 a0d146ed 2005-07-12 devnull typedef struct Lump Lump;
22 a0d146ed 2005-07-12 devnull typedef struct DBlock DBlock;
23 a0d146ed 2005-07-12 devnull typedef struct Part Part;
24 a0d146ed 2005-07-12 devnull typedef struct Statbin Statbin;
25 a0d146ed 2005-07-12 devnull typedef struct Statdesc Statdesc;
26 a0d146ed 2005-07-12 devnull typedef struct Stats Stats;
27 a0d146ed 2005-07-12 devnull typedef struct ZBlock ZBlock;
28 a0d146ed 2005-07-12 devnull typedef struct Round Round;
29 a0d146ed 2005-07-12 devnull typedef struct Bloom Bloom;
31 a0d146ed 2005-07-12 devnull #define TWID32 ((u32int)~(u32int)0)
32 a0d146ed 2005-07-12 devnull #define TWID64 ((u64int)~(u64int)0)
33 a0d146ed 2005-07-12 devnull #define TWID8 ((u8int)~(u8int)0)
37 a0d146ed 2005-07-12 devnull ABlockLog = 9, /* log2(512), the quantum for reading arenas */
38 a0d146ed 2005-07-12 devnull ANameSize = 64,
39 a0d146ed 2005-07-12 devnull MaxDiskBlock = 64*1024, /* max. allowed size for a disk block */
40 a0d146ed 2005-07-12 devnull MaxIoSize = 64*1024, /* max. allowed size for a disk io operation */
41 a0d146ed 2005-07-12 devnull PartBlank = 256*1024, /* untouched section at beginning of partition */
42 a0d146ed 2005-07-12 devnull HeadSize = 512, /* size of a header after PartBlank */
43 a0d146ed 2005-07-12 devnull MinArenaSize = 1*1024*1024, /* smallest reasonable arena size */
44 a0d146ed 2005-07-12 devnull IndexBase = 1024*1024, /* initial address to use in an index */
45 a0d146ed 2005-07-12 devnull MaxIo = 64*1024, /* max size of a single read or write operation */
46 a0d146ed 2005-07-12 devnull ICacheBits = 16, /* default bits for indexing icache */
47 a0d146ed 2005-07-12 devnull ICacheDepth = 4, /* default depth of an icache hash chain */
48 a0d146ed 2005-07-12 devnull MaxAMap = 2*1024, /* max. allowed arenas in an address mapping; must be < 32*1024 */
51 a0d146ed 2005-07-12 devnull * return codes from syncarena
53 a0d146ed 2005-07-12 devnull SyncDataErr = 1 << 0, /* problem reading the clump data */
54 a0d146ed 2005-07-12 devnull SyncCIErr = 1 << 1, /* found erroneous clump directory entries */
55 a0d146ed 2005-07-12 devnull SyncCIZero = 1 << 2, /* found unwritten clump directory entries */
56 a0d146ed 2005-07-12 devnull SyncFixErr = 1 << 3, /* error writing fixed data */
57 a0d146ed 2005-07-12 devnull SyncHeader = 1 << 4, /* altered header fields */
60 a0d146ed 2005-07-12 devnull * error severity
62 a0d146ed 2005-07-12 devnull EOk = 0, /* error expected in normal operation */
63 a0d146ed 2005-07-12 devnull EStrange, /* strange error that should be logged */
64 a0d146ed 2005-07-12 devnull ECorrupt, /* corrupted data found in arenas */
65 a0d146ed 2005-07-12 devnull EICorrupt, /* corrupted data found in index */
66 a0d146ed 2005-07-12 devnull EAdmin, /* should be brought to administrators' attention */
67 a0d146ed 2005-07-12 devnull ECrash, /* really bad internal error */
68 a0d146ed 2005-07-12 devnull EBug, /* a limitation which should be fixed */
69 a0d146ed 2005-07-12 devnull EInconsist, /* inconsistencies between index and arena */
73 a0d146ed 2005-07-12 devnull * internal disk formats for the venti archival storage system
76 a0d146ed 2005-07-12 devnull * magic numbers on disk
78 bcac59d8 2005-08-11 devnull _ClumpMagic = 0xd15cb10cU, /* clump header, deprecated */
79 a0d146ed 2005-07-12 devnull ClumpFreeMagic = 0, /* free clump; terminates active clump log */
81 bcac59d8 2005-08-11 devnull ArenaPartMagic = 0xa9e4a5e7U, /* arena partition header */
82 bcac59d8 2005-08-11 devnull ArenaMagic = 0xf2a14eadU, /* arena trailer */
83 bcac59d8 2005-08-11 devnull ArenaHeadMagic = 0xd15c4eadU, /* arena header */
85 bcac59d8 2005-08-11 devnull BloomMagic = 0xb1004eadU, /* bloom filter header */
86 a0d146ed 2005-07-12 devnull BloomMaxHash = 32,
88 bcac59d8 2005-08-11 devnull ISectMagic = 0xd15c5ec7U, /* index header */
90 a0d146ed 2005-07-12 devnull ArenaPartVersion = 3,
91 a0d146ed 2005-07-12 devnull ArenaVersion4 = 4,
92 a0d146ed 2005-07-12 devnull ArenaVersion5 = 5,
93 a0d146ed 2005-07-12 devnull BloomVersion = 1,
94 a0d146ed 2005-07-12 devnull IndexVersion = 1,
95 a0d146ed 2005-07-12 devnull ISectVersion1 = 1,
96 a0d146ed 2005-07-12 devnull ISectVersion2 = 2,
99 a0d146ed 2005-07-12 devnull * encodings of clumps on disk
101 a0d146ed 2005-07-12 devnull ClumpEErr = 0, /* can't happen */
102 a0d146ed 2005-07-12 devnull ClumpENone, /* plain */
103 a0d146ed 2005-07-12 devnull ClumpECompress, /* compressed */
104 a0d146ed 2005-07-12 devnull ClumpEMax,
107 a0d146ed 2005-07-12 devnull * sizes in bytes on disk
109 a0d146ed 2005-07-12 devnull U8Size = 1,
110 a0d146ed 2005-07-12 devnull U16Size = 2,
111 a0d146ed 2005-07-12 devnull U32Size = 4,
112 a0d146ed 2005-07-12 devnull U64Size = 8,
114 a0d146ed 2005-07-12 devnull ArenaPartSize = 4 * U32Size,
115 a0d146ed 2005-07-12 devnull ArenaSize4 = 2 * U64Size + 6 * U32Size + ANameSize + U8Size,
116 a0d146ed 2005-07-12 devnull ArenaSize5 = ArenaSize4 + U32Size,
117 a0d146ed 2005-07-12 devnull ArenaHeadSize4 = U64Size + 3 * U32Size + ANameSize,
118 a0d146ed 2005-07-12 devnull ArenaHeadSize5 = ArenaHeadSize4 + U32Size,
119 a0d146ed 2005-07-12 devnull BloomHeadSize = 4 * U32Size,
120 a0d146ed 2005-07-12 devnull ISectSize1 = 7 * U32Size + 2 * ANameSize,
121 a0d146ed 2005-07-12 devnull ISectSize2 = ISectSize1 + U32Size,
122 a0d146ed 2005-07-12 devnull ClumpInfoSize = U8Size + 2 * U16Size + VtScoreSize,
123 a0d146ed 2005-07-12 devnull ClumpSize = ClumpInfoSize + U8Size + 3 * U32Size,
124 a0d146ed 2005-07-12 devnull MaxBloomSize = 1<<(32-3), /* 2^32 bits */
125 a0d146ed 2005-07-12 devnull MaxBloomHash = 32, /* bits per score */
127 a0d146ed 2005-07-12 devnull * BUG - The various block copies that manipulate entry buckets
128 a0d146ed 2005-07-12 devnull * would be faster if we bumped IBucketSize up to 8 and IEntrySize up to 40,
129 a0d146ed 2005-07-12 devnull * so that everything is word-aligned. Buildindex is actually cpu-bound
130 a0d146ed 2005-07-12 devnull * by the (byte at a time) copying in qsort.
132 a0d146ed 2005-07-12 devnull IBucketSize = U32Size + U16Size,
133 a0d146ed 2005-07-12 devnull IEntrySize = U64Size + U32Size + 2*U16Size + 2*U8Size + VtScoreSize,
134 a0d146ed 2005-07-12 devnull IEntryTypeOff = VtScoreSize + U64Size + U32Size + 2 * U16Size,
136 a0d146ed 2005-07-12 devnull MaxClumpBlocks = (VtMaxLumpSize + ClumpSize + (1 << ABlockLog) - 1) >> ABlockLog,
139 a0d146ed 2005-07-12 devnull * dirty flags - order controls disk write order
141 a0d146ed 2005-07-12 devnull DirtyArena = 1,
142 a0d146ed 2005-07-12 devnull DirtyArenaCib,
143 a0d146ed 2005-07-12 devnull DirtyArenaTrailer,
144 a0d146ed 2005-07-12 devnull DirtyMax,
146 a0d146ed 2005-07-12 devnull VentiZZZZZZZZ
149 a0d146ed 2005-07-12 devnull extern char TraceDisk[];
150 a0d146ed 2005-07-12 devnull extern char TraceLump[];
151 a0d146ed 2005-07-12 devnull extern char TraceBlock[];
152 a0d146ed 2005-07-12 devnull extern char TraceProc[];
153 a0d146ed 2005-07-12 devnull extern char TraceWork[];
154 a0d146ed 2005-07-12 devnull extern char TraceQuiet[];
155 a0d146ed 2005-07-12 devnull extern char TraceRpc[];
158 a0d146ed 2005-07-12 devnull * results of parsing and initializing a config file
160 a0d146ed 2005-07-12 devnull struct Config
162 a0d146ed 2005-07-12 devnull char *index; /* name of the index to initialize */
163 a0d146ed 2005-07-12 devnull int naparts; /* arena partitions initialized */
164 a0d146ed 2005-07-12 devnull ArenaPart **aparts;
165 a0d146ed 2005-07-12 devnull int nsects; /* index sections initialized */
166 a0d146ed 2005-07-12 devnull ISect **sects;
167 a0d146ed 2005-07-12 devnull Bloom *bloom; /* bloom filter */
168 a0d146ed 2005-07-12 devnull u32int bcmem;
169 a0d146ed 2005-07-12 devnull u32int mem;
170 a0d146ed 2005-07-12 devnull u32int icmem;
171 a0d146ed 2005-07-12 devnull int queuewrites;
172 a0d146ed 2005-07-12 devnull char* haddr;
173 a0d146ed 2005-07-12 devnull char* vaddr;
174 a0d146ed 2005-07-12 devnull char* webroot;
178 a0d146ed 2005-07-12 devnull * a Part is the low level interface to files or disks.
179 a0d146ed 2005-07-12 devnull * there are two main types of partitions
180 a0d146ed 2005-07-12 devnull * arena paritions, which some number of arenas, each in a sub-partition.
181 a0d146ed 2005-07-12 devnull * index partition, which only have one subpartition.
183 a0d146ed 2005-07-12 devnull struct Part
185 a0d146ed 2005-07-12 devnull int fd; /* rock for accessing the disk */
186 a0d146ed 2005-07-12 devnull int mode;
187 a0d146ed 2005-07-12 devnull u64int offset;
188 a0d146ed 2005-07-12 devnull u64int size; /* size of the partiton */
189 a0d146ed 2005-07-12 devnull u32int blocksize; /* block size for reads and writes */
190 a0d146ed 2005-07-12 devnull u32int fsblocksize; /* minimum file system block size */
191 a0d146ed 2005-07-12 devnull char *name;
192 a0d146ed 2005-07-12 devnull char *filename;
193 a0d146ed 2005-07-12 devnull Channel *writechan; /* chan[dcache.nblock](DBlock*) */
197 a0d146ed 2005-07-12 devnull * a cached block from the partition
198 a0d146ed 2005-07-12 devnull * yuck -- most of this is internal structure for the cache
199 a0d146ed 2005-07-12 devnull * all other routines should only use data
201 a0d146ed 2005-07-12 devnull struct DBlock
203 a0d146ed 2005-07-12 devnull u8int *data;
205 a0d146ed 2005-07-12 devnull Part *part; /* partition in which cached */
206 a0d146ed 2005-07-12 devnull u64int addr; /* base address on the partition */
207 a0d146ed 2005-07-12 devnull u32int size; /* amount of data available, not amount allocated; should go away */
208 a0d146ed 2005-07-12 devnull u32int mode;
209 a0d146ed 2005-07-12 devnull u32int dirty;
210 a0d146ed 2005-07-12 devnull u32int dirtying;
211 a0d146ed 2005-07-12 devnull DBlock *next; /* doubly linked hash chains */
212 a0d146ed 2005-07-12 devnull DBlock *prev;
213 a0d146ed 2005-07-12 devnull u32int heap; /* index in heap table */
214 a0d146ed 2005-07-12 devnull u32int used; /* last reference times */
215 a0d146ed 2005-07-12 devnull u32int used2;
216 a0d146ed 2005-07-12 devnull u32int ref; /* reference count */
217 a0d146ed 2005-07-12 devnull RWLock lock; /* for access to data only */
218 a0d146ed 2005-07-12 devnull Channel *writedonechan;
219 a0d146ed 2005-07-12 devnull void* chanbuf[1]; /* buffer for the chan! */
223 a0d146ed 2005-07-12 devnull * a cached block from the partition
224 a0d146ed 2005-07-12 devnull * yuck -- most of this is internal structure for the cache
225 a0d146ed 2005-07-12 devnull * all other routines should only use data
226 a0d146ed 2005-07-12 devnull * double yuck -- this is mostly the same as a DBlock
228 a0d146ed 2005-07-12 devnull struct Lump
230 a0d146ed 2005-07-12 devnull Packet *data;
232 a0d146ed 2005-07-12 devnull Part *part; /* partition in which cached */
233 a0d146ed 2005-07-12 devnull u8int score[VtScoreSize]; /* score of packet */
234 a0d146ed 2005-07-12 devnull u8int type; /* type of packet */
235 a0d146ed 2005-07-12 devnull u32int size; /* amount of data allocated to hold packet */
236 a0d146ed 2005-07-12 devnull Lump *next; /* doubly linked hash chains */
237 a0d146ed 2005-07-12 devnull Lump *prev;
238 a0d146ed 2005-07-12 devnull u32int heap; /* index in heap table */
239 a0d146ed 2005-07-12 devnull u32int used; /* last reference times */
240 a0d146ed 2005-07-12 devnull u32int used2;
241 a0d146ed 2005-07-12 devnull u32int ref; /* reference count */
242 a0d146ed 2005-07-12 devnull QLock lock; /* for access to data only */
246 a0d146ed 2005-07-12 devnull * mapping between names and address ranges
248 a0d146ed 2005-07-12 devnull struct AMap
250 a0d146ed 2005-07-12 devnull u64int start;
251 a0d146ed 2005-07-12 devnull u64int stop;
252 a0d146ed 2005-07-12 devnull char name[ANameSize];
256 a0d146ed 2005-07-12 devnull * an AMap along with a length
258 a0d146ed 2005-07-12 devnull struct AMapN
261 a0d146ed 2005-07-12 devnull AMap *map;
265 a0d146ed 2005-07-12 devnull * an ArenaPart is a partition made up of Arenas
266 a0d146ed 2005-07-12 devnull * it exists because most os's don't support many partitions,
267 a0d146ed 2005-07-12 devnull * and we want to have many different Arenas
269 a0d146ed 2005-07-12 devnull struct ArenaPart
271 a0d146ed 2005-07-12 devnull Part *part;
272 a0d146ed 2005-07-12 devnull u64int size; /* size of underlying partition, rounded down to blocks */
273 a0d146ed 2005-07-12 devnull Arena **arenas;
274 a0d146ed 2005-07-12 devnull u32int tabbase; /* base address of arena table on disk */
275 a0d146ed 2005-07-12 devnull u32int tabsize; /* max. bytes in arena table */
278 a0d146ed 2005-07-12 devnull * fields stored on disk
280 a0d146ed 2005-07-12 devnull u32int version;
281 a0d146ed 2005-07-12 devnull u32int blocksize; /* "optimal" block size for reads and writes */
282 a0d146ed 2005-07-12 devnull u32int arenabase; /* base address of first arena */
285 a0d146ed 2005-07-12 devnull * stored in the arena mapping table on disk
287 a0d146ed 2005-07-12 devnull AMap *map;
288 a0d146ed 2005-07-12 devnull int narenas;
292 a0d146ed 2005-07-12 devnull * info about one block in the clump info cache
294 a0d146ed 2005-07-12 devnull struct CIBlock
296 a0d146ed 2005-07-12 devnull u32int block; /* blocks in the directory */
297 a0d146ed 2005-07-12 devnull int offset; /* offsets of one clump in the data */
298 a0d146ed 2005-07-12 devnull DBlock *data;
302 a0d146ed 2005-07-12 devnull * Statistics kept in the tail.
304 a0d146ed 2005-07-12 devnull struct ATailStats
306 a0d146ed 2005-07-12 devnull u32int clumps; /* number of clumps */
307 a0d146ed 2005-07-12 devnull u32int cclumps; /* number of compressed clumps */
308 a0d146ed 2005-07-12 devnull u64int used;
309 a0d146ed 2005-07-12 devnull u64int uncsize;
310 a0d146ed 2005-07-12 devnull u8int sealed;
314 a0d146ed 2005-07-12 devnull * Arena state - represents a point in the data log
316 a0d146ed 2005-07-12 devnull struct AState
318 a0d146ed 2005-07-12 devnull Arena *arena;
319 a0d146ed 2005-07-12 devnull u64int aa; /* index address */
320 a0d146ed 2005-07-12 devnull ATailStats stats;
324 a0d146ed 2005-07-12 devnull * an Arena is a log of Clumps, preceeded by an ArenaHeader,
325 a0d146ed 2005-07-12 devnull * and followed by a Arena, each in one disk block.
326 a0d146ed 2005-07-12 devnull * struct on disk is not always up to date, but should be self-consistent.
327 a0d146ed 2005-07-12 devnull * to sync after reboot, follow clumps starting at used until ClumpFreeMagic if found.
328 a0d146ed 2005-07-12 devnull * <struct name="Arena" type="Arena *">
329 a0d146ed 2005-07-12 devnull * <field name="name" val="s->name" type="AName"/>
330 a0d146ed 2005-07-12 devnull * <field name="version" val="s->version" type="U32int"/>
331 a0d146ed 2005-07-12 devnull * <field name="partition" val="s->part->name" type="AName"/>
332 a0d146ed 2005-07-12 devnull * <field name="blocksize" val="s->blocksize" type="U32int"/>
333 a0d146ed 2005-07-12 devnull * <field name="start" val="s->base" type="U64int"/>
334 a0d146ed 2005-07-12 devnull * <field name="stop" val="s->base+2*s->blocksize" type="U64int"/>
335 a0d146ed 2005-07-12 devnull * <field name="created" val="s->ctime" type="U32int"/>
336 a0d146ed 2005-07-12 devnull * <field name="modified" val="s->wtime" type="U32int"/>
337 a0d146ed 2005-07-12 devnull * <field name="sealed" val="s->sealed" type="Sealed"/>
338 a0d146ed 2005-07-12 devnull * <field name="score" val="s->score" type="Score"/>
339 a0d146ed 2005-07-12 devnull * <field name="clumps" val="s->clumps" type="U32int"/>
340 a0d146ed 2005-07-12 devnull * <field name="compressedclumps" val="s->cclumps" type="U32int"/>
341 a0d146ed 2005-07-12 devnull * <field name="data" val="s->uncsize" type="U64int"/>
342 a0d146ed 2005-07-12 devnull * <field name="compresseddata" val="s->used - s->clumps * ClumpSize" type="U64int"/>
343 a0d146ed 2005-07-12 devnull * <field name="storage" val="s->used + s->clumps * ClumpInfoSize" type="U64int"/>
344 a0d146ed 2005-07-12 devnull * </struct>
346 a0d146ed 2005-07-12 devnull struct Arena
348 a0d146ed 2005-07-12 devnull QLock lock; /* lock for arena fields, writing to disk */
349 a0d146ed 2005-07-12 devnull Part *part; /* partition in which arena lives */
350 a0d146ed 2005-07-12 devnull int blocksize; /* size of block to read or write */
351 a0d146ed 2005-07-12 devnull u64int base; /* base address on disk */
352 a0d146ed 2005-07-12 devnull u64int size; /* total space in the arena */
353 a0d146ed 2005-07-12 devnull u64int limit; /* storage limit for clumps */
354 a0d146ed 2005-07-12 devnull u8int score[VtScoreSize]; /* score of the entire sealed & summed arena */
356 a0d146ed 2005-07-12 devnull int clumpmax; /* ClumpInfos per block */
357 a0d146ed 2005-07-12 devnull AState mem;
358 a0d146ed 2005-07-12 devnull int inqueue;
359 a0d146ed 2005-07-12 devnull DigestState sha1;
362 a0d146ed 2005-07-12 devnull * fields stored on disk
364 a0d146ed 2005-07-12 devnull u32int version;
365 a0d146ed 2005-07-12 devnull char name[ANameSize]; /* text label */
366 a0d146ed 2005-07-12 devnull ATailStats memstats;
367 a0d146ed 2005-07-12 devnull ATailStats diskstats;
368 a0d146ed 2005-07-12 devnull u32int ctime; /* first time a block was written */
369 a0d146ed 2005-07-12 devnull u32int wtime; /* last time a block was written */
370 a0d146ed 2005-07-12 devnull u32int clumpmagic;
374 a0d146ed 2005-07-12 devnull * redundant storage of some fields at the beginning of each arena
376 a0d146ed 2005-07-12 devnull struct ArenaHead
378 a0d146ed 2005-07-12 devnull u32int version;
379 a0d146ed 2005-07-12 devnull char name[ANameSize];
380 a0d146ed 2005-07-12 devnull u32int blocksize;
381 a0d146ed 2005-07-12 devnull u64int size;
382 a0d146ed 2005-07-12 devnull u32int clumpmagic;
386 a0d146ed 2005-07-12 devnull * most interesting meta information for a clump.
387 a0d146ed 2005-07-12 devnull * stored in each clump's header and in the Arena's directory,
388 a0d146ed 2005-07-12 devnull * stored in reverse order just prior to the arena trailer
390 a0d146ed 2005-07-12 devnull struct ClumpInfo
392 a0d146ed 2005-07-12 devnull u8int type;
393 a0d146ed 2005-07-12 devnull u16int size; /* size of disk data, not including header */
394 a0d146ed 2005-07-12 devnull u16int uncsize; /* size of uncompressed data */
395 a0d146ed 2005-07-12 devnull u8int score[VtScoreSize]; /* score of the uncompressed data only */
399 a0d146ed 2005-07-12 devnull * header for an immutable clump of data
401 a0d146ed 2005-07-12 devnull struct Clump
403 a0d146ed 2005-07-12 devnull ClumpInfo info;
404 a0d146ed 2005-07-12 devnull u8int encoding;
405 a0d146ed 2005-07-12 devnull u32int creator; /* initial client which wrote the block */
406 a0d146ed 2005-07-12 devnull u32int time; /* creation at gmt seconds since 1/1/1970 */
410 a0d146ed 2005-07-12 devnull * index of all clumps according to their score
411 a0d146ed 2005-07-12 devnull * this is just a wrapper to tie together the index sections
412 a0d146ed 2005-07-12 devnull * <struct name="Index" type="Index *">
413 a0d146ed 2005-07-12 devnull * <field name="name" val="s->name" type="AName"/>
414 a0d146ed 2005-07-12 devnull * <field name="version" val="s->version" type="U32int"/>
415 a0d146ed 2005-07-12 devnull * <field name="blocksize" val="s->blocksize" type="U32int"/>
416 a0d146ed 2005-07-12 devnull * <field name="tabsize" val="s->tabsize" type="U32int"/>
417 a0d146ed 2005-07-12 devnull * <field name="buckets" val="s->buckets" type="U32int"/>
418 a0d146ed 2005-07-12 devnull * <field name="buckdiv" val="s->div" type="U32int"/>
419 a0d146ed 2005-07-12 devnull * <field name="bitblocks" val="s->div" type="U32int"/>
420 a0d146ed 2005-07-12 devnull * <field name="maxdepth" val="s->div" type="U32int"/>
421 a0d146ed 2005-07-12 devnull * <field name="bitkeylog" val="s->div" type="U32int"/>
422 a0d146ed 2005-07-12 devnull * <field name="bitkeymask" val="s->div" type="U32int"/>
423 a0d146ed 2005-07-12 devnull * <array name="sect" val="&s->smap[i]" elems="s->nsects" type="Amap"/>
424 a0d146ed 2005-07-12 devnull * <array name="amap" val="&s->amap[i]" elems="s->narenas" type="Amap"/>
425 a0d146ed 2005-07-12 devnull * <array name="arena" val="s->arenas[i]" elems="s->narenas" type="Arena"/>
426 a0d146ed 2005-07-12 devnull * </struct>
427 a0d146ed 2005-07-12 devnull * <struct name="Amap" type="AMap *">
428 a0d146ed 2005-07-12 devnull * <field name="name" val="s->name" type="AName"/>
429 a0d146ed 2005-07-12 devnull * <field name="start" val="s->start" type="U64int"/>
430 a0d146ed 2005-07-12 devnull * <field name="stop" val="s->stop" type="U64int"/>
431 a0d146ed 2005-07-12 devnull * </struct>
433 a0d146ed 2005-07-12 devnull struct Index
435 a0d146ed 2005-07-12 devnull u32int div; /* divisor for mapping score to bucket */
436 a0d146ed 2005-07-12 devnull u32int buckets; /* last bucket used in disk hash table */
437 a0d146ed 2005-07-12 devnull u32int blocksize;
438 a0d146ed 2005-07-12 devnull u32int tabsize; /* max. bytes in index config */
439 a0d146ed 2005-07-12 devnull u32int bitblocks; //XXX remove these fields
440 a0d146ed 2005-07-12 devnull u32int maxdepth;
441 a0d146ed 2005-07-12 devnull u32int bitkeylog;
442 a0d146ed 2005-07-12 devnull u32int bitkeymask;
444 a0d146ed 2005-07-12 devnull int mapalloc; /* first arena to check when adding a lump */
445 a0d146ed 2005-07-12 devnull Arena **arenas; /* arenas in the mapping */
446 a0d146ed 2005-07-12 devnull ISect **sects; /* sections which hold the buckets */
447 a0d146ed 2005-07-12 devnull Bloom *bloom; /* bloom filter */
450 a0d146ed 2005-07-12 devnull * fields stored in config file
452 a0d146ed 2005-07-12 devnull u32int version;
453 a0d146ed 2005-07-12 devnull char name[ANameSize]; /* text label */
454 a0d146ed 2005-07-12 devnull int nsects;
455 a0d146ed 2005-07-12 devnull AMap *smap; /* mapping of buckets to index sections */
456 a0d146ed 2005-07-12 devnull int narenas;
457 a0d146ed 2005-07-12 devnull AMap *amap; /* mapping from index addesses to arenas */
461 a0d146ed 2005-07-12 devnull * one part of the bucket storage for an index.
462 a0d146ed 2005-07-12 devnull * the index blocks are sequentially allocated
463 a0d146ed 2005-07-12 devnull * across all of the sections.
465 a0d146ed 2005-07-12 devnull struct ISect
467 a0d146ed 2005-07-12 devnull Part *part;
468 a0d146ed 2005-07-12 devnull int blocklog; /* log2(blocksize) */
469 a0d146ed 2005-07-12 devnull int buckmax; /* max. entries in a index bucket */
470 a0d146ed 2005-07-12 devnull u32int tabbase; /* base address of index config table on disk */
471 a0d146ed 2005-07-12 devnull u32int tabsize; /* max. bytes in index config */
472 a0d146ed 2005-07-12 devnull Channel *writechan;
473 a0d146ed 2005-07-12 devnull Channel *writedonechan;
476 a0d146ed 2005-07-12 devnull * fields stored on disk
478 a0d146ed 2005-07-12 devnull u32int version;
479 a0d146ed 2005-07-12 devnull u32int bucketmagic;
480 a0d146ed 2005-07-12 devnull char name[ANameSize]; /* text label */
481 a0d146ed 2005-07-12 devnull char index[ANameSize]; /* index owning the section */
482 a0d146ed 2005-07-12 devnull u32int blocksize; /* size of hash buckets in index */
483 a0d146ed 2005-07-12 devnull u32int blockbase; /* address of start of on disk index table */
484 a0d146ed 2005-07-12 devnull u32int blocks; /* total blocks on disk; some may be unused */
485 a0d146ed 2005-07-12 devnull u32int start; /* first bucket in this section */
486 a0d146ed 2005-07-12 devnull u32int stop; /* limit of buckets in this section */
490 a0d146ed 2005-07-12 devnull * externally interesting part of an IEntry
492 a0d146ed 2005-07-12 devnull struct IAddr
494 a0d146ed 2005-07-12 devnull u64int addr;
495 a0d146ed 2005-07-12 devnull u16int size; /* uncompressed size */
496 a0d146ed 2005-07-12 devnull u8int type; /* type of block */
497 a0d146ed 2005-07-12 devnull u8int blocks; /* arena io quanta for Clump + data */
501 a0d146ed 2005-07-12 devnull * entries in the index
502 a0d146ed 2005-07-12 devnull * kept in IBuckets in the disk index table,
503 a0d146ed 2005-07-12 devnull * cached in the memory ICache.
505 a0d146ed 2005-07-12 devnull struct IEntry
507 a0d146ed 2005-07-12 devnull u8int score[VtScoreSize];
508 a0d146ed 2005-07-12 devnull IEntry *next; /* next in hash chain */
509 a0d146ed 2005-07-12 devnull IEntry *nextdirty; /* next in dirty chain */
510 a0d146ed 2005-07-12 devnull u32int wtime; /* last write time */
511 a0d146ed 2005-07-12 devnull u16int train; /* relative train containing the most recent ref; 0 if no ref, 1 if in same car */
512 a0d146ed 2005-07-12 devnull u8int rac; /* read ahead count */
513 a0d146ed 2005-07-12 devnull u8int dirty; /* is dirty */
514 a0d146ed 2005-07-12 devnull IAddr ia;
518 a0d146ed 2005-07-12 devnull * buckets in the on disk index table
520 a0d146ed 2005-07-12 devnull struct IBucket
522 a0d146ed 2005-07-12 devnull u16int n; /* number of active indices */
523 a0d146ed 2005-07-12 devnull u32int buck; /* used by buildindex/checkindex only */
524 a0d146ed 2005-07-12 devnull u8int *data;
528 a0d146ed 2005-07-12 devnull * temporary buffers used by individual threads
530 a0d146ed 2005-07-12 devnull struct ZBlock
532 a0d146ed 2005-07-12 devnull u32int len;
533 a0d146ed 2005-07-12 devnull u32int _size;
534 a0d146ed 2005-07-12 devnull u8int *data;
535 a0d146ed 2005-07-12 devnull u8int *free;
539 a0d146ed 2005-07-12 devnull * simple input buffer for a '\0' terminated text file
541 a0d146ed 2005-07-12 devnull struct IFile
543 a0d146ed 2005-07-12 devnull char *name; /* name of the file */
544 a0d146ed 2005-07-12 devnull ZBlock *b; /* entire contents of file */
545 a0d146ed 2005-07-12 devnull u32int pos; /* current position in the file */
548 a0d146ed 2005-07-12 devnull struct Statdesc
550 a0d146ed 2005-07-12 devnull char *name;
551 a0d146ed 2005-07-12 devnull ulong max;
554 a0d146ed 2005-07-12 devnull /* keep in sync with stats.c:/statdesc and httpd.c:/graphname*/
557 a0d146ed 2005-07-12 devnull StatRpcTotal,
558 a0d146ed 2005-07-12 devnull StatRpcRead,
559 a0d146ed 2005-07-12 devnull StatRpcReadOk,
560 a0d146ed 2005-07-12 devnull StatRpcReadFail,
561 a0d146ed 2005-07-12 devnull StatRpcReadBytes,
562 a0d146ed 2005-07-12 devnull StatRpcReadTime,
563 a0d146ed 2005-07-12 devnull StatRpcReadCached,
564 a0d146ed 2005-07-12 devnull StatRpcReadCachedTime,
565 a0d146ed 2005-07-12 devnull StatRpcReadUncached,
566 a0d146ed 2005-07-12 devnull StatRpcReadUncachedTime,
567 a0d146ed 2005-07-12 devnull StatRpcWrite,
568 a0d146ed 2005-07-12 devnull StatRpcWriteNew,
569 a0d146ed 2005-07-12 devnull StatRpcWriteOld,
570 a0d146ed 2005-07-12 devnull StatRpcWriteFail,
571 a0d146ed 2005-07-12 devnull StatRpcWriteBytes,
572 a0d146ed 2005-07-12 devnull StatRpcWriteTime,
573 a0d146ed 2005-07-12 devnull StatRpcWriteNewTime,
574 a0d146ed 2005-07-12 devnull StatRpcWriteOldTime,
576 a0d146ed 2005-07-12 devnull StatLcacheHit,
577 a0d146ed 2005-07-12 devnull StatLcacheMiss,
578 a0d146ed 2005-07-12 devnull StatLcacheRead,
579 a0d146ed 2005-07-12 devnull StatLcacheWrite,
580 a0d146ed 2005-07-12 devnull StatLcacheSize,
581 a0d146ed 2005-07-12 devnull StatLcacheStall,
582 a0d146ed 2005-07-12 devnull StatLcacheReadTime,
584 a0d146ed 2005-07-12 devnull StatDcacheHit,
585 a0d146ed 2005-07-12 devnull StatDcacheMiss,
586 a0d146ed 2005-07-12 devnull StatDcacheLookup,
587 a0d146ed 2005-07-12 devnull StatDcacheRead,
588 a0d146ed 2005-07-12 devnull StatDcacheWrite,
589 a0d146ed 2005-07-12 devnull StatDcacheDirty,
590 a0d146ed 2005-07-12 devnull StatDcacheSize,
591 a0d146ed 2005-07-12 devnull StatDcacheFlush,
592 a0d146ed 2005-07-12 devnull StatDcacheStall,
593 a0d146ed 2005-07-12 devnull StatDcacheLookupTime,
595 a0d146ed 2005-07-12 devnull StatDblockStall,
596 a0d146ed 2005-07-12 devnull StatLumpStall,
598 a0d146ed 2005-07-12 devnull StatIcacheHit,
599 a0d146ed 2005-07-12 devnull StatIcacheMiss,
600 a0d146ed 2005-07-12 devnull StatIcacheRead,
601 a0d146ed 2005-07-12 devnull StatIcacheWrite,
602 a0d146ed 2005-07-12 devnull StatIcacheFill,
603 a0d146ed 2005-07-12 devnull StatIcachePrefetch,
604 a0d146ed 2005-07-12 devnull StatIcacheDirty,
605 a0d146ed 2005-07-12 devnull StatIcacheSize,
606 a0d146ed 2005-07-12 devnull StatIcacheFlush,
607 a0d146ed 2005-07-12 devnull StatIcacheStall,
608 a0d146ed 2005-07-12 devnull StatIcacheReadTime,
610 a0d146ed 2005-07-12 devnull StatBloomHit,
611 a0d146ed 2005-07-12 devnull StatBloomMiss,
612 a0d146ed 2005-07-12 devnull StatBloomFalseMiss,
613 a0d146ed 2005-07-12 devnull StatBloomLookup,
614 a0d146ed 2005-07-12 devnull StatBloomOnes,
615 a0d146ed 2005-07-12 devnull StatBloomBits,
616 a0d146ed 2005-07-12 devnull StatBloomLookupTime,
618 a0d146ed 2005-07-12 devnull StatApartRead,
619 a0d146ed 2005-07-12 devnull StatApartReadBytes,
620 a0d146ed 2005-07-12 devnull StatApartWrite,
621 a0d146ed 2005-07-12 devnull StatApartWriteBytes,
623 a0d146ed 2005-07-12 devnull StatIsectRead,
624 a0d146ed 2005-07-12 devnull StatIsectReadBytes,
625 a0d146ed 2005-07-12 devnull StatIsectWrite,
626 a0d146ed 2005-07-12 devnull StatIsectWriteBytes,
628 a0d146ed 2005-07-12 devnull StatSumRead,
629 a0d146ed 2005-07-12 devnull StatSumReadBytes,
634 a0d146ed 2005-07-12 devnull extern Statdesc statdesc[NStat];
637 a0d146ed 2005-07-12 devnull * statistics about the operation of the server
638 a0d146ed 2005-07-12 devnull * mainly for performance monitoring and profiling.
640 a0d146ed 2005-07-12 devnull struct Stats
642 a0d146ed 2005-07-12 devnull ulong now;
643 a0d146ed 2005-07-12 devnull ulong n[NStat];
646 a0d146ed 2005-07-12 devnull struct Statbin
648 a0d146ed 2005-07-12 devnull uint nsamp;
649 a0d146ed 2005-07-12 devnull uint min;
650 a0d146ed 2005-07-12 devnull uint max;
651 a0d146ed 2005-07-12 devnull uint avg;
654 a0d146ed 2005-07-12 devnull struct Graph
656 a0d146ed 2005-07-12 devnull long (*fn)(Stats*, Stats*, void*);
657 a0d146ed 2005-07-12 devnull void *arg;
658 a0d146ed 2005-07-12 devnull long t0;
659 a0d146ed 2005-07-12 devnull long t1;
660 a0d146ed 2005-07-12 devnull long min;
661 a0d146ed 2005-07-12 devnull long max;
662 a0d146ed 2005-07-12 devnull long wid;
663 a0d146ed 2005-07-12 devnull long ht;
664 a0d146ed 2005-07-12 devnull int fill;
668 a0d146ed 2005-07-12 devnull * for kicking background processes that run one round after another after another
670 a0d146ed 2005-07-12 devnull struct Round
672 a0d146ed 2005-07-12 devnull QLock lock;
673 a0d146ed 2005-07-12 devnull Rendez start;
674 a0d146ed 2005-07-12 devnull Rendez finish;
675 a0d146ed 2005-07-12 devnull Rendez delaywait;
676 a0d146ed 2005-07-12 devnull int delaytime;
677 a0d146ed 2005-07-12 devnull int delaykick;
678 a0d146ed 2005-07-12 devnull char* name;
679 a0d146ed 2005-07-12 devnull int last;
680 a0d146ed 2005-07-12 devnull int current;
681 a0d146ed 2005-07-12 devnull int next;
682 a0d146ed 2005-07-12 devnull int doanother;
686 a0d146ed 2005-07-12 devnull * Bloom filter of stored block hashes
688 a0d146ed 2005-07-12 devnull struct Bloom
690 a0d146ed 2005-07-12 devnull RWLock lk; /* protects nhash, nbits, tab, mb */
691 a0d146ed 2005-07-12 devnull QLock mod; /* one marker at a time, protects nb */
692 a0d146ed 2005-07-12 devnull int nhash;
693 a0d146ed 2005-07-12 devnull ulong size; /* bytes in tab */
694 a0d146ed 2005-07-12 devnull ulong mask; /* to produce index */
695 a0d146ed 2005-07-12 devnull u8int *data;
696 a0d146ed 2005-07-12 devnull Part *part;
697 a0d146ed 2005-07-12 devnull Channel *writechan;
698 a0d146ed 2005-07-12 devnull Channel *writedonechan;
701 a0d146ed 2005-07-12 devnull extern Index *mainindex;
702 a0d146ed 2005-07-12 devnull extern u32int maxblocksize; /* max. block size used by any partition */
703 a0d146ed 2005-07-12 devnull extern int paranoid; /* should verify hashes on disk read */
704 a0d146ed 2005-07-12 devnull extern int queuewrites; /* put all lump writes on a queue and finish later */
705 a0d146ed 2005-07-12 devnull extern int readonly; /* only allowed to read the disk data */
706 a0d146ed 2005-07-12 devnull extern Stats stats;
707 a0d146ed 2005-07-12 devnull extern u8int zeroscore[VtScoreSize];
708 a0d146ed 2005-07-12 devnull extern int compressblocks;
709 a0d146ed 2005-07-12 devnull extern int writestodevnull; /* dangerous - for performance debugging */
710 a0d146ed 2005-07-12 devnull extern int collectstats;
711 a0d146ed 2005-07-12 devnull extern QLock memdrawlock;
712 a0d146ed 2005-07-12 devnull extern int icachesleeptime;
713 a0d146ed 2005-07-12 devnull extern int arenasumsleeptime;
715 a0d146ed 2005-07-12 devnull #ifndef PLAN9PORT
716 a0d146ed 2005-07-12 devnull #pragma varargck type "V" uchar*
717 a0d146ed 2005-07-12 devnull #define ODIRECT 0