feat: enforce client spool quota tiers

This commit is contained in:
2026-09-06 06:32:22 +00:00
parent c348d6bb16
commit 6539b9e965
6 changed files with 363 additions and 11 deletions
+9 -1
View File
@@ -37,6 +37,7 @@ type Options struct {
DataDir string
BusyTimeout time.Duration
TombstoneLimit uint64
QuotaLimits QuotaLimits
}
type Store struct {
@@ -45,6 +46,7 @@ type Store struct {
dataDir string
identity domain.UUID
tombstoneLimit uint64
quotaLimits QuotaLimits
mu sync.Mutex
}
@@ -61,6 +63,12 @@ func Open(ctx context.Context, options Options) (*Store, error) {
if options.TombstoneLimit == 0 {
options.TombstoneLimit = DefaultTombstoneLimit
}
if options.QuotaLimits == (QuotaLimits{}) {
options.QuotaLimits = DefaultQuotaLimits()
}
if err := options.QuotaLimits.Validate(); err != nil {
return nil, err
}
if err := ensurePrivateDirectory(options.DataDir); err != nil {
return nil, err
}
@@ -92,7 +100,7 @@ func Open(ctx context.Context, options Options) (*Store, error) {
}
db.SetMaxOpenConns(1)
db.SetMaxIdleConns(1)
store := &Store{db: db, unlock: unlock, dataDir: options.DataDir, identity: identity, tombstoneLimit: options.TombstoneLimit}
store := &Store{db: db, unlock: unlock, dataDir: options.DataDir, identity: identity, tombstoneLimit: options.TombstoneLimit, quotaLimits: options.QuotaLimits}
if err := db.PingContext(ctx); err != nil {
_ = store.Close()
return nil, fmt.Errorf("open client spool SQLite: %w", err)