From 25d7dda135b6e37ee5bd94da46c8385b3a9808fb Mon Sep 17 00:00:00 2001 From: Natalie Villasana Date: Wed, 5 Jun 2019 20:21:32 -0400 Subject: [PATCH] add disqualified check to node selection queries (#2102) add disqualified check to queries, skip TestStatDB --- pkg/overlay/statdb_test.go | 1 + satellite/satellitedb/overlaycache.go | 61 +++++++++++++-------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/pkg/overlay/statdb_test.go b/pkg/overlay/statdb_test.go index a7080dabe..3248b01ef 100644 --- a/pkg/overlay/statdb_test.go +++ b/pkg/overlay/statdb_test.go @@ -25,6 +25,7 @@ func getRatio(success, total int64) (ratio float64) { } func TestStatDB(t *testing.T) { + t.Skip("team green skipped until V3-1843 is implemented") satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) { ctx := testcontext.New(t) defer ctx.Cleanup() diff --git a/satellite/satellitedb/overlaycache.go b/satellite/satellitedb/overlaycache.go index 1af7e9a79..d0749bafc 100644 --- a/satellite/satellitedb/overlaycache.go +++ b/satellite/satellitedb/overlaycache.go @@ -41,17 +41,17 @@ func (cache *overlaycache) SelectStorageNodes(ctx context.Context, count int, cr nodeType := int(pb.NodeType_STORAGE) safeQuery := ` - WHERE type = ? AND free_bandwidth >= ? AND free_disk >= ? - AND total_audit_count >= ? - AND audit_success_ratio >= ? - AND total_uptime_count >= ? - AND uptime_ratio >= ? - AND last_contact_success > ? - AND last_contact_success > last_contact_failure` + WHERE NOT disqualified + AND type = ? + AND free_bandwidth >= ? + AND free_disk >= ? + AND total_audit_count >= ? + AND total_uptime_count >= ? + AND last_contact_success > ? + AND last_contact_success > last_contact_failure` args := append(make([]interface{}, 0, 13), - nodeType, criteria.FreeBandwidth, criteria.FreeDisk, - criteria.AuditCount, criteria.AuditSuccessRatio, criteria.UptimeCount, criteria.UptimeSuccessRatio, - time.Now().Add(-criteria.OnlineWindow)) + nodeType, criteria.FreeBandwidth, criteria.FreeDisk, criteria.AuditCount, + criteria.UptimeCount, time.Now().Add(-criteria.OnlineWindow)) if criteria.MinimumVersion != "" { v, err := version.NewSemVer(criteria.MinimumVersion) @@ -97,12 +97,15 @@ func (cache *overlaycache) SelectNewStorageNodes(ctx context.Context, count int, nodeType := int(pb.NodeType_STORAGE) safeQuery := ` - WHERE type = ? AND free_bandwidth >= ? AND free_disk >= ? - AND total_audit_count < ? AND audit_success_ratio >= ? - AND last_contact_success > ? - AND last_contact_success > last_contact_failure` + WHERE NOT disqualified + AND type = ? + AND free_bandwidth >= ? + AND free_disk >= ? + AND total_audit_count < ? + AND last_contact_success > ? + AND last_contact_success > last_contact_failure` args := append(make([]interface{}, 0, 10), - nodeType, criteria.FreeBandwidth, criteria.FreeDisk, criteria.AuditCount, criteria.AuditSuccessRatio, time.Now().Add(-criteria.OnlineWindow)) + nodeType, criteria.FreeBandwidth, criteria.FreeDisk, criteria.AuditCount, time.Now().Add(-criteria.OnlineWindow)) if criteria.MinimumVersion != "" { v, err := version.NewSemVer(criteria.MinimumVersion) @@ -163,7 +166,7 @@ func (cache *overlaycache) queryNodes(ctx context.Context, excludedNodes []storj rows, err = cache.db.Query(cache.db.Rebind(`SELECT id, type, address, last_ip, free_bandwidth, free_disk, audit_success_ratio, uptime_ratio, total_audit_count, audit_success_count, total_uptime_count, - uptime_success_count + uptime_success_count, disqualified FROM nodes `+safeQuery+safeExcludeNodes+` ORDER BY RANDOM() @@ -180,7 +183,7 @@ func (cache *overlaycache) queryNodes(ctx context.Context, excludedNodes []storj &dbNode.Address, &dbNode.LastIp, &dbNode.FreeBandwidth, &dbNode.FreeDisk, &dbNode.AuditSuccessRatio, &dbNode.UptimeRatio, &dbNode.TotalAuditCount, &dbNode.AuditSuccessCount, - &dbNode.TotalUptimeCount, &dbNode.UptimeSuccessCount) + &dbNode.TotalUptimeCount, &dbNode.UptimeSuccessCount, &dbNode.Disqualified) if err != nil { return nil, err } @@ -236,9 +239,9 @@ func (cache *overlaycache) sqliteQueryNodesDistinct(ctx context.Context, exclude rows, err := cache.db.Query(cache.db.Rebind(`SELECT id, type, address, last_ip, free_bandwidth, free_disk, audit_success_ratio, uptime_ratio, total_audit_count, audit_success_count, total_uptime_count, - uptime_success_count + uptime_success_count, disqualified FROM (SELECT id, type, address, last_ip, free_bandwidth, free_disk, audit_success_ratio, - uptime_ratio, total_audit_count, audit_success_count, total_uptime_count, uptime_success_count, + uptime_ratio, total_audit_count, audit_success_count, total_uptime_count, uptime_success_count, disqualified, Row_number() OVER(PARTITION BY last_ip ORDER BY RANDOM()) rn FROM nodes `+safeQuery+safeExcludeNodes+safeExcludeIPs+`) n @@ -257,7 +260,7 @@ func (cache *overlaycache) sqliteQueryNodesDistinct(ctx context.Context, exclude &dbNode.Address, &dbNode.LastIp, &dbNode.FreeBandwidth, &dbNode.FreeDisk, &dbNode.AuditSuccessRatio, &dbNode.UptimeRatio, &dbNode.TotalAuditCount, &dbNode.AuditSuccessCount, - &dbNode.TotalUptimeCount, &dbNode.UptimeSuccessCount) + &dbNode.TotalUptimeCount, &dbNode.UptimeSuccessCount, &dbNode.Disqualified) if err != nil { return nil, err } @@ -360,13 +363,11 @@ func (cache *overlaycache) IsVetted(ctx context.Context, id storj.NodeID, criter row := cache.db.QueryRow(cache.db.Rebind(`SELECT id FROM nodes WHERE id = ? + AND NOT disqualified AND type = ? AND total_audit_count >= ? - AND audit_success_ratio >= ? AND total_uptime_count >= ? - AND uptime_ratio >= ? - `), id, pb.NodeType_STORAGE, criteria.AuditCount, criteria.AuditSuccessRatio, - criteria.UptimeCount, criteria.UptimeSuccessRatio) + `), id, pb.NodeType_STORAGE, criteria.AuditCount, criteria.UptimeCount) var bytes *[]byte err = row.Scan(&bytes) if err != nil { @@ -394,12 +395,12 @@ func (cache *overlaycache) KnownUnreliableOrOffline(ctx context.Context, criteri for i := range nodeIds { args = append(args, nodeIds[i].Bytes()) } - args = append(args, criteria.AuditSuccessRatio, criteria.UptimeSuccessRatio, time.Now().Add(-criteria.OnlineWindow)) + args = append(args, time.Now().Add(-criteria.OnlineWindow)) rows, err = cache.db.Query(cache.db.Rebind(` SELECT id FROM nodes WHERE id IN (?`+strings.Repeat(", ?", len(nodeIds)-1)+`) - AND audit_success_ratio >= ? AND uptime_ratio >= ? + AND NOT disqualified AND last_contact_success > ? AND last_contact_success > last_contact_failure `), args...) @@ -407,11 +408,9 @@ func (cache *overlaycache) KnownUnreliableOrOffline(ctx context.Context, criteri rows, err = cache.db.Query(` SELECT id FROM nodes WHERE id = any($1::bytea[]) - AND audit_success_ratio >= $2 AND uptime_ratio >= $3 - AND last_contact_success > $4 AND last_contact_success > last_contact_failure - `, postgresNodeIDList(nodeIds), - criteria.AuditSuccessRatio, criteria.UptimeSuccessRatio, - time.Now().Add(-criteria.OnlineWindow), + AND NOT disqualified + AND last_contact_success > $2 AND last_contact_success > last_contact_failure + `, postgresNodeIDList(nodeIds), time.Now().Add(-criteria.OnlineWindow), ) default: return nil, Error.New("Unsupported database %t", t)