1 typedef struct Config Config;
2 typedef struct AMap AMap;
3 typedef struct AMapN AMapN;
4 typedef struct Arena Arena;
5 typedef struct AState AState;
6 typedef struct ArenaHead ArenaHead;
7 typedef struct ArenaPart ArenaPart;
8 typedef struct ArenaTail ArenaTail;
9 typedef struct ATailStats ATailStats;
10 typedef struct CIBlock CIBlock;
11 typedef struct Clump Clump;
12 typedef struct ClumpInfo ClumpInfo;
13 typedef struct Graph Graph;
14 typedef struct IAddr IAddr;
15 typedef struct IBucket IBucket;
16 typedef struct IEStream IEStream;
17 typedef struct IEntry IEntry;
18 typedef struct IFile IFile;
19 typedef struct ISect ISect;
20 typedef struct Index Index;
21 typedef struct Lump Lump;
22 typedef struct DBlock DBlock;
23 typedef struct Part Part;
24 typedef struct Statbin Statbin;
25 typedef struct Statdesc Statdesc;
26 typedef struct Stats Stats;
27 typedef struct ZBlock ZBlock;
28 typedef struct Round Round;
29 typedef struct Bloom Bloom;
31 #define TWID32 ((u32int)~(u32int)0)
32 #define TWID64 ((u64int)~(u64int)0)
33 #define TWID8 ((u8int)~(u8int)0)
37 ABlockLog = 9, /* log2(512), the quantum for reading arenas */
39 MaxDiskBlock = 64*1024, /* max. allowed size for a disk block */
40 MaxIoSize = 64*1024, /* max. allowed size for a disk io operation */
41 PartBlank = 256*1024, /* untouched section at beginning of partition */
42 HeadSize = 512, /* size of a header after PartBlank */
43 MinArenaSize = 1*1024*1024, /* smallest reasonable arena size */
44 IndexBase = 1024*1024, /* initial address to use in an index */
45 MaxIo = 64*1024, /* max size of a single read or write operation */
46 ICacheBits = 16, /* default bits for indexing icache */
47 ICacheDepth = 4, /* default depth of an icache hash chain */
48 MaxAMap = 2*1024, /* max. allowed arenas in an address mapping; must be < 32*1024 */
51 * return codes from syncarena
53 SyncDataErr = 1 << 0, /* problem reading the clump data */
54 SyncCIErr = 1 << 1, /* found erroneous clump directory entries */
55 SyncCIZero = 1 << 2, /* found unwritten clump directory entries */
56 SyncFixErr = 1 << 3, /* error writing fixed data */
57 SyncHeader = 1 << 4, /* altered header fields */
62 EOk = 0, /* error expected in normal operation */
63 EStrange, /* strange error that should be logged */
64 ECorrupt, /* corrupted data found in arenas */
65 EICorrupt, /* corrupted data found in index */
66 EAdmin, /* should be brought to administrators' attention */
67 ECrash, /* really bad internal error */
68 EBug, /* a limitation which should be fixed */
69 EInconsist, /* inconsistencies between index and arena */
73 * internal disk formats for the venti archival storage system
76 * magic numbers on disk
78 _ClumpMagic = 0xd15cb10cU, /* clump header, deprecated */
79 ClumpFreeMagic = 0, /* free clump; terminates active clump log */
81 ArenaPartMagic = 0xa9e4a5e7U, /* arena partition header */
82 ArenaMagic = 0xf2a14eadU, /* arena trailer */
83 ArenaHeadMagic = 0xd15c4eadU, /* arena header */
85 BloomMagic = 0xb1004eadU, /* bloom filter header */
88 ISectMagic = 0xd15c5ec7U, /* index header */
99 * encodings of clumps on disk
101 ClumpEErr = 0, /* can't happen */
102 ClumpENone, /* plain */
103 ClumpECompress, /* compressed */
107 * sizes in bytes on disk
114 ArenaPartSize = 4 * U32Size,
115 ArenaSize4 = 2 * U64Size + 6 * U32Size + ANameSize + U8Size,
116 ArenaSize5 = ArenaSize4 + U32Size,
117 ArenaHeadSize4 = U64Size + 3 * U32Size + ANameSize,
118 ArenaHeadSize5 = ArenaHeadSize4 + U32Size,
119 BloomHeadSize = 4 * U32Size,
120 ISectSize1 = 7 * U32Size + 2 * ANameSize,
121 ISectSize2 = ISectSize1 + U32Size,
122 ClumpInfoSize = U8Size + 2 * U16Size + VtScoreSize,
123 ClumpSize = ClumpInfoSize + U8Size + 3 * U32Size,
124 MaxBloomSize = 1<<(32-3), /* 2^32 bits */
125 MaxBloomHash = 32, /* bits per score */
127 * BUG - The various block copies that manipulate entry buckets
128 * would be faster if we bumped IBucketSize up to 8 and IEntrySize up to 40,
129 * so that everything is word-aligned. Buildindex is actually cpu-bound
130 * by the (byte at a time) copying in qsort.
132 IBucketSize = U32Size + U16Size,
133 IEntrySize = U64Size + U32Size + 2*U16Size + 2*U8Size + VtScoreSize,
134 IEntryTypeOff = VtScoreSize + U64Size + U32Size + 2 * U16Size,
136 MaxClumpBlocks = (VtMaxLumpSize + ClumpSize + (1 << ABlockLog) - 1) >> ABlockLog,
139 * dirty flags - order controls disk write order
149 extern char TraceDisk[];
150 extern char TraceLump[];
151 extern char TraceBlock[];
152 extern char TraceProc[];
153 extern char TraceWork[];
154 extern char TraceQuiet[];
155 extern char TraceRpc[];
158 * results of parsing and initializing a config file
162 char *index; /* name of the index to initialize */
163 int naparts; /* arena partitions initialized */
165 int nsects; /* index sections initialized */
167 Bloom *bloom; /* bloom filter */
178 * a Part is the low level interface to files or disks.
179 * there are two main types of partitions
180 * arena paritions, which some number of arenas, each in a sub-partition.
181 * index partition, which only have one subpartition.
185 int fd; /* rock for accessing the disk */
188 u64int size; /* size of the partiton */
189 u32int blocksize; /* block size for reads and writes */
190 u32int fsblocksize; /* minimum file system block size */
193 Channel *writechan; /* chan[dcache.nblock](DBlock*) */
197 * a cached block from the partition
198 * yuck -- most of this is internal structure for the cache
199 * all other routines should only use data
205 Part *part; /* partition in which cached */
206 u64int addr; /* base address on the partition */
207 u32int size; /* amount of data available, not amount allocated; should go away */
211 DBlock *next; /* doubly linked hash chains */
213 u32int heap; /* index in heap table */
214 u32int used; /* last reference times */
216 u32int ref; /* reference count */
217 RWLock lock; /* for access to data only */
218 Channel *writedonechan;
219 void* chanbuf[1]; /* buffer for the chan! */
223 * a cached block from the partition
224 * yuck -- most of this is internal structure for the cache
225 * all other routines should only use data
226 * double yuck -- this is mostly the same as a DBlock
232 Part *part; /* partition in which cached */
233 u8int score[VtScoreSize]; /* score of packet */
234 u8int type; /* type of packet */
235 u32int size; /* amount of data allocated to hold packet */
236 Lump *next; /* doubly linked hash chains */
238 u32int heap; /* index in heap table */
239 u32int used; /* last reference times */
241 u32int ref; /* reference count */
242 QLock lock; /* for access to data only */
246 * mapping between names and address ranges
252 char name[ANameSize];
256 * an AMap along with a length
265 * an ArenaPart is a partition made up of Arenas
266 * it exists because most os's don't support many partitions,
267 * and we want to have many different Arenas
272 u64int size; /* size of underlying partition, rounded down to blocks */
274 u32int tabbase; /* base address of arena table on disk */
275 u32int tabsize; /* max. bytes in arena table */
278 * fields stored on disk
281 u32int blocksize; /* "optimal" block size for reads and writes */
282 u32int arenabase; /* base address of first arena */
285 * stored in the arena mapping table on disk
292 * info about one block in the clump info cache
296 u32int block; /* blocks in the directory */
297 int offset; /* offsets of one clump in the data */
302 * Statistics kept in the tail.
306 u32int clumps; /* number of clumps */
307 u32int cclumps; /* number of compressed clumps */
314 * Arena state - represents a point in the data log
319 u64int aa; /* index address */
324 * an Arena is a log of Clumps, preceeded by an ArenaHeader,
325 * and followed by a Arena, each in one disk block.
326 * struct on disk is not always up to date, but should be self-consistent.
327 * to sync after reboot, follow clumps starting at used until ClumpFreeMagic if found.
328 * <struct name="Arena" type="Arena *">
329 * <field name="name" val="s->name" type="AName"/>
330 * <field name="version" val="s->version" type="U32int"/>
331 * <field name="partition" val="s->part->name" type="AName"/>
332 * <field name="blocksize" val="s->blocksize" type="U32int"/>
333 * <field name="start" val="s->base" type="U64int"/>
334 * <field name="stop" val="s->base+2*s->blocksize" type="U64int"/>
335 * <field name="created" val="s->ctime" type="U32int"/>
336 * <field name="modified" val="s->wtime" type="U32int"/>
337 * <field name="sealed" val="s->sealed" type="Sealed"/>
338 * <field name="score" val="s->score" type="Score"/>
339 * <field name="clumps" val="s->clumps" type="U32int"/>
340 * <field name="compressedclumps" val="s->cclumps" type="U32int"/>
341 * <field name="data" val="s->uncsize" type="U64int"/>
342 * <field name="compresseddata" val="s->used - s->clumps * ClumpSize" type="U64int"/>
343 * <field name="storage" val="s->used + s->clumps * ClumpInfoSize" type="U64int"/>
348 QLock lock; /* lock for arena fields, writing to disk */
349 Part *part; /* partition in which arena lives */
350 int blocksize; /* size of block to read or write */
351 u64int base; /* base address on disk */
352 u64int size; /* total space in the arena */
353 u64int limit; /* storage limit for clumps */
354 u8int score[VtScoreSize]; /* score of the entire sealed & summed arena */
356 int clumpmax; /* ClumpInfos per block */
362 * fields stored on disk
365 char name[ANameSize]; /* text label */
367 ATailStats diskstats;
368 u32int ctime; /* first time a block was written */
369 u32int wtime; /* last time a block was written */
374 * redundant storage of some fields at the beginning of each arena
379 char name[ANameSize];
386 * most interesting meta information for a clump.
387 * stored in each clump's header and in the Arena's directory,
388 * stored in reverse order just prior to the arena trailer
393 u16int size; /* size of disk data, not including header */
394 u16int uncsize; /* size of uncompressed data */
395 u8int score[VtScoreSize]; /* score of the uncompressed data only */
399 * header for an immutable clump of data
405 u32int creator; /* initial client which wrote the block */
406 u32int time; /* creation at gmt seconds since 1/1/1970 */
410 * index of all clumps according to their score
411 * this is just a wrapper to tie together the index sections
412 * <struct name="Index" type="Index *">
413 * <field name="name" val="s->name" type="AName"/>
414 * <field name="version" val="s->version" type="U32int"/>
415 * <field name="blocksize" val="s->blocksize" type="U32int"/>
416 * <field name="tabsize" val="s->tabsize" type="U32int"/>
417 * <field name="buckets" val="s->buckets" type="U32int"/>
418 * <field name="buckdiv" val="s->div" type="U32int"/>
419 * <field name="bitblocks" val="s->div" type="U32int"/>
420 * <field name="maxdepth" val="s->div" type="U32int"/>
421 * <field name="bitkeylog" val="s->div" type="U32int"/>
422 * <field name="bitkeymask" val="s->div" type="U32int"/>
423 * <array name="sect" val="&s->smap[i]" elems="s->nsects" type="Amap"/>
424 * <array name="amap" val="&s->amap[i]" elems="s->narenas" type="Amap"/>
425 * <array name="arena" val="s->arenas[i]" elems="s->narenas" type="Arena"/>
427 * <struct name="Amap" type="AMap *">
428 * <field name="name" val="s->name" type="AName"/>
429 * <field name="start" val="s->start" type="U64int"/>
430 * <field name="stop" val="s->stop" type="U64int"/>
435 u32int div; /* divisor for mapping score to bucket */
436 u32int buckets; /* last bucket used in disk hash table */
438 u32int tabsize; /* max. bytes in index config */
439 u32int bitblocks; //XXX remove these fields
444 int mapalloc; /* first arena to check when adding a lump */
445 Arena **arenas; /* arenas in the mapping */
446 ISect **sects; /* sections which hold the buckets */
447 Bloom *bloom; /* bloom filter */
450 * fields stored in config file
453 char name[ANameSize]; /* text label */
455 AMap *smap; /* mapping of buckets to index sections */
457 AMap *amap; /* mapping from index addesses to arenas */
461 * one part of the bucket storage for an index.
462 * the index blocks are sequentially allocated
463 * across all of the sections.
468 int blocklog; /* log2(blocksize) */
469 int buckmax; /* max. entries in a index bucket */
470 u32int tabbase; /* base address of index config table on disk */
471 u32int tabsize; /* max. bytes in index config */
473 Channel *writedonechan;
476 * fields stored on disk
480 char name[ANameSize]; /* text label */
481 char index[ANameSize]; /* index owning the section */
482 u32int blocksize; /* size of hash buckets in index */
483 u32int blockbase; /* address of start of on disk index table */
484 u32int blocks; /* total blocks on disk; some may be unused */
485 u32int start; /* first bucket in this section */
486 u32int stop; /* limit of buckets in this section */
490 * externally interesting part of an IEntry
495 u16int size; /* uncompressed size */
496 u8int type; /* type of block */
497 u8int blocks; /* arena io quanta for Clump + data */
501 * entries in the index
502 * kept in IBuckets in the disk index table,
503 * cached in the memory ICache.
507 u8int score[VtScoreSize];
508 IEntry *next; /* next in hash chain */
509 IEntry *nextdirty; /* next in dirty chain */
510 u32int wtime; /* last write time */
511 u16int train; /* relative train containing the most recent ref; 0 if no ref, 1 if in same car */
512 u8int rac; /* read ahead count */
513 u8int dirty; /* is dirty */
518 * buckets in the on disk index table
522 u16int n; /* number of active indices */
523 u32int buck; /* used by buildindex/checkindex only */
528 * temporary buffers used by individual threads
539 * simple input buffer for a '\0' terminated text file
543 char *name; /* name of the file */
544 ZBlock *b; /* entire contents of file */
545 u32int pos; /* current position in the file */
554 /* keep in sync with stats.c:/statdesc and httpd.c:/graphname*/
564 StatRpcReadCachedTime,
566 StatRpcReadUncachedTime,
593 StatDcacheLookupTime,
634 extern Statdesc statdesc[NStat];
637 * statistics about the operation of the server
638 * mainly for performance monitoring and profiling.
656 long (*fn)(Stats*, Stats*, void*);
668 * for kicking background processes that run one round after another after another
686 * Bloom filter of stored block hashes
690 RWLock lk; /* protects nhash, nbits, tab, mb */
691 QLock mod; /* one marker at a time, protects nb */
693 ulong size; /* bytes in tab */
694 ulong mask; /* to produce index */
698 Channel *writedonechan;
701 extern Index *mainindex;
702 extern u32int maxblocksize; /* max. block size used by any partition */
703 extern int paranoid; /* should verify hashes on disk read */
704 extern int queuewrites; /* put all lump writes on a queue and finish later */
705 extern int readonly; /* only allowed to read the disk data */
707 extern u8int zeroscore[VtScoreSize];
708 extern int compressblocks;
709 extern int writestodevnull; /* dangerous - for performance debugging */
710 extern int collectstats;
711 extern QLock memdrawlock;
712 extern int icachesleeptime;
713 extern int arenasumsleeptime;
716 #pragma varargck type "V" uchar*