Skip to content
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

Simplify engine internals #3010

Merged
merged 5 commits into from
Nov 13, 2024
Merged

Simplify engine internals #3010

merged 5 commits into from
Nov 13, 2024

Conversation

roman-khimov
Copy link
Member

This continues #3008 with internal refactoring that is mostly about making code simpler and dropping useless code.

It's not used in any way as a struct.

Signed-off-by: Roman Khimov <[email protected]>
That's where KISS and DRY get into a little conflict. My take is that KISS
wins here:
 * it's five lines of code
 * yeah it's repetitive, but e.execIfNotBlocked() is repetitive as well with
   three lines of code minimum
 * it inherently requires lambdas
 * variables need to be defined and properly managed, some code looks a bit
   strange where we return (smth, error) and smth gets its value in a lambda,
   but error is the result of e.execIfNotBlocked()
 * in most cases it also leads to the need of additional "internal" functions
 * overall we get _less_ code after this patch
 * nothing hidden, clear execution flow

Signed-off-by: Roman Khimov <[email protected]>
It's a simple alias since 6ad2624 and the
only difference is an additional Hash() method that might as well be a part
of shardWrapper method set. This also simplifies sortShardsByWeight, we don't
need to hold the lock while sorting.

Signed-off-by: Roman Khimov <[email protected]>
These _seriously_ complicate the code for zero reason. We have to:
 * create/pass some lambdas
 * mess with input/output variables
 * mess with iterator flow instead of shortcutting to exit
 * have fun with defers and named return variables

Which leads to code bloat and increased cognitive load for developers. For
what purpose? I have no idea, dropping them makes code much easier.

Signed-off-by: Roman Khimov <[email protected]>
A lot of the same code, the only difference is apistatus.ObjectOutOfRange
handling which doesn't hurt for Get and is very much relevant for GetRange.

Signed-off-by: Roman Khimov <[email protected]>
@roman-khimov roman-khimov added enhancement Improving existing functionality U4 Nothing urgent S3 Minimally significant I4 No visible changes labels Nov 12, 2024
@roman-khimov roman-khimov added this to the v0.44.0 milestone Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 162 lines in your changes missing coverage. Please review.

Project coverage is 22.83%. Comparing base (6ea74d2) to head (99d4320).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
pkg/local_object_storage/engine/inhume.go 45.31% 33 Missing and 2 partials ⚠️
pkg/local_object_storage/engine/container.go 0.00% 31 Missing ⚠️
pkg/local_object_storage/engine/select.go 16.66% 19 Missing and 1 partial ⚠️
pkg/local_object_storage/engine/lock.go 48.38% 15 Missing and 1 partial ⚠️
pkg/local_object_storage/engine/get.go 78.87% 9 Missing and 6 partials ⚠️
pkg/local_object_storage/engine/status.go 0.00% 9 Missing ⚠️
pkg/local_object_storage/engine/head.go 72.00% 7 Missing ⚠️
pkg/local_object_storage/engine/tree.go 0.00% 7 Missing ⚠️
pkg/local_object_storage/engine/exists.go 25.00% 5 Missing and 1 partial ⚠️
pkg/local_object_storage/engine/put.go 64.28% 4 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3010      +/-   ##
==========================================
- Coverage   22.99%   22.83%   -0.16%     
==========================================
  Files         790      790              
  Lines       58500    58342     -158     
==========================================
- Hits        13454    13325     -129     
+ Misses      44167    44136      -31     
- Partials      879      881       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roman-khimov
Copy link
Member Author

Copy link
Member

@carpawell carpawell left a comment

Choose a reason for hiding this comment

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

One step closer to heaven.


// stop iterating over shards if SplitInfo structure is complete
return !outSI.GetLink().IsZero() && !outSI.GetLastPart().IsZero()
if !splitInfo.GetLink().IsZero() && !splitInfo.GetLastPart().IsZero() {
return logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo))
Copy link
Member

Choose a reason for hiding this comment

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

can this line be just break?

Copy link
Member Author

@roman-khimov roman-khimov Nov 12, 2024

Choose a reason for hiding this comment

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

That in fact is one of the things I wanted to discuss. It looks like split info collection we attempt to do here (with iteration-persistent splitInfo) is totally useless, we can return immediately upon seeing any split info because that's what we do ultimately anyway. But maybe I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

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

split information may or may not have a link object and a last part (it is theoretically ok to have a middle object only, be resynced, etc)

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding the comment above --- having a complete split info is beneficial to the caller (even though it gets an error), so this if can't be removed even though lacking a proper info we will return whatever is available.

Regarding break/return --- both are valid, so it doesn't matter much, post-loop can be extended in which case return is better even though currently it duplicates error wrapping a bit.


// stop iterating over shards if SplitInfo structure is complete
return !outSI.GetLink().IsZero() && !outSI.GetLastPart().IsZero()
if !splitInfo.GetLink().IsZero() && !splitInfo.GetLastPart().IsZero() {
return nil, logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo))
Copy link
Member

Choose a reason for hiding this comment

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

same here


// stop iterating over shards if SplitInfo structure is complete
return !outSI.GetLink().IsZero() && !outSI.GetLastPart().IsZero()
if !splitInfo.GetLink().IsZero() && !splitInfo.GetLastPart().IsZero() {
return nil, logicerr.Wrap(objectSDK.NewSplitInfoError(splitInfo))
Copy link
Member

Choose a reason for hiding this comment

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

same

@roman-khimov roman-khimov merged commit 76a9b10 into master Nov 13, 2024
21 of 22 checks passed
@roman-khimov roman-khimov deleted the simplify-engine-internals branch November 13, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving existing functionality I4 No visible changes S3 Minimally significant U4 Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants