[#92] Refactor policer and add some unit tests #485

Merged
fyrchik merged 3 commits from ale64bit/frostfs-node:fix/policer-refactor-test into master 2023-07-03 07:05:33 +00:00
Member

Signed-off-by: Alejandro Lopez a.lopez@yadro.com

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
ale64bit requested review from storage-core-committers 2023-06-29 09:18:36 +00:00
ale64bit requested review from storage-core-developers 2023-06-29 09:18:36 +00:00
fyrchik approved these changes 2023-06-29 15:03:52 +00:00
@ -0,0 +30,4 @@
type RedundantCopyCallback func(context.Context, oid.Address)
// BuryFunc is the function to bury (i.e. inhume) an object.
type BuryFunc func(context.Context, oid.Address) error
Owner

So BuryFunc is a function, but Replicator is a single-method interface.
What are the differences?

So `BuryFunc` is a function, but `Replicator` is a single-method interface. What are the differences?
Author
Member

I don't think there's a major difference, except where the wrapper will live. In this case, I tried to preserve the call-site option for Replicator by making it an interface in policer, while the bury function wasn't there in the first place so there was no need to wrap it in a struct/interface.

I don't think there's a major difference, except where the wrapper will live. In this case, I tried to preserve the call-site option for `Replicator` by making it an interface in policer, while the bury function wasn't there in the first place so there was no need to wrap it in a struct/interface.
fyrchik marked this conversation as resolved
@ -0,0 +51,4 @@
log *logger.Logger
keySpaceIt KeySpaceIterator
Owner

Why It and not Iterator?

Why `It` and not `Iterator`?
Author
Member

It's a well-known abbreviation so it seems clear to shorten it.
Other fields use similar or less-known abbreviations, e.g. cfg, cnrSrc, cbRedundantCopy, rebalanceFreq` and so on.

It's a well-known abbreviation so it seems clear to shorten it. Other fields use similar or less-known abbreviations, e.g. `cfg, `cnrSrc`, `cbRedundantCopy`, `rebalanceFreq` and so on.
Owner

Ok, but I had some troubles with parsing -- it is also an anaphor and it is hard to tell the meaning without looking at the type.

Ok, but I had some troubles with parsing -- `it` is also an anaphor and it is hard to tell the meaning without looking at the type.
Author
Member

done

it is also an anaphor and it is hard to tell the meaning without looking at the type.

I don't think I've ever seen people writing variable names like iLikeToMoveItMoveIt or anything like that, where an It suffix might be ambiguous.

done > it is also an anaphor and it is hard to tell the meaning without looking at the type. I don't think I've ever seen people writing variable names like `iLikeToMoveItMoveIt` or anything like that, where an `It` suffix might be ambiguous.
Owner

Ironially, we have ToMoveIt in the metabase code. I don't like it though.

Ironially, we have `ToMoveIt` in the metabase code. I don't like it though.
@ -26,3 +13,2 @@
type objectsInWork struct {
m sync.RWMutex
sync.RWMutex
Owner

Why this change? Could you move it to a separate commit?

Why this change? Could you move it to a separate commit?
Author
Member

Why this change?

If the purpose of the struct is just to wrap a field and its lock, it seems cleaner to me to embed the lock to avoid the .mu stutter in methods.

Could you move it to a separate commit?

done

> Why this change? If the purpose of the `struct` is just to wrap a field and its lock, it seems cleaner to me to embed the lock to avoid the `.mu` stutter in methods. > Could you move it to a separate commit? done
fyrchik marked this conversation as resolved
@ -0,0 +168,4 @@
}
}
placementBuilder := func(cnr cid.ID, obj *oid.ID, p netmap.PlacementPolicy) ([][]netmap.NodeInfo, error) {
if cnr == addr.Container() && obj != nil && *obj == addr.Object() {
Owner

We have cid.ID.Equals() for this purpose, which is better (see the comment to Equals). Same for oid.ID.

We have `cid.ID.Equals()` for this purpose, which is better (see the comment to `Equals`). Same for `oid.ID`.
Author
Member

done

done
fyrchik marked this conversation as resolved
@ -0,0 +220,4 @@
WithBuryFunc(buryFn),
WithRedundantCopyCallback(func(_ context.Context, a oid.Address) {
if a != addr {
t.Errorf("unexpected redundant copy callback: a=%v", a)
Owner

Why not require.Equal?

Why not `require.Equal`?
Author
Member
done (https://git.frostfs.info/TrueCloudLab/frostfs-sdk-go/issues/101)
Owner

No, I mean that we use https://github.com/stretchr/testify and not t.* directly across the codebase. Do we have a compelling reason to not be uniform here?

No, I mean that we use https://github.com/stretchr/testify and not `t.*` directly across the codebase. Do we have a compelling reason to not be uniform here?
Author
Member

but ... I did change it to:

require.True(t, eqAddr(a, addr), "unexpected redundant copy callback: a=%v", a)

What exactly do you propose?

but ... I did change it to: ``` require.True(t, eqAddr(a, addr), "unexpected redundant copy callback: a=%v", a) ``` What exactly do you propose?
Owner

I see, looked at the old version first.

I see, looked at the old version first.
fyrchik marked this conversation as resolved
@ -0,0 +271,4 @@
return ret, nil
}
// containerSrcFunc is a container.Source backed by a function
Owner

Dot at the end (here and below), tests are skipped by linter, godot would complain

Dot at the end (here and below), tests are skipped by linter, godot would complain
Author
Member

done

done
fyrchik marked this conversation as resolved
@ -67,3 +54,1 @@
p.cache.Add(addr.Address, time.Now())
p.objsInWork.remove(addr.Address)
if p.objsInWork.add(addr.Address) {
Owner

What was the problem here? Anyway, could you move this to a separate commit?

What was the problem here? Anyway, could you move this to a separate commit?
Author
Member

Seems to me that it's possible (in theory, I don't have a test case yet) for an object to be worked on concurrently, with enough bad luck and proper scheduler timing. This ensures it can't happen.

Seems to me that it's possible (in theory, I don't have a test case yet) for an object to be worked on concurrently, with enough bad luck and proper scheduler timing. This ensures it can't happen.
fyrchik marked this conversation as resolved
ale64bit force-pushed fix/policer-refactor-test from c1bdf2cf13 to 99c8b9e641 2023-06-30 07:17:11 +00:00 Compare
ale64bit force-pushed fix/policer-refactor-test from 99c8b9e641 to fb0d6d1e5d 2023-06-30 08:02:03 +00:00 Compare
ale64bit requested review from fyrchik 2023-06-30 08:02:39 +00:00
dstepanov-yadro approved these changes 2023-06-30 08:31:59 +00:00
ale64bit force-pushed fix/policer-refactor-test from fb0d6d1e5d to e7f3a9fc19 2023-07-03 06:42:03 +00:00 Compare
acid-ant approved these changes 2023-07-03 06:54:04 +00:00
fyrchik approved these changes 2023-07-03 07:05:27 +00:00
fyrchik merged commit 26acf5689e into master 2023-07-03 07:05:33 +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#485
No description provided.