Help us shape the future of Go! Take the 2026 Go Developer Survey

cdn_bstore

package
v0.57.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPointerTTL = 30 * time.Second

DefaultPointerTTL is the fallback TTL for cached root pointers when the caller does not override it.

View Source
const MaxRootPackedmsgBytes int64 = 4 << 20

MaxRootPackedmsgBytes caps anonymous root.packedmsg fetches.

Variables

This section is empty.

Functions

func FetchRootPointer

func FetchRootPointer(ctx context.Context, httpCli *http.Client, cdnBaseURL, spaceID string) (*cdn.CdnRootPointer, error)

FetchRootPointer fetches and decodes root.packedmsg for a CDN Space. Returns nil, nil on 404 so callers can treat fresh Spaces as empty.

func NewAnonymousOpener

func NewAnonymousOpener(httpCli *http.Client, cdnBaseURL, spaceID string) packfile_store.Opener

NewAnonymousOpener returns a packfile_store.Opener that builds shared pack readers for anonymous HTTP Range requests against the public CDN. The opener does not sign requests and does not issue HEAD requests; the pack size must be passed in from the manifest entry.

func PackIndexObjectStoreID added in v0.56.1

func PackIndexObjectStoreID(spaceID string) string

PackIndexObjectStoreID returns the stable metadata ObjectStore ID for a CDN Space's durable packfile index cache.

Types

type CachedBlockStoreOptions added in v0.57.2

type CachedBlockStoreOptions struct {
	// CdnBaseURL is the public CDN origin (e.g. https://cdn.spacewave.app).
	CdnBaseURL string
	// SpaceID is the CDN Space ULID.
	SpaceID string
	// CacheBlockStoreID is the bus block store used for writeback and
	// pack-index persistence. Empty disables the local cache.
	CacheBlockStoreID string
	// PointerTTL is the cache TTL for the decoded root pointer. See Options.
	PointerTTL time.Duration
	// WritebackWindowBytes bounds co-block writeback buffering.
	WritebackWindowBytes int64
	// HttpClient overrides the default http.Client.
	HttpClient *http.Client
	// Release is called when a looked-up cache dependency is disposed while
	// the assembled store is still live. Callers whose store sits under a
	// lifecycle owner pass their invalidation callback here. Callers that
	// own the store for their whole lifetime may leave it nil; the bus
	// references are still freed by the returned release function.
	Release func()
}

CachedBlockStoreOptions configure NewCachedBlockStore.

type CdnBlockStore

type CdnBlockStore struct {
	// contains filtered or unexported fields
}

CdnBlockStore is a read-only block.StoreOps backed by the public Spacewave CDN. Reads are served by a packfile_store.PackfileStore fed by an anonymous HTTP Range opener. Writes return ErrReadOnly. The cached root pointer is refreshed lazily when the TTL expires or Invalidate is called.

func NewCachedBlockStore added in v0.57.2

func NewCachedBlockStore(ctx context.Context, b bus.Bus, opts CachedBlockStoreOptions) (*CdnBlockStore, func(), error)

NewCachedBlockStore assembles a CdnBlockStore with its local cache wiring.

With CacheBlockStoreID set it looks up the writeback block store and the durable pack-index object store on the bus, wires both into the CDN store, and returns a release function that closes the store and frees the bus references. On assembly failure every acquired reference is freed before the error returns.

func NewCdnBlockStore

func NewCdnBlockStore(opts Options) (*CdnBlockStore, error)

NewCdnBlockStore constructs a new CdnBlockStore. The pointer is fetched lazily on the first read; pass a pre-populated pointer via SetPointer if the caller already has one.

func (*CdnBlockStore) BeginReadOperation added in v0.51.7

func (s *CdnBlockStore) BeginReadOperation(context.Context) (block.StoreOps, func(), error)

BeginReadOperation returns the CDN block store as the scoped read handle.

func (*CdnBlockStore) Close added in v0.51.7

func (s *CdnBlockStore) Close()

