diff options
| author | Fuwn <[email protected]> | 2026-02-27 09:26:06 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-27 09:26:06 -0800 |
| commit | 8980607ef8e7426b601f942f26ae2cd4c4f3edff (patch) | |
| tree | 60bdb4bbbe5755223c3387179ee7406432d084ab /internal/config | |
| parent | fix: make mirror replay lossless with strict seq accounting and trace (diff) | |
| download | plutia-test-8980607ef8e7426b601f942f26ae2cd4c4f3edff.tar.xz plutia-test-8980607ef8e7426b601f942f26ae2cd4c4f3edff.zip | |
feat: add thin mode for on-demand verified PLC resolution
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 17 | ||||
| -rw-r--r-- | internal/config/config_thin_test.go | 35 |
2 files changed, 51 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index f777a21..e94b5ea 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,6 +14,7 @@ import ( const ( ModeResolver = "resolver" ModeMirror = "mirror" + ModeThin = "thin" VerifyFull = "full" VerifyLazy = "lazy" VerifyStateOnly = "state-only" @@ -31,6 +32,8 @@ type Config struct { VerifyWorkers int `yaml:"verify_workers"` ExportPageSize int `yaml:"export_page_size"` ReplayTrace bool `yaml:"replay_trace"` + ThinCacheTTL time.Duration `yaml:"thin_cache_ttl"` + ThinCacheMaxEntries int `yaml:"thin_cache_max_entries"` ListenAddr string `yaml:"listen_addr"` MirrorPrivateKeyPath string `yaml:"mirror_private_key_path"` PollInterval time.Duration `yaml:"poll_interval"` @@ -61,6 +64,8 @@ func Default() Config { VerifyWorkers: runtime.NumCPU(), ExportPageSize: 1000, ReplayTrace: false, + ThinCacheTTL: 24 * time.Hour, + ThinCacheMaxEntries: 100000, ListenAddr: ":8080", MirrorPrivateKeyPath: "./mirror.key", PollInterval: 5 * time.Second, @@ -153,6 +158,8 @@ func applyEnv(cfg *Config) { setInt("PLUTIA_VERIFY_WORKERS", &cfg.VerifyWorkers) setInt("PLUTIA_EXPORT_PAGE_SIZE", &cfg.ExportPageSize) setBool("PLUTIA_REPLAY_TRACE", &cfg.ReplayTrace) + setDuration("PLUTIA_THIN_CACHE_TTL", &cfg.ThinCacheTTL) + setInt("PLUTIA_THIN_CACHE_MAX_ENTRIES", &cfg.ThinCacheMaxEntries) setUint64("PLUTIA_CHECKPOINT_INTERVAL", &cfg.CheckpointInterval) setString("PLUTIA_LISTEN_ADDR", &cfg.ListenAddr) setString("PLUTIA_MIRROR_PRIVATE_KEY_PATH", &cfg.MirrorPrivateKeyPath) @@ -168,7 +175,7 @@ func applyEnv(cfg *Config) { } func (c Config) Validate() error { - if c.Mode != ModeResolver && c.Mode != ModeMirror { + if c.Mode != ModeResolver && c.Mode != ModeMirror && c.Mode != ModeThin { return fmt.Errorf("invalid mode %q", c.Mode) } @@ -210,6 +217,14 @@ func (c Config) Validate() error { return fmt.Errorf("export_page_size must be between 1 and 1000, got %d", c.ExportPageSize) } + if c.ThinCacheTTL <= 0 { + return errors.New("thin_cache_ttl must be > 0") + } + + if c.ThinCacheMaxEntries <= 0 { + return errors.New("thin_cache_max_entries must be > 0") + } + if c.ListenAddr == "" { return errors.New("listen_addr is required") } diff --git a/internal/config/config_thin_test.go b/internal/config/config_thin_test.go new file mode 100644 index 0000000..ff549e1 --- /dev/null +++ b/internal/config/config_thin_test.go @@ -0,0 +1,35 @@ +package config + +import ( + "testing" + "time" +) + +func TestValidateAcceptsThinMode(t *testing.T) { + cfg := Default() + cfg.Mode = ModeThin + cfg.ThinCacheTTL = 24 * time.Hour + cfg.ThinCacheMaxEntries = 10 + + if err := cfg.Validate(); err != nil { + t.Fatalf("validate thin mode: %v", err) + } +} + +func TestValidateRejectsInvalidThinCacheConfig(t *testing.T) { + cfg := Default() + cfg.Mode = ModeThin + cfg.ThinCacheTTL = 0 + + if err := cfg.Validate(); err == nil { + t.Fatalf("expected thin_cache_ttl validation error") + } + + cfg = Default() + cfg.Mode = ModeThin + cfg.ThinCacheMaxEntries = 0 + + if err := cfg.Validate(); err == nil { + t.Fatalf("expected thin_cache_max_entries validation error") + } +} |