Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satellite/{nodeselection,repair}: Placement level invariant for custo…
…mizable declumping This patch extends the placement with the 'Invariant' interface. It's used by the repairer/repair checker to decide if declumping is needed. This will extend declumping, and will make it possible to use any invariant, not just last_node based rules. Change-Id: Ic8537ecd19022a2cfa06445f47a00d1110a7afa6
- Loading branch information
Showing
13 changed files
with
88 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (C) 2023 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package nodeselection | ||
|
||
import ( | ||
"storj.io/storj/private/intset" | ||
"storj.io/storj/satellite/metabase" | ||
) | ||
|
||
// Invariant checks the current placement, and identifies the pieces which should be moved. | ||
// Used by repair jobs. | ||
type Invariant func(pieces metabase.Pieces, nodes []SelectedNode) intset.Set | ||
|
||
// AllGood is an invariant, which accepts all piece sets as good. | ||
func AllGood() Invariant { | ||
return func(pieces metabase.Pieces, nodes []SelectedNode) intset.Set { | ||
return intset.NewSet(0) | ||
} | ||
} | ||
|
||
// ClumpingByAttribute allows only one selected piece by attribute groups. | ||
func ClumpingByAttribute(attr NodeAttribute, maxAllowed int) Invariant { | ||
return func(pieces metabase.Pieces, nodes []SelectedNode) intset.Set { | ||
usedGroups := make(map[string]int, len(pieces)) | ||
|
||
maxPieceNum := 0 | ||
for _, piece := range pieces { | ||
if int(piece.Number) > maxPieceNum { | ||
maxPieceNum = int(piece.Number) | ||
} | ||
} | ||
maxPieceNum++ | ||
|
||
res := intset.NewSet(maxPieceNum) | ||
|
||
for index, nodeRecord := range nodes { | ||
attribute := attr(nodeRecord) | ||
if attribute == "" { | ||
continue | ||
} | ||
pieceNum := pieces[index].Number | ||
count := usedGroups[attribute] | ||
if count >= maxAllowed { | ||
// this group was already seen, enough times | ||
res.Include(int(pieceNum)) | ||
} else { | ||
// add to the list of seen groups | ||
usedGroups[attribute] = count + 1 | ||
} | ||
} | ||
|
||
return res | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters