feat: persist resumable client script uploads

This commit is contained in:
2026-09-06 06:39:12 +00:00
parent 6539b9e965
commit 62c0052979
5 changed files with 447 additions and 2 deletions
+12 -1
View File
@@ -38,6 +38,7 @@ type Options struct {
BusyTimeout time.Duration
TombstoneLimit uint64
QuotaLimits QuotaLimits
MaxScriptBytes uint64
}
type Store struct {
@@ -47,6 +48,7 @@ type Store struct {
identity domain.UUID
tombstoneLimit uint64
quotaLimits QuotaLimits
maxScriptBytes uint64
mu sync.Mutex
}
@@ -69,6 +71,15 @@ func Open(ctx context.Context, options Options) (*Store, error) {
if err := options.QuotaLimits.Validate(); err != nil {
return nil, err
}
if options.MaxScriptBytes == 0 {
options.MaxScriptBytes = 10 << 20
if options.MaxScriptBytes > options.QuotaLimits.CommandTotalBytes {
options.MaxScriptBytes = options.QuotaLimits.CommandTotalBytes
}
}
if options.MaxScriptBytes > options.QuotaLimits.CommandTotalBytes {
return nil, errors.New("script maximum exceeds client command quota")
}
if err := ensurePrivateDirectory(options.DataDir); err != nil {
return nil, err
}
@@ -100,7 +111,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, quotaLimits: options.QuotaLimits}
store := &Store{db: db, unlock: unlock, dataDir: options.DataDir, identity: identity, tombstoneLimit: options.TombstoneLimit, quotaLimits: options.QuotaLimits, maxScriptBytes: options.MaxScriptBytes}
if err := db.PingContext(ctx); err != nil {
_ = store.Close()
return nil, fmt.Errorf("open client spool SQLite: %w", err)