/
types.go
204 lines (166 loc) · 4.38 KB
/
types.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package types
import (
"io"
"strings"
"time"
"github.com/longhorn/types/pkg/generated/enginerpc"
)
const (
WO = Mode("WO")
RW = Mode("RW")
ERR = Mode("ERR")
ProcessStateComplete = ProcessState("complete")
ProcessStateError = ProcessState("error")
ProcessStateInProgress = ProcessState("in_progress")
StateUp = State("up")
StateDown = State("down")
AWSAccessKey = "AWS_ACCESS_KEY_ID"
AWSSecretKey = "AWS_SECRET_ACCESS_KEY"
AWSEndPoint = "AWS_ENDPOINTS"
AWSCert = "AWS_CERT"
CIFSUsername = "CIFS_USERNAME"
CIFSPassword = "CIFS_PASSWORD"
AZBlobAccountName = "AZBLOB_ACCOUNT_NAME"
AZBlobAccountKey = "AZBLOB_ACCOUNT_KEY"
AZBlobEndpoint = "AZBLOB_ENDPOINT"
AZBlobCert = "AZBLOB_CERT"
HTTPSProxy = "HTTPS_PROXY"
HTTPProxy = "HTTP_PROXY"
NOProxy = "NO_PROXY"
VirtualHostedStyle = "VIRTUAL_HOSTED_STYLE"
RetryCounts = 30
RetryInterval = 1 * time.Second
EngineFrontendBlockDev = "tgt-blockdev"
EngineFrontendISCSI = "tgt-iscsi"
VolumeHeadName = "volume-head"
)
type DataServerProtocol string
const (
DataServerProtocolTCP = DataServerProtocol("tcp")
DataServerProtocolUNIX = DataServerProtocol("unix")
)
type ReplicaState string
const (
ReplicaStateInitial = ReplicaState("initial")
ReplicaStateOpen = ReplicaState("open")
ReplicaStateClosed = ReplicaState("closed")
ReplicaStateDirty = ReplicaState("dirty")
ReplicaStateRebuilding = ReplicaState("rebuilding")
ReplicaStateError = ReplicaState("error")
)
type ReaderWriterUnmapperAt interface {
io.ReaderAt
io.WriterAt
UnmapperAt
}
type UnmapperAt interface {
UnmapAt(length uint32, off int64) (n int, err error)
}
type DiffDisk interface {
ReaderWriterUnmapperAt
io.Closer
Fd() uintptr
Size() (int64, error)
}
type MonitorChannel chan error
type Backend interface {
ReaderWriterUnmapperAt
io.Closer
Snapshot(name string, userCreated bool, created string, labels map[string]string) error
Expand(size int64) error
Size() (int64, error)
SectorSize() (int64, error)
GetRevisionCounter() (int64, error)
SetRevisionCounter(counter int64) error
GetState() (string, error)
GetMonitorChannel() MonitorChannel
StopMonitoring()
IsRevisionCounterDisabled() (bool, error)
GetLastModifyTime() (int64, error)
GetHeadFileSize() (int64, error)
GetUnmapMarkSnapChainRemoved() (bool, error)
SetUnmapMarkSnapChainRemoved(enabled bool) error
ResetRebuild() error
SetSnapshotMaxCount(count int) error
SetSnapshotMaxSize(size int64) error
GetSnapshotCountAndSizeUsage() (int, int64, error)
}
type BackendFactory interface {
Create(volumeName, address string, dataServerProtocol DataServerProtocol, engineReplicaTimeout time.Duration) (Backend, error)
}
type Controller interface {
AddReplica(address string) error
RemoveReplica(address string) error
SetReplicaMode(address string, mode Mode) error
ListReplicas() []Replica
Start(address ...string) error
Shutdown() error
}
type Server interface {
ReaderWriterUnmapperAt
Controller
}
type Mode string
type ProcessState string
type State string
type Replica struct {
Address string
Mode Mode
}
type ReplicaSalvageInfo struct {
LastModifyTime int64
HeadFileSize int64
}
type Frontend interface {
FrontendName() string
Init(name string, size, sectorSize int64) error
Startup(rwu ReaderWriterUnmapperAt) error
Shutdown() error
State() State
Endpoint() string
Upgrade(name string, size, sectorSize int64, rwu ReaderWriterUnmapperAt) error
Expand(size int64) error
}
type DataProcessor interface {
ReaderWriterUnmapperAt
PingResponse() error
}
const (
EventTypeVolume = "volume"
EventTypeReplica = "replica"
EventTypeMetrics = "metrics"
)
type Metrics struct {
Throughput RWMetrics // in byte
TotalLatency RWMetrics // in nanoseconds
IOPS RWMetrics
}
type RWMetrics struct {
Read uint64
Write uint64
}
func IsAlreadyPurgingError(err error) bool {
return strings.Contains(err.Error(), "already purging")
}
func ReplicaModeToGRPCReplicaMode(mode Mode) enginerpc.ReplicaMode {
switch mode {
case WO:
return enginerpc.ReplicaMode_WO
case RW:
return enginerpc.ReplicaMode_RW
case ERR:
return enginerpc.ReplicaMode_ERR
}
return enginerpc.ReplicaMode_ERR
}
func GRPCReplicaModeToReplicaMode(replicaMode enginerpc.ReplicaMode) Mode {
switch replicaMode {
case enginerpc.ReplicaMode_WO:
return WO
case enginerpc.ReplicaMode_RW:
return RW
case enginerpc.ReplicaMode_ERR:
return ERR
}
return ERR
}