Browse Source

Remove legacy bidirectional datastore sync code

Since #4438 removed 2-way sync and treats any changed+newer files on disk as an error, we no longer need to determine if files are newer on disk/db or if there is a conflicting mix of both. Any changed+newer file is an error, unless we're doing a cluster reset in which case everything is unconditionally replaced.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5870/head
Brad Davidson 2 years ago committed by Brad Davidson
parent
commit
fc1c100ffd
  1. 115
      pkg/cluster/bootstrap.go

115
pkg/cluster/bootstrap.go

@ -316,13 +316,11 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker,
buf.Seek(0, 0) buf.Seek(0, 0)
} }
type update struct { // Compare on-disk content to the datastore.
db, disk, conflict bool // If the files differ and the timestamp in the datastore is newer, data on disk will be updated.
} // If the files differ and the timestamp on disk is newer, an error will be raised listing the conflicting files.
var updateDisk bool var updateDisk bool
var newerOnDisk []string
results := make(map[string]update)
for pathKey, fileData := range files { for pathKey, fileData := range files {
path, ok := paths[pathKey] path, ok := paths[pathKey]
if !ok || path == "" { if !ok || path == "" {
@ -338,123 +336,44 @@ func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker,
updateDisk = true updateDisk = true
continue continue
} }
return err return errors.Wrapf(err, "reconcile failed to open %s", pathKey)
} }
defer f.Close() defer f.Close()
fData, err := ioutil.ReadAll(f) fData, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
return err return errors.Wrapf(err, "reconcile failed to read %s", pathKey)
} }
if !bytes.Equal(fileData.Content, fData) { if !bytes.Equal(fileData.Content, fData) {
info, err := os.Stat(path) updateDisk = true
info, err := f.Stat()
if err != nil { if err != nil {
return err return errors.Wrapf(err, "reconcile failed to stat %s", pathKey)
} }
switch { if info.ModTime().Unix()-fileData.Timestamp.Unix() >= systemTimeSkew {
case info.ModTime().Unix()-files[pathKey].Timestamp.Unix() >= systemTimeSkew: newerOnDisk = append(newerOnDisk, path)
if _, ok := results[path]; !ok { } else {
results[path] = update{ logrus.Warn(path + " will be updated from the datastore.")
db: true,
}
}
for pk := range files {
p, ok := paths[pk]
if !ok || p == "" {
continue
}
if filepath.Base(p) == info.Name() {
continue
}
i, err := os.Stat(p)
if err != nil {
return err
}
if i.ModTime().Unix()-files[pk].Timestamp.Unix() >= systemTimeSkew {
if _, ok := results[path]; !ok {
results[path] = update{
conflict: true,
}
}
}
}
case info.ModTime().Unix()-files[pathKey].Timestamp.Unix() <= systemTimeSkew:
if _, ok := results[info.Name()]; !ok {
results[path] = update{
disk: true,
}
}
for pk := range files {
p, ok := paths[pk]
if !ok || p == "" {
continue
}
if filepath.Base(p) == info.Name() {
continue
}
i, err := os.Stat(p)
if err != nil {
return err
}
if i.ModTime().Unix()-files[pk].Timestamp.Unix() <= systemTimeSkew {
if _, ok := results[path]; !ok {
results[path] = update{
conflict: true,
}
}
}
}
default:
if _, ok := results[path]; ok {
results[path] = update{}
}
} }
} }
} }
if c.config.ClusterReset { if c.config.ClusterReset {
updateDisk = true
serverTLSDir := filepath.Join(c.config.DataDir, "tls") serverTLSDir := filepath.Join(c.config.DataDir, "tls")
tlsBackupDir := filepath.Join(c.config.DataDir, "tls-"+strconv.Itoa(int(time.Now().Unix()))) tlsBackupDir := filepath.Join(c.config.DataDir, "tls-"+strconv.Itoa(int(time.Now().Unix())))
logrus.Infof("Cluster reset: backing up certificates directory to " + tlsBackupDir) logrus.Infof("Cluster reset: backing up certificates directory to " + tlsBackupDir)
if _, err := os.Stat(serverTLSDir); err != nil { if _, err := os.Stat(serverTLSDir); err != nil {
return err return errors.Wrap(err, "cluster reset failed to stat server TLS dir")
} }
if err := copy.Copy(serverTLSDir, tlsBackupDir); err != nil { if err := copy.Copy(serverTLSDir, tlsBackupDir); err != nil {
return err return errors.Wrap(err, "cluster reset failed to back up server TLS dir")
} }
} } else if len(newerOnDisk) > 0 {
var newerOnDisk []string
for path, res := range results {
switch {
case res.disk:
updateDisk = true
logrus.Warn("Datastore newer than " + path)
case res.db:
if c.config.ClusterReset {
logrus.Infof("Cluster reset: replacing file on disk: " + path)
updateDisk = true
continue
}
newerOnDisk = append(newerOnDisk, path)
case res.conflict:
logrus.Warnf("Datastore / disk conflict: %s newer than in the datastore", path)
}
}
if len(newerOnDisk) > 0 {
logrus.Fatal(strings.Join(newerOnDisk, ", ") + " newer than datastore and could cause a cluster outage. Remove the file(s) from disk and restart to be recreated from datastore.") logrus.Fatal(strings.Join(newerOnDisk, ", ") + " newer than datastore and could cause a cluster outage. Remove the file(s) from disk and restart to be recreated from datastore.")
} }

Loading…
Cancel
Save