mirror of
https://github.com/zrepl/zrepl.git
synced 2025-04-28 21:38:35 +02:00
daemon/job: track active side state explicitly
This commit is contained in:
parent
5efeec1819
commit
f704b28cad
@ -38,10 +38,29 @@ type ActiveSide struct {
|
|||||||
tasks activeSideTasks
|
tasks activeSideTasks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//go:generate enumer -type=ActiveSideState
|
||||||
|
type ActiveSideState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
ActiveSideReplicating ActiveSideState = 1 << iota
|
||||||
|
ActiveSidePruneSender
|
||||||
|
ActiveSidePruneReceiver
|
||||||
|
ActiveSideDone // also errors
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
type activeSideTasks struct {
|
type activeSideTasks struct {
|
||||||
|
state ActiveSideState
|
||||||
|
|
||||||
|
// valid for state ActiveSideReplicating, ActiveSidePruneSender, ActiveSidePruneReceiver, ActiveSideDone
|
||||||
replication *replication.Replication
|
replication *replication.Replication
|
||||||
replicationCancel context.CancelFunc
|
replicationCancel context.CancelFunc
|
||||||
|
|
||||||
|
// valid for state ActiveSidePruneSender, ActiveSidePruneReceiver, ActiveSideDone
|
||||||
prunerSender, prunerReceiver *pruner.Pruner
|
prunerSender, prunerReceiver *pruner.Pruner
|
||||||
|
|
||||||
|
// valid for state ActiveSidePruneReceiver, ActiveSideDone
|
||||||
prunerSenderCancel, prunerReceiverCancel context.CancelFunc
|
prunerSenderCancel, prunerReceiverCancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,6 +356,7 @@ func (j *ActiveSide) do(ctx context.Context) {
|
|||||||
*tasks = activeSideTasks{}
|
*tasks = activeSideTasks{}
|
||||||
tasks.replicationCancel = repCancel
|
tasks.replicationCancel = repCancel
|
||||||
tasks.replication = replication.NewReplication(j.promRepStateSecs, j.promBytesReplicated)
|
tasks.replication = replication.NewReplication(j.promRepStateSecs, j.promBytesReplicated)
|
||||||
|
tasks.state = ActiveSideReplicating
|
||||||
})
|
})
|
||||||
log.Info("start replication")
|
log.Info("start replication")
|
||||||
tasks.replication.Drive(ctx, sender, receiver)
|
tasks.replication.Drive(ctx, sender, receiver)
|
||||||
@ -353,6 +373,7 @@ func (j *ActiveSide) do(ctx context.Context) {
|
|||||||
tasks := j.updateTasks(func(tasks *activeSideTasks) {
|
tasks := j.updateTasks(func(tasks *activeSideTasks) {
|
||||||
tasks.prunerSender = j.prunerFactory.BuildSenderPruner(ctx, sender, sender)
|
tasks.prunerSender = j.prunerFactory.BuildSenderPruner(ctx, sender, sender)
|
||||||
tasks.prunerSenderCancel = senderCancel
|
tasks.prunerSenderCancel = senderCancel
|
||||||
|
tasks.state = ActiveSidePruneSender
|
||||||
})
|
})
|
||||||
log.Info("start pruning sender")
|
log.Info("start pruning sender")
|
||||||
tasks.prunerSender.Prune()
|
tasks.prunerSender.Prune()
|
||||||
@ -369,10 +390,16 @@ func (j *ActiveSide) do(ctx context.Context) {
|
|||||||
tasks := j.updateTasks(func(tasks *activeSideTasks) {
|
tasks := j.updateTasks(func(tasks *activeSideTasks) {
|
||||||
tasks.prunerReceiver = j.prunerFactory.BuildReceiverPruner(ctx, receiver, sender)
|
tasks.prunerReceiver = j.prunerFactory.BuildReceiverPruner(ctx, receiver, sender)
|
||||||
tasks.prunerReceiverCancel = receiverCancel
|
tasks.prunerReceiverCancel = receiverCancel
|
||||||
|
tasks.state = ActiveSidePruneReceiver
|
||||||
})
|
})
|
||||||
log.Info("start pruning receiver")
|
log.Info("start pruning receiver")
|
||||||
tasks.prunerReceiver.Prune()
|
tasks.prunerReceiver.Prune()
|
||||||
log.Info("finished pruning receiver")
|
log.Info("finished pruning receiver")
|
||||||
receiverCancel()
|
receiverCancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j.updateTasks(func(tasks *activeSideTasks) {
|
||||||
|
tasks.state = ActiveSideDone
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
66
daemon/job/activesidestate_enumer.go
Normal file
66
daemon/job/activesidestate_enumer.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Code generated by "enumer -type=ActiveSideState"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package job
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ActiveSideStateName_0 = "ActiveSideReplicatingActiveSidePruneSender"
|
||||||
|
_ActiveSideStateName_1 = "ActiveSidePruneReceiver"
|
||||||
|
_ActiveSideStateName_2 = "ActiveSideDone"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ActiveSideStateIndex_0 = [...]uint8{0, 21, 42}
|
||||||
|
_ActiveSideStateIndex_1 = [...]uint8{0, 23}
|
||||||
|
_ActiveSideStateIndex_2 = [...]uint8{0, 14}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i ActiveSideState) String() string {
|
||||||
|
switch {
|
||||||
|
case 1 <= i && i <= 2:
|
||||||
|
i -= 1
|
||||||
|
return _ActiveSideStateName_0[_ActiveSideStateIndex_0[i]:_ActiveSideStateIndex_0[i+1]]
|
||||||
|
case i == 4:
|
||||||
|
return _ActiveSideStateName_1
|
||||||
|
case i == 8:
|
||||||
|
return _ActiveSideStateName_2
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("ActiveSideState(%d)", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ActiveSideStateValues = []ActiveSideState{1, 2, 4, 8}
|
||||||
|
|
||||||
|
var _ActiveSideStateNameToValueMap = map[string]ActiveSideState{
|
||||||
|
_ActiveSideStateName_0[0:21]: 1,
|
||||||
|
_ActiveSideStateName_0[21:42]: 2,
|
||||||
|
_ActiveSideStateName_1[0:23]: 4,
|
||||||
|
_ActiveSideStateName_2[0:14]: 8,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveSideStateString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func ActiveSideStateString(s string) (ActiveSideState, error) {
|
||||||
|
if val, ok := _ActiveSideStateNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to ActiveSideState values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveSideStateValues returns all values of the enum
|
||||||
|
func ActiveSideStateValues() []ActiveSideState {
|
||||||
|
return _ActiveSideStateValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAActiveSideState returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i ActiveSideState) IsAActiveSideState() bool {
|
||||||
|
for _, v := range _ActiveSideStateValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user