Skip to content

Commit

Permalink
Merge pull request #5 from apecloud/support/rename-offpg-to-vanilla-p…
Browse files Browse the repository at this point in the history
…ostgresql

chore: rename official-postgresql to vanilla-postgresql
  • Loading branch information
kizuna-lek authored Nov 15, 2024
2 parents 85b9ebf + ee60cd7 commit aae7062
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 2,814 deletions.
4 changes: 2 additions & 2 deletions engines/models/engine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
MySQL EngineType = "mysql"
WeSQL EngineType = "wesql"
PostgreSQL EngineType = "postgresql"
OfficialPostgreSQL EngineType = "official-postgresql"
VanillaPostgreSQL EngineType = "vanilla-postgresql"
ApecloudPostgreSQL EngineType = "apecloud-postgresql"
Redis EngineType = "redis"
ETCD EngineType = "etcd"
Expand All @@ -45,7 +45,7 @@ func GetEngineTypeList() []EngineType {
MySQL,
WeSQL,
PostgreSQL,
OfficialPostgreSQL,
VanillaPostgreSQL,
ApecloudPostgreSQL,
Redis,
ETCD,
Expand Down
115 changes: 0 additions & 115 deletions engines/postgres/local_command.go

This file was deleted.

40 changes: 0 additions & 40 deletions engines/postgres/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,6 @@ func NewManager(properties map[string]string) (engines.DBManager, error) {
return mgr, nil
}

func (mgr *Manager) IsRunning() bool {
if mgr.Proc != nil {
if isRunning, err := mgr.Proc.IsRunning(); isRunning && err == nil {
return true
}
mgr.Proc = nil
}

return mgr.newProcessFromPidFile() == nil
}

func (mgr *Manager) newProcessFromPidFile() error {
pidFile, err := readPidFile(mgr.DataDir)
if err != nil {
mgr.Logger.Error(err, "read pid file failed, err")
return err
}

proc, err := process.NewProcess(pidFile.pid)
if err != nil {
mgr.Logger.Error(err, "new process failed, err")
return err
}

mgr.Proc = proc
return nil
}

func (mgr *Manager) Recover(context.Context, *dcs.Cluster) error {
return nil
}

func (mgr *Manager) GetHealthiestMember(*dcs.Cluster, string) *dcs.Member {
return nil
}

func (mgr *Manager) SetIsLeader(isLeader bool) {
if isLeader {
mgr.isLeader = 1
Expand Down Expand Up @@ -222,7 +186,3 @@ func (mgr *Manager) Unlock(ctx context.Context) error {
mgr.Logger.Info("UnLock db success")
return nil
}

func (mgr *Manager) ShutDownWithWait() {
mgr.Pool.Close()
}
71 changes: 0 additions & 71 deletions engines/postgres/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"testing"

"github.com/pashagolub/pgxmock/v2"
"github.com/shirou/gopsutil/v3/process"
"github.com/spf13/afero"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -63,49 +61,6 @@ func MockDatabase(t *testing.T) (*Manager, pgxmock.PgxPoolIface, error) {
return manager, mock, err
}

func TestIsRunning(t *testing.T) {
manager, mock, _ := MockDatabase(t)
defer mock.Close()

t.Run("proc is nil, can't read file", func(t *testing.T) {
isRunning := manager.IsRunning()
assert.False(t, isRunning)
})

t.Run("proc is not nil ,process is not exist", func(t *testing.T) {
manager.Proc = &process.Process{
Pid: 100000,
}

isRunning := manager.IsRunning()
assert.False(t, isRunning)
})
}

func TestNewProcessFromPidFile(t *testing.T) {
fs = afero.NewMemMapFs()
manager, mock, _ := MockDatabase(t)
defer mock.Close()

t.Run("file is not exist", func(t *testing.T) {
err := manager.newProcessFromPidFile()
assert.NotNil(t, err)
assert.ErrorContains(t, err, "file does not exist")
})

t.Run("process is not exist", func(t *testing.T) {
data := "100000\n/postgresql/data\n1692770488\n5432\n/var/run/postgresql\n*\n 2388960 4\nready"
err := afero.WriteFile(fs, manager.DataDir+"/postmaster.pid", []byte(data), 0644)
if err != nil {
t.Fatal(err)
}

err = manager.newProcessFromPidFile()
assert.NotNil(t, err)
assert.ErrorContains(t, err, "process does not exist")
})
}

func TestReadWrite(t *testing.T) {
ctx := context.TODO()
manager, mock, _ := MockDatabase(t)
Expand Down Expand Up @@ -173,32 +128,6 @@ func TestPgIsReady(t *testing.T) {
}
}

func TestSetAndUnsetIsLeader(t *testing.T) {
manager, mock, _ := MockDatabase(t)
defer mock.Close()

t.Run("set is leader", func(t *testing.T) {
manager.SetIsLeader(true)
isSet, isLeader := manager.GetIsLeader()
assert.True(t, isSet)
assert.True(t, isLeader)
})

t.Run("set is not leader", func(t *testing.T) {
manager.SetIsLeader(false)
isSet, isLeader := manager.GetIsLeader()
assert.True(t, isSet)
assert.False(t, isLeader)
})

t.Run("unset is leader", func(t *testing.T) {
manager.UnsetIsLeader()
isSet, isLeader := manager.GetIsLeader()
assert.False(t, isSet)
assert.False(t, isLeader)
})
}

func TestIsLeaderMember(t *testing.T) {
ctx := context.TODO()
manager, mock, _ := MockDatabase(t)
Expand Down
Loading

0 comments on commit aae7062

Please sign in to comment.