PUT to cluster send to all nodes rather than none
authorJoey Hess <joeyh@joeyh.name>
Tue, 25 Jun 2024 14:32:34 +0000 (10:32 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 25 Jun 2024 14:32:34 +0000 (10:32 -0400)
If the location log says all nodes contain content, pass in all nodes,
rather than none.

The location log can be wrong. While it's good to avoid unncessessary
connections to nodes that already contain a key, it would be bad to
refuse to accept an upload at all when the location log is wrong.

Also, passing in no nodes leaves the proxy in an untenable state. It
can't proxy to no nodes. So it closes the connection. Passing in all
nodes means it has to do the work to connect to all of them, and see
that they say they already have the content, and then it can tell the
client that.

Annex/Cluster.hs

index 10125e9c5f6d2cb4e7ba32e7c683f288a365a2b5..4f60f6ca25bf62a7c9ea7ea7009fef13d15b79e1 100644 (file)
@@ -67,10 +67,15 @@ clusterProxySelector clusteruuid protocolversion = do
        return $ ProxySelector
                { proxyCHECKPRESENT = nodecontaining remotesides
                , proxyGET = nodecontaining remotesides
-               -- Send the key to every node that does not yet contain it.
+               -- The key is sent to multiple nodes at the same time,
+               -- skipping nodes where it's known/expected to already be
+               -- present to avoid needing to connect to those.
                , proxyPUT = \k -> do
                        locs <- S.fromList <$> loggedLocations k
-                       return $ filter (flip S.notMember locs . remoteUUID) remotesides
+                       let l = filter (flip S.notMember locs . remoteUUID) remotesides
+                       return $ if null l
+                               then remotesides
+                               else l
                -- Remove the key from every node that contains it.
                -- But, since it's possible the location log for some nodes
                -- could be out of date, actually try to remove from every