Skip to content

Commit

Permalink
[PLAT-15031] yba installer os patch guardrails
Browse files Browse the repository at this point in the history
Summary:
Implemented 2 guardrails to help with --without-data install.
First, we have a new .version file in the data directory. This file will
be used to ensure an older YBA does not start against a newer data file.

In addition, the data disk size only runs when required, and on the
data directory directly

Test Plan:
tested various combinations of version file vs a yba version
tested using --without-data to upgrade yba

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37818
  • Loading branch information
shubin-yb authored and mchiddy committed Sep 9, 2024
1 parent d806031 commit c628f76
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions managed/yba-installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ var installCmd = &cobra.Command{

// Preflight checks
// TODO: Add preflight checks for ybdb.
if dataless {
skippedPreflightChecks = append(skippedPreflightChecks, "disk-availability")
}
var results *checks.MappedResults
if common.IsPostgresEnabled() {
results = preflight.Run(preflight.InstallChecksWithPostgres, skippedPreflightChecks...)
Expand Down
3 changes: 3 additions & 0 deletions managed/yba-installer/cmd/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var preflightCmd = &cobra.Command{
}
// TODO: We should allow the user to better specify which checks to run.
// Will do this as we implement a set of upgrade preflight checks
if dataless {
skippedPreflightChecks = append(skippedPreflightChecks, "disk-availability")
}
results := preflight.Run(checksToRun, skippedPreflightChecks...)
preflight.PrintPreflightResults(results)
if preflight.ShouldFail(results) {
Expand Down
14 changes: 14 additions & 0 deletions managed/yba-installer/cmd/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/spf13/cobra"
"github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/common"
log "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/logging"
"github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/preflight"
"github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/preflight/checks"
"github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/ybactlstate"
)

Expand Down Expand Up @@ -36,7 +38,15 @@ var startCmd = &cobra.Command{
log.Fatal("cannot start services - need installed state got " +
state.CurrentStatus.String())
}

// Initialize if it has not already happened. Do this instead of normal start workflow
if !state.Initialized {
// Run preflight check for data directory size if we have to initialize.
results := preflight.Run([]preflight.Check{checks.DiskAvail})
preflight.PrintPreflightResults(results)
if preflight.ShouldFail(results) {
log.Fatal("preflight failed")
}
log.Info("Initializing YBA before starting services")
if err := common.Initialize(); err != nil {
log.Fatal("Failed to initialize common components: " + err.Error())
Expand All @@ -57,6 +67,10 @@ var startCmd = &cobra.Command{
// We can exit early, as initialize will also start the services
return
}

if err := common.CheckDataVersionFile(); err != nil {
log.Fatal("Failed to validate data version: " + err.Error())
}
if len(args) == 1 {
if err := services[args[0]].Start(); err != nil {
log.Fatal("Failed to start " + args[0] + ": " + err.Error())
Expand Down
33 changes: 33 additions & 0 deletions managed/yba-installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func Initialize() error {
return err
}

// Validate or create the data version file.
if err := CheckOrCreateDataVersionFile(); err != nil {
return err
}

// Generate certs if required.
var serverCertPath, serverKeyPath string
if len(viper.GetString("server_cert_path")) == 0 {
Expand Down Expand Up @@ -171,6 +176,34 @@ func CreateDirs(createDirs []string) error {
return nil
}

// CheckOrCreateDataVersionFile checks if the YBA Version is older than the data version file. This is not
// supported as an older YBA cannot run with newer data due to PG migrations. If the file does not
// exist, it will instead create it with the current version
func CheckOrCreateDataVersionFile() error {
_, err := os.Stat(DataVersionFile())
if os.IsNotExist(err) {
return os.WriteFile(DataVersionFile(), []byte(Version), 0644)
}
return CheckDataVersionFile()
}

// CheckDataVersionFile checks if the YBA Version is older than the data version file. This is not
// supported as an older YBA cannot run with newer data due to PG migrations
func CheckDataVersionFile() error {
buf, err := os.ReadFile(DataVersionFile())
if !os.IsNotExist(err) {
if err != nil {
return fmt.Errorf("could not open data version file: %w", err)
}
dataVersion := strings.TrimSpace(string(buf))
if LessVersions(Version, dataVersion) {
return fmt.Errorf("YBA version %s is older than data version %s", Version, dataVersion)
}
}
// Update to the latest version.
return os.WriteFile(DataVersionFile(), []byte(Version), 0644)
}

// Copies over necessary files for all services from yba_installer_full to the GetSoftwareRoot()
func copyBits(vers string) error {
yugabundleBinary := "yugabundle-" + vers + "-centos-x86_64.tar.gz"
Expand Down
9 changes: 6 additions & 3 deletions managed/yba-installer/pkg/common/directory_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ import (

// ALl of our install files and directories.
const (
//installMarkerName string = ".install_marker"
//installLocationOne string = "one"
//installLocationTwo string = "two"
InstallSymlink string = "active"

dataVersionFileName = ".version.txt"
)

// Directory names for config files
Expand Down Expand Up @@ -73,6 +72,10 @@ func GetDataRoot() string {
return filepath.Join(dm.BaseInstall(), "data")
}

func DataVersionFile() string {
return filepath.Join(GetDataRoot(), dataVersionFileName)
}

// GetInstallRoot returns the InstallRoot where YBA is installed.
func GetSoftwareRoot() string {
return dm.WorkingDirectory()
Expand Down
2 changes: 1 addition & 1 deletion managed/yba-installer/pkg/preflight/checks/diskavail.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r diskAvailCheck) Execute() Result {
Status: StatusPassed,
}

baseDir := common.GetBaseInstall()
baseDir := common.GetDataRoot()
bytesAvail, err := getFreeBytes(baseDir)
if err != nil {
res.Error = err
Expand Down

0 comments on commit c628f76

Please sign in to comment.