Documentation
¶
Index ¶
- Constants
- Variables
- type Bark
- type BarkConfig
- type BlobStoreBark
- func (b *BlobStoreBark) Close() error
- func (b *BlobStoreBark) Delete(txn types.Txn, key []byte) error
- func (b *BlobStoreBark) DeleteBlock(txn types.Txn, slot uint64, hash []byte, id uint64) error
- func (b *BlobStoreBark) DeleteTx(txn types.Txn, txHash []byte) error
- func (b *BlobStoreBark) DeleteUtxo(txn types.Txn, txId []byte, outputIdx uint32) error
- func (b *BlobStoreBark) DetectsWriteConflicts() bool
- func (b *BlobStoreBark) DiskSize() (int64, error)
- func (b *BlobStoreBark) Get(txn types.Txn, key []byte) ([]byte, error)
- func (b *BlobStoreBark) GetBlock(txn types.Txn, slot uint64, hash []byte) ([]byte, types.BlockMetadata, error)
- func (b *BlobStoreBark) GetBlockLocal(txn types.Txn, slot uint64, hash []byte) ([]byte, types.BlockMetadata, error)
- func (b *BlobStoreBark) GetBlockURL(ctx context.Context, txn types.Txn, point ocommon.Point) (types.SignedURL, types.BlockMetadata, error)
- func (b *BlobStoreBark) GetCommitTimestamp() (int64, error)
- func (b *BlobStoreBark) GetTx(txn types.Txn, txHash []byte) ([]byte, error)
- func (b *BlobStoreBark) GetUtxo(txn types.Txn, txId []byte, outputIdx uint32) ([]byte, error)
- func (b *BlobStoreBark) NewIterator(txn types.Txn, opts types.BlobIteratorOptions) types.BlobIterator
- func (b *BlobStoreBark) NewTransaction(b2 bool) types.Txn
- func (b *BlobStoreBark) RemainingTxnEntries(txn types.Txn, entryBytes int) (int, bool)
- func (b *BlobStoreBark) Set(txn types.Txn, key, val []byte) error
- func (b *BlobStoreBark) SetBlock(txn types.Txn, slot uint64, hash []byte, cbor []byte, id uint64, ...) error
- func (b *BlobStoreBark) SetCommitTimestamp(i int64, txn types.Txn) error
- func (b *BlobStoreBark) SetTx(txn types.Txn, txHash []byte, offsetData []byte) error
- func (b *BlobStoreBark) SetUtxo(txn types.Txn, txId []byte, outputIdx uint32, cbor []byte) error
- func (b *BlobStoreBark) Sync() error
- func (b *BlobStoreBark) TombstoneBlock(txn types.Txn, slot uint64, hash []byte) error
- type BlobStoreBarkConfig
- type NodeControl
Constants ¶
const ( // DefaultArchiveLookupsPerSecond is the default for // BarkConfig.ArchiveLookupsPerSecond. DefaultArchiveLookupsPerSecond = 200 // DefaultArchiveCallerLookupsPerSecond is the default for // BarkConfig.ArchiveCallerLookupsPerSecond. DefaultArchiveCallerLookupsPerSecond = 50 )
const ( // DefaultMaxRequestBody bounds each incoming Connect message before it is // decoded or authenticated. Connect applies this per-message limit to both // compressed wire bytes and the decompressed message. DefaultMaxRequestBody = 1 << 20 // 1 MiB // DefaultMaxResponseBody bounds each outgoing Connect message without // imposing a whole-stream limit on StreamOperationProgress. DefaultMaxResponseBody = 1 << 20 // 1 MiB // DefaultMaxFetchBlockRefs bounds the storage/signing work and response // growth driven by one anonymous ArchiveService request. DefaultMaxFetchBlockRefs = 100 // DefaultMaxArchiveConcurrentFetches is the default for // BarkConfig.ArchiveMaxConcurrentFetches. DefaultMaxArchiveConcurrentFetches = 16 // DefaultRequestReadTimeout bounds request headers and bodies while leaving // response writes unbounded for long-lived server streams. DefaultRequestReadTimeout = 60 * time.Second )
Variables ¶
var ( // ErrArchiveBlockUndecodable reports an archive response body that does // not decode as a block of the type the archive claimed. ErrArchiveBlockUndecodable = errors.New( "bark: archive block could not be decoded", ) // ErrArchiveBlockHashMismatch reports a decoded block whose computed // hash is not the hash that was requested. ErrArchiveBlockHashMismatch = errors.New( "bark: archive block hash does not match the requested hash", ) // ErrArchiveBlockSlotMismatch reports a decoded block that does not sit // at the slot that was requested. ErrArchiveBlockSlotMismatch = errors.New( "bark: archive block slot does not match the requested slot", ) // ErrArchiveMetadataMismatch reports archive-supplied metadata that // contradicts the contents of the verified block it accompanied. ErrArchiveMetadataMismatch = errors.New( "bark: archive metadata contradicts the block", ) )
Errors reported when an archive response fails local verification. They are distinct from transport failures on purpose: a transport error is worth retrying, whereas these mean the archive served something that is not the block that was asked for, and its answers cannot be trusted as chain data.
var ( // ErrShutdownInProgress is returned by NodeControl.RequestShutdown when a // stop or restart has already been accepted. ErrShutdownInProgress = errors.New( "bark: a stop or restart is already in progress", ) // ErrRestartUnsupported is returned by NodeControl.RequestShutdown for a // restart on a platform that cannot re-execute the process in place. ErrRestartUnsupported = errors.New( "bark: restart is not supported on this platform", ) )
ErrDBUnavailable is returned by Acquire when there is currently no usable database to hand out — either none has been set yet, or a live Restore/Truncate has paused access via PauseDB while it swaps the old one out for a freshly rebuilt one. Handlers should map this to connect.CodeUnavailable rather than surfacing it as an internal error.
Functions ¶
This section is empty.
Types ¶
type Bark ¶
type Bark struct {
// contains filtered or unexported fields
}
func NewBark ¶
func NewBark(cfg BarkConfig) (*Bark, error)
func (*Bark) Acquire ¶ added in v0.69.0
Acquire pins the current database for the duration of one request: callers must use the returned db for every call they make during the request, then call release exactly once (typically via defer) when done with it. Pinning matters because a live Restore/Truncate closes the old database and opens a new one in place — without pinning, a request that fetched the pointer at the top and kept calling methods on it over its lifetime (as GetDatabaseInfo and FetchBlock both do) could end up racing that close, anywhere from a confusing internal error (sqlite queries against a closed *sql.DB) to an outright panic (Badger panics opening a transaction against a closed DB). Acquire's underlying dbGate stays read-locked for exactly as long as release is unheld, so PauseDB's write-lock acquisition — and therefore the actual database close it's guarding — waits for every in-flight Acquire to finish first.
Returns ErrDBUnavailable (with a nil db and release) if no database is currently set, or if PauseDB currently has the gate held: Acquire never blocks waiting for a pause to end, since that could be a long-running Restore/Truncate — callers report unavailable immediately instead.
The config.DB read below deliberately does not take b.mu: Stop holds b.mu for the entire duration of its blocking server.Shutdown call, which waits for in-flight requests — including ones calling Acquire — to finish. If Acquire also needed b.mu here, a request whose handler is exactly what Shutdown is waiting to drain could deadlock against Stop forever. It's safe to skip: dbGate alone is sufficient synchronization for this access, since ResumeDB always finishes writing config.DB (under its own b.mu critical section) before it unlocks dbGate, and Go's mutex happens-before guarantee means that unlock is visible to whichever Acquire's TryRLock above next succeeds — no separate b.mu read needed.
func (*Bark) Addr ¶ added in v0.69.0
Addr returns the address the server is actually listening on (e.g. "127.0.0.1:54321"), populated once Start has bound the listener — most useful when Port was 0, letting a test or an operator discover the OS-assigned port without a separate, racy net.Listen-then-close probe. Returns "" before Start has been called, and again once the server has stopped (Stop, or the listener automatically shutting down when Start's ctx is cancelled) — never a stale address for a listener that is no longer actually open.
func (*Bark) PauseDB ¶ added in v0.69.0
func (b *Bark) PauseDB()
PauseDB blocks new Acquire calls (which fail immediately with ErrDBUnavailable rather than blocking behind it) and waits for every currently in-flight Acquire to release, so the database it currently points at can be safely closed once this returns. Must always be followed by a later ResumeDB call — typically bracketing a live Restore/Truncate's quiesce-close-reinitialize sequence — or Bark's database access is left paused permanently.
func (*Bark) ResumeDB ¶ added in v0.69.0
ResumeDB publishes db as what Acquire hands out going forward, then releases the pause PauseDB put in place. Call this only once the replacement database is fully initialized and ready to serve — e.g. from a live Restore/Truncate's reinitializeAPIServers step — so no Acquire caller ever observes a database that's still mid-setup.
type BarkConfig ¶
type BarkConfig struct {
Logger *slog.Logger
DB *database.Database
Lifecycle *dblifecycle.Service
// Node, if set, mounts the LifecycleService (remote Stop, Restart and
// GetStatus). Like Lifecycle it requires TLS and a client CA. Stop and
// Restart require LifecycleOperatorCertificateFingerprints.
Node NodeControl
// SnapshotDir is the base directory the DatabaseService's CreateSnapshot/
// Restore RPCs write to and read from — required when Lifecycle is set.
// Each snapshot's generated ID is its directory name directly under
// SnapshotDir. DatabaseService maintains a persistent local catalog for
// bounded ListSnapshots pages and rebuilds it from these directories when
// the handler starts.
SnapshotDir string
// SnapshotCloudDestination, if set, is the same cloud destination URI
// as databaseLifecycle.snapshotCloudDestination — passed through here
// so ListAvailableSnapshots can additionally list what's stored there
// (via database/lifecycle.ListCloudSnapshots), merged with the local
// catalog. Empty disables cloud listing; CreateSnapshot's own upload
// path doesn't need this field since it goes through Lifecycle, which
// already has its own copy of the same config value. The URI may contain
// provider credentials or parameters and must not be returned directly;
// SnapshotInfo.location uses a redacted display form.
SnapshotCloudDestination string
// DestinationRegistry supplies the cloud destination schemes (s3, gcs)
// this Bark instance's DatabaseService handler can resolve
// SnapshotCloudDestination/cloud snapshot URIs against — composition
// code owns constructing it; nil is valid when no cloud destination
// is ever configured.
DestinationRegistry *lifecycle.DestinationRegistry
TlsCertFilePath string
TlsKeyFilePath string
// TlsClientCAFilePath is a PEM CA bundle used to verify client
// certificates (mTLS) on this listener. Required whenever Lifecycle is
// set: the DatabaseService's destructive RPCs (CreateSnapshot,
// DeleteSnapshot, VerifySnapshot, Restore, Truncate, CancelOperation)
// refuse any request whose connection didn't present a certificate
// verified against this CA — see newOperatorAuthInterceptor in auth.go.
// ArchiveService remains public, but every DatabaseService RPC requires a
// verified certificate. Destructive DatabaseService RPCs additionally
// require a fingerprint in OperatorCertificateFingerprints. Requires
// TlsCertFilePath/TlsKeyFilePath to also be set, since mTLS has no meaning
// without the server's own TLS listener underneath it. Start (not NewBark)
// fails closed if Lifecycle is set without these policies.
TlsClientCAFilePath string
// OperatorCertificateFingerprints is the explicit authorization policy for
// destructive DatabaseService calls. Values are SHA-256 fingerprints of
// client certificate DER bytes; hexadecimal values may contain colons and
// are matched case-insensitively. Read-only DatabaseService calls require a
// verified client certificate but do not require membership in this list.
OperatorCertificateFingerprints []string
// LifecycleOperatorCertificateFingerprints is the independent
// authorization policy for LifecycleService Stop and Restart. GetStatus
// requires a verified client certificate but not membership in this list.
LifecycleOperatorCertificateFingerprints []string
Host string
// Port is the TCP port to listen on. 0 selects a free port, which Addr
// reports once Start has bound it.
Port uint
// CORSAllowedOrigins configures Access-Control-Allow-Origin.
// Empty disables CORS.
CORSAllowedOrigins []string
// ArchiveMaxConcurrentFetches bounds how many ArchiveService.FetchBlock
// requests run at once; a request over the limit is refused immediately
// rather than queued. ArchiveService takes no client credentials, so this
// and DefaultMaxFetchBlockRefs are what bound the work anyone who can
// reach the listener can cause. Zero selects
// DefaultMaxArchiveConcurrentFetches; a negative value is invalid.
ArchiveMaxConcurrentFetches int
// ArchiveLookupsPerSecond is the sustained rate of block lookups, each
// of which can cost cloud storage requests, that ArchiveService serves
// across all callers combined. A reference by hash or slot costs one
// lookup; one by height alone also pays for the index search it runs
// (see archiveHeightSearchLookups). A FetchBlock whose references do not
// fit the remaining budget is refused whole, so the bucket is never
// smaller than one maximum-size batch of hash or slot references. Zero
// selects DefaultArchiveLookupsPerSecond; a negative value is invalid.
ArchiveLookupsPerSecond int
// ArchiveCallerLookupsPerSecond is the same rate for one caller, keyed
// by IPv4 address or IPv6 /64, so a single client cannot spend the whole
// global budget. Callers behind one proxy share an address and therefore
// an allowance. Zero
// selects DefaultArchiveCallerLookupsPerSecond; a negative value is
// invalid.
ArchiveCallerLookupsPerSecond int
}
type BlobStoreBark ¶
type BlobStoreBark struct {
// contains filtered or unexported fields
}
func NewBarkBlobStore ¶
func NewBarkBlobStore( config BlobStoreBarkConfig, upstream blob.BlobStore, ) (*BlobStoreBark, error)
func (*BlobStoreBark) Close ¶
func (b *BlobStoreBark) Close() error
func (*BlobStoreBark) DeleteBlock ¶
func (*BlobStoreBark) DeleteTx ¶
func (b *BlobStoreBark) DeleteTx(txn types.Txn, txHash []byte) error
func (*BlobStoreBark) DeleteUtxo ¶
func (*BlobStoreBark) DetectsWriteConflicts ¶ added in v0.82.0
func (b *BlobStoreBark) DetectsWriteConflicts() bool
DetectsWriteConflicts forwards the upstream transaction capability.
func (*BlobStoreBark) DiskSize ¶ added in v0.29.0
func (b *BlobStoreBark) DiskSize() (int64, error)
func (*BlobStoreBark) GetBlock ¶
func (b *BlobStoreBark) GetBlock( txn types.Txn, slot uint64, hash []byte, ) ([]byte, types.BlockMetadata, error)
func (*BlobStoreBark) GetBlockLocal ¶ added in v0.70.1
func (b *BlobStoreBark) GetBlockLocal( txn types.Txn, slot uint64, hash []byte, ) ([]byte, types.BlockMetadata, error)
GetBlockLocal bypasses Bark's archive fallback. Nested wrappers are unwrapped through the same optional interface.
func (*BlobStoreBark) GetBlockURL ¶
func (*BlobStoreBark) GetCommitTimestamp ¶
func (b *BlobStoreBark) GetCommitTimestamp() (int64, error)
func (*BlobStoreBark) NewIterator ¶
func (b *BlobStoreBark) NewIterator( txn types.Txn, opts types.BlobIteratorOptions, ) types.BlobIterator
func (*BlobStoreBark) NewTransaction ¶
func (b *BlobStoreBark) NewTransaction(b2 bool) types.Txn
func (*BlobStoreBark) RemainingTxnEntries ¶ added in v0.71.1
RemainingTxnEntries forwards the upstream store's transaction budget. Transactions come from upstream unchanged, so its bound is the one a caller staging a bulk delete has to respect; a wrapper that swallowed the question would leave that caller staging without one.
func (*BlobStoreBark) SetCommitTimestamp ¶
func (b *BlobStoreBark) SetCommitTimestamp(i int64, txn types.Txn) error
func (*BlobStoreBark) Sync ¶ added in v0.69.0
func (b *BlobStoreBark) Sync() error
func (*BlobStoreBark) TombstoneBlock ¶ added in v0.39.1
type BlobStoreBarkConfig ¶
type BlobStoreBarkConfig struct {
BaseUrl string
HTTPClient *http.Client
BlockDownloadAllowedHosts []string
// BlockDownloadAllowPrivateAddresses permits the Bark service and block
// downloads to use private, loopback, and other special-use addresses,
// such as an archive and S3-compatible store on a private network. Origin,
// HTTPS download, redirect, and proxy restrictions still apply. Defaults
// to false.
BlockDownloadAllowPrivateAddresses bool
// MaxBlockSize reports the largest block, in bytes, an archive download may
// carry. It is read on every download, so a limit that follows the live
// protocol parameters stays current. A nil func, or a zero result, selects
// the default cap.
MaxBlockSize func() uint64
// contains filtered or unexported fields
}
type NodeControl ¶ added in v0.81.0
type NodeControl interface {
// RequestShutdown accepts a graceful stop, or a stop followed by
// re-execution when restart is true. A zero timeout selects the node's
// default. It returns the timeout and deadline actually enforced, or
// ErrShutdownInProgress / ErrRestartUnsupported.
RequestShutdown(
restart bool,
timeout time.Duration,
) (time.Duration, time.Time, error)
// LifecycleStatus reports the node's lifecycle state, health, uptime,
// version and chain synchronization state.
LifecycleStatus() *lifecyclev1alpha1.GetStatusResponse
}
NodeControl is the node-side half of LifecycleService: bark owns the transport, authentication and request validation, the node owns the shutdown itself.