Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: reinstall mysqlbinlog if libncurses5 does not exist (#1708)

h3n4l7e197fac0bb7
diff --git a/resources/mysqlutil/mysqlutil.go b/resources/mysqlutil/mysqlutil.go
index 81379b343f..4aa2c29079 100644
--- a/resources/mysqlutil/mysqlutil.go
+++ b/resources/mysqlutil/mysqlutil.go
@@ -81,27 +81,56 @@ func Install(resourceDir string) (*Instance, error) {
return nil, fmt.Errorf("failed to check binary directory path %q, error: %w", mysqlutilDir, err)
}
// Install if not exist yet
- tmpDir := path.Join(resourceDir, fmt.Sprintf("tmp-%s", version))
- if err := os.RemoveAll(tmpDir); err != nil {
- return nil, fmt.Errorf("failed to remove mysqlutil binaries temp directory %q, error: %w", tmpDir, err)
+ if err := install(resourceDir, mysqlutilDir, tarName, version); err != nil {
+ return nil, fmt.Errorf("cannot install mysqlutil, error: %w", err)
}
+ }
- f, err := resources.Open(tarName)
- if err != nil {
- return nil, fmt.Errorf("failed to find %q in embedded resources, error: %v", tarName, err)
+ // TODO(zp): remove this block in the next few months
+ // We change Dockerfile's base image from alpine to debian slim in v1.2.1,
+ // and add libncurses.so.5 and libtinfo.so.5 to make mysqlbinlog run successfully.
+ // So we need to reinstall mysqlutil if the users upgrade from an older version that missing these shared libraries.
+ libncursesPath := path.Join(mysqlutilDir, "lib", "private", "libncurses.so.5")
+ if _, err := os.Stat(libncursesPath); err != nil {
+ if !os.IsNotExist(err) {
+ return nil, fmt.Errorf("failed to check libncurses library path %q, error: %w", libncursesPath, err)
}
- defer f.Close()
-
- if err := utils.ExtractTarGz(f, tmpDir); err != nil {
- return nil, fmt.Errorf("failed to extract tar.gz file, error: %w", err)
+ // Remove mysqlutil of old version and reinstall it
+ if err := os.RemoveAll(mysqlutilDir); err != nil {
+ return nil, fmt.Errorf("failed to remove the old version mysqlutil binary directory %q, error: %w", mysqlutilDir, err)
}
-
- if err := os.Rename(tmpDir, mysqlutilDir); err != nil {
- return nil, fmt.Errorf("failed to rename mysqlutil binaries directory from %q to %q, error: %w", tmpDir, mysqlutilDir, err)
+ // Install the current version
+ if err := install(resourceDir, mysqlutilDir, tarName, version); err != nil {
+ return nil, fmt.Errorf("cannot install mysqlutil, error: %w", err)
}
}
+
return &Instance{
mysqlBinPath: filepath.Join(mysqlutilDir, "bin", "mysql"),
mysqlbinlogBinPath: filepath.Join(mysqlutilDir, "bin", "mysqlbinlog"),
}, nil
}
+
+// install installs mysqlutil in resourceDir
+func install(resourceDir, mysqlutilDir, tarName, version string) error {
+ tmpDir := path.Join(resourceDir, fmt.Sprintf("tmp-%s", version))
+ if err := os.RemoveAll(tmpDir); err != nil {
+ return fmt.Errorf("failed to remove mysqlutil binaries temp directory %q, error: %w", tmpDir, err)
+ }
+
+ f, err := resources.Open(tarName)
+ if err != nil {
+ return fmt.Errorf("failed to find %q in embedded resources, error: %v", tarName, err)
+ }
+ defer f.Close()
+
+ if err := utils.ExtractTarGz(f, tmpDir); err != nil {
+ return fmt.Errorf("failed to extract tar.gz file, error: %w", err)
+ }
+
+ if err := os.Rename(tmpDir, mysqlutilDir); err != nil {
+ return fmt.Errorf("failed to rename mysqlutil binaries directory from %q to %q, error: %w", tmpDir, mysqlutilDir, err)
+ }
+
+ return nil
+}
diff --git a/resources/mysqlutil/mysqlutil_test.go b/resources/mysqlutil/mysqlutil_test.go
index 4517fb27b9..a815069aca 100644
--- a/resources/mysqlutil/mysqlutil_test.go
+++ b/resources/mysqlutil/mysqlutil_test.go
@@ -1,6 +1,9 @@
package mysqlutil
import (
+ "os"
+ "path/filepath"
+ "runtime"
"testing"
"github.com/stretchr/testify/require"
@@ -26,3 +29,36 @@ func TestRunBinary(t *testing.T) {
a.NoError(err)
})
}
+
+// TODO(zp): remove this test when remove the related block in mysqlutil.go.
+// TestReinstallOnLinuxAmd64 tests is it possible to reinstall mysqlutil on linux amd64.
+func TestReinstallOnLinuxAmd64(t *testing.T) {
+ t.Parallel()
+
+ if !(runtime.GOOS == "linux" && runtime.GOARCH == "amd64") {
+ return
+ }
+
+ a := require.New(t)
+ tmpDir := t.TempDir()
+ instance, err := Install(tmpDir)
+ a.NoError(err)
+
+ libDir := filepath.Join(tmpDir, "mysqlutil-8.0.28-linux-glibc2.17-x86_64" /*Hard code, don't care about this*/, "lib", "private")
+
+ libncursesPath := filepath.Join(libDir, "libncurses.so.5")
+ libtinfoPath := filepath.Join(libDir, "libtinfo.so.5")
+ mysqlPath := instance.GetPath(MySQL)
+ a.FileExists(libncursesPath)
+
+ err = os.RemoveAll(libncursesPath)
+ a.NoError(err)
+ a.NoFileExists(libncursesPath)
+
+ _, err = Install(tmpDir)
+ a.NoError(err)
+
+ a.FileExists(libncursesPath)
+ a.FileExists(libtinfoPath)
+ a.FileExists(mysqlPath)
+}