Skip to content

Commit

Permalink
Merge pull request #136 from swapnilgm/cherry-pick-fixes
Browse files Browse the repository at this point in the history
Cherry pick fixes from master
  • Loading branch information
swapnilgm authored Mar 13, 2019
2 parents 6663f2f + 167a406 commit 89fbe7f
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 139 deletions.
3 changes: 3 additions & 0 deletions chart/templates/etcd-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ spec:
- --data-dir=/var/etcd/data/new.etcd
- --storage-provider={{ .Values.backup.storageProvider }}
- --store-prefix=etcd-{{ .Values.role }}
{{- if .Values.backup.embeddedEtcdQuotaBytes }}
- --embeddedEtcdQuotaBytes={{ .Values.backup.embeddedEtcdQuotaBytes }}
{{- end }}
{{- if .Values.tls }}
- --cert=/var/etcd/ssl/client/tls.crt
- --key=/var/etcd/ssl/client/tls.key
Expand Down
2 changes: 2 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ backup:

storageContainer: ""

embeddedEtcdQuotaBytes: 8589934592

# env should include the right list of values for the
# storageProvider you use, follow the comments below
env: [] # Follow comments below
Expand Down
15 changes: 8 additions & 7 deletions cmd/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ func NewInitializeCommand(stopCh <-chan struct{}) *cobra.Command {
}

options := &restorer.RestoreOptions{
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
}

var snapstoreConfig *snapstore.Config
Expand Down
20 changes: 11 additions & 9 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ func NewRestoreCommand(stopCh <-chan struct{}) *cobra.Command {
rs := restorer.NewRestorer(store, logger)

options := &restorer.RestoreOptions{
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
BaseSnapshot: *baseSnap,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
BaseSnapshot: *baseSnap,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
}

err = rs.Restore(*options)
Expand All @@ -107,6 +108,7 @@ func initializeEtcdFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&restoreName, "name", defaultName, "human-readable name for this member")
cmd.Flags().BoolVar(&skipHashCheck, "skip-hash-check", false, "ignore snapshot integrity hash value (required if copied from data directory)")
cmd.Flags().IntVar(&restoreMaxFetchers, "max-fetchers", 6, "maximum number of threads that will fetch delta snapshots in parallel")
cmd.Flags().Int64Var(&embeddedEtcdQuotaBytes, "embedded-etcd-quota-bytes", int64(8*1024*1024*1024), "maximum backend quota for the embedded etcd used for applying delta snapshots")
}

func initialClusterFromName(name string) string {
Expand Down
15 changes: 8 additions & 7 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
}

options := &restorer.RestoreOptions{
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
RestoreDataDir: path.Clean(restoreDataDir),
Name: restoreName,
ClusterURLs: clusterUrlsMap,
PeerURLs: peerUrls,
ClusterToken: restoreClusterToken,
SkipHashCheck: skipHashCheck,
MaxFetchers: restoreMaxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
}

