Skip to content

libnet/ds, libnet/config: various cleanups#47992

Merged
thaJeztah merged 4 commits intomoby:masterfrom
akerouanton:libnet-datastore-cleanup
Sep 20, 2024
Merged

libnet/ds, libnet/config: various cleanups#47992
thaJeztah merged 4 commits intomoby:masterfrom
akerouanton:libnet-datastore-cleanup

Conversation

@akerouanton
Copy link
Copy Markdown
Member

@akerouanton akerouanton commented Jun 15, 2024

- What I did

libnet/i/kv/boltdb: remove unused field 'timeout'

libnetwork: unit tests: drop OptionBoltdbWithRandomDBFile

This option fn was defining a custom directory, file name and bucket name for boltdb. Users can only change data-dir through OptionDataDir. Better reuse that function instead, that'll make refactorings easier.

It won't set a custom bucket name or file name as OptionBoltdbWithRandomDBFile was doing, but that's not needed since every test will use a different temp dir anyway.

libnet/ds: simplify datastore.New()

That function was needlessly complex. Instead of relying on a struct and a sub-struct, it now just takes two string params: a path and a bucket name.

Libnetwork config is now initialized with default values. A new struct is introduced in libnetwork/config to let tests customize the path and bucket name.

libnet/i/kv/boltdb: fail fast in case of contention

Make sure an error is returned straight away if there's contention on the underlying db file. This makes sure we don't reintroduce the issue fixed in d21d088, and it will help detect contention in parallelized tests if they're badly written. It effectively adds a new error mode to the daemon, but if anyone faces this error, they should fix their process manager.

- How to verify it

CI.

- A picture of a cute animal (not mandatory but encouraged)

@akerouanton akerouanton added status/2-code-review area/networking Networking kind/refactor PR's that refactor, or clean-up code labels Jun 15, 2024
@akerouanton akerouanton requested review from corhere and thaJeztah June 15, 2024 09:17
@akerouanton akerouanton self-assigned this Jun 15, 2024
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! I left a couple of comments;

  • ⚠️ I went through commit-by-commit, so best to look through them as such, but
  • 👉 some of my comments may have become obsolete in commits after that.
  • 💡 it may still make sense to look at my "outdated" comments, in case they provide alternative options.

Comment thread libnetwork/datastore/datastore.go Outdated
Comment thread libnetwork/datastore/datastore.go Outdated
Comment thread libnetwork/libnetwork_linux_test.go Outdated
Comment thread libnetwork/config/config.go Outdated
Comment thread libnetwork/internal/kvstore/boltdb/boltdb.go Outdated
Comment thread libnetwork/store_test.go Outdated
Comment thread libnetwork/internal/kvstore/boltdb/boltdb.go Outdated
Comment thread libnetwork/internal/kvstore/boltdb/boltdb.go Outdated
Comment thread libnetwork/internal/kvstore/boltdb/boltdb.go Outdated
Comment thread libnetwork/datastore/datastore.go Outdated
@akerouanton akerouanton force-pushed the libnet-datastore-cleanup branch 2 times, most recently from 30e4e17 to 6ff6d10 Compare September 19, 2024 11:16
This option fn was defining a custom directory, file name and bucket
name for boltdb. Users can only change data-dir through `OptionDataDir`.
Better reuse that function instead, that'll make refactorings easier.

It won't set a custom bucket name or file name as `OptionBoltdbWithRandomDBFile`
was doing, but that's not needed since every test will use a different
temp dir anyway.

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the libnet-datastore-cleanup branch 2 times, most recently from 7314fe6 to 8b766a8 Compare September 19, 2024 13:01
Comment thread libnetwork/store_test.go Outdated
Comment thread libnetwork/internal/kvstore/boltdb/boltdb.go Outdated
That function was needlessly complex. Instead of relying on a struct and
a sub-struct, it now just takes two string params: a path and a bucket
name.

Libnetwork config is now initialized with default values. A new struct
is introduced in libnetwork/config to let tests customize the path and
bucket name.

Signed-off-by: Albin Kerouanton <[email protected]>
Make sure an error is returned straight away if there's contention on
the underlying db file. This makes sure we don't reintroduce the issue
fixed in d21d088, and it will help detect contention in parallelized
tests if they're badly written. It effectively adds a new error mode to
the daemon, but if anyone faces this error, they should fix their
process manager.

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the libnet-datastore-cleanup branch from 8b766a8 to edcefd4 Compare September 20, 2024 06:48
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Comment on lines +39 to +52
// The bbolt package opens the underlying db file and then issues an
// exclusive flock to ensures that it can safely write to the db. If
// it fails, it'll re-issue flocks every few ms until Timeout is
// reached.
// This nanosecond timeout bypasses that retry loop and make sure the
// bbolt package returns an ErrTimeout straight away. That way, the
// daemon, and unit tests, will fail fast and loudly instead of
// silently introducing delays.
Timeout: time.Nanosecond,
})
if err != nil {
if errors.Is(err, bolt.ErrTimeout) {
return nil, fmt.Errorf("boltdb file %s is already open", path)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use extra eyes on this logic, just to be sure 🫶

@akerouanton akerouanton requested a review from robmry September 20, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking Networking kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants