-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2953 from ipfs/feature/blocks-bloom-no-rebuild
core: do not run bloom in case of ephemeral node
- Loading branch information
Showing
6 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package blockstore | ||
|
||
import ( | ||
"errors" | ||
|
||
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" | ||
) | ||
|
||
// Next to each option is it aproximate memory usage per unit | ||
type CacheOpts struct { | ||
HasBloomFilterSize int // 1 bit | ||
HasBloomFilterHashes int // No size, 7 is usually best, consult bloom papers | ||
HasARCCacheSize int // 32 bytes | ||
} | ||
|
||
func DefaultCacheOpts() CacheOpts { | ||
return CacheOpts{ | ||
HasBloomFilterSize: 512 * 8 * 1024, | ||
HasBloomFilterHashes: 7, | ||
HasARCCacheSize: 64 * 1024, | ||
} | ||
} | ||
|
||
func CachedBlockstore(bs GCBlockstore, | ||
ctx context.Context, opts CacheOpts) (cbs GCBlockstore, err error) { | ||
cbs = bs | ||
|
||
if opts.HasBloomFilterSize < 0 || opts.HasBloomFilterHashes < 0 || | ||
opts.HasARCCacheSize < 0 { | ||
return nil, errors.New("all options for cache need to be greater than zero") | ||
} | ||
|
||
if opts.HasBloomFilterSize != 0 && opts.HasBloomFilterHashes == 0 { | ||
return nil, errors.New("bloom filter hash count can't be 0 when there is size set") | ||
} | ||
if opts.HasBloomFilterSize != 0 { | ||
cbs, err = bloomCached(cbs, ctx, opts.HasBloomFilterSize, opts.HasBloomFilterHashes, | ||
opts.HasARCCacheSize) | ||
} | ||
|
||
return cbs, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters