feat: persist resumable client script uploads
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user