diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 8fc14429..1bdc9746 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -192,12 +192,14 @@ func ServeCmd() *cobra.Command { cmd.Flags().Int("aio-store-batch-size", 100, "max submissions processed each tick by a store worker") cmd.Flags().String("aio-store-sqlite-path", "resonate.db", "sqlite database path") cmd.Flags().Duration("aio-store-sqlite-tx-timeout", 250*time.Millisecond, "sqlite transaction timeout") + cmd.Flags().Bool("aio-store-sqlite-reset", false, "sqlite database clean on shutdown") cmd.Flags().String("aio-store-postgres-host", "localhost", "postgres host") cmd.Flags().String("aio-store-postgres-port", "5432", "postgres port") cmd.Flags().String("aio-store-postgres-username", "", "postgres username") cmd.Flags().String("aio-store-postgres-password", "", "postgres password") cmd.Flags().String("aio-store-postgres-database", "resonate", "postgres database name") cmd.Flags().Duration("aio-store-postgres-tx-timeout", 250*time.Millisecond, "postgres transaction timeout") + cmd.Flags().Bool("aio-store-postgres-reset", false, "postgres database clean on shutdown") cmd.Flags().Int("aio-network-size", 100, "size of network submission queue buffered channel") cmd.Flags().Int("aio-network-workers", 3, "number of concurrent http requests") cmd.Flags().Int("aio-network-batch-size", 100, "max submissions processed each tick by a network worker") @@ -210,6 +212,7 @@ func ServeCmd() *cobra.Command { _ = viper.BindPFlag("aio.subsystems.store.subsystem.batchSize", cmd.Flags().Lookup("aio-store-batch-size")) _ = viper.BindPFlag("aio.subsystems.store.config.sqlite.path", cmd.Flags().Lookup("aio-store-sqlite-path")) _ = viper.BindPFlag("aio.subsystems.store.config.sqlite.txTimeout", cmd.Flags().Lookup("aio-store-sqlite-tx-timeout")) + _ = viper.BindPFlag("aio.subsystems.store.config.sqlite.reset", cmd.Flags().Lookup("aio-store-sqlite-reset")) _ = viper.BindPFlag("aio.subsystems.store.config.postgres.host", cmd.Flags().Lookup("aio-store-postgres-host")) _ = viper.BindPFlag("aio.subsystems.store.config.postgres.port", cmd.Flags().Lookup("aio-store-postgres-port")) _ = viper.BindPFlag("aio.subsystems.store.config.postgres.username", cmd.Flags().Lookup("aio-store-postgres-username")) @@ -217,6 +220,7 @@ func ServeCmd() *cobra.Command { _ = viper.BindPFlag("aio.subsystems.store.config.postgres.database", cmd.Flags().Lookup("aio-store-postgres-database")) _ = viper.BindPFlag("aio.subsystems.store.config.postgres.database", cmd.Flags().Lookup("aio-store-postgres-database")) _ = viper.BindPFlag("aio.subsystems.store.config.postgres.txTimeout", cmd.Flags().Lookup("aio-store-postgres-tx-timeout")) + _ = viper.BindPFlag("aio.subsystems.store.config.postgres.reset", cmd.Flags().Lookup("aio-store-postgres-reset")) _ = viper.BindPFlag("aio.subsystems.network.subsystem.size", cmd.Flags().Lookup("aio-network-size")) _ = viper.BindPFlag("aio.subsystems.network.subsystem.workers", cmd.Flags().Lookup("aio-network-workers")) _ = viper.BindPFlag("aio.subsystems.network.subsystem.batchSize", cmd.Flags().Lookup("aio-network-batch-size")) diff --git a/internal/app/subsystems/aio/store/postgres/postgres.go b/internal/app/subsystems/aio/store/postgres/postgres.go index 12f5ed11..4d76e511 100644 --- a/internal/app/subsystems/aio/store/postgres/postgres.go +++ b/internal/app/subsystems/aio/store/postgres/postgres.go @@ -306,6 +306,7 @@ type Config struct { Password string Database string TxTimeout time.Duration + Reset bool } type PostgresStore struct { @@ -355,10 +356,18 @@ func (s *PostgresStore) Start() error { } func (s *PostgresStore) Stop() error { + + if s.config.Reset { + if err := s.Reset(); err != nil { + return err + } + } + return s.db.Close() } func (s *PostgresStore) Reset() error { + if _, err := s.db.Exec(DROP_TABLE_STATEMENT); err != nil { return err } diff --git a/internal/app/subsystems/aio/store/sqlite/sqlite.go b/internal/app/subsystems/aio/store/sqlite/sqlite.go index fc59be20..7f50e49d 100644 --- a/internal/app/subsystems/aio/store/sqlite/sqlite.go +++ b/internal/app/subsystems/aio/store/sqlite/sqlite.go @@ -296,6 +296,7 @@ const ( type Config struct { Path string TxTimeout time.Duration + Reset bool } type SqliteStore struct { @@ -332,10 +333,18 @@ func (s *SqliteStore) Start() error { } func (s *SqliteStore) Stop() error { + + if s.config.Reset { + if err := s.Reset(); err != nil { + return err + } + } + return s.db.Close() } func (s *SqliteStore) Reset() error { + if _, err := os.Stat(s.config.Path); err != nil { return nil }