Merge branch '15148-lost-collection-pdh'
[arvados.git] / services / keep-balance / collection.go
index 8f4ebb6bdfa277b33deeaf6cf2c0e2f2ecade076..534928bc82340bb23574f71ceac85c7872d8deb0 100644 (file)
@@ -36,23 +36,37 @@ func EachCollection(c *arvados.Client, pageSize int, f func(arvados.Collection)
        }
 
        expectCount, err := countCollections(c, arvados.ResourceListParams{
-               IncludeTrash: true,
+               IncludeTrash:       true,
+               IncludeOldVersions: true,
        })
        if err != nil {
                return err
        }
 
+       // Note the obvious way to get all collections (sorting by
+       // UUID) would be much easier, but would lose data: If a
+       // client were to move files from collection with uuid="zzz"
+       // to a collection with uuid="aaa" around the time when we
+       // were fetching the "mmm" page, we would never see those
+       // files' block IDs at all -- even if the client is careful to
+       // save "aaa" before saving "zzz".
+       //
+       // Instead, we get pages in modified_at order. Collections
+       // that are modified during the run will be re-fetched in a
+       // subsequent page.
+
        limit := pageSize
        if limit <= 0 {
                // Use the maximum page size the server allows
                limit = 1<<31 - 1
        }
        params := arvados.ResourceListParams{
-               Limit:        &limit,
-               Order:        "modified_at, uuid",
-               Count:        "none",
-               Select:       []string{"uuid", "unsigned_manifest_text", "modified_at", "portable_data_hash", "replication_desired"},
-               IncludeTrash: true,
+               Limit:              &limit,
+               Order:              "modified_at, uuid",
+               Count:              "none",
+               Select:             []string{"uuid", "unsigned_manifest_text", "modified_at", "portable_data_hash", "replication_desired"},
+               IncludeTrash:       true,
+               IncludeOldVersions: true,
        }
        var last arvados.Collection
        var filterTime time.Time
@@ -140,7 +154,8 @@ func EachCollection(c *arvados.Client, pageSize int, f func(arvados.Collection)
                        Attr:     "modified_at",
                        Operator: "<=",
                        Operand:  filterTime}},
-               IncludeTrash: true,
+               IncludeTrash:       true,
+               IncludeOldVersions: true,
        }); err != nil {
                return err
        } else if callCount < checkCount {