VtBlock, VtCache, vtblockcopy, vtblockduplock, vtblockput, vtblockwrite,
vtcachealloc, vtcacheallocblock, vtcachefree, vtcacheglobal, vtcachelocal,
vtcachesetwrite, vtglobaltolocal, vtlocaltoglobal - Venti block cache
typedef struct VtBlock
VtCache* vtcachealloc(VtConn *z, ulong maxmem);
void vtcachefree(VtCache *c);
u32int vtglobaltolocal(uchar score[VtScoreSize])
void vtlocaltoglobal(u32int local, uchar score[VtScoreSize])
VtBlock* vtcacheallocblock(VtCache *c, int type, ulong size);
VtBlock* vtcachelocal(VtCache *c, u32int addr, int type);
VtBlock* vtcacheglobal(VtCache *c, uchar[VtScoreSize], int type, ulong size);
void vtblockput(VtBlock *b);
void vtblockduplock(VtBlock *b);
int vtblockwrite(VtBlock *b);
void vtcachesetwrite(VtCache *c,
int (*write)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
VtBlock* vtblockcopy(VtBlock *b);
These functions provide access to a simple in-memory cache of blocks already
stored on a Venti server and blocks that will eventually be stored on a Venti
represents a venti data block. Blocks stored on a venti server,
called global blocks
, are named by the SHA1 hash of their contents.
This hash is recorded as the block's score
. Such blocks are immutable.
The cache also stores mutable blocks that have not yet been written to a venti
server. These blocks are called local blocks
, and have special scores
that are 16 zero bytes followed by a 4-byte big-endian address
address is an index into the internal set of cache blocks.
The user-visible contents of a VtBlock
, a pointer to the
, the venti block type; score
, the block's score; and
, the block's cache address.
allocates a new cache using the client connection z
(3) and venti-client
(3)), with maxmem
bytes of memory.
frees a cache and all the associated blocks.
returns the local address corresponding to the given
. If passed a global score, vtglobaltolocal
the special constant NilBlock
the opposite, setting score
to the local score for the cache address
allocates a new local block with the given type
retrieves the local block at address addr
cache. The given type
must match the type of the block found at
retrieves the block with the given score
from the cache, consulting the Venti server if
necessary. If passed a local score, vtcacheglobal
The block references returned by vtcacheallocblock
must be released when no longer needed.
releases such a reference.
It is occasionally convenient to have multiple variables refer to the same
increments the block's reference count so that an
will be required in order to release the block.
writes a local block to the Venti server, changing the block
to a global block. It calls the cache's write
function to write the
block to the server. The default write
function is vtwrite
is used by clients to install replacement functions
that run writes in the background or perform other additional processing.
copies a block in preparation for modifying its contents. The
old block may be a local or global block, but the new block will be a local
The cache only evicts global blocks. Local blocks can only leave the cache via
, which turns them into global blocks, making them
candidates for eviction.
If a new cache block must be allocated (for vtcacheallocblock
, or vtblockcopy
), but the
cache is filled (with local blocks and blocks that have not yet been released
), the library prints the score and reference count of
every block in the cache and then aborts. A full cache indicates either that
the cache is too small, or, more commonly, that cache blocks are being leaked.