Documentation
¶
Overview ¶
Package storedbytes owns durable byte claims and account capacity.
Index ¶
- Constants
- Variables
- func FinalizeAccountReplay(ctx context.Context, source RecoveryReader, state AccountReplayState) ([]storage.CompareAndSwapMutation, error)
- func PrepareAccountReplay(ctx context.Context, source RecoveryReader, state AccountReplayState, ...) ([]storage.CompareAndSwapMutation, error)
- func VerifyRecoveryAttachment(claim *RecoveryClaim, file *RecoveryAttachment) error
- func VerifyRecoveryTotal(total *int64, held int64) error
- type AccountReplayState
- type RecoveryAttachment
- type RecoveryClaim
- type RecoveryReader
- type RecoveryRecord
- type StorageMeter
- func (m *StorageMeter) Abort(ctx context.Context, holder, id string) error
- func (m *StorageMeter) Attachment(ctx context.Context, holder, id string) (storage.CompareAndSwapMutation, error)
- func (m *StorageMeter) InitializeEmpty(ctx context.Context, holder string) error
- func (m *StorageMeter) RecoverPending(ctx context.Context) error
- func (m *StorageMeter) Release(ctx context.Context, holder, id string) error
- func (m *StorageMeter) Reserve(ctx context.Context, holder, id string, size, bound int64) error
- func (m *StorageMeter) Resize(ctx context.Context, holder, id string, size int64) error
- func (m *StorageMeter) Total(ctx context.Context, holder string) (int64, error)
Constants ¶
const ( // StoredBytesSchemaVersion identifies durable byte claims and their aggregate. StoredBytesSchemaVersion = 2 // StoredBytesPrefix is the durable byte accounting namespace. StoredBytesPrefix = "limits:v2:stored_bytes:" )
const ReplayStoragePrefix = "limits:v2:stored_bytes_replay:"
ReplayStoragePrefix marks unfinished byte-account reconstruction.
const StoredBytesPendingGrace = 10 * time.Minute
StoredBytesPendingGrace bounds unattached preparation. Recovery competes with attachment on the same claim, so a delayed writer cannot attach a closed claim.
Variables ¶
var ( // ErrStorageFull refuses a claim beyond the account byte bound. ErrStorageFull = errors.New("stored bytes limit exceeded") // ErrStorageHistoryUnknown requires recovery before more byte claims. ErrStorageHistoryUnknown = errors.New("stored byte history requires recovery") // ErrStorageClaimConflict preserves a retained claim identity. ErrStorageClaimConflict = errors.New("stored byte claim conflicts with retained identity") // ErrStorageClaimReleased refuses reuse of a closed claim. ErrStorageClaimReleased = errors.New("stored byte claim is closed") )
Functions ¶
func FinalizeAccountReplay ¶
func FinalizeAccountReplay(ctx context.Context, source RecoveryReader, state AccountReplayState) ([]storage.CompareAndSwapMutation, error)
FinalizeAccountReplay publishes the exact independently accepted total after a complete census. It removes only this owner's matching staging marker. It never creates fresh budget history.
func PrepareAccountReplay ¶
func PrepareAccountReplay(ctx context.Context, source RecoveryReader, state AccountReplayState, claims []RecoveryClaim) ([]storage.CompareAndSwapMutation, error)
PrepareAccountReplay stages at most 64 typed claims while preserving original total bytes. The final census must include every old claim. Omitted records never disappear.
func VerifyRecoveryAttachment ¶
func VerifyRecoveryAttachment(claim *RecoveryClaim, file *RecoveryAttachment) error
VerifyRecoveryAttachment checks both claim-to-file and file-to-claim references. Released attached claims may retain deleting metadata until cleanup completes.
func VerifyRecoveryTotal ¶
VerifyRecoveryTotal requires retained total evidence and the exact held-claim sum.
Types ¶
type AccountReplayState ¶
type AccountReplayState struct {
Version int `json:"version"`
Holder string `json:"holder"`
Claims int64 `json:"claims"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
}
AccountReplayState binds a complete independently retained account byte census. The coordinator must establish its provenance and complete interval coverage.
func CaptureAccountReplayState ¶
func CaptureAccountReplayState(ctx context.Context, source RecoveryReader, holder string) (AccountReplayState, error)
CaptureAccountReplayState verifies the independent total and every retained claim. Missing total evidence never means zero consumption.
type RecoveryAttachment ¶
type RecoveryAttachment struct {
Holder, FileID string
Metered, Deleting, Ready, Retired bool
Bytes int64
}
RecoveryAttachment describes the file facts needed to check its byte claim.
type RecoveryClaim ¶
type RecoveryClaim struct {
Version int `json:"version"`
Holder string `json:"holder"`
ID string `json:"id"`
Initial int64 `json:"initial"`
Bytes int64 `json:"bytes"`
Bound int64 `json:"bound"`
Measured bool `json:"measured"`
Attached bool `json:"attached"`
Released bool `json:"released"`
CreatedAt time.Time `json:"created_at"`
}
RecoveryClaim preserves the complete durable byte claim during operator recovery.
type RecoveryReader ¶
type RecoveryReader interface {
ReadCaptured(context.Context, string, int) (storage.TransferRecord, error)
Enumerate(context.Context, func(storage.TransferRecord) error) error
}
RecoveryReader exposes an immutable complete captured view, in strict key order.
type RecoveryRecord ¶
type RecoveryRecord struct {
Holder string
Total *int64
Claim *RecoveryClaim
}
RecoveryRecord identifies one strictly decoded owner record.
func VerifyRecoveryRecord ¶
func VerifyRecoveryRecord(record storage.TransferRecord) (RecoveryRecord, error)
VerifyRecoveryRecord rejects unsupported fields, transient records, and identity mismatches.
type StorageMeter ¶
type StorageMeter struct {
// contains filtered or unexported fields
}
StorageMeter owns durable file claims and their atomic account total.
func NewStorageMeter ¶
func NewStorageMeter(store storage.KVStore) (*StorageMeter, error)
NewStorageMeter binds durable byte accounting to the selected store.
func (*StorageMeter) Abort ¶
func (m *StorageMeter) Abort(ctx context.Context, holder, id string) error
Abort fences an unattached preparation without releasing a published file.
func (*StorageMeter) Attachment ¶
func (m *StorageMeter) Attachment(ctx context.Context, holder, id string) (storage.CompareAndSwapMutation, error)
Attachment joins a reserved byte claim to the file metadata write.
func (*StorageMeter) InitializeEmpty ¶
func (m *StorageMeter) InitializeEmpty(ctx context.Context, holder string) error
InitializeEmpty requires the file owner to prove that the account has no files. Existing legacy or claim evidence prevents an implicit reset to zero.
func (*StorageMeter) RecoverPending ¶
func (m *StorageMeter) RecoverPending(ctx context.Context) error
RecoverPending closes abandoned preparations. Attached files remain under the file owner's cleanup protocol. Each pass reads native pages for at most thirty seconds. The next sweep resumes at the retained cursor.
func (*StorageMeter) Release ¶
func (m *StorageMeter) Release(ctx context.Context, holder, id string) error
Release closes a claim after its bytes disappear. Retried cleanup releases nothing twice.
func (*StorageMeter) Reserve ¶
Reserve records one file claim before bytes or file metadata can publish.