Documentation
¶
Overview ¶
Package mappedresource defines TreeDB's shared vocabulary for immutable file-backed resource views. It is intentionally small: subsystem-specific caches may remain specialized while using these keys, scopes, handles, stats, and maintenance pins as the common contract.
Index ¶
- Variables
- func Float32View(data []byte) ([]float32, error)
- func Float64View(data []byte) ([]float64, error)
- func Int64View(data []byte) ([]int64, error)
- func NativeLittleEndian() bool
- func Uint16View(data []byte) ([]uint16, error)
- func Uint32View(data []byte) ([]uint32, error)
- func Uint64View(data []byte) ([]uint64, error)
- func ValidateDirectView(data []byte, opts DirectViewOptions) (int, error)
- type AcquireOptions
- type Class
- type DenyReason
- type DirectViewOptions
- type FallbackReason
- type Handle
- type Key
- type Manager
- func (m *Manager) AcquireBytes(key Key, scope Scope, source Source, data []byte, opts AcquireOptions) (*Handle, error)
- func (m *Manager) AcquireFileRange(key Key, scope Scope, path string, opts AcquireOptions) (*Handle, error)
- func (m *Manager) Float32View(h *Handle) ([]float32, error)
- func (m *Manager) Float64View(h *Handle) ([]float64, error)
- func (m *Manager) Int64View(h *Handle) ([]int64, error)
- func (m *Manager) PinSummary() []Pin
- func (m *Manager) RecordHit()
- func (m *Manager) RecordMiss()
- func (m *Manager) Stats() Stats
- func (m *Manager) Uint16View(h *Handle) ([]uint16, error)
- func (m *Manager) Uint32View(h *Handle) ([]uint32, error)
- func (m *Manager) Uint64View(h *Handle) ([]uint64, error)
- type Pin
- type Scope
- type ScopeKind
- type Section
- type Source
- type Stats
- type ValidationMode
Constants ¶
This section is empty.
Variables ¶
var ( ErrDirectViewNilHandle = errors.New("mappedresource: nil handle") ErrDirectViewReleasedHandle = errors.New("mappedresource: handle is released") ErrDirectViewWrongEndian = errors.New("mappedresource: direct view wrong endian") ErrDirectViewLengthMultiple = errors.New("mappedresource: direct view length multiple mismatch") ErrDirectViewUnaligned = errors.New("mappedresource: direct view unaligned") )
Functions ¶
func Float32View ¶
Float32View exposes bytes as []float32 after validation.
func Float64View ¶
Float64View exposes bytes as []float64 after validation.
func NativeLittleEndian ¶
func NativeLittleEndian() bool
func Uint16View ¶
Uint16View exposes bytes as []uint16 after validation.
func Uint32View ¶
Uint32View exposes bytes as []uint32 after validation.
func Uint64View ¶
Uint64View exposes bytes as []uint64 after validation.
func ValidateDirectView ¶
func ValidateDirectView(data []byte, opts DirectViewOptions) (int, error)
ValidateDirectView validates length, alignment, and endian eligibility for a zero-copy typed view. It returns the element count.
Types ¶
type AcquireOptions ¶
type AcquireOptions struct {
Reason string
ValidationMode ValidationMode
PreferMapped bool
AllowHeapCopy bool
FallbackReason FallbackReason
ResourceRoot string
ResourcePath string
}
AcquireOptions controls resource acquisition and accounting labels. ResourceRoot and ResourcePath identify the durable storage root/path for maintenance filtering when the handle protects file-backed resources.
type Class ¶
type Class string
Class identifies the resource family. It is coarse enough for shared accounting but does not replace subsystem-specific formats.
type DenyReason ¶
type DenyReason string
DenyReason and FallbackReason provide stable accounting labels.
const ( DenyInvalidKey DenyReason = "invalid_key" DenyInvalidScope DenyReason = "invalid_scope" DenyUnsupported DenyReason = "unsupported" DenyOpenFailed DenyReason = "open_failed" DenyOutOfBounds DenyReason = "out_of_bounds" DenyReadFailed DenyReason = "read_failed" DenyMmapFailed DenyReason = "mmap_failed" DenyReleaseMismatch DenyReason = "release_mismatch" )
type DirectViewOptions ¶
type DirectViewOptions struct {
ElementSize uintptr
Alignment uintptr
TypeName string
RequireLittleEndian bool
}
DirectViewOptions controls validation before raw bytes are reinterpreted as a fixed-width typed slice.
type FallbackReason ¶
type FallbackReason string
const ( FallbackMmapFailed FallbackReason = "mmap_failed" FallbackReadAt FallbackReason = "readat" )
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle owns a live resource view. Bytes are valid until Release. Release is idempotent and updates accounting only once.
type Key ¶
type Key struct {
Class Class
Namespace string
Kind string
Generation uint64
PartID uint64
FileID uint32
Offset int64
Length int64
Checksum uint64
Version uint16
Encoding string
Section Section
}
Key is the stable identity for a mapped or copied resource range.
Offset/Length are a physical range in FileID/object identity. Section is an optional logical refinement for internally sectioned assets. Checksum is a generic content checksum/digest slot; callers may use the lower bits when the source format stores uint32 checksums.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager tracks resource handles and accounting. It intentionally does not choose a global cache policy; subsystems can wrap existing caches while using this manager for lifetime, pin, and stats visibility.
func (*Manager) AcquireBytes ¶
func (m *Manager) AcquireBytes(key Key, scope Scope, source Source, data []byte, opts AcquireOptions) (*Handle, error)
AcquireBytes registers caller-provided immutable bytes as a resource handle. The manager does not copy bytes; callers must ensure the slice remains stable for the handle lifetime.
func (*Manager) AcquireFileRange ¶
func (m *Manager) AcquireFileRange(key Key, scope Scope, path string, opts AcquireOptions) (*Handle, error)
AcquireFileRange opens path and returns either an mmap-backed or heap-copy handle for key.Offset:key.Offset+key.Length. Mmap is best-effort when PreferMapped is set; AllowHeapCopy controls fallback.
func (*Manager) Float32View ¶
Float32View records direct-view success/failure in addition to validating.
func (*Manager) Float64View ¶
Float64View records direct-view success/failure in addition to validating.
func (*Manager) Int64View ¶
Int64View records direct-view success/failure in addition to validating.
func (*Manager) PinSummary ¶
PinSummary returns active handles visible to maintenance.
func (*Manager) RecordMiss ¶
func (m *Manager) RecordMiss()
RecordMiss records an adapter cache miss.
func (*Manager) Uint16View ¶
Uint16View records direct-view success/failure in addition to validating.
func (*Manager) Uint32View ¶
Uint32View records direct-view success/failure in addition to validating.
type Pin ¶
type Pin struct {
ID uint64
Key Key
Scope Scope
Source Source
Bytes int64
Reason string
Root string
Path string
}
Pin describes one active handle visible to maintenance planning. Root and Path carry storage identity for DB-local filtering; AcquireFileRange fills Path from the opened file path when callers leave ResourcePath empty.
func GlobalPinSummary ¶
func GlobalPinSummary() []Pin
GlobalPinSummary returns all active process-local resource handles visible to destructive maintenance. Callers must still filter by resource class, namespace, and subsystem-specific identity before acting.
type Scope ¶
type Scope struct {
Kind ScopeKind
ID string
ParentID string
Collection string
Namespace string
Generation uint64
Reason string
}
Scope ties a physical resource handle to a logical lifetime. Snapshot/read view scopes should anchor ordinary query/search handles; maintenance scopes anchor destructive planning and protection checks.
func (Scope) Validate ¶
Validate rejects lifetime-less scopes. A non-empty ID makes ownership and tests explicit even when the scope is only process-local.
func (Scope) ValidateForKey ¶
ValidateForKey checks both the scope and key. It also catches accidental namespace mismatches when both sides carry a namespace.
type ScopeKind ¶
type ScopeKind string
ScopeKind identifies the logical lifetime that owns a resource handle.
const ( ScopeDB ScopeKind = "db" ScopeSnapshot ScopeKind = "snapshot" ScopeCollectionReadView ScopeKind = "collection_read_view" ScopeManifestGeneration ScopeKind = "manifest_generation" ScopeMaintenance ScopeKind = "maintenance" ScopePreparedQuery ScopeKind = "prepared_query" ScopePreparedSearch ScopeKind = "prepared_search" ScopeTypedRowReader ScopeKind = "typed_row_reader" ScopeColumnPartReader ScopeKind = "column_part_reader" )
type Section ¶
Section identifies a logical sub-range within an immutable asset. Column-part assets use this to address descriptor, dictionary, vector, adjacency, and scalar payload sections without requiring one OS file per section.
type Stats ¶
type Stats struct {
ActiveHandles int64
ActiveMappedBytes int64
ActiveHeapCopyBytes int64
ActiveDerivedMetadataBytes int64
TotalAcquires uint64
TotalReleases uint64
TotalMappedBytes uint64
TotalHeapCopyBytes uint64
TotalDerivedMetadataBytes uint64
Hits uint64
Misses uint64
FallbackReads uint64
Opens uint64
Closes uint64
Errors uint64
DirectViewSuccesses uint64
DirectViewFailures uint64
DeniedByReason map[DenyReason]uint64
FallbacksByReason map[FallbackReason]uint64
ValidationModeReads map[ValidationMode]uint64
}
Stats is the common row+column resource accounting shape used by adapters and future column-part readers.
func GlobalStats ¶
func GlobalStats() Stats
GlobalStats returns process-wide resource accounting across mappedresource managers. It is intended for maintenance diagnostics; subsystem-local Stats remains the precise per-manager view.
type ValidationMode ¶
type ValidationMode string
const ( ValidationVerify ValidationMode = "verify" ValidationCachedVerify ValidationMode = "cached_verify" ValidationSkipChecksum ValidationMode = "skip_checksums" )