-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
build: update to walletdb/bdb version w/ mmap pre-sizing #4243
Changes from all commits
7a4613a
bb94b76
6c76351
d29f1a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11" | ||
"github.com/lightningnetwork/lnd/clock" | ||
"github.com/lightningnetwork/lnd/lnwire" | ||
"go.etcd.io/bbolt" | ||
) | ||
|
||
const ( | ||
|
@@ -165,7 +166,10 @@ func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) { | |
|
||
// Specify bbolt freelist options to reduce heap pressure in case the | ||
// freelist grows to be very large. | ||
bdb, err := kvdb.Open(kvdb.BoltBackendName, path, opts.NoFreelistSync) | ||
bboltOpts := &bbolt.Options{ | ||
NoFreelistSync: opts.NoFreelistSync, | ||
} | ||
bdb, err := kvdb.Open(kvdb.BoltBackendName, path, bboltOpts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -251,7 +255,10 @@ func createChannelDB(dbPath string) error { | |
} | ||
|
||
path := filepath.Join(dbPath, dbName) | ||
bdb, err := kvdb.Create(kvdb.BoltBackendName, path, true) | ||
bboltOpts := &bbolt.Options{ | ||
NoFreelistSync: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though this is just for creating the db, should this be user-specified as well? Setting it one way or another shouldn't give any performance benefit as:
So both scenarios are quicker in one area and slower in another. Only reason I think would be for consistency. |
||
} | ||
bdb, err := kvdb.Create(kvdb.BoltBackendName, path, bboltOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,22 @@ var ( | |
htlcFailInfoKey = []byte("htlc-fail-info") | ||
|
||
byteOrder = binary.BigEndian | ||
|
||
// failInfo is an empty fail info value for the legacy pre MPP | ||
// payments. | ||
failInfo = []byte{ | ||
// Fail time unknown. | ||
0, 0, 0, 0, 0, 0, 0, 0, | ||
|
||
// Zero length wire message. | ||
0, | ||
|
||
// Failure reason unknown. | ||
0, | ||
|
||
// Failure source index zero. | ||
0, 0, 0, 0, | ||
} | ||
) | ||
|
||
// MigrateMPP migrates the payments to a new structure that accommodates for mpp | ||
|
@@ -69,6 +85,10 @@ func MigrateMPP(tx kvdb.RwTx) error { | |
} | ||
|
||
// With all keys retrieved, start the migration. | ||
var ( | ||
zero [8]byte | ||
attemptID [8]byte | ||
) | ||
for _, k := range paymentKeys { | ||
bucket := paymentsBucket.NestedReadWriteBucket(k) | ||
|
||
|
@@ -114,15 +134,12 @@ func MigrateMPP(tx kvdb.RwTx) error { | |
} | ||
|
||
// Save attempt id for later use. | ||
attemptID := attemptInfo[:8] | ||
|
||
// Discard attempt id. It will become a bucket key in the new | ||
// structure. | ||
attemptInfo = attemptInfo[8:] | ||
copy(attemptID[:], attemptInfo[:8]) | ||
|
||
// Append unknown (zero) attempt time. | ||
var zero [8]byte | ||
attemptInfo = append(attemptInfo, zero[:]...) | ||
// Copy over the attempt info into a new slice, the last 8 | ||
// bytes will be zero to mark a zero attempt time. | ||
newAttemptInfo := make([]byte, len(attemptInfo)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can use a buffer pool both here and above, assuming the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
copy(newAttemptInfo, attemptInfo[8:]) | ||
|
||
// Create bucket that contains all htlcs. | ||
htlcsBucket, err := bucket.CreateBucket(paymentHtlcsBucket) | ||
|
@@ -131,13 +148,13 @@ func MigrateMPP(tx kvdb.RwTx) error { | |
} | ||
|
||
// Create an htlc for this attempt. | ||
htlcBucket, err := htlcsBucket.CreateBucket(attemptID) | ||
htlcBucket, err := htlcsBucket.CreateBucket(attemptID[:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Save migrated attempt info. | ||
err = htlcBucket.Put(htlcAttemptInfoKey, attemptInfo) | ||
err = htlcBucket.Put(htlcAttemptInfoKey, newAttemptInfo) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -175,21 +192,6 @@ func MigrateMPP(tx kvdb.RwTx) error { | |
|
||
// The htlc failed. Add htlc fail info with reason unknown. We | ||
// don't have access to the original failure reason anymore. | ||
failInfo := []byte{ | ||
// Fail time unknown. | ||
0, 0, 0, 0, 0, 0, 0, 0, | ||
|
||
// Zero length wire message. | ||
0, | ||
|
||
// Failure reason unknown. | ||
0, | ||
|
||
// Failure source index zero. | ||
0, 0, 0, 0, | ||
} | ||
|
||
// Save fail info. | ||
err = htlcBucket.Put(htlcFailInfoKey, failInfo) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: In the etcd PR
NoFreeListSync
is anlncfg
option. I wonder if we ever intend to actually set this to false? And if no, then perhaps we could default it somewhere (walletdb?) such that it's less hurdle to later on remove them from the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want this to be user-configurable as some users have reported slow startup times on weak machines (mobile, rpi) and opt to not set
NoFreeListSync
.