if storageProvider != "" {
Expand Down
15 changes: 8 additions & 7 deletions cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ var (
enableProfiling bool

//restore flags
restoreCluster string
restoreClusterToken string
restoreDataDir string
restorePeerURLs []string
restoreName string
skipHashCheck bool
restoreMaxFetchers int
restoreCluster string
restoreClusterToken string
restoreDataDir string
restorePeerURLs []string
restoreName string
skipHashCheck bool
restoreMaxFetchers int
embeddedEtcdQuotaBytes int64

//snapstore flags
storageProvider string
Expand Down
5 changes: 5 additions & 0 deletions pkg/snapshot/restorer/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (r *Restorer) Restore(ro RestoreOptions) error {
if ro.MaxFetchers < 1 {
return fmt.Errorf("Maximum number of fetchers should be greater than zero. Input MaxFetchers: %d", ro.MaxFetchers)
}
if ro.EmbeddedEtcdQuotaBytes <= 0 {
r.logger.Infof("Quota size for etcd must be greater than 0. Input EmbeddedEtcdQuotaBytes: %d. Defaulting to 8GB.", ro.EmbeddedEtcdQuotaBytes)
ro.EmbeddedEtcdQuotaBytes = int64(8 * 1024 * 1024 * 1024)
}
if err := r.restoreFromBaseSnapshot(ro); err != nil {
return fmt.Errorf("failed to restore from the base snapshot :%v", err)
}
Expand Down Expand Up @@ -308,6 +312,7 @@ func makeWALAndSnap(waldir, snapdir string, cl *membership.RaftCluster, restoreN
func startEmbeddedEtcd(ro RestoreOptions) (*embed.Etcd, error) {
cfg := embed.NewConfig()
cfg.Dir = filepath.Join(ro.RestoreDataDir)
cfg.QuotaBackendBytes = ro.EmbeddedEtcdQuotaBytes
e, err := embed.StartEtcd(cfg)
if err != nil {
return nil, err
Expand Down
92 changes: 49 additions & 43 deletions pkg/snapshot/restorer/restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ var _ = Describe("Running Restorer", func() {
store snapstore.SnapStore
rstr *Restorer

restoreCluster string
restoreClusterToken string
restoreDataDir string
restorePeerURLs []string
restoreName string
skipHashCheck bool
maxFetchers int
restoreCluster string
restoreClusterToken string
restoreDataDir string
restorePeerURLs []string
restoreName string
skipHashCheck bool
maxFetchers int
embeddedEtcdQuotaBytes int64

clusterUrlsMap types.URLsMap
peerUrls types.URLs
Expand All @@ -68,6 +69,7 @@ var _ = Describe("Running Restorer", func() {
Expect(err).ShouldNot(HaveOccurred())
skipHashCheck = false
maxFetchers = 6
embeddedEtcdQuotaBytes = 8 * 1024 * 1024 * 1024

err = corruptEtcdDir()
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -87,15 +89,16 @@ var _ = Describe("Running Restorer", func() {
maxFetchers = 0

restoreOptions := RestoreOptions{
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
}
err = rstr.Restore(restoreOptions)
Expect(err).Should(HaveOccurred())
Expand All @@ -108,15 +111,16 @@ var _ = Describe("Running Restorer", func() {
maxFetchers = 1

restoreOptions := RestoreOptions{
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
}
err = rstr.Restore(restoreOptions)
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -132,15 +136,16 @@ var _ = Describe("Running Restorer", func() {
maxFetchers = 4

restoreOptions := RestoreOptions{
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
}
err = rstr.Restore(restoreOptions)
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -156,15 +161,16 @@ var _ = Describe("Running Restorer", func() {
maxFetchers = 100

restoreOptions := RestoreOptions{
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
ClusterURLs: clusterUrlsMap,
ClusterToken: restoreClusterToken,
RestoreDataDir: restoreDataDir,
PeerURLs: peerUrls,
SkipHashCheck: skipHashCheck,
Name: restoreName,
MaxFetchers: maxFetchers,
EmbeddedEtcdQuotaBytes: embeddedEtcdQuotaBytes,
BaseSnapshot: *baseSnapshot,
DeltaSnapList: deltaSnapList,
}
err = rstr.Restore(restoreOptions)
Expect(err).ShouldNot(HaveOccurred())
Expand Down
15 changes: 8 additions & 7 deletions pkg/snapshot/restorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ type Restorer struct {

// RestoreOptions hold all snapshot restore related fields
type RestoreOptions struct {
ClusterURLs types.URLsMap
ClusterToken string
RestoreDataDir string
PeerURLs types.URLs
SkipHashCheck bool
Name string
MaxFetchers int
ClusterURLs types.URLsMap
ClusterToken string
RestoreDataDir string
PeerURLs types.URLs
SkipHashCheck bool
Name string
MaxFetchers int
EmbeddedEtcdQuotaBytes int64
// Base full snapshot + delta snapshots to restore from
BaseSnapshot snapstore.Snapshot
DeltaSnapList snapstore.SnapList
Expand Down
Loading

0 comments on commit 89fbe7f

Please sign in to comment.