/
fsm_discovering.go
66 lines (58 loc) · 1.81 KB
/
fsm_discovering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package fsm
import (
"github.com/dotmesh-io/dotmesh/pkg/store"
"github.com/dotmesh-io/dotmesh/pkg/types"
log "github.com/sirupsen/logrus"
)
func discoveringState(f *FsMachine) StateFn {
f.transitionedTo("discovering", "loading")
log.Printf("entering discovering state for %s", f.filesystemId)
_, err := f.filesystemStore.GetMaster(f.filesystemId)
if err != nil && store.IsKeyNotFound(err) {
log.WithFields(log.Fields{
"error": err,
"filesystem_id": f.filesystemId,
}).Warn("[discoveringState] filesystem doesn't exist in the KV store, entering failed state forever")
return failedState
}
err = f.discover()
if err != nil {
log.WithFields(log.Fields{
"error": err,
"filesystem_id": f.filesystemId,
}).Error("[discoveringState] got error while discovering state")
return missingState
}
if !f.filesystem.Exists {
return missingState
} else {
err := f.state.AlignMountStateWithMasters(f.filesystemId)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"filesystem_id": f.filesystemId,
}).Error("[discoveringState] error trying to align mount state with masters, going into failed state forever")
return failedState
}
if f.filesystem.Mounted {
return activeState
} else {
return inactiveState
}
}
}
// If we initiated pull or push, we're only really finished after discovery,
// otherwise in-memory state won't match on-disk state and we can get race
// conditions due to that. So this wraps discovery and then only marks transfer
// as finished when discovery is done.
func discoveringAfterTransferInitiatorState(f *FsMachine) StateFn {
result := discoveringState(f)
f.transferUpdates <- types.TransferUpdate{
Kind: types.TransferStatus,
Changes: types.TransferPollResult{
Status: "finished",
Message: "",
},
}
return result
}