Code Monkey home page Code Monkey logo

go-ipfs-blockstore's Introduction

go-ipfs-blockstore

go-ipfs-blockstore implements a thin wrapper over a datastore, giving a clean interface for Getting and Putting block objects.

standard-readme compliant GoDoc Build Status

โ— This repo is no longer maintained.

๐Ÿ‘‰ We highly recommend switching to the maintained version at https://github.com/ipfs/boxo/tree/main/blockstore. ๐ŸŽ๏ธ Good news! There is tooling and documentation to expedite a switch in your repo.

โš ๏ธ If you continue using this repo, please note that security fixes will not be provided (unless someone steps in to maintain it).

๐Ÿ“š Learn more, including how to take the maintainership mantle or ask questions, here.

Table of Contents

Install

go-ipfs-blockstore works like a regular Go module:

> go get github.com/ipfs/go-ipfs-blockstore

Usage

import "github.com/ipfs/go-ipfs-blockstore"

Check the GoDoc documentation

License

MIT ยฉ Protocol Labs, Inc.

go-ipfs-blockstore's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ipfs-blockstore's Issues

Bloom filter blockstore not checking cache on GetSize

We have:

func (b *bloomcache) GetSize(k cid.Cid) (int, error) {
return b.blockstore.GetSize(k)
}

Unlike:

func (b *bloomcache) Get(k cid.Cid) (blocks.Block, error) {
if has, ok := b.hasCached(k); ok && !has {
return nil, ErrNotFound
}
return b.blockstore.Get(k)
}

This needs to be fixed in both v0 and v1 of the blockstore.

Optimize the has cache

The "has" cache uses a ton of memory. Go reports ~40MiB but that likely doesn't include allocator overhead. There are two things we may be able to do to help with this:

  1. Only record that we don't have something. If we do have something, we'll have to load it anyways so caching the fact that we have it doesn't help much.
  2. Use a better ARC cache. While the ARC cache was using ~40MiB, we only had ~7.5MiB worth of CIDs. Given (1), we may be able to make this more efficient with an ARC set.

Ideally, we'd use the bloom filter. Even for a 1% failure rate, at 1M items an optimal bloom filter would only be about a megabyte (requiring 7 lookups per check). However, loading the bloom filter is a bit of a pain.

HashOnRead Has A Race Condition

While working on some tests to detect race conditions with a blockstore wrapper I'm working on, I create multiple goroutines to execute the various blockstore functions. I noticed that when I had each goroutine call Blockstore::HashOnRead(num%2==0) where num is the goroutine number, that a race condition is triggered.

Subsequently I looked into the blockstore and found this:

type blockstore struct {
	datastore ds.Batching

	rehash bool
}

func (bs *blockstore) HashOnRead(enabled bool) {
	bs.rehash = enabled
}

This seems a little unsafe, since there's no documentation explicitly saying that this shouldn't be called by multiple goroutines. It should either be guarded by a mutex, or, alternatively use an atomic boolean

edit:

Doing some more digging, this race condition will not only effect HashOnRead, but also Get, GetSize

TestHasIsBloomCached failures

Moved from: ipfs/kubo#3208

--- FAIL: TestHasIsBloomCached (0.03s)
    bloom_cache_test.go:100: Bloom filter has cache miss rate of more than 5%
FAIL
FAIL    github.com/ipfs/go-ipfs/blocks/blockstore   0.053s

Delete race in ARC cache

Steps:

  1. Call Put & Delete on the same block at the same time.
  2. After finishing step 1, call Put on the block.

After step 1, the block may or may not be in the blockstore depending on how the operations serialize. However, after step 2, the block must be in the datastore.

Unfortunately, there's a race:

  1. Put 1: put the block.
  2. Delete 1: Delete the block.
  3. Delete 1: Cache that we don't have the block.
  4. Put 1: Cache that we have the block.
  5. Put 2: Check the cache, see that we should have the block, and walk away.

There's also a similar race between get & delete and get & put.

Fix: add striped (by CID) locking.
Impact:

  1. Put & Delete: data loss (in go-ipfs, requires GC)
  2. Get & Delete: data loss (in go-ipfs, requires GC)
  3. Get & Put: Inability to retrieve a block from the datastore (until restarting).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.