Copy old bootstrap buffer data for use during migration (#4215)

pull/4231/head
Brian Downs 2021-10-15 10:17:29 -07:00 committed by GitHub
parent 0a91dbb36e
commit 34080b23b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -154,7 +154,7 @@ func (c *Cluster) certDirsExist() error {
}
// migrateBootstrapData migrates bootstrap data from the old format to the new format.
func migrateBootstrapData(ctx context.Context, data *bytes.Buffer, files bootstrap.PathsDataformat) error {
func migrateBootstrapData(ctx context.Context, data io.Reader, files bootstrap.PathsDataformat) error {
logrus.Info("Migrating bootstrap data to new format")
var oldBootstrapData map[string][]byte
@ -182,7 +182,7 @@ const systemTimeSkew = int64(3)
// bootstrap data in the datastore is newer than on disk or different
// and dependingon where the difference is, the newer data is written
// to the older.
func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf *bytes.Buffer, crb *config.ControlRuntimeBootstrap) error {
func (c *Cluster) ReconcileBootstrapData(ctx context.Context, buf io.ReadSeeker, crb *config.ControlRuntimeBootstrap) error {
logrus.Info("Reconciling bootstrap data between datastore and disk")
if err := c.certDirsExist(); err != nil {
@ -243,11 +243,13 @@ RETRY:
}
files := make(bootstrap.PathsDataformat)
if err := json.NewDecoder(buf).Decode(&files); err != nil {
// This will fail if data is being pulled from old an cluster since
// older clusters used a map[string][]byte for the data structure.
// Therefore, we need to perform a migration to the newer bootstrap
// format; bootstrap.BootstrapFile.
buf.Seek(0, 0)
if err := migrateBootstrapData(ctx, buf, files); err != nil {
return err
}
@ -395,7 +397,7 @@ func (c *Cluster) httpBootstrap(ctx context.Context) error {
return err
}
return c.ReconcileBootstrapData(ctx, bytes.NewBuffer(content), &c.config.Runtime.ControlRuntimeBootstrap)
return c.ReconcileBootstrapData(ctx, bytes.NewReader(content), &c.config.Runtime.ControlRuntimeBootstrap)
}
// bootstrap performs cluster bootstrapping, either via HTTP (for managed databases) or direct load from datastore.

View File

@ -132,8 +132,7 @@ func (c *Cluster) storageBootstrap(ctx context.Context) error {
return err
}
return c.ReconcileBootstrapData(ctx, bytes.NewBuffer(data), &c.config.Runtime.ControlRuntimeBootstrap)
//return bootstrap.WriteToDiskFromStorage(bytes.NewBuffer(data), &c.runtime.ControlRuntimeBootstrap)
return c.ReconcileBootstrapData(ctx, bytes.NewReader(data), &c.config.Runtime.ControlRuntimeBootstrap)
}
// getBootstrapKeyFromStorage will list all keys that has prefix /bootstrap and will check for key that is