From 0490926b5352ceb68517853040f122b99a1d7300 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Wed, 1 May 2024 13:45:23 -0700 Subject: [PATCH 1/2] Added pragma page size logic to config --- config/config.go | 21 +++++++++++++++++++++ main.go | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index d49353a..3f88137 100644 --- a/config/config.go +++ b/config/config.go @@ -41,6 +41,7 @@ type broker struct { } type Config struct { + PageSize int64 `yaml:"pragmaPageSize"` Port int64 `yaml:"port"` PprofPort int `yaml:"pprofPort"` HealthcheckPort int64 `yaml:"healthcheck"` @@ -154,6 +155,26 @@ func LoadConfig(fname string) (*Config, error) { log.Root().SetHandler(log.LvlFilterHandler(logLvl, log.Root().GetHandler())) + log.Error("this is the page size", "ps", cfg.PageSize) + if cfg.PageSize == 0 { + cfg.PageSize = 4096 + } + if cfg.PageSize > 65536 { + log.Warn("config: pragma page size miust be less than or equal to 65536, setting to largest possible value: 65536") + cfg.PageSize = 65536 + } + if cfg.PageSize > 0 && (cfg.PageSize&(cfg.PageSize-1)) != 0 { + var bit int64 = 1 + for cfg.PageSize > 0 { + cfg.PageSize >>= 1 + bit <<= 1 + } + val := bit >> 1 + log.Warn(fmt.Sprintf("config: pragma page size miust be a power of two, setting size to: %v", val)) + cfg.PageSize = val + } + + log.Error("This is the port", "p", cfg.Port) if cfg.Port == 0 { cfg.Port = 8000 } diff --git a/main.go b/main.go index a67cad8..97db5ab 100644 --- a/main.go +++ b/main.go @@ -61,7 +61,7 @@ func main() { &sqlite3.SQLiteDriver{ ConnectHook: func(conn *sqlite3.SQLiteConn) error { for name, path := range cfg.Databases { - conn.Exec(fmt.Sprintf("ATTACH DATABASE '%v' AS '%v'; PRAGMA %v.page_size = 65536 ; PRAGMA %v.journal_mode = WAL ; PRAGMA %v.synchronous = OFF ; pragma %v.max_page_count = 4294967294;", path, name, name, name, name, name), nil) + conn.Exec(fmt.Sprintf("ATTACH DATABASE '%v' AS '%v'; PRAGMA %v.page_size = %v ; PRAGMA %v.journal_mode = WAL ; PRAGMA %v.synchronous = OFF ; pragma %v.max_page_count = 4294967294;", path, name, name, cfg.PageSize, name, name, name), nil) } return nil }, From 5cf8290542e6b11da944715f922b01308d62c10c Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Wed, 1 May 2024 17:10:56 -0700 Subject: [PATCH 2/2] logging warning for page unacceptable page size only --- config/config.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/config/config.go b/config/config.go index 3f88137..a985bfd 100644 --- a/config/config.go +++ b/config/config.go @@ -155,26 +155,10 @@ func LoadConfig(fname string) (*Config, error) { log.Root().SetHandler(log.LvlFilterHandler(logLvl, log.Root().GetHandler())) - log.Error("this is the page size", "ps", cfg.PageSize) - if cfg.PageSize == 0 { - cfg.PageSize = 4096 - } - if cfg.PageSize > 65536 { - log.Warn("config: pragma page size miust be less than or equal to 65536, setting to largest possible value: 65536") - cfg.PageSize = 65536 - } - if cfg.PageSize > 0 && (cfg.PageSize&(cfg.PageSize-1)) != 0 { - var bit int64 = 1 - for cfg.PageSize > 0 { - cfg.PageSize >>= 1 - bit <<= 1 - } - val := bit >> 1 - log.Warn(fmt.Sprintf("config: pragma page size miust be a power of two, setting size to: %v", val)) - cfg.PageSize = val + if cfg.PageSize < 4096 || cfg.PageSize > 65536 || (cfg.PageSize&(cfg.PageSize-1)) != 0 { + log.Warn(fmt.Sprintf("config: invalid pragma page size of %v, setting to default of 4096", cfg.PageSize)) } - log.Error("This is the port", "p", cfg.Port) if cfg.Port == 0 { cfg.Port = 8000 }