move node type definition to db level for node selection (#1295)
This commit is contained in:
parent
6e38481de1
commit
c6c23a319b
@ -124,8 +124,6 @@ func (cache *Cache) FindStorageNodes(ctx context.Context, req *pb.FindStorageNod
|
|||||||
}
|
}
|
||||||
|
|
||||||
reputableNodes, err := cache.db.SelectNodes(ctx, reputableNodeCount, &NodeCriteria{
|
reputableNodes, err := cache.db.SelectNodes(ctx, reputableNodeCount, &NodeCriteria{
|
||||||
Type: pb.NodeType_STORAGE,
|
|
||||||
|
|
||||||
FreeBandwidth: freeBandwidth,
|
FreeBandwidth: freeBandwidth,
|
||||||
FreeDisk: freeDisk,
|
FreeDisk: freeDisk,
|
||||||
|
|
||||||
@ -142,8 +140,6 @@ func (cache *Cache) FindStorageNodes(ctx context.Context, req *pb.FindStorageNod
|
|||||||
|
|
||||||
newNodeCount := int64(float64(reputableNodeCount) * preferences.NewNodePercentage)
|
newNodeCount := int64(float64(reputableNodeCount) * preferences.NewNodePercentage)
|
||||||
newNodes, err := cache.db.SelectNewNodes(ctx, int(newNodeCount), &NewNodeCriteria{
|
newNodes, err := cache.db.SelectNewNodes(ctx, int(newNodeCount), &NewNodeCriteria{
|
||||||
Type: pb.NodeType_STORAGE,
|
|
||||||
|
|
||||||
FreeBandwidth: freeBandwidth,
|
FreeBandwidth: freeBandwidth,
|
||||||
FreeDisk: freeDisk,
|
FreeDisk: freeDisk,
|
||||||
|
|
||||||
|
@ -176,9 +176,7 @@ func TestRandomizedSelection(t *testing.T) {
|
|||||||
|
|
||||||
// select numNodesToSelect nodes selectIterations times
|
// select numNodesToSelect nodes selectIterations times
|
||||||
for i := 0; i < selectIterations; i++ {
|
for i := 0; i < selectIterations; i++ {
|
||||||
nodes, err := cache.SelectNodes(ctx, numNodesToSelect, &overlay.NodeCriteria{
|
nodes, err := cache.SelectNodes(ctx, numNodesToSelect, &overlay.NodeCriteria{})
|
||||||
Type: pb.NodeType_STORAGE,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, nodes, numNodesToSelect)
|
require.Len(t, nodes, numNodesToSelect)
|
||||||
|
|
||||||
|
@ -67,8 +67,6 @@ func (server *Server) BulkLookup(ctx context.Context, reqs *pb.LookupRequests) (
|
|||||||
|
|
||||||
// NodeCriteria are the requirements for selecting nodes
|
// NodeCriteria are the requirements for selecting nodes
|
||||||
type NodeCriteria struct {
|
type NodeCriteria struct {
|
||||||
Type pb.NodeType
|
|
||||||
|
|
||||||
FreeBandwidth int64
|
FreeBandwidth int64
|
||||||
FreeDisk int64
|
FreeDisk int64
|
||||||
|
|
||||||
@ -82,8 +80,6 @@ type NodeCriteria struct {
|
|||||||
|
|
||||||
// NewNodeCriteria are the requirement for selecting new nodes
|
// NewNodeCriteria are the requirement for selecting new nodes
|
||||||
type NewNodeCriteria struct {
|
type NewNodeCriteria struct {
|
||||||
Type pb.NodeType
|
|
||||||
|
|
||||||
FreeBandwidth int64
|
FreeBandwidth int64
|
||||||
FreeDisk int64
|
FreeDisk int64
|
||||||
|
|
||||||
|
@ -24,22 +24,24 @@ type overlaycache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cache *overlaycache) SelectNodes(ctx context.Context, count int, criteria *overlay.NodeCriteria) ([]*pb.Node, error) {
|
func (cache *overlaycache) SelectNodes(ctx context.Context, count int, criteria *overlay.NodeCriteria) ([]*pb.Node, error) {
|
||||||
|
nodeType := int(pb.NodeType_STORAGE)
|
||||||
return cache.queryFilteredNodes(ctx, criteria.Excluded, count, `
|
return cache.queryFilteredNodes(ctx, criteria.Excluded, count, `
|
||||||
WHERE node_type = ? AND free_bandwidth >= ? AND free_disk >= ?
|
WHERE node_type = ? AND free_bandwidth >= ? AND free_disk >= ?
|
||||||
AND audit_count >= ?
|
AND audit_count >= ?
|
||||||
AND audit_success_ratio >= ?
|
AND audit_success_ratio >= ?
|
||||||
AND uptime_count >= ?
|
AND uptime_count >= ?
|
||||||
AND audit_uptime_ratio >= ?
|
AND audit_uptime_ratio >= ?
|
||||||
`, int(criteria.Type), criteria.FreeBandwidth, criteria.FreeDisk,
|
`, nodeType, criteria.FreeBandwidth, criteria.FreeDisk,
|
||||||
criteria.AuditCount, criteria.AuditSuccessRatio, criteria.UptimeCount, criteria.UptimeSuccessRatio,
|
criteria.AuditCount, criteria.AuditSuccessRatio, criteria.UptimeCount, criteria.UptimeSuccessRatio,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cache *overlaycache) SelectNewNodes(ctx context.Context, count int, criteria *overlay.NewNodeCriteria) ([]*pb.Node, error) {
|
func (cache *overlaycache) SelectNewNodes(ctx context.Context, count int, criteria *overlay.NewNodeCriteria) ([]*pb.Node, error) {
|
||||||
|
nodeType := int(pb.NodeType_STORAGE)
|
||||||
return cache.queryFilteredNodes(ctx, criteria.Excluded, count, `
|
return cache.queryFilteredNodes(ctx, criteria.Excluded, count, `
|
||||||
WHERE node_type = ? AND free_bandwidth >= ? AND free_disk >= ?
|
WHERE node_type = ? AND free_bandwidth >= ? AND free_disk >= ?
|
||||||
AND audit_count < ?
|
AND audit_count < ?
|
||||||
`, int(criteria.Type), criteria.FreeBandwidth, criteria.FreeDisk,
|
`, nodeType, criteria.FreeBandwidth, criteria.FreeDisk,
|
||||||
criteria.AuditThreshold,
|
criteria.AuditThreshold,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user