Close fences root publication, then cancels pack transport work and releases the decoded-block cache.

func (*CdnBlockStore) EnsureDecodedBlockCacheFresh added in v0.51.7

func (s *CdnBlockStore) EnsureDecodedBlockCacheFresh(ctx context.Context) error

EnsureDecodedBlockCacheFresh refreshes pointer state before decoded cache reads.

func (*CdnBlockStore) GetBlock

func (s *CdnBlockStore) GetBlock(ctx context.Context, ref *block.BlockRef) ([]byte, bool, error)

GetBlock reads a block by reference, refreshing the pointer if needed.

func (*CdnBlockStore) GetBlockExists

func (s *CdnBlockStore) GetBlockExists(ctx context.Context, ref *block.BlockRef) (bool, error)

GetBlockExists checks if a block exists.

func (*CdnBlockStore) GetBlockExistsBatch

func (s *CdnBlockStore) GetBlockExistsBatch(ctx context.Context, refs []*block.BlockRef) ([]bool, error)

GetBlockExistsBatch checks whether each block exists.

func (*CdnBlockStore) GetDecodedBlockCache added in v0.51.7

func (s *CdnBlockStore) GetDecodedBlockCache() *block.DecodedBlockCache

GetDecodedBlockCache returns the lifecycle-owned decoded-block cache.

func (*CdnBlockStore) GetHashType

func (s *CdnBlockStore) GetHashType() hash.HashType

GetHashType returns the preferred block hash type.

func (*CdnBlockStore) GetID

func (s *CdnBlockStore) GetID() string

GetID returns the block store id; CDN block stores use the Space ULID verbatim because the mount is 1:1 with a Space.

func (*CdnBlockStore) GetStoredBlock

func (s *CdnBlockStore) GetStoredBlock(ctx context.Context, ref *block.BlockRef) (*block.StoredBlock, error)

GetStoredBlock serves the block without refs because this store keeps block bytes without their refs.

func (*CdnBlockStore) GetSupportedFeatures

func (s *CdnBlockStore) GetSupportedFeatures() block.StoreFeature

GetSupportedFeatures returns the native feature bitset.

func (*CdnBlockStore) Invalidate

func (s *CdnBlockStore) Invalidate()

Invalidate drops the cached pointer so the next read re-fetches.

func (*CdnBlockStore) Pointer

func (s *CdnBlockStore) Pointer() *cdn.CdnRootPointer

Pointer returns the currently-cached root pointer without triggering a refresh. Returns nil if no pointer has been fetched yet.

func (*CdnBlockStore) PutBlock

func (s *CdnBlockStore) PutBlock(_ context.Context, _ []byte, _ *block.PutOpts) (*block.BlockRef, bool, error)

PutBlock is not supported on an anonymous CDN block store.

func (*CdnBlockStore) PutBlockBatch

func (s *CdnBlockStore) PutBlockBatch(_ context.Context, entries []*block.PutBatchEntry) error

PutBlockBatch is not supported on an anonymous CDN block store.

func (*CdnBlockStore) ReclaimStorage

func (s *CdnBlockStore) ReclaimStorage(context.Context, func(context.Context) error) (time.Time, error)

ReclaimStorage returns zero: the CDN block store is read-only.

func (*CdnBlockStore) Refresh

func (s *CdnBlockStore) Refresh(ctx context.Context) (*cdn.CdnRootPointer, error)

Refresh forces a re-fetch of the root pointer and updates the manifest. Returns the new pointer (nil if the CDN Space is empty).

func (*CdnBlockStore) RmBlock

func (s *CdnBlockStore) RmBlock(_ context.Context, _ *block.BlockRef) error

RmBlock is not supported on an anonymous CDN block store.

func (*CdnBlockStore) SetPointer

func (s *CdnBlockStore) SetPointer(ptr *cdn.CdnRootPointer)

SetPointer replaces the cached pointer without issuing a network request. Callers use it after receiving a CDN root-change signal on an external channel.

func (*CdnBlockStore) SetRangeCacheMaxBytes added in v0.51.0

func (s *CdnBlockStore) SetRangeCacheMaxBytes(maxBytes int64)

SetRangeCacheMaxBytes sets the resident range-cache budget per pack reader.

func (*CdnBlockStore) SetWriteback added in v0.51.0

func (s *CdnBlockStore) SetWriteback(ctx context.Context, target block.StoreOps, windowBytes int64)

SetWriteback enables local co-block persistence through the underlying packfile store.

func (*CdnBlockStore) StatBlock

func (s *CdnBlockStore) StatBlock(ctx context.Context, ref *block.BlockRef) (*block.BlockStat, error)

StatBlock returns block metadata without reading the data.

func (*CdnBlockStore) Sync added in v0.52.0

func (s *CdnBlockStore) Sync(_ context.Context) (bool, error)

Sync reports always-durable: the CDN block store holds no buffered writes.

type Options

type Options struct {
	// CdnBaseURL is the public CDN origin (e.g. https://cdn.spacewave.app).
	CdnBaseURL string
	// SpaceID is the CDN Space ULID.
	SpaceID string
	// HttpClient overrides the default http.Client.
	HttpClient *http.Client
	// PointerTTL is the cache TTL for the decoded root pointer. Zero falls
	// back to DefaultPointerTTL. Negative disables the TTL (pointer is cached
	// until explicitly invalidated).
	PointerTTL time.Duration
	// IndexCache optionally persists raw packfile index tails across restarts.
	IndexCache packfile_store.IndexCache
}

Options configure a CdnBlockStore.

type RootBlockStore added in v0.57.2

type RootBlockStore interface {
	// BlockStore reads blocks for the CDN Space.
	bstore.BlockStore

	// Pointer returns the currently-cached root pointer without
	// triggering a fetch. Returns nil if no pointer has been fetched yet.
	Pointer() *cdn.CdnRootPointer
	// Refresh re-fetches the root pointer.
	// Returns nil if the CDN Space has no published root.
	Refresh(ctx context.Context) (*cdn.CdnRootPointer, error)
	// Close releases resources owned by the store.
	Close()
}

RootBlockStore reads a CDN Space and tracks its root pointer.

The pointer carries the SORoot a reader builds its world head from, so every mount of a CDN Space needs one whether or not that mount owns the CDN transport. CdnBlockStore owns transport, pack readers, and writeback; SuppliedBlockStore reads through an owner that already holds them.

type SuppliedBlockStore added in v0.57.2

type SuppliedBlockStore struct {
	// contains filtered or unexported fields
}

SuppliedBlockStore reads a CDN Space through a block store supplied by another owner while fetching the root pointer itself.

It exists for compositions that mount one CDN Space in two processes: the owning process holds the single CDN transport, pack readers, index cache, decoded-block cache, and durable writeback, and every other process reads the same Space through that owner rather than opening a second transport. The root pointer stays local so the reader can build its world view.

func NewSuppliedBlockStore added in v0.57.2

func NewSuppliedBlockStore(opts SuppliedOptions) (*SuppliedBlockStore, error)

NewSuppliedBlockStore constructs a SuppliedBlockStore. The pointer is not fetched until Refresh is called.

func (*SuppliedBlockStore) BeginReadOperation added in v0.57.2

func (s *SuppliedBlockStore) BeginReadOperation(ctx context.Context) (block.StoreOps, func(), error)

BeginReadOperation opens a read scope on the supplied store.

func (*SuppliedBlockStore) Close added in v0.57.2

func (s *SuppliedBlockStore) Close()

Close releases resources used by the store. The supplied store is owned by its supplier and is not closed here.

func (*SuppliedBlockStore) GetBlock added in v0.57.2

func (s *SuppliedBlockStore) GetBlock(ctx context.Context, ref *block.BlockRef) ([]byte, bool, error)

GetBlock forwards to the supplied store.

func (*SuppliedBlockStore) GetBlockExists added in v0.57.2

func (s *SuppliedBlockStore) GetBlockExists(ctx context.Context, ref *block.BlockRef) (bool, error)

GetBlockExists forwards to the supplied store.

func (*SuppliedBlockStore) GetBlockExistsBatch added in v0.57.2

func (s *SuppliedBlockStore) GetBlockExistsBatch(ctx context.Context, refs []*block.BlockRef) ([]bool, error)

GetBlockExistsBatch forwards to the supplied store.

func (*SuppliedBlockStore) GetDecodedBlockCache added in v0.57.2

func (s *SuppliedBlockStore) GetDecodedBlockCache() *block.DecodedBlockCache

GetDecodedBlockCache returns nil: the supplying owner holds the decoded-block cache for this Space, so readers build their own short-lived cache instead of borrowing one across the supply boundary.

func (*SuppliedBlockStore) GetHashType added in v0.57.2

func (s *SuppliedBlockStore) GetHashType() block_hash.HashType

GetHashType forwards to the supplied store.

func (*SuppliedBlockStore) GetID added in v0.57.2

func (s *SuppliedBlockStore) GetID() string

GetID returns the block store id; CDN block stores use the Space ULID verbatim because the mount is 1:1 with a Space.

func (*SuppliedBlockStore) GetStoredBlock

func (s *SuppliedBlockStore) GetStoredBlock(ctx context.Context, ref *block.BlockRef) (*block.StoredBlock, error)

GetStoredBlock forwards to the inner store.

func (*SuppliedBlockStore) GetSupportedFeatures added in v0.57.2

func (s *SuppliedBlockStore) GetSupportedFeatures() block.StoreFeature

GetSupportedFeatures forwards to the supplied store.

func (*SuppliedBlockStore) Pointer added in v0.57.2

func (s *SuppliedBlockStore) Pointer() *cdn.CdnRootPointer

Pointer returns the currently-cached root pointer without triggering a refresh. Returns nil if no pointer has been fetched yet.

func (*SuppliedBlockStore) PutBlock added in v0.57.2

func (s *SuppliedBlockStore) PutBlock(_ context.Context, _ []byte, _ *block.PutOpts) (*block.BlockRef, bool, error)

PutBlock is not supported: the supplying owner writes this Space.

func (*SuppliedBlockStore) PutBlockBatch added in v0.57.2

func (s *SuppliedBlockStore) PutBlockBatch(_ context.Context, entries []*block.PutBatchEntry) error

PutBlockBatch is not supported: the supplying owner writes this Space.

func (*SuppliedBlockStore) ReclaimStorage

func (s *SuppliedBlockStore) ReclaimStorage(context.Context, func(context.Context) error) (time.Time, error)

ReclaimStorage returns zero: the supplying owner holds the storage.

func (*SuppliedBlockStore) Refresh added in v0.57.2

Refresh forces a re-fetch of the root pointer. Returns the new pointer (nil if the CDN Space is empty).

func (*SuppliedBlockStore) RmBlock added in v0.57.2

RmBlock is not supported: the supplying owner writes this Space.

func (*SuppliedBlockStore) StatBlock added in v0.57.2

func (s *SuppliedBlockStore) StatBlock(ctx context.Context, ref *block.BlockRef) (*block.BlockStat, error)

StatBlock forwards to the supplied store.

func (*SuppliedBlockStore) Sync added in v0.57.2

func (s *SuppliedBlockStore) Sync(ctx context.Context) (bool, error)

Sync forwards the durability barrier to the supplied store.

type SuppliedOptions added in v0.57.2

type SuppliedOptions struct {
	// CdnBaseURL is the public CDN origin (e.g. https://cdn.spacewave.app).
	CdnBaseURL string
	// SpaceID is the CDN Space ULID.
	SpaceID string
	// HttpClient overrides the default http.Client for root pointer fetches.
	HttpClient *http.Client
	// Store serves every block read. Another owner holds the CDN transport,
	// pack readers, and durable writeback behind it.
	Store block_store.Store
}

SuppliedOptions configure a SuppliedBlockStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL