version.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package version
  15. import (
  16. "os"
  17. "path"
  18. "github.com/coreos/etcd/pkg/fileutil"
  19. "github.com/coreos/etcd/pkg/types"
  20. )
  21. var (
  22. // MinClusterVersion is the min cluster version this etcd binary is compatible with.
  23. MinClusterVersion = "2.0.0"
  24. Version = "2.1.1+git"
  25. // Git SHA Value will be set during build
  26. GitSHA = "Not provided (use ./build instead of go build)"
  27. )
  28. // WalVersion is an enum for versions of etcd logs.
  29. type DataDirVersion string
  30. const (
  31. DataDirUnknown DataDirVersion = "Unknown WAL"
  32. DataDir2_0 DataDirVersion = "2.0.0"
  33. DataDir2_0Proxy DataDirVersion = "2.0 proxy"
  34. DataDir2_0_1 DataDirVersion = "2.0.1"
  35. )
  36. type Versions struct {
  37. Server string `json:"etcdserver"`
  38. Cluster string `json:"etcdcluster"`
  39. // TODO: raft state machine version
  40. }
  41. func DetectDataDir(dirpath string) (DataDirVersion, error) {
  42. names, err := fileutil.ReadDir(dirpath)
  43. if err != nil {
  44. if os.IsNotExist(err) {
  45. err = nil
  46. }
  47. // Error reading the directory
  48. return DataDirUnknown, err
  49. }
  50. nameSet := types.NewUnsafeSet(names...)
  51. if nameSet.Contains("member") {
  52. ver, err := DetectDataDir(path.Join(dirpath, "member"))
  53. if ver == DataDir2_0 {
  54. return DataDir2_0_1, nil
  55. }
  56. return ver, err
  57. }
  58. if nameSet.ContainsAll([]string{"snap", "wal"}) {
  59. // .../wal cannot be empty to exist.
  60. walnames, err := fileutil.ReadDir(path.Join(dirpath, "wal"))
  61. if err == nil && len(walnames) > 0 {
  62. return DataDir2_0, nil
  63. }
  64. }
  65. if nameSet.ContainsAll([]string{"proxy"}) {
  66. return DataDir2_0Proxy, nil
  67. }
  68. return DataDirUnknown, nil
  69. }