Use LockPrm and LockRes to store Lock operation parameters and results #1556

Closed
a-savchuk wants to merge 5 commits from a-savchuk:add-lock-prm into master
Member

Close #1421

Refactor Lock operation to use LockPrm and LockRes structures to store operation parameters and results, respectively

Close #1421 Refactor `Lock` operation to use `LockPrm` and `LockRes` structures to store operation parameters and results, respectively
a-savchuk added 5 commits 2024-12-11 13:50:09 +00:00
Refactor `Lock` method to use `LockPrm` and `LockRes` structures
to store operation parameters and results, respectively.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
[#1421] engine: Use LockPrm to store Lock operation parameters
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 3m6s
DCO action / DCO (pull_request) Successful in 3m43s
Tests and linters / Staticcheck (pull_request) Successful in 5m19s
Vulncheck / Vulncheck (pull_request) Successful in 6m38s
Build / Build Components (pull_request) Successful in 7m31s
Pre-commit hooks / Pre-commit (pull_request) Successful in 7m30s
Tests and linters / Tests (pull_request) Successful in 7m52s
Tests and linters / gopls check (pull_request) Successful in 8m9s
Tests and linters / Tests with -race (pull_request) Successful in 8m12s
Tests and linters / Lint (pull_request) Successful in 8m22s
6f28a52e1a
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
a-savchuk requested review from storage-core-committers 2024-12-11 13:50:09 +00:00
a-savchuk requested review from storage-core-developers 2024-12-11 13:50:09 +00:00
dstepanov-yadro reviewed 2024-12-11 15:04:57 +00:00
@ -33,0 +45,4 @@
// SetTarget sets lock object ID and IDs of objects to be locked.
//
// The list of locked objects should be unique. Panics if the list is empty.

But there is no check if list is empty and no panic...

But there is no check if list is empty and no panic...

Three arguments is not so much. Moreover, in all functions, the first step is to expand the structure:

func (db *DB) Lock(ctx context.Context, prm LockPrm) (LockRes, error) {
	cnr := prm.cnt
	locker := prm.lock
	locked := prm.locked
	
...
Three arguments is not so much. Moreover, in all functions, the first step is to expand the structure: ``` func (db *DB) Lock(ctx context.Context, prm LockPrm) (LockRes, error) { cnr := prm.cnt locker := prm.lock locked := prm.locked ... ```
a-savchuk force-pushed add-lock-prm from 6f28a52e1a to fb5c4b0ad3 2024-12-11 22:39:59 +00:00 Compare
Owner

@a-savchuk what is the motivation for this PR?

@a-savchuk what is the motivation for this PR?
Author
Member

The initial motivation was to have a flag with a default value for the Lock and Inhume operations while working on #1445. The flag was meant to be used for writing tests those need to populate a metabase with locks of both old and new formats. Consider the following code snippet:

type LockPrm struct {
    // ...
    expEpoch uint64
   
   // Flag default value is false.
   // Should be used for test purposes only.
    skipExpEpochCheck bool
}

// ...

func TestLock(t *testing.T) {
    db := newDB(t)
    
    var prm meta.LockPrm
    
    prm.SetExpEpoch(100)
    _, _ = db.Lock(ctx, prm)
    
    prm.SetExpEpoch(meta.NoExpEpoch)
    prm.SkipExpEpochCheck()
    _, _ = db.Lock(ctx, prm)
}

Discussed with @fyrchik IRL
Decided not to add expiration epoch check at all and make setting expiration epoch explicit with lock target

The initial motivation was to have a flag with a default value for the Lock and Inhume operations while working on https://git.frostfs.info/TrueCloudLab/frostfs-node/issues/1445. The flag was meant to be used for writing tests those need to populate a metabase with locks of both old and new formats. Consider the following code snippet: ```go type LockPrm struct { // ... expEpoch uint64 // Flag default value is false. // Should be used for test purposes only. skipExpEpochCheck bool } // ... func TestLock(t *testing.T) { db := newDB(t) var prm meta.LockPrm prm.SetExpEpoch(100) _, _ = db.Lock(ctx, prm) prm.SetExpEpoch(meta.NoExpEpoch) prm.SkipExpEpochCheck() _, _ = db.Lock(ctx, prm) } ``` Discussed with @fyrchik IRL Decided not to add expiration epoch check at all and make setting expiration epoch explicit with lock target
a-savchuk closed this pull request 2024-12-12 08:13:41 +00:00
a-savchuk deleted branch add-lock-prm 2024-12-12 08:13:51 +00:00
All checks were successful
DCO action / DCO (pull_request) Successful in 2m1s
Required
Details
Tests and linters / Run gofumpt (pull_request) Successful in 2m30s
Required
Details
Vulncheck / Vulncheck (pull_request) Successful in 4m1s
Required
Details
Build / Build Components (pull_request) Successful in 4m34s
Required
Details
Tests and linters / gopls check (pull_request) Successful in 4m37s
Required
Details
Pre-commit hooks / Pre-commit (pull_request) Successful in 5m38s
Required
Details
Tests and linters / Tests (pull_request) Successful in 5m40s
Required
Details
Tests and linters / Tests with -race (pull_request) Successful in 5m48s
Required
Details
Tests and linters / Staticcheck (pull_request) Successful in 5m45s
Required
Details
Tests and linters / Lint (pull_request) Successful in 5m57s
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
TrueCloudLab/storage-core-committers
TrueCloudLab/storage-core-developers
No milestone
No project
No assignees
3 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#1556
No description provided.