restore: Rework extraction pipeline to use xsync.WorkGroup
The pattern where multiple workers are spawned to work on a common task and where whole work needs to be canceled on first error is now well understood, with the functionality to broadcast cancel and propagate errors being wrapped into libraries such as https://godoc.org/golang.org/x/sync/errgroup and https://godoc.org/lab.nexedi.com/kirr/go123/xsync#WorkGroup (kirr/go123@515a6d14) Let's streamline the code by using xsync.WorkGroup (it is in our hands, a bit more well designed (imho), has analog in Pygolang, and can be changed/enhanced as needed). The other reason to rework the code is that the workgroup is created under context (currently always background) and can be canceled by that context cancel. In the next patch we'll teach all git-backup subcommands, including restore, to work under context, and by using xsync.WorkGroup we will automatically handle cancellation from outside, while without reworking extraction pipeline we would need to additionally glue ctx cancel to signal to workers to stop. Compared to previous state both xsync.WorkGroup and errogroup return only the first error, however it should likely not cause problems in practice as the first error is usually the most informative one.
Showing
Please register or sign in to comment