mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
- A limiter's first fetch checks the host configuration under configuration.lock, publishing it when absent (configGuard, now shared with cut admission): a fetch-only process with other flags gets ErrConfig. - No blocking lock: with every slot held, one fetch per process polls every slot each 20 ms (the others wait for its turn, within their context). An ended wait leaves no lock request, descriptor or goroutine; lockBlocking is removed. - The waiting is unordered and bounded by the caller's context alone; the docs say so instead of promising a kernel queue. - A slot taken when the context has already ended is given back, with the context's error. - INV-HOST-FETCH-CAP-001, M7 and the v1.1 note state the contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
665 B
Go
27 lines
665 B
Go
//go:build windows
|
|
|
|
package hostlimit
|
|
|
|
import (
|
|
"errors"
|
|
"golang.org/x/sys/windows"
|
|
"os"
|
|
)
|
|
|
|
func tryLock(f *os.File) error {
|
|
err := windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &windows.Overlapped{})
|
|
if errors.Is(err, windows.ERROR_LOCK_VIOLATION) {
|
|
return ErrBusy
|
|
}
|
|
return err
|
|
}
|
|
|
|
// tryLockShared takes a shared lock on f without waiting.
|
|
func tryLockShared(f *os.File) error {
|
|
err := windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &windows.Overlapped{})
|
|
if errors.Is(err, windows.ERROR_LOCK_VIOLATION) {
|
|
return ErrBusy
|
|
}
|
|
return err
|
|
}
|