[#653] Pass context.Context to StorageEngine Open #672

Merged
fyrchik merged 1 commit from elebedeva/frostfs-node:open-context into master 2023-09-07 16:18:28 +00:00
Member

Close #653

Signed-off-by: Ekaterina Lebedeva ekaterina.lebedeva@yadro.com

Close #653 Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
fyrchik reviewed 2023-08-31 17:00:24 +00:00
fyrchik left a comment
Owner

It seems you have a really old branch, please rebase on the actual master.

It seems you have a really old branch, please rebase on the actual master.
@ -44,3 +45,3 @@
meta.WithEpochState(epochState{}),
)
common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(true)))
common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(context.Background(), true)))
Owner

cmd.Context() is what we usually use for this.

`cmd.Context()` is what we usually use for this.
Author
Member

Fixed.

Fixed.
fyrchik marked this conversation as resolved
Owner

Don't forget to add reviewers! Our team has core- in it's name -- pick both options.

Don't forget to add reviewers! Our team has `core-` in it's name -- pick both options.
elebedeva force-pushed open-context from a454b19589 to b60014d415 2023-09-01 12:36:59 +00:00 Compare
elebedeva requested review from storage-core-developers 2023-09-01 12:39:04 +00:00
elebedeva requested review from storage-core-committers 2023-09-01 12:39:05 +00:00
dstepanov-yadro requested changes 2023-09-01 12:55:12 +00:00
@ -932,3 +932,3 @@
c.log.Info(logs.FrostFSNodeClosingComponentsOfTheStorageEngine)
err := ls.Close()
err := ls.Close(ctx)

Need to check: if onShutdown calls afetr ctx is cancelled, then Close() may fail. So context.Background() or detached https://pkg.go.dev/context#WithoutCancel should be used.

Need to check: if `onShutdown` calls afetr ctx is cancelled, then `Close()` may fail. So `context.Background()` or detached https://pkg.go.dev/context#WithoutCancel should be used.
Owner

WithoutCancel() was added in 1.21, but we need to support 1.20 too.

`WithoutCancel()` was added in 1.21, but we need to support 1.20 too.
Author
Member

changed ls.Close(ctx) to ls.Close(context.Background())

changed `ls.Close(ctx)` to `ls.Close(context.Background())`
fyrchik marked this conversation as resolved
@ -22,3 +23,3 @@
err := b.Close()
if err == nil {
if err = b.Open(m.ReadOnly()); err == nil {
if err = b.Open(context.Background(), m.ReadOnly()); err == nil {

context.TODO is more preferred in such cases (or we should pass ctx to SetMode too :) )

context.TODO is more preferred in such cases (or we should pass ctx to SetMode too :) )
Author
Member

fixed

fixed
fyrchik marked this conversation as resolved
@ -28,3 +29,3 @@
db.boltDB = nil
case m.ReadOnly():
err = db.Open(true)
err = db.Open(context.Background(), true)

context.TODO too

context.TODO too
Author
Member

fixed

fixed
fyrchik marked this conversation as resolved
elebedeva force-pushed open-context from b60014d415 to ce614e8a94 2023-09-05 10:23:16 +00:00 Compare
fyrchik reviewed 2023-09-05 11:06:38 +00:00
@ -177,3 +179,3 @@
isMeta := errors.As(err, new(metaerr.Error))
if block {
e.moveToDegraded(sh, errCount, isMeta)
e.moveToDegraded(ctx, sh, errCount, isMeta)
Owner

Same here the ctx here is taken from operation, I believe SetMode should not be affected by it.

Same here the `ctx` here is taken from operation, I believe `SetMode` should not be affected by it.
fyrchik marked this conversation as resolved
@ -57,2 +59,3 @@
for i, component := range components {
if err := component.Open(false); err != nil {
if err := component.Open(ctx, false); err != nil {
select {
Owner

What is this select for? We have an error, no need to check the context. For the component == s.metaBase check it is already checked in the loop.

What is this select for? We have an error, no need to check the context. For the `component == s.metaBase` check it is already checked in the loop.
Author
Member

Removed unnecessary select

Removed unnecessary select
fyrchik marked this conversation as resolved
@ -38,3 +38,3 @@
for _, shardID := range s.getShardIDList(req.Body.GetShard_ID()) {
err = s.s.SetShardMode(shardID, m, req.Body.GetResetErrorCounter())
err = s.s.SetShardMode(ctx, shardID, m, req.Body.GetResetErrorCounter())
Owner

This may be a problem -- ctx is a context for stream operation, while ctx for Open/Init/SetMode is for the storage lifetime. Have you checked how this context is used?

This may be a problem -- ctx is a context for stream operation, while ctx for `Open`/`Init`/`SetMode` is for the storage lifetime. Have you checked how this context is used?
fyrchik marked this conversation as resolved
elebedeva force-pushed open-context from ce614e8a94 to 3327355ebc 2023-09-07 14:53:18 +00:00 Compare
elebedeva force-pushed open-context from 3327355ebc to 8a81af5a3b 2023-09-07 15:08:13 +00:00 Compare
fyrchik approved these changes 2023-09-07 15:10:28 +00:00
aarifullin approved these changes 2023-09-07 16:08:24 +00:00
aarifullin left a comment
Member

Very nice!

Very nice!
fyrchik merged commit 8a81af5a3b into master 2023-09-07 16:18:28 +00:00
elebedeva deleted branch open-context 2023-09-08 07:27:27 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#672
No description provided.