Documentation
¶
Index ¶
- Constants
- Variables
- func EditionSHA256(edition string) ([32]byte, error)
- func MarshalEnvelope(e Envelope) ([]byte, error)
- func PersistentBackendEnabled(goos, goarch string) bool
- func UseMemoryOpenForTest(t *testing.T)
- func UseUserCacheDirErrorForTest(t *testing.T)
- func UseUserCacheDirForTest(t *testing.T, dir string)
- type Artifact
- type ArtifactExpectation
- type ArtifactKind
- type Cache
- func (c *Cache) AcquireLock(ctx context.Context, timeout time.Duration) (*Lock, error)
- func (c *Cache) Close() error
- func (c *Cache) Directory() string
- func (c *Cache) OpenPayloads(identity ExpectedIdentity, expected ArtifactExpectation) (*Registry, error)
- func (c *Cache) OpenRegistry(identity ExpectedIdentity, expected ArtifactExpectation) (*Registry, error)
- func (c *Cache) Publish(identity ExpectedIdentity, registry, meta Artifact, extra ...Artifact) error
- func (c *Cache) ReadMeta(identity ExpectedIdentity, expected ArtifactExpectation) ([]byte, error)
- func (c *Cache) WriteArtifact(identity ExpectedIdentity, artifact Artifact) error
- type Counters
- type Envelope
- type ExpectedIdentity
- type IOSnapshot
- type Lock
- type Option
- type RangeDescriptor
- type Registry
Constants ¶
const ( HeaderSize = 208 EnvelopeVersion = uint16(1) DTOFormatVersion = uint32(2) SerializerProtobuf = uint8(2) CodecRaw = uint8(0) MaxMetaFileSize = uint64(4 << 20) MaxRegistryFileSize = uint64(64 << 20) MaxProductRangeSize = uint64(8 << 20) MaxRegistryPayloadSize = MaxRegistryFileSize - HeaderSize )
Variables ¶
var ( ErrDisabled = errors.New("schema cache disabled on this platform") ErrNotFound = errors.New("schema cache artifact not found") ErrInvalidArtifact = errors.New("invalid schema cache artifact") ErrIdentityMismatch = errors.New("schema cache identity mismatch") ErrUnsafePath = errors.New("unsafe schema cache path") ErrLockTimeout = errors.New("schema cache lock timeout") ErrClosed = errors.New("schema cache handle closed") )
Functions ¶
func EditionSHA256 ¶
func MarshalEnvelope ¶
func PersistentBackendEnabled ¶
PersistentBackendEnabled is the reviewed v1 disk-cache surface: darwin, linux, and windows on amd64/arm64. Each machine generates identity locally, so the backend is not limited to the old compile-time proof pair. Other targets stay live-only.
func UseMemoryOpenForTest ¶
UseMemoryOpenForTest swaps Open onto a portable file backend under t.TempDir so targets without the unix backend (Windows coverage) can Publish and Read the same artifacts. Production must not call this; the ForTest suffix is the boundary. The swap is inlined (not testseam) so schemacache stays out of the thin Schema dependency closure.
func UseUserCacheDirErrorForTest ¶
UseUserCacheDirErrorForTest makes the per-user cache base lookup fail for the test (covers the fallback's user-cache-unavailable error leg).
func UseUserCacheDirForTest ¶
UseUserCacheDirForTest points the per-user cache base at dir for the test. Production must not call this; the ForTest suffix is the boundary.
Types ¶
type Artifact ¶
type Artifact struct {
Expectation ArtifactExpectation
Payload []byte
}
Artifact pairs a trusted expectation with the exact payload to publish.
type ArtifactExpectation ¶
type ArtifactExpectation struct {
Kind ArtifactKind
Serializer uint8
Codec uint8
FormatVersion uint32
EncodedLength uint64
DecodedLength uint64
EncodedSHA256 [32]byte
}
ArtifactExpectation is the binary-pinned identity of one exact artifact.
type ArtifactKind ¶
type ArtifactKind uint8
const ( KindMeta ArtifactKind = 1 KindRegistry ArtifactKind = 2 KindPayloads ArtifactKind = 3 )
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a securely opened edition-specific cache directory.
func (*Cache) AcquireLock ¶
func (*Cache) OpenPayloads ¶
func (c *Cache) OpenPayloads(identity ExpectedIdentity, expected ArtifactExpectation) (*Registry, error)
OpenPayloads opens the command payload file for bounded ReadRange calls. It is deliberately independent of the registry so a corrupted registry cannot affect payload reads.
func (*Cache) OpenRegistry ¶
func (c *Cache) OpenRegistry(identity ExpectedIdentity, expected ArtifactExpectation) (*Registry, error)
OpenRegistry authenticates the header and binary-pinned total identity. It deliberately does not hash Registry payload bytes on this leaf path.
func (*Cache) Publish ¶
func (c *Cache) Publish(identity ExpectedIdentity, registry, meta Artifact, extra ...Artifact) error
Publish commits Registry first and Meta last. Meta is the generation commit marker.
func (*Cache) ReadMeta ¶
func (c *Cache) ReadMeta(identity ExpectedIdentity, expected ArtifactExpectation) ([]byte, error)
ReadMeta authenticates the exact complete Meta payload before returning it.
func (*Cache) WriteArtifact ¶
func (c *Cache) WriteArtifact(identity ExpectedIdentity, artifact Artifact) error
WriteArtifact atomically replaces one artifact. Publish should be used when committing a Registry and Meta pair.
type Counters ¶
type Counters struct {
// contains filtered or unexported fields
}
func (*Counters) Snapshot ¶
func (c *Counters) Snapshot() IOSnapshot
type Envelope ¶
type Envelope struct {
Kind ArtifactKind
Serializer uint8
Codec uint8
Flags uint8
FormatVersion uint32
CatalogSnapshotVersion uint32
EncodedLength uint64
DecodedLength uint64
EditionSHA256 [32]byte
SourceSHA256 [32]byte
SurfaceSHA256 [32]byte
BuildID [32]byte
EncodedSHA256 [32]byte
}
Envelope is the fixed, allocation-free portion of a cache artifact.
func ParseEnvelope ¶
func (Envelope) MarshalBinary ¶
type ExpectedIdentity ¶
type ExpectedIdentity struct {
CatalogSnapshotVersion uint32
EditionSHA256 [32]byte
SourceSHA256 [32]byte
SurfaceSHA256 [32]byte
BuildID [32]byte
}
ExpectedIdentity contains only values pinned by the running binary. Header values are compared with this identity and are never accepted on their own.
func (ExpectedIdentity) Authenticate ¶
func (i ExpectedIdentity) Authenticate(e Envelope, a ArtifactExpectation) error
Authenticate compares every envelope identity field with binary-pinned trusted values. It does not authenticate payload bytes by itself.
type IOSnapshot ¶
type IOSnapshot struct {
RootOpenOps uint64
MkdirOps uint64
FileOpenOps uint64
StatOps uint64
HeaderReadOps uint64
MetaPayloadReadOps uint64
MetaPayloadReadBytes uint64
RegistryReadOps uint64
RegistryReadBytes uint64
PayloadReadOps uint64
PayloadReadBytes uint64
WriteOps uint64
WriteBytes uint64
FileSyncOps uint64
CloseOps uint64
RenameOps uint64
RemoveOps uint64
DirectorySyncOps uint64
LockAttempts uint64
}
IOSnapshot exposes cache-only operations without coupling callers to payload parsing.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a process-local and cross-process rebuild lock.
type Option ¶
type Option func(*openOptions)
func WithCounters ¶
func WithNoCreate ¶
func WithNoCreate() Option
WithNoCreate turns a missing cache ancestry into ErrNotFound instead of creating it. Speculative readers must never mutate the filesystem.
func WithUserOnly ¶
func WithUserOnly() Option
WithUserOnly bypasses the DWS_SCHEMA_CACHE_DIR / shared / system bases and opens the per-user cache directly. The repair path uses it to persist and reuse a repair when the preferred shared cache exists but cannot be locked (typically root-owned read-only with corrupted artifacts).
type RangeDescriptor ¶
RangeDescriptor must come from an already authenticated Meta payload. Offset is relative to the Registry payload, after its fixed header.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry keeps one authenticated regular file open for bounded ReadRange calls.
func (*Registry) ReadRange ¶
func (r *Registry) ReadRange(descriptor RangeDescriptor) ([]byte, error)
func (*Registry) ValidateAggregate ¶
ValidateAggregate hashes the complete Registry payload for repair or full audit. ReadRange does not call it.