-
Notifications
You must be signed in to change notification settings - Fork 80
/
foundationdb_version.go
279 lines (243 loc) · 9.5 KB
/
foundationdb_version.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* foundationdb_version.go
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2021-2022 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package v1beta2
import (
"fmt"
"regexp"
"strconv"
)
// Version represents a version of FoundationDB.
//
// This provides convenience methods for checking features available in
// different versions.
type Version struct {
// Major is the major version
Major int
// Minor is the minor version
Minor int
// Patch is the patch version
Patch int
// ReleaseCandidate is the number from the `-rc\d+` suffix version
// of the version if it exists
ReleaseCandidate int
}
// VersionRegex describes the format of a FoundationDB version.
var VersionRegex = regexp.MustCompile(`(\d+)\.(\d+)\.(\d+)(-rc(\d+))?`)
// ParseFdbVersion parses a version from its string representation.
func ParseFdbVersion(version string) (Version, error) {
matches := VersionRegex.FindStringSubmatch(version)
if matches == nil {
return Version{}, fmt.Errorf("could not parse FDB version from %s", version)
}
major, err := strconv.Atoi(matches[1])
if err != nil {
return Version{}, err
}
minor, err := strconv.Atoi(matches[2])
if err != nil {
return Version{}, err
}
patch, err := strconv.Atoi(matches[3])
if err != nil {
return Version{}, err
}
rc, err := strconv.Atoi(matches[5])
if err != nil {
rc = 0
}
return Version{Major: major, Minor: minor, Patch: patch, ReleaseCandidate: rc}, nil
}
// String gets the string representation of an FDB version.
func (version Version) String() string {
if version.ReleaseCandidate == 0 {
return fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch)
}
return fmt.Sprintf("%d.%d.%d-rc%d", version.Major, version.Minor, version.Patch, version.ReleaseCandidate)
}
// Compact prints the version in the major.minor format.
func (version Version) Compact() string {
return fmt.Sprintf("%d.%d", version.Major, version.Minor)
}
// IsAtLeast determines if a version is greater than or equal to another version.
func (version Version) IsAtLeast(other Version) bool {
if version.Major < other.Major {
return false
}
if version.Major > other.Major {
return true
}
if version.Minor < other.Minor {
return false
}
if version.Minor > other.Minor {
return true
}
if version.Patch < other.Patch {
return false
}
if version.Patch > other.Patch {
return true
}
if version.ReleaseCandidate == 0 {
return true
}
if other.ReleaseCandidate == 0 {
return false
}
if version.ReleaseCandidate < other.ReleaseCandidate {
return false
}
if version.ReleaseCandidate > other.ReleaseCandidate {
return true
}
return true
}
// GetBinaryVersion Returns a version string compatible with the log implemented in the sidecars
func (version Version) GetBinaryVersion() string {
if version.ReleaseCandidate > 0 {
return version.String()
}
return version.Compact()
}
// IsProtocolCompatible determines whether two versions of FDB are protocol
// compatible.
func (version Version) IsProtocolCompatible(other Version) bool {
return version.Major == other.Major && version.Minor == other.Minor && version.ReleaseCandidate == other.ReleaseCandidate
}
// HasNonBlockingExcludes determines if a version has support for non-blocking
// exclude commands.
func (version Version) HasNonBlockingExcludes(useNonBlockingExcludes bool) bool {
return version.IsAtLeast(Version{Major: 6, Minor: 3, Patch: 5}) && useNonBlockingExcludes
}
// HasSeparatedProxies determines if a version has support for separate
// grv/commit proxies
func (version Version) HasSeparatedProxies() bool {
return version.IsAtLeast(Version{Major: 7, Minor: 0, Patch: 0})
}
// NextMajorVersion returns the next major version of FoundationDB.
func (version Version) NextMajorVersion() Version {
return Version{Major: version.Major + 1, Minor: 0, Patch: 0}
}
// NextMinorVersion returns the next minor version of FoundationDB.
func (version Version) NextMinorVersion() Version {
return Version{Major: version.Major, Minor: version.Minor + 1, Patch: 0}
}
// NextPatchVersion returns the next patch version of FoundationDB.
func (version Version) NextPatchVersion() Version {
return Version{Major: version.Major, Minor: version.Minor, Patch: version.Patch + 1}
}
// Equal checks if two Version are the same.
func (version Version) Equal(other Version) bool {
return version.Major == other.Major &&
version.Minor == other.Minor &&
version.Patch == other.Patch &&
version.ReleaseCandidate == other.ReleaseCandidate
}
// IsSupported defines the minimum supported FDB version.
func (version Version) IsSupported() bool {
return version.IsAtLeast(Versions.MinimumVersion)
}
// IsStorageEngineSupported return true if storage engine is supported by FDB version.
func (version Version) IsStorageEngineSupported(storageEngine StorageEngine) bool {
if storageEngine == StorageEngineRocksDbV1 {
return version.IsAtLeast(Versions.SupportsRocksDBV1)
} else if storageEngine == StorageEngineRocksDbExperimental {
return !version.IsAtLeast(Versions.SupportsRocksDBV1)
} else if storageEngine == StorageEngineShardedRocksDB {
return version.IsAtLeast(Versions.SupportsShardedRocksDB)
} else if storageEngine == StorageEngineRedwood1Experimental {
return version.IsAtLeast(Versions.SupportsRedwood1Experimental)
} else if storageEngine == StorageEngineRedwood1 {
return version.IsAtLeast(Versions.SupportsRedwood1)
}
return true
}
// IsReleaseCandidate returns true if the version is a release candidate or not
func (version Version) IsReleaseCandidate() bool {
return version.ReleaseCandidate > 0
}
// SupportsIsPresent returns true if the sidecar of this version supports the is_present endpoint
func (version Version) SupportsIsPresent() bool {
return version.IsAtLeast(Versions.SupportsIsPresent)
}
// SupportsRecoveryState returns true if the version of FDB supports the recovered since field.
func (version Version) SupportsRecoveryState() bool {
return version.IsAtLeast(Versions.SupportsRecoveryState)
}
// SupportsDNSInClusterFile returns true if the version of FDB supports the usage of DNS names in the cluster file.
func (version Version) SupportsDNSInClusterFile() bool {
return version.IsAtLeast(Versions.SupportsDNSInClusterFile)
}
// SupportsVersionChange returns true if the current version can be downgraded or upgraded to provided other version.
func (version Version) SupportsVersionChange(other Version) bool {
return version.IsProtocolCompatible(other) || other.IsAtLeast(version)
}
// SupportsLocalityBasedExclusions returns true if the current version supports locality based exclusions.
func (version Version) SupportsLocalityBasedExclusions() bool {
// If the version is 7.1.* we have to check if it supports locality based exclusions. For all newer versions
// we will check against the 7.3 version.
if version.IsProtocolCompatible(Version{Major: 7, Minor: 1, Patch: 0}) {
return version.IsAtLeast(Versions.SupportsLocalityBasedExclusions71)
}
return version.IsAtLeast(Versions.SupportsLocalityBasedExclusions)
}
// AutomaticallyRemovesDeadTesterProcesses returns true if the FDB version automatically removes old tester processes
// from the list of processes.
func (version Version) AutomaticallyRemovesDeadTesterProcesses() bool {
if version.IsProtocolCompatible(Version{Major: 7, Minor: 3, Patch: 0}) {
return version.IsAtLeast(Version{Major: 7, Minor: 3, Patch: 35})
}
return version.IsAtLeast(Version{Major: 7, Minor: 1, Patch: 55})
}
// Versions provides a shorthand for known versions.
// This is only to be used in testing.
var Versions = struct {
NextMajorVersion,
NextPatchVersion,
MinimumVersion,
SupportsRocksDBV1,
SupportsIsPresent,
SupportsShardedRocksDB,
SupportsRedwood1Experimental,
SupportsRedwood1,
IncompatibleVersion,
PreviousPatchVersion,
SupportsRecoveryState,
SupportsDNSInClusterFile,
SupportsLocalityBasedExclusions71,
SupportsLocalityBasedExclusions,
Default Version
}{
Default: Version{Major: 6, Minor: 2, Patch: 21},
IncompatibleVersion: Version{Major: 6, Minor: 1, Patch: 0},
PreviousPatchVersion: Version{Major: 6, Minor: 2, Patch: 20},
NextPatchVersion: Version{Major: 6, Minor: 2, Patch: 22},
NextMajorVersion: Version{Major: 7, Minor: 0, Patch: 0},
MinimumVersion: Version{Major: 6, Minor: 2, Patch: 20},
SupportsRocksDBV1: Version{Major: 7, Minor: 1, Patch: 0, ReleaseCandidate: 4},
SupportsIsPresent: Version{Major: 7, Minor: 1, Patch: 4},
SupportsShardedRocksDB: Version{Major: 7, Minor: 2, Patch: 0},
SupportsRedwood1Experimental: Version{Major: 7, Minor: 0, Patch: 0},
SupportsRedwood1: Version{Major: 7, Minor: 3, Patch: 0},
SupportsRecoveryState: Version{Major: 7, Minor: 1, Patch: 22},
SupportsDNSInClusterFile: Version{Major: 7, Minor: 0, Patch: 0},
SupportsLocalityBasedExclusions71: Version{Major: 7, Minor: 1, Patch: 42},
SupportsLocalityBasedExclusions: Version{Major: 7, Minor: 3, Patch: 26},
}