Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rkuris/cache read strategy expose to ffi #791

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

rkuris
Copy link
Collaborator

@rkuris rkuris commented Feb 12, 2025

Adds an additional required uint8_t to the ffi database open, which is now accessible from firewood.go, but it currently hardcodes it to zero (the default).

Fixed up the README as there is no longer a makefile as the doc describes

Has a decent impact to the load times on my mac:

  $ cargo run --profile maxperf --bin benchmark -- -n 100 create
    Finished `maxperf` profile [optimized] target(s) in 0.33s
     Running `target/maxperf/benchmark -n 100 create`
  [2025-02-12T20:27:46Z INFO  benchmark::create] Generated and inserted 100 batches of size 10000 in 9s 981ms

  $ cargo run --profile maxperf --bin benchmark -- -n 100 -C branch-reads create
    Finished `maxperf` profile [optimized] target(s) in 0.14s
     Running `target/maxperf/benchmark -n 100 -C branch-reads create`
  [2025-02-12T20:29:58Z INFO  benchmark::create] Generated and inserted 100 batches of size 10000 in 10s 179ms

  $ cargo run --profile maxperf --bin benchmark -- -n 100 -C all create
    Finished `maxperf` profile [optimized] target(s) in 0.33s
     Running `target/maxperf/benchmark -n 100 -C all create`
  [2025-02-12T20:27:29Z INFO  benchmark::create] Generated and inserted 100 batches of size 10000 in 12s 596ms
Some were in the flattened structure, others were not.
Adds an additional required uint8_t to the ffi database open, which is now
accessible from firewood.go, but it currently hardcodes it to zero
(the default).

Fixed up the README as there is no longer a makefile as the doc
describes
Updated documentation as well. To create a database, you now should do:

    db := NewDatabase(WithPath("somewhere.db"), WithCreate(true))

This exposes a few new options, such as the number of revisions, the
size of the cache, and the read cache strategy.

The documentaton provides more details...
The following is from `go doc -all`:

    package firewood // import "github.com/ava-labs/firewood/ffi/v2"

    TYPES

    type Firewood struct {
            // Has unexported fields.
    }
        Firewood is a handle to a Firewood database

    func NewDatabase(options ...OpenOption) Firewood
        NewDatabase opens or creates a new Firewood database with the given options.
        Returns a handle that can be used for subsequent database operations.

    func (f *Firewood) Batch(ops []KeyValue) []byte

    func (f *Firewood) Close() error
        Close closes the database and releases all held resources.

    func (f *Firewood) Commit(root []byte) error
        Commit does nothing, since update already persists changes

    func (f *Firewood) Get(input_key []byte) ([]byte, error)
        Get retrieves the value for the given key.

    func (f *Firewood) Prefetch(key []byte) ([]byte, error)
        Prefetch does nothing since we don't need to prefetch for firewood

    func (f *Firewood) Root() []byte
        Root returns the current root hash of the trie.

    func (f *Firewood) Update(keys, vals [][]byte) ([]byte, error)
        Update batches all the keys and values and applies them to the database

    type KeyValue struct {
            Key   []byte
            Value []byte
    }
        KeyValue is a key-value pair

    type OpenConfig struct {
            // Has unexported fields.
    }
        OpenConfig is used to configure the database at open time

    type OpenOption func(*OpenConfig)
        OpenOption is a function that configures the database at open time

    func WithCreate(create bool) OpenOption
        WithCreate sets whether to create a new database If false, the database will
        be opened If true, the database will be created

    func WithNodeCacheEntries(entries uintptr) OpenOption
        WithNodeCacheEntries sets the number of node cache entries

    func WithPath(path string) OpenOption
        WithPath sets the path for the database

    func WithReadCacheStrategy(strategy int8) OpenOption
        WithReadCacheStrategy sets the read cache strategy 0: Only writes are cached
        1: Branch reads are cached 2: All reads are cached

    func WithRevisions(revisions uintptr) OpenOption
        WithRevisions sets the number of revisions to keep
@rkuris rkuris enabled auto-merge (squash) February 12, 2025 23:51
@rkuris rkuris merged commit a18b8ae into main Feb 12, 2025
5 checks passed
@rkuris rkuris deleted the rkuris/cache-read-strategy-expose-to-ffi branch February 12, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants