Skip to content

Commit

Permalink
Merge branch 'master' into add-scram-sha-256-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnl88 committed Apr 20, 2021
2 parents 3c2651a + 057389f commit f2a4219
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 103 deletions.
14 changes: 7 additions & 7 deletions .agola/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ local task_integration_tests(store, pgversion, arch) = {
},
],
depends: [
'build go 1.14 ' + arch,
'build go 1.16 ' + arch,
],
};

Expand Down Expand Up @@ -165,22 +165,22 @@ local task_build_push_images(name, pgversions, istag, push) =
[
task_build_go(version, arch),
]
for version in ['1.13', '1.14']
for version in ['1.15', '1.16']
for arch in ['amd64' /*, 'arm64' */]
]) + std.flattenArrays([
[
task_integration_tests(store, pgversion, 'amd64'),
]
for store in ['etcdv2', 'consul']
for pgversion in ['12']
for pgversion in ['13']
]) + std.flattenArrays([
[
task_integration_tests(store, pgversion, 'amd64'),
]
for store in ['etcdv3']
for pgversion in ['9.5', '9.6', '10', '11', '12']
for pgversion in [ '9.6', '10', '11', '12', '13']
]) + [
task_build_push_images('test build docker "stolon" images', '9.4 9.5 9.6 10 11 12', false, false)
task_build_push_images('test build docker "stolon" images', '9.6 10 11 12 13', false, false)
+ {
when: {
branch: {
Expand All @@ -190,13 +190,13 @@ local task_build_push_images(name, pgversions, istag, push) =
ref: '#refs/pull/\\d+/head#',
},
},
task_build_push_images('build and push docker "stolon" master branch images', '9.4 9.5 9.6 10 11 12', false, true)
task_build_push_images('build and push docker "stolon" master branch images', '9.6 10 11 12 13', false, true)
+ {
when: {
branch: 'master',
},
},
task_build_push_images('build and push docker "stolon" tag images', '9.4 9.5 9.6 10 11 12', true, true)
task_build_push_images('build and push docker "stolon" tag images', '9.6 10 11 12 13', true, true)
+ {
when: {
tag: '#v.*#',
Expand Down
82 changes: 61 additions & 21 deletions cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type config struct {

canBeMaster bool
canBeSynchronousReplica bool
disableDataDirLocking bool
}

var cfg config
Expand Down Expand Up @@ -142,6 +143,7 @@ func init() {

CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeMaster, "can-be-master", true, "prevent keeper from being elected as master")
CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeSynchronousReplica, "can-be-synchronous-replica", true, "prevent keeper from being chosen as synchronous replica")
CmdKeeper.PersistentFlags().BoolVar(&cfg.disableDataDirLocking, "disable-data-dir-locking", false, "disable locking on data dir. Warning! It'll cause data corruptions if two keepers are concurrently running with the same data dir.")

if err := CmdKeeper.PersistentFlags().MarkDeprecated("id", "please use --uid"); err != nil {
log.Fatal(err)
Expand All @@ -154,6 +156,7 @@ func init() {
var managedPGParameters = []string{
"unix_socket_directories",
"wal_keep_segments",
"wal_keep_size",
"hot_standby",
"listen_addresses",
"port",
Expand Down Expand Up @@ -248,13 +251,42 @@ func (p *PostgresKeeper) walKeepSegments(db *cluster.DB) int {
return walKeepSegments
}

func (p *PostgresKeeper) walKeepSize(db *cluster.DB) string {
// assume default 16Mib wal segment size
walKeepSize := strconv.Itoa(minWalKeepSegments * 16)

// TODO(sgotti) currently we ignore if wal_keep_size value is less than our
// min value or wrong and just return it as is
if db.Spec.PGParameters != nil {
if v, ok := db.Spec.PGParameters["wal_keep_size"]; ok {
return v
}
}

return walKeepSize
}

func (p *PostgresKeeper) mandatoryPGParameters(db *cluster.DB) common.Parameters {
return common.Parameters{
params := common.Parameters{
"unix_socket_directories": common.PgUnixSocketDirectories,
"wal_level": p.walLevel(db),
"wal_keep_segments": fmt.Sprintf("%d", p.walKeepSegments(db)),
"hot_standby": "on",
}

maj, _, err := p.pgm.BinaryVersion()
if err != nil {
// in case we fail to parse the binary version don't return any wal_keep_segments or wal_keep_size
log.Warnf("failed to get postgres binary version: %v", err)
return params
}

if maj >= 13 {
params["wal_keep_size"] = p.walKeepSize(db)
} else {
params["wal_keep_segments"] = fmt.Sprintf("%d", p.walKeepSegments(db))
}

return params
}

func (p *PostgresKeeper) getSUConnParams(db, followedDB *cluster.DB) pg.ConnParams {
Expand Down Expand Up @@ -1259,6 +1291,7 @@ func (p *PostgresKeeper) postgresKeeperSM(pctx context.Context) {
log.Errorw("failed to stop pg instance", zap.Error(err))
return
}

case cluster.DBInitModeResync:
log.Infow("resyncing the database cluster")
ndbls := &DBLocalState{
Expand Down Expand Up @@ -1474,6 +1507,9 @@ func (p *PostgresKeeper) postgresKeeperSM(pctx context.Context) {
log.Errorw("database cluster not initialized but requested role is master. This shouldn't happen!")
return
}

pgm.SetRecoveryOptions(nil)

started, err := pgm.IsStarted()
if err != nil {
log.Errorw("failed to retrieve instance status", zap.Error(err))
Expand All @@ -1499,7 +1535,6 @@ func (p *PostgresKeeper) postgresKeeperSM(pctx context.Context) {

if localRole == common.RoleStandby {
log.Infow("promoting to master")
pgm.SetRecoveryOptions(nil)
if err = pgm.Promote(); err != nil {
log.Errorw("failed to promote instance", zap.Error(err))
return
Expand Down Expand Up @@ -2033,26 +2068,29 @@ func keeper(c *cobra.Command, args []string) {
// Open (and create if needed) the lock file.
// There is no need to clean up this file since we don't use the file as an actual lock. We get a lock
// on the file. So the lock get released when our process stops (or log.Fatalfs).
lockFileName := filepath.Join(cfg.dataDir, "lock")
lockFile, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("cannot take exclusive lock on data dir %q: %v", lockFileName, err)
}
var lockFile *os.File
if !cfg.disableDataDirLocking {
lockFileName := filepath.Join(cfg.dataDir, "lock")
lockFile, err = os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("cannot take exclusive lock on data dir %q: %v", lockFileName, err)
}

// Get a lock on our lock file.
ft := &syscall.Flock_t{
Type: syscall.F_WRLCK,
Whence: int16(io.SeekStart),
Start: 0,
Len: 0, // Entire file.
}
// Get a lock on our lock file.
ft := &syscall.Flock_t{
Type: syscall.F_WRLCK,
Whence: int16(io.SeekStart),
Start: 0,
Len: 0, // Entire file.
}

err = syscall.FcntlFlock(lockFile.Fd(), syscall.F_SETLK, ft)
if err != nil {
log.Fatalf("cannot take exclusive lock on data dir %q: %v", lockFileName, err)
}
err = syscall.FcntlFlock(lockFile.Fd(), syscall.F_SETLK, ft)
if err != nil {
log.Fatalf("cannot take exclusive lock on data dir %q: %v", lockFileName, err)
}

log.Infow("exclusive lock on data dir taken")
log.Infow("exclusive lock on data dir taken")
}

if cfg.uid != "" {
if !pg.IsValidReplSlotName(cfg.uid) {
Expand Down Expand Up @@ -2085,5 +2123,7 @@ func keeper(c *cobra.Command, args []string) {

<-end

lockFile.Close()
if !cfg.disableDataDirLocking {
lockFile.Close()
}
}
5 changes: 4 additions & 1 deletion doc/commands/stolon-keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ stolon-keeper [flags]
### Options

```
--can-be-master prevent keeper from being elected as master (default true)
--can-be-synchronous-replica prevent keeper from being chosen as synchronous replica (default true)
--cluster-name string cluster name
--data-dir string data directory
--disable-data-dir-locking disable locking on data dir. Warning! It'll cause data corruptions if two keepers are concurrently running with the same data dir.
-h, --help help for stolon-keeper
--kube-resource-kind string the k8s resource kind to be used to store stolon clusterdata and do sentinel leader election (only "configmap" is currently supported)
--log-color enable color in log output (default if attached to a terminal)
Expand Down Expand Up @@ -44,4 +47,4 @@ stolon-keeper [flags]
--uid string keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.
```

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolon-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ stolon-proxy [flags]
--tcp-keepalive-interval int set tcp keepalive interval (seconds)
```

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolon-sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ stolon-sentinel [flags]
--store-timeout duration store request timeout (default 5s)
```

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ stolonctl [flags]
* [stolonctl update](stolonctl_update.md) - Update a cluster specification
* [stolonctl version](stolonctl_version.md) - Display the version

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_clusterdata.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Manage current cluster data
* [stolonctl clusterdata read](stolonctl_clusterdata_read.md) - Retrieve the current cluster data
* [stolonctl clusterdata write](stolonctl_clusterdata_write.md) - Write cluster data

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_clusterdata_read.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl clusterdata read [flags]

* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_clusterdata_write.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ stolonctl clusterdata write [flags]

* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_failkeeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl failkeeper [keeper uid] [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ stolonctl init [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_promote.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl promote [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_register.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ stolonctl register [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_removekeeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl removekeeper [keeper uid] [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl spec [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ stolonctl status [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ stolonctl update [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion doc/commands/stolonctl_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ stolonctl version [flags]

* [stolonctl](stolonctl.md) - stolon command line client

###### Auto generated by spf13/cobra on 6-Mar-2020
###### Auto generated by spf13/cobra on 24-Feb-2021
2 changes: 1 addition & 1 deletion examples/kubernetes/image/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG PGVERSION

# base build image
FROM golang:1.14-buster AS build_base
FROM golang:1.16-buster AS build_base

WORKDIR /stolon

Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/sorintlab/stolon

require (
// force github.com/coreos/etcd to v3.3.18 that doesn't use github.com/ugorji/go
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.18+incompatible // indirect
github.com/davecgh/go-spew v1.1.1
github.com/docker/leadership v0.1.0
Expand All @@ -10,21 +10,22 @@ require (
github.com/golang/mock v1.4.0
github.com/google/go-cmp v0.4.0
github.com/hashicorp/consul/api v1.4.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lib/pq v1.3.0
github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/copystructure v1.0.0
github.com/prometheus/client_golang v1.4.1
github.com/satori/go.uuid v1.2.0
github.com/sgotti/gexpect v0.0.0-20161123102107-0afc6c19f50a
github.com/sgotti/gexpect v0.0.0-20210315095146-1ec64e69809b
github.com/sorintlab/pollon v0.0.0-20181009091703-248c68238c16
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
go.etcd.io/etcd v0.0.0-20201125193152-8a03d2e9614b
go.uber.org/zap v1.13.0
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/client-go v0.17.3
)

go 1.12

replace github.com/coreos/bbolt v1.3.3 => github.com/etcd-io/bbolt v1.3.3
Loading

0 comments on commit f2a4219

Please sign in to comment.