Skip to content

Commit

Permalink
fix(cmd): Rename replication flags to follow consistent convention
Browse files Browse the repository at this point in the history
Signed-off-by: Bartłomiej Święcki <[email protected]>
  • Loading branch information
Bartłomiej Święcki committed Nov 9, 2022
1 parent f42bceb commit bda1945
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
35 changes: 22 additions & 13 deletions cmd/immuadmin/command/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,33 @@ func addDbUpdateFlags(c *cobra.Command) {
c.Flags().Bool("replication-is-replica", false, "set database as a replica")
c.Flags().Bool("replication-sync-enabled", false, "enable synchronous replication")
c.Flags().Uint32("replication-sync-acks", 0, "set a minimum number of replica acknowledgements required before transactions can be committed")
c.Flags().String("replication-master-database", "", "set master database to be replicated")
c.Flags().String("replication-master-address", "", "set master address")
c.Flags().Uint32("replication-master-port", 0, "set master port")
c.Flags().String("replication-follower-username", "", "set username used for replication")
c.Flags().String("replication-follower-password", "", "set password used for replication")
c.Flags().String("replication-primary-database", "", "set primary database to be replicated")
c.Flags().String("replication-primary-host", "", "set primary database host")
c.Flags().Uint32("replication-primary-port", 0, "set primary database port")
c.Flags().String("replication-primary-username", "", "set username used for replication to connect to the primary database")
c.Flags().String("replication-primary-password", "", "set password used for replication to connect to the primary database")
c.Flags().Uint32("replication-prefetch-tx-buffer-size", uint32(replication.DefaultPrefetchTxBufferSize), "maximum number of prefeched transactions")
c.Flags().Uint32("replication-commit-concurrency", uint32(replication.DefaultReplicationCommitConcurrency), "number of concurrent replications")
c.Flags().Bool("replication-allow-tx-discarding", replication.DefaultAllowTxDiscarding, "allow precommitted transactions to be discarded if the follower diverges from the master")
c.Flags().Bool("replication-allow-tx-discarding", replication.DefaultAllowTxDiscarding, "allow precommitted transactions to be discarded if the replica diverges from the primary")
c.Flags().Uint32("write-tx-header-version", 1, "set write tx header version (use 0 for compatibility with immudb 1.1, 1 for immudb 1.2+)")
c.Flags().Uint32("max-commit-concurrency", store.DefaultMaxConcurrency, "set the maximum commit concurrency")
c.Flags().Duration("sync-frequency", store.DefaultSyncFrequency, "set the fsync frequency during commit process")
c.Flags().Uint32("write-buffer-size", store.DefaultWriteBufferSize, "set the size of in-memory buffers for file abstractions")
c.Flags().Uint32("read-tx-pool-size", database.DefaultReadTxPoolSize, "set transaction read pool size (used for reading transaction objects)")
c.Flags().Bool("autoload", true, "enable database autoloading")

flagNameMapping := map[string]string{
"replication-enabled": "replication-is-replica",
"replication-follower-username": "replication-primary-username",
"replication-follower-password": "replication-primary-password",
"replication-master-database": "replication-primary-database",
"replication-master-address": "replication-primary-host",
"replication-master-port": "replication-primary-port",
}

c.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
if name == "replication-enabled" {
name = "replication-is-replica"
if newName, ok := flagNameMapping[name]; ok {
name = newName
}
return pflag.NormalizedName(name)
})
Expand Down Expand Up @@ -390,27 +399,27 @@ func prepareDatabaseNullableSettings(flags *pflag.FlagSet) (*schema.DatabaseNull
return nil, err
}

ret.ReplicationSettings.MasterDatabase, err = condString("replication-master-database")
ret.ReplicationSettings.MasterDatabase, err = condString("replication-primary-database")
if err != nil {
return nil, err
}

ret.ReplicationSettings.MasterAddress, err = condString("replication-master-address")
ret.ReplicationSettings.MasterAddress, err = condString("replication-primary-host")
if err != nil {
return nil, err
}

ret.ReplicationSettings.MasterPort, err = condUInt32("replication-master-port")
ret.ReplicationSettings.MasterPort, err = condUInt32("replication-primary-port")
if err != nil {
return nil, err
}

ret.ReplicationSettings.FollowerUsername, err = condString("replication-follower-username")
ret.ReplicationSettings.FollowerUsername, err = condString("replication-primary-username")
if err != nil {
return nil, err
}

ret.ReplicationSettings.FollowerPassword, err = condString("replication-follower-password")
ret.ReplicationSettings.FollowerPassword, err = condString("replication-primary-password")
if err != nil {
return nil, err
}
Expand Down
23 changes: 16 additions & 7 deletions cmd/immudb/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func (cl *Commandline) setupFlags(cmd *cobra.Command, options *server.Options) {
cmd.Flags().Bool("replication-is-replica", false, "set systemdb and defaultdb as replica")
cmd.Flags().Bool("replication-sync-enabled", false, "enable synchronous replication")
cmd.Flags().Int("replication-sync-acks", 0, "set a minimum number of replica acknowledgements required before transactions can be committed")
cmd.Flags().String("replication-master-address", "", "master address (if replica=true)")
cmd.Flags().Int("replication-master-port", 3322, "master port (if replica=true)")
cmd.Flags().String("replication-follower-username", "", "username used for replication of systemdb and defaultdb")
cmd.Flags().String("replication-follower-password", "", "password used for replication of systemdb and defaultdb")
cmd.Flags().String("replication-primary-host", "", "primary database host (if replica=true)")
cmd.Flags().Int("replication-primary-port", 3322, "primary database port (if replica=true)")
cmd.Flags().String("replication-primary-username", "", "username in the primary database used for replication of systemdb and defaultdb")
cmd.Flags().String("replication-primary-password", "", "password in the primary database used for replication of systemdb and defaultdb")
cmd.Flags().Int("replication-prefetch-tx-buffer-size", options.ReplicationOptions.PrefetchTxBufferSize, "maximum number of prefeched transactions")
cmd.Flags().Int("replication-commit-concurrency", options.ReplicationOptions.ReplicationCommitConcurrency, "number of concurrent replications")
cmd.Flags().Bool("replication-allow-tx-discarding", replication.DefaultAllowTxDiscarding, "allow precommitted transactions to be discarded if the follower diverges from the master")
cmd.Flags().Bool("replication-allow-tx-discarding", replication.DefaultAllowTxDiscarding, "allow precommitted transactions to be discarded if the replica diverges from the primary")

cmd.PersistentFlags().StringVar(&cl.config.CfgFn, "config", "", "config file (default path are configs or $HOME. Default filename is immudb.toml)")
cmd.Flags().String("pidfile", options.Pidfile, "pid path with filename e.g. /var/run/immudb.pid")
Expand Down Expand Up @@ -84,9 +84,18 @@ func (cl *Commandline) setupFlags(cmd *cobra.Command, options *server.Options) {
cmd.Flags().Duration("sessions-guard-check-interval", 1*time.Minute, "sessions guard check interval")
cmd.Flags().MarkHidden("sessions-guard-check-interval")

flagNameMapping := map[string]string{
"replication-enabled": "replication-is-replica",
"replication-follower-username": "replication-primary-username",
"replication-follower-password": "replication-primary-password",
"replication-master-database": "replication-primary-database",
"replication-master-address": "replication-primary-host",
"replication-master-port": "replication-primary-port",
}

cmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
if name == "replication-enabled" {
name = "replication-is-replica"
if newName, ok := flagNameMapping[name]; ok {
name = newName
}
return pflag.NormalizedName(name)
})
Expand Down
8 changes: 4 additions & 4 deletions cmd/immudb/command/parse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func parseOptions() (options *server.Options, err error) {

if replicationOptions.IsReplica {
replicationOptions.
WithMasterAddress(viper.GetString("replication-master-address")).
WithMasterPort(viper.GetInt("replication-master-port")).
WithFollowerUsername(viper.GetString("replication-follower-username")).
WithFollowerPassword(viper.GetString("replication-follower-password")).
WithMasterAddress(viper.GetString("replication-primary-host")).
WithMasterPort(viper.GetInt("replication-primary-port")).
WithFollowerUsername(viper.GetString("replication-primary-username")).
WithFollowerPassword(viper.GetString("replication-primary-password")).
WithPrefetchTxBufferSize(viper.GetInt("replication-prefetch-tx-buffer-size")).
WithReplicationCommitConcurrency(viper.GetInt("replication-commit-concurrency")).
WithAllowTxDiscarding(viper.GetBool("replication-allow-tx-discarding"))
Expand Down

0 comments on commit bda1945

Please sign in to comment.