@@ -36,6 +36,7 @@ import (
3636 "github.com/function61/varasto/pkg/stoserver/stodbimportexport"
3737 "github.com/function61/varasto/pkg/stoserver/stohealth"
3838 "github.com/function61/varasto/pkg/stoserver/stointegrityverifier"
39+ "github.com/function61/varasto/pkg/stoserver/storeplication"
3940 "github.com/function61/varasto/pkg/stoserver/stoservertypes"
4041 "github.com/function61/varasto/pkg/stotypes"
4142 "github.com/function61/varasto/pkg/stoutils"
@@ -850,19 +851,49 @@ func (h *handlers) GetSchedulerJobs(rctx *httpauth.RequestContext, w http.Respon
850851}
851852
852853func (h * handlers ) GetReplicationStatuses (rctx * httpauth.RequestContext , w http.ResponseWriter , r * http.Request ) * []stoservertypes.ReplicationStatus {
854+ tx , err := h .db .Begin (false )
855+ panicIfError (err )
856+ defer func () { ignoreError (tx .Rollback ()) }()
857+
858+ dbObjects := []stotypes.Volume {}
859+ panicIfError (stodb .VolumeRepository .Each (stodb .Appender (& dbObjects ), tx ))
860+
853861 statuses := []stoservertypes.ReplicationStatus {}
854- for volID , controller := range h .conf .ReplicationControllers {
855- statuses = append (statuses , stoservertypes.ReplicationStatus {
856- VolumeId : volID ,
857- Progress : controller .Progress (),
858- Error : func () * string {
859- if err := controller .Error (); err != nil {
860- return gokitbp .Pointer (err .Error ())
862+ for _ , vol := range dbObjects {
863+ controller , hasController := h .conf .ReplicationControllers [vol .ID ]
864+
865+ makeStat := func (progress int , err * string ) stoservertypes.ReplicationStatus {
866+ return stoservertypes.ReplicationStatus {
867+ Error : err ,
868+ Progress : progress ,
869+ VolumeId : vol .ID ,
870+ }
871+ }
872+
873+ status := func () stoservertypes.ReplicationStatus {
874+ if hasController {
875+ errorStr := func () * string {
876+ if err := controller .Error (); err != nil {
877+ return gokitbp .Pointer (err .Error ())
878+ } else {
879+ return nil
880+ }
881+ }()
882+
883+ return makeStat (controller .Progress (), errorStr )
884+ } else {
885+ anyQueued , err := storeplication .HasQueuedWriteIOsForVolume (vol .ID , tx )
886+ panicIfError (err )
887+
888+ if anyQueued {
889+ return makeStat (0 , gokitbp .Pointer ("Queued I/Os but replication paused" ))
861890 } else {
862- return nil
891+ return makeStat ( 100 , nil )
863892 }
864- }(),
865- })
893+ }
894+ }()
895+
896+ statuses = append (statuses , status )
866897 }
867898
868899 return & statuses
0 commit comments