[#92] Refactor policer and add some unit tests #485
No reviewers
Labels
No labels
P0
P1
P2
P3
badger
frostfs-adm
frostfs-cli
frostfs-ir
frostfs-lens
frostfs-node
good first issue
triage
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#485
Loading…
Reference in a new issue
No description provided.
Delete branch "ale64bit/frostfs-node:fix/policer-refactor-test"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Signed-off-by: Alejandro Lopez a.lopez@yadro.com
@ -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
So
BuryFunc
is a function, butReplicator
is a single-method interface.What are the differences?
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.@ -0,0 +51,4 @@
log *logger.Logger
keySpaceIt KeySpaceIterator
Why
It
and notIterator
?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.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.done
I don't think I've ever seen people writing variable names like
iLikeToMoveItMoveIt
or anything like that, where anIt
suffix might be ambiguous.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
Why this change? Could you move it to a separate commit?
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.done
@ -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() {
We have
cid.ID.Equals()
for this purpose, which is better (see the comment toEquals
). Same foroid.ID
.done
@ -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)
Why not
require.Equal
?done (TrueCloudLab/frostfs-sdk-go#101)
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?but ... I did change it to:
What exactly do you propose?
I see, looked at the old version first.
@ -0,0 +271,4 @@
return ret, nil
}
// containerSrcFunc is a container.Source backed by a function
Dot at the end (here and below), tests are skipped by linter, godot would complain
done
@ -67,3 +54,1 @@
p.cache.Add(addr.Address, time.Now())
p.objsInWork.remove(addr.Address)
if p.objsInWork.add(addr.Address) {
What was the problem here? Anyway, could you move this to a separate commit?
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.
c1bdf2cf13
to99c8b9e641
99c8b9e641
tofb0d6d1e5d
fb0d6d1e5d
toe7f3a9fc19