Skip to content

Commit 66b1b97

Browse files
authored
feat: support pebble datastore (#166)
1 parent f66ecf7 commit 66b1b97

File tree

6 files changed

+165
-4
lines changed

6 files changed

+165
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The following emojis are used to highlight certain changes:
1515

1616
### Added
1717
- Ability to specify the maximum blocksize that bitswap will replace WantHave with WantBlock responses, and to disable replacement when set to zero. [#165](https://github.com/ipfs/rainbow/pull/165)
18+
- Support use and configuration of pebble as [datastore](https://github.com/ipfs/rainbow/blob/main/docs/blockstores.md). Pebble provides a high-performance alternative to badger. Options are available to configure key tuning parameters (`pebble-*` in `rainbow --help`).
1819

1920
### Changed
2021

docs/blockstores.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ filesystem (i.e. not just how bytes are stored on disk but file and directory st
2020
optimizations to be had in selection of the filesystem and disk types. For example, choosing a filesystem that enables
2121
putting file metadata on a fast SSD while keeping the actual data on a slower disk might ease various lookup types.
2222

23+
## Pebble
24+
25+
`rainbow` ships with [Pebble](https://github.com/cockroachdb/pebble) (version in `go.mod`)
26+
27+
The main reasons to choose Pebble compared to FlatFS are:
28+
- Much faster with reasonable configuration
29+
- It comes with the ability to compress data on disk
30+
- Native bloom filters
31+
- Highly configurable to tune performance to your needs
32+
2333
## Badger
2434

2535
`rainbow` ships with [Badger-v4](https://github.com/dgraph-io/badger).
@@ -30,4 +40,4 @@ The main reasons to choose Badger compared to FlatFS are:
3040
- Native bloom filters
3141

3242
The main difficulty with Badger is that its internal garbage collection functionality (not `rainbow`'s) is dependent on
33-
workload which makes it difficult to ahead-of-time judge the kinds of capacity you need.
43+
workload which makes it difficult to ahead-of-time judge the kinds of capacity you need.

go.mod

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/ipfs/rainbow
33
go 1.22
44

55
require (
6+
github.com/cockroachdb/pebble v1.1.2
67
github.com/coreos/go-systemd/v22 v22.5.0
78
github.com/dgraph-io/badger/v4 v4.3.0
89
github.com/dustin/go-humanize v1.0.1
@@ -16,6 +17,7 @@ require (
1617
github.com/ipfs/go-ds-badger4 v0.1.5
1718
github.com/ipfs/go-ds-flatfs v0.5.1
1819
github.com/ipfs/go-ds-leveldb v0.5.0
20+
github.com/ipfs/go-ds-pebble v0.3.2-0.20241002075519-c174835dc84a
1921
github.com/ipfs/go-ipfs-delay v0.0.1
2022
github.com/ipfs/go-log/v2 v2.5.1
2123
github.com/ipfs/go-metrics-interface v0.0.1
@@ -49,13 +51,19 @@ require (
4951
)
5052

5153
require (
54+
github.com/DataDog/zstd v1.4.5 // indirect
5255
github.com/Jorropo/jsync v1.0.1 // indirect
5356
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
5457
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 // indirect
5558
github.com/benbjohnson/clock v1.3.5 // indirect
5659
github.com/beorn7/perks v1.0.1 // indirect
5760
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
5861
github.com/cespare/xxhash/v2 v2.3.0 // indirect
62+
github.com/cockroachdb/errors v1.11.3 // indirect
63+
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
64+
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
65+
github.com/cockroachdb/redact v1.1.5 // indirect
66+
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
5967
github.com/containerd/cgroups v1.1.0 // indirect
6068
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
6169
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668 // indirect
@@ -70,6 +78,7 @@ require (
7078
github.com/francoispqt/gojay v1.2.13 // indirect
7179
github.com/fsnotify/fsnotify v1.7.0 // indirect
7280
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
81+
github.com/getsentry/sentry-go v0.27.0 // indirect
7382
github.com/go-logr/logr v1.4.2 // indirect
7483
github.com/go-logr/stdr v1.2.2 // indirect
7584
github.com/go-ole/go-ole v1.3.0 // indirect
@@ -116,6 +125,8 @@ require (
116125
github.com/klauspost/compress v1.17.9 // indirect
117126
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
118127
github.com/koron/go-ssdp v0.0.4 // indirect
128+
github.com/kr/pretty v0.3.1 // indirect
129+
github.com/kr/text v0.2.0 // indirect
119130
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
120131
github.com/libp2p/go-cidranger v1.1.0 // indirect
121132
github.com/libp2p/go-doh-resolver v0.4.0 // indirect
@@ -175,6 +186,7 @@ require (
175186
github.com/quic-go/quic-go v0.45.2 // indirect
176187
github.com/quic-go/webtransport-go v0.8.0 // indirect
177188
github.com/raulk/go-watchdog v1.3.0 // indirect
189+
github.com/rogpeppe/go-internal v1.12.0 // indirect
178190
github.com/russross/blackfriday/v2 v2.1.0 // indirect
179191
github.com/samber/lo v1.39.0 // indirect
180192
github.com/spaolacci/murmur3 v1.1.0 // indirect

go.sum

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
1010
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
1111
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
1212
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
13+
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
14+
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
1315
github.com/Jorropo/jsync v1.0.1 h1:6HgRolFZnsdfzRUj+ImB9og1JYOxQoReSywkHOGSaUU=
1416
github.com/Jorropo/jsync v1.0.1/go.mod h1:jCOZj3vrBCri3bSU3ErUYvevKlnbssrXeCivybS5ABQ=
1517
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
@@ -46,6 +48,20 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
4648
github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX2Qs=
4749
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
4850
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
51+
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
52+
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
53+
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
54+
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
55+
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/esnpM7Geqxka4WSqI1SZc7sMJFd3y4=
56+
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M=
57+
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
58+
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
59+
github.com/cockroachdb/pebble v1.1.2 h1:CUh2IPtR4swHlEj48Rhfzw6l/d0qA31fItcIszQVIsA=
60+
github.com/cockroachdb/pebble v1.1.2/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU=
61+
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
62+
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
63+
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
64+
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
4965
github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
5066
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
5167
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
@@ -64,6 +80,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV
6480
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
6581
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668 h1:ZFUue+PNxmHlu7pYv+IYMtqlaO/0VwaGEqKepZf9JpA=
6682
github.com/crackcomm/go-gitignore v0.0.0-20231225121904-e25f5bc08668/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
83+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
6784
github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0=
6885
github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis=
6986
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -114,10 +131,14 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
114131
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
115132
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
116133
github.com/garyburd/redigo v1.1.1-0.20170914051019-70e1b1943d4f/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
134+
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
135+
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
117136
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
118137
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
119138
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
120139
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
140+
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
141+
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
121142
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
122143
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
123144
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -263,6 +284,8 @@ github.com/ipfs/go-ds-flatfs v0.5.1/go.mod h1:RWTV7oZD/yZYBKdbVIFXTX2fdY2Tbvl94N
263284
github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8=
264285
github.com/ipfs/go-ds-leveldb v0.5.0 h1:s++MEBbD3ZKc9/8/njrn4flZLnCuY9I79v94gBUNumo=
265286
github.com/ipfs/go-ds-leveldb v0.5.0/go.mod h1:d3XG9RUDzQ6V4SHi8+Xgj9j1XuEk1z82lquxrVbml/Q=
287+
github.com/ipfs/go-ds-pebble v0.3.2-0.20241002075519-c174835dc84a h1:OouXE/TSvgFP3Scv/3WA1brxKC+FM40EeusWnLGilgY=
288+
github.com/ipfs/go-ds-pebble v0.3.2-0.20241002075519-c174835dc84a/go.mod h1:ZyYU+weIni+4NG/Yjva+cPkU3ghlsU1HA2R/VLHJ9sM=
266289
github.com/ipfs/go-ipfs-blockstore v1.3.1 h1:cEI9ci7V0sRNivqaOr0elDsamxXFxJMMMy7PTTDQNsQ=
267290
github.com/ipfs/go-ipfs-blockstore v1.3.1/go.mod h1:KgtZyc9fq+P2xJUiCAzbRdhhqJHvsw8u2Dlqy2MyRTE=
268291
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
@@ -520,6 +543,8 @@ github.com/pelletier/go-toml v1.0.1-0.20170904195809-1d6b12b7cb29/go.mod h1:5z9K
520543
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
521544
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 h1:1/WtZae0yGtPq+TI6+Tv1WTxkukpXeMlviSxvL7SRgk=
522545
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9/go.mod h1:x3N5drFsm2uilKKuuYo6LdyD8vZAW55sH/9w+pbo1sw=
546+
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
547+
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
523548
github.com/pion/datachannel v1.5.8 h1:ph1P1NsGkazkjrvyMfhRBUAWMxugJjq2HfQifaOoSNo=
524549
github.com/pion/datachannel v1.5.8/go.mod h1:PgmdpoaNBLX9HNzNClmdki4DYW5JtI7Yibu8QzbL3tI=
525550
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
@@ -562,6 +587,7 @@ github.com/pion/turn/v2 v2.1.6 h1:Xr2niVsiPTB0FPtt+yAWKFUkU1eotQbGgpTIld4x1Gc=
562587
github.com/pion/turn/v2 v2.1.6/go.mod h1:huEpByKKHix2/b9kmTAM3YoX6MKP+/D//0ClgUYR2fY=
563588
github.com/pion/webrtc/v3 v3.3.0 h1:Rf4u6n6U5t5sUxhYPQk/samzU/oDv7jk6BA5hyO2F9I=
564589
github.com/pion/webrtc/v3 v3.3.0/go.mod h1:hVmrDJvwhEertRWObeb1xzulzHGeVUoPlWvxdGzcfU0=
590+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
565591
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
566592
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
567593
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -596,6 +622,7 @@ github.com/quic-go/webtransport-go v0.8.0/go.mod h1:N99tjprW432Ut5ONql/aUhSLT0YV
596622
github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk=
597623
github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU=
598624
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
625+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
599626
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
600627
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
601628
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529 h1:18kd+8ZUlt/ARXhljq+14TwAoKa61q6dX8jtwOf6DH8=

main.go

+74-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Generate an identity seed and launch a gateway:
184184
Name: "inmem-block-cache",
185185
Value: 1 << 30,
186186
EnvVars: []string{"RAINBOW_INMEM_BLOCK_CACHE"},
187-
Usage: "Size of the in-memory block cache (currently only used for badger). 0 to disable (disables compression on disk too)",
187+
Usage: "Size of the in-memory block cache (currently only used for pebble and badger). 0 to disable (disables compression on disk too)",
188188
},
189189
&cli.Uint64Flag{
190190
Name: "libp2p-max-memory",
@@ -246,7 +246,7 @@ Generate an identity seed and launch a gateway:
246246
Name: "blockstore",
247247
Value: "flatfs",
248248
EnvVars: []string{"RAINBOW_BLOCKSTORE"},
249-
Usage: "Type of blockstore to use, such as flatfs or badger. See https://github.com/ipfs/rainbow/blob/main/docs/blockstores.md for more details",
249+
Usage: "Type of blockstore to use, such as flatfs or pebble. See https://github.com/ipfs/rainbow/blob/main/docs/blockstores.md for more details",
250250
},
251251
&cli.DurationFlag{
252252
Name: "ipns-max-cache-ttl",
@@ -315,6 +315,66 @@ Generate an identity seed and launch a gateway:
315315
EnvVars: []string{"RAINBOW_SAMPLING_FRACTION"},
316316
Usage: "Rate at which to sample gateway requests. Does not include traceheaders which will always sample",
317317
},
318+
&cli.IntFlag{
319+
Name: "pebble-bytes-per-sync",
320+
Value: 0,
321+
EnvVars: []string{"PEBBLE_BYTES_PER_SYNC"},
322+
Usage: "Sync sstables periodically in order to smooth out writes to disk",
323+
},
324+
&cli.BoolFlag{
325+
Name: "pebble-disable-wal",
326+
Value: false,
327+
EnvVars: []string{"PEBBLE_DISABLE_WAL"},
328+
Usage: "Disable the write-ahead log (WAL) at expense of prohibiting crash recoveryfg",
329+
},
330+
&cli.IntFlag{
331+
Name: "pebble-l0-compaction-threshold",
332+
Value: 0,
333+
EnvVars: []string{"PEBBLE_L0_COMPACTION_THRESHOLD"},
334+
Usage: "Count of L0 files necessary to trigger an L0 compaction",
335+
},
336+
&cli.IntFlag{
337+
Name: "pebble-l0-stop-writes-threshold",
338+
Value: 0,
339+
EnvVars: []string{"PEBBLE_L0_STOP_WRITES_THRESHOLD"},
340+
Usage: "Limit on L0 read-amplification, computed as the number of L0 sublevels",
341+
},
342+
&cli.Int64Flag{
343+
Name: "pebble-lbase-max-bytes",
344+
Value: 0,
345+
EnvVars: []string{"PEBBLE_LBASE_MAX_BYTES"},
346+
Usage: "Maximum number of bytes for LBase. The base level is the level which L0 is compacted into",
347+
},
348+
&cli.Uint64Flag{
349+
Name: "pebble-mem-table-size",
350+
Value: 0,
351+
EnvVars: []string{"PEBBLE_MEM_TABLE_SIZE"},
352+
Usage: "Size of a MemTable in steady state. The actual MemTable size starts at min(256KB, MemTableSize) and doubles for each subsequent MemTable up to MemTableSize",
353+
},
354+
&cli.IntFlag{
355+
Name: "pebble-mem-table-stop-writes-threshold",
356+
Value: 0,
357+
EnvVars: []string{"PEBBLE_MEM_TABLE_STOP_WRITES_THRESHOLD"},
358+
Usage: "Limit on the number of queued of MemTables",
359+
},
360+
&cli.IntFlag{
361+
Name: "pebble-wal-bytes-per-sync",
362+
Value: 0,
363+
EnvVars: []string{"PEBBLE_WAL_BYTES_PER_SYNC"},
364+
Usage: "Sets the number of bytes to write to a WAL before calling Sync on it in the background",
365+
},
366+
&cli.IntFlag{
367+
Name: "pebble-max-concurrent-compactions",
368+
Value: 0,
369+
EnvVars: []string{"PEBBLE_MAX_CONCURRENT_COMPACTIONS"},
370+
Usage: "Maximum number of concurrent compactions",
371+
},
372+
&cli.DurationFlag{
373+
Name: "pebble-wal-min-sync-interval",
374+
Value: 0,
375+
EnvVars: []string{"PEBBLE_WAL_MIN_SYNC_INTERVAL"},
376+
Usage: "Sets the minimum duration between syncs of the WAL",
377+
},
318378
}
319379

320380
app.Commands = []*cli.Command{
@@ -461,8 +521,19 @@ share the same seed as long as the indexes are different.
461521
GCThreshold: cctx.Float64("gc-threshold"),
462522
ListenAddrs: cctx.StringSlice("libp2p-listen-addrs"),
463523
TracingAuthToken: cctx.String("tracing-auth"),
464-
}
465524

525+
// Pebble config
526+
BytesPerSync: cctx.Int("pebble-bytes-per-sync"),
527+
DisableWAL: cctx.Bool("pebble-disable-wal"),
528+
L0CompactionThreshold: cctx.Int("pebble-l0-compaction-threshold"),
529+
L0StopWritesThreshold: cctx.Int("pebble-l0-stop-writes-threshold"),
530+
LBaseMaxBytes: cctx.Int64("pebble-lbase-max-bytes"),
531+
MemTableSize: cctx.Uint64("pebble-mem-table-size"),
532+
MemTableStopWritesThreshold: cctx.Int("pebble-mem-table-stop-writes-threshold"),
533+
WALBytesPerSync: cctx.Int("pebble-wal-Bytes-per-sync"),
534+
MaxConcurrentCompactions: cctx.Int("pebble-max-concurrent-compactions"),
535+
WALMinSyncInterval: time.Second * time.Duration(cctx.Int("pebble-wal-min-sync-interval-sec")),
536+
}
466537
var gnd *Node
467538

468539
goLog.Infof("Rainbow config: %+v", cfg)

setup.go

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"time"
1212

13+
"github.com/cockroachdb/pebble"
1314
"github.com/dgraph-io/badger/v4"
1415
"github.com/dgraph-io/badger/v4/options"
1516
nopfs "github.com/ipfs-shipyard/nopfs"
@@ -27,6 +28,7 @@ import (
2728
"github.com/ipfs/go-datastore"
2829
badger4 "github.com/ipfs/go-ds-badger4"
2930
flatfs "github.com/ipfs/go-ds-flatfs"
31+
pebbleds "github.com/ipfs/go-ds-pebble"
3032
mprome "github.com/ipfs/go-metrics-prometheus"
3133
"github.com/ipfs/go-unixfsnode"
3234
dagpb "github.com/ipld/go-codec-dagpb"
@@ -133,6 +135,18 @@ type Config struct {
133135
TracingAuthToken string
134136

135137
disableMetrics bool // only meant to be used during testing
138+
139+
// Pebble config values
140+
BytesPerSync int
141+
DisableWAL bool
142+
L0CompactionThreshold int
143+
L0StopWritesThreshold int
144+
LBaseMaxBytes int64
145+
MemTableSize uint64
146+
MemTableStopWritesThreshold int
147+
WALBytesPerSync int
148+
MaxConcurrentCompactions int
149+
WALMinSyncInterval time.Duration
136150
}
137151

138152
func SetupNoLibp2p(ctx context.Context, cfg Config, dnsCache *cachedDNS) (*Node, error) {
@@ -350,6 +364,11 @@ func setupDatastore(cfg Config) (datastore.Batching, error) {
350364
switch cfg.BlockstoreType {
351365
case "flatfs":
352366
return flatfs.CreateOrOpen(filepath.Join(cfg.DataDir, "flatfs"), flatfs.NextToLast(3), false)
367+
case "pebble":
368+
return pebbleds.NewDatastore(filepath.Join(cfg.DataDir, "pebbleds"),
369+
pebbleds.WithCacheSize(cfg.InMemBlockCache),
370+
pebbleds.WithPebbleOpts(getPebbleOpts(cfg)),
371+
)
353372
case "badger":
354373
badgerOpts := badger.DefaultOptions("")
355374
badgerOpts.CompactL0OnClose = false
@@ -557,3 +576,24 @@ func (s *switchingBlockstore) HashOnRead(enabled bool) {
557576
}
558577

559578
var _ blockstore.Blockstore = (*switchingBlockstore)(nil)
579+
580+
func getPebbleOpts(cfg Config) *pebble.Options {
581+
opts := &pebble.Options{
582+
BytesPerSync: cfg.BytesPerSync,
583+
DisableWAL: cfg.DisableWAL,
584+
L0CompactionThreshold: cfg.L0CompactionThreshold,
585+
L0StopWritesThreshold: cfg.L0StopWritesThreshold,
586+
LBaseMaxBytes: cfg.LBaseMaxBytes,
587+
MemTableSize: cfg.MemTableSize,
588+
MemTableStopWritesThreshold: cfg.MemTableStopWritesThreshold,
589+
WALBytesPerSync: cfg.WALBytesPerSync,
590+
}
591+
if cfg.MaxConcurrentCompactions != 0 {
592+
opts.MaxConcurrentCompactions = func() int { return cfg.MaxConcurrentCompactions }
593+
}
594+
if cfg.WALMinSyncInterval != 0 {
595+
opts.WALMinSyncInterval = func() time.Duration { return cfg.WALMinSyncInterval }
596+
}
597+
598+
return opts
599+
}

0 commit comments

Comments
 (0)