holiman / billy

Very simple datastore
BSD 3-Clause "New" or "Revised" License
50 stars 7 forks source link

Billy

Go Reference CircleCI codecov DeepSource

Billy (previously BagDB) is a super simple datastore. It can't quite be called a database, because it avoids implementing some of the most complex parts of an actual database. It's intended to be used in very particular circumstances.

billy

It is named after the bookcase, because it's very much like a bookcase, with N shelves of various heights.

Cheats

A 'proper' database is very complex, and has to solve several difficult problems:

What if?

But what if we don't need to maintain an index? There are two obvious cavats here:

What are the upsides?

In practice

For the proposal by @karalabe about implementing a disk-backed transaction pool for geth, we have very special circumstances:

shelves

Compaction

Saying that we can't do compaction is not strictly true: there are two things that can be (and are) done to minimize the disk usage.

Data format

The identifer for accessing an item, a uint64 is composed as follows:

bit range usage
0-23 24 bits, 16M reserved for future use
23-35 12 bits, 4K shelf id - Shelf identifier
35-63 28 bits, 256M slotkey - slot identifier

The items themselves are stored with size as a 32-bit big-endian encoded integer, followed by the item itself. The 'slack-space' after size is not cleared, so might contain old data.

uint32: size | <data>