Skip to content

Commit cd5ce97

Browse files
authored
fix: e2e failure for online upgrade test cases (cloudnative-pg#364)
Signed-off-by: Tao Li <tao.li@enterprisedb.com>
1 parent e8ae0e7 commit cd5ce97

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

pkg/management/postgres/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func (instance *Instance) Reload() error {
396396
// Run this instance returning an OS process needed
397397
// to control the instance execution
398398
func (instance Instance) Run() (*execlog.StreamingCmd, error) {
399-
process, err := instance.CheckForExistingPostmaster(postgresName)
399+
process, err := instance.CheckForExistingPostmaster()
400400
if err != nil {
401401
return nil, err
402402
}

pkg/management/postgres/pidfile.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ const PostgresqlPidFile = "postmaster.pid" //wokeignore:rule=master
3939
// directory and check the existence of the relative process. If the
4040
// process exists, then that process entry is returned.
4141
// If it doesn't exist then the PID file is stale and is removed.
42-
func (instance *Instance) CheckForExistingPostmaster(postgresExecutable string) (*os.Process, error) {
42+
func (instance *Instance) CheckForExistingPostmaster() (*os.Process, error) {
4343
pidFile := path.Join(instance.PgData, PostgresqlPidFile)
4444
contextLog := log.WithValues("file", pidFile)
4545
pidFileContents, pid, err := instance.GetPostmasterPidFromFile(pidFile)
4646
if err != nil {
4747
// The content of the PID file is wrong.
4848
// In this case we just remove the PID file, which is assumed
4949
// to be stale, and continue our work
50-
contextLog.Info("The PID file content is wrong, deleting it and assuming it's stale")
51-
contextLog.Debug("PID file", "contents", pidFileContents)
50+
contextLog.Info("The PID file content is wrong, deleting it and assuming it's stale",
51+
"err", err, "pidFileContents", pidFileContents)
5252
return nil, instance.CleanUpStalePid()
5353
}
5454

@@ -60,15 +60,14 @@ func (instance *Instance) CheckForExistingPostmaster(postgresExecutable string)
6060
}
6161
if process == nil {
6262
// The process doesn't exist and this PID file is stale
63-
contextLog.Info("The PID file is stale, deleting it")
64-
contextLog.Debug("PID file", "contents", pidFileContents)
63+
contextLog.Info("The PID file is stale, deleting it", "pidFileContents", pidFileContents)
6564
return nil, instance.CleanUpStalePid()
6665
}
6766

68-
if process.Executable() != postgresExecutable {
67+
if process.Executable() != postgresName {
6968
// The process is not running PostgreSQL and this PID file is stale
70-
contextLog.Info("The PID file is stale (executable mismatch), deleting it")
71-
contextLog.Debug("PID file", "contents", pidFileContents)
69+
contextLog.Info("The PID file is stale (executable mismatch), deleting it",
70+
"pidFileContents", pidFileContents, "postgresExecutable", process.Executable())
7271
return nil, instance.CleanUpStalePid()
7372
}
7473

pkg/management/postgres/pidfile_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"os"
2323
"path/filepath"
2424

25-
"github.com/mitchellh/go-ps"
26-
2725
"github.com/cloudnative-pg/cloudnative-pg/pkg/fileutils"
2826

2927
. "github.com/onsi/ginkgo/v2"
@@ -51,7 +49,7 @@ var _ = Describe("the detection of a postmaster process using the pid file", fun
5149
instance := NewInstance()
5250
instance.PgData = pgdata
5351
instance.SocketDirectory = socketDir
54-
process, err := instance.CheckForExistingPostmaster(postgresName)
52+
process, err := instance.CheckForExistingPostmaster()
5553
Expect(err).ShouldNot(HaveOccurred())
5654
Expect(process).To(BeNil())
5755
})
@@ -69,7 +67,7 @@ var _ = Describe("the detection of a postmaster process using the pid file", fun
6967
err = ioutil.WriteFile(filepath.Join(socketDir, ".s.PGSQL.5432.lock"), []byte("1234"), 0o400)
7068
Expect(err).ShouldNot(HaveOccurred())
7169

72-
process, err := instance.CheckForExistingPostmaster(postgresName)
70+
process, err := instance.CheckForExistingPostmaster()
7371
Expect(err).ShouldNot(HaveOccurred())
7472
Expect(process).To(BeNil())
7573

@@ -91,12 +89,10 @@ var _ = Describe("the detection of a postmaster process using the pid file", fun
9189
filepath.Join(pgdata, PostgresqlPidFile),
9290
[]byte(fmt.Sprintf("%v", myPid)), 0o400)
9391
Expect(err).ShouldNot(HaveOccurred())
94-
myProcess, err := ps.FindProcess(myPid)
95-
Expect(err).ShouldNot(HaveOccurred())
96-
myExecutable := myProcess.Executable()
9792

98-
process, err := instance.CheckForExistingPostmaster(myExecutable)
93+
process, err := instance.CheckForExistingPostmaster()
9994
Expect(err).ShouldNot(HaveOccurred())
100-
Expect(process).ToNot(BeNil())
95+
// to be null because executable file name is not postgres
96+
Expect(process).To(BeNil())
10197
})
10298
})

0 commit comments

Comments
 (0)