mirror of
https://github.com/samuelncui/acp.git
synced 2026-11-08 04:21:16 +00:00
Replaces the streaming request/result API with caller-owned items and consolidates the content options, following the Job execution performance design. - `Item`, `BatchSource` and `Run` replace `StreamRequest`, `StreamResult`, `StreamSource`, `StreamSink` and `RunStream`. Every accepted item receives exactly one terminal callback from a single goroutine and without doing I/O; an item ACP cannot process reports `Failed`, and a completion carries one outcome per requested target in request order with its error identity preserved. A graceful stop stops feeding, finishes the items in flight and reports the rest, and a hard stop abandons per-item accounting. - One `HashPolicy` replaces `WithHash`, `WithSignatureCache` and `ForceRehash`. A stored hash is read whenever the policy uses the cache, reused only where the policy allows it, and refreshed only when it differs. - A source-only `WithReadMode` selects buffered (the default) or mapped reads, and buffered sources open with `O_NOATIME` where the platform has it. `LinearDevice` keeps request ordering, append targets and abort-on-error but no longer selects the read mode. - `Overwrite` becomes a target-device option, `WithReadBuffer` sets the read buffer, and `SelectFiles` returns the entries the command line copies, replacing `AccurateJob`, `WildcardJob` and the walk options. - Copy consumers share one reference-counted chunk buffer each from a common pool, and the per-item write goroutines finish before the result channel closes, so no finished item can be dropped. The command line tools, the documentation and the test suite move with the API, including semantic tests for the callback contract, the stop and drain paths, the hash policy matrix and the read modes.
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package acp
|
|
|
|
import "fmt"
|
|
|
|
// ReadMode selects how a source device reads its content.
|
|
type ReadMode uint8
|
|
|
|
const (
|
|
// ReadBuffered reads through the kernel's buffered path, which is the default.
|
|
ReadBuffered ReadMode = iota
|
|
// ReadMapped reads through a memory mapping.
|
|
ReadMapped
|
|
)
|
|
|
|
func (m ReadMode) String() string {
|
|
switch m {
|
|
case ReadBuffered:
|
|
return "buffered"
|
|
case ReadMapped:
|
|
return "mapped"
|
|
}
|
|
return fmt.Sprintf("unknown(%d)", uint8(m))
|
|
}
|
|
|
|
type deviceOption struct {
|
|
linear bool
|
|
threads int
|
|
overwrite bool
|
|
readMode ReadMode
|
|
}
|
|
|
|
func (do *deviceOption) check() error {
|
|
if do.threads < 0 {
|
|
return fmt.Errorf("device threads cannot be negative, threads=%d", do.threads)
|
|
}
|
|
if do.threads == 0 {
|
|
do.threads = 8
|
|
}
|
|
if do.linear {
|
|
do.threads = 1
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type DeviceOption func(*deviceOption) *deviceOption
|
|
|
|
func LinearDevice(b bool) DeviceOption {
|
|
return func(d *deviceOption) *deviceOption {
|
|
d.linear = b
|
|
return d
|
|
}
|
|
}
|
|
|
|
func DeviceThreads(threads int) DeviceOption {
|
|
return func(d *deviceOption) *deviceOption {
|
|
d.threads = threads
|
|
return d
|
|
}
|
|
}
|
|
|
|
// WithReadMode selects how a source device reads its content. It applies to the source
|
|
// device only and defaults to buffered reads.
|
|
func WithReadMode(mode ReadMode) DeviceOption {
|
|
return func(d *deviceOption) *deviceOption {
|
|
d.readMode = mode
|
|
return d
|
|
}
|
|
}
|