Documentation
¶
Overview ¶
Package nativewire implements TreeDB's native client/server wire transport.
Index ¶
- Variables
- func AdmitClusterMutation(ctx context.Context, submitter ClusterSubmitter) error
- func IsCatalogVersionMismatch(err error) bool
- func WithExpectedCatalogVersion(ctx context.Context, version uint64) context.Context
- func WithIdempotencyKey(ctx context.Context, key []byte) context.Context
- type AckPolicy
- type AppliedIndexReadBarrierProvider
- type AppliedIndexReadCoordinator
- type CatalogClusterRouteProvider
- type Client
- func (c *Client) Checkpoint(ctx context.Context) error
- func (c *Client) CheckpointWithAck(ctx context.Context, ack AckPolicy) error
- func (c *Client) Close() error
- func (c *Client) CloseCollection(ctx context.Context, handle CollectionHandle) error
- func (c *Client) CreateCollection(ctx context.Context, meta collections.CollectionMeta) (collections.CollectionMeta, error)
- func (c *Client) CreateIndex(ctx context.Context, collection string, def collections.IndexDefinition) (collections.CollectionMeta, error)
- func (c *Client) CurrentCatalogVersion(ctx context.Context) (uint64, error)
- func (c *Client) CursorClose(ctx context.Context, cursorID uint64) error
- func (c *Client) CursorNext(ctx context.Context, cursorID uint64, limits CursorLimits) (DocumentsResult, error)
- func (c *Client) CursorNextWithOptions(ctx context.Context, cursorID uint64, limits CursorLimits, opts ReadOptions) (DocumentsResult, error)
- func (c *Client) DeleteBatch(ctx context.Context, collection string, ids [][]byte, ack AckPolicy) (int, error)
- func (c *Client) DropIndex(ctx context.Context, collection, index string) (collections.CollectionMeta, error)
- func (c *Client) FlushAll(ctx context.Context) error
- func (c *Client) FlushAllWithAck(ctx context.Context, ack AckPolicy) error
- func (c *Client) FlushCollection(ctx context.Context, collection string) error
- func (c *Client) FlushCollectionWithAck(ctx context.Context, collection string, ack AckPolicy) error
- func (c *Client) GetMany(ctx context.Context, collection string, ids [][]byte) ([][]byte, []bool, error)
- func (c *Client) GetManyHandle(ctx context.Context, handle CollectionHandle, ids [][]byte) ([][]byte, []bool, error)
- func (c *Client) GetManyHandleWithOptions(ctx context.Context, handle CollectionHandle, ids [][]byte, opts ReadOptions) (DocumentsResult, error)
- func (c *Client) GetManyWithOptions(ctx context.Context, collection string, ids [][]byte, opts ReadOptions) (DocumentsResult, error)
- func (c *Client) Goaway(ctx context.Context) error
- func (c *Client) Hello(ctx context.Context) error
- func (c *Client) IndexLookup(ctx context.Context, collection, index string, value any, limits CursorLimits) ([][]byte, bool, error)
- func (c *Client) IndexLookupWithOptions(ctx context.Context, collection, index string, value any, limits CursorLimits, ...) (IDResult, error)
- func (c *Client) IndexRange(ctx context.Context, collection, index string, opts IndexRange) ([][]byte, bool, error)
- func (c *Client) IndexRangeWithOptions(ctx context.Context, collection, index string, opts IndexRange, ...) (IDResult, error)
- func (c *Client) InsertBatch(ctx context.Context, collection string, format collections.DocumentFormat, ...) ([][]byte, error)
- func (c *Client) InsertBatchHandle(ctx context.Context, handle CollectionHandle, ...) ([][]byte, error)
- func (c *Client) InsertBatchHandleNoResult(ctx context.Context, handle CollectionHandle, ...) error
- func (c *Client) InsertBatchNoResult(ctx context.Context, collection string, format collections.DocumentFormat, ...) error
- func (c *Client) ListCollections(ctx context.Context) ([]collections.CollectionMeta, error)
- func (c *Client) ListIndexes(ctx context.Context, collection string) ([]collections.IndexDefinition, error)
- func (c *Client) OpenCollection(ctx context.Context, name string) (CollectionHandle, error)
- func (c *Client) OpenScan(ctx context.Context, collection string, limits CursorLimits) (DocumentsResult, error)
- func (c *Client) OpenScanWithOptions(ctx context.Context, collection string, limits CursorLimits, opts ReadOptions) (DocumentsResult, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) ReplaceBatch(ctx context.Context, collection string, format collections.DocumentFormat, ...) (matched, modified int, err error)
- func (c *Client) Stats(ctx context.Context) (map[string]string, error)
- func (c *Client) UpdateBSONSet(ctx context.Context, collection string, id []byte, ...) (matched, modified int, err error)
- func (c *Client) UpdateBSONSetHandle(ctx context.Context, handle CollectionHandle, id []byte, ...) (matched, modified int, err error)
- type ClusterAdmissionProvider
- type ClusterAdmissionStatus
- type ClusterReadCoordinator
- type ClusterReadRequest
- type ClusterReadResult
- type ClusterRequestMetadata
- type ClusterRouteProvider
- type ClusterRouteRequest
- type ClusterRouteShape
- type ClusterRouteTarget
- type ClusterSubmitResult
- type ClusterSubmitter
- type CollectionHandle
- type ConsistencyPolicy
- type CursorLimits
- type CursorMeta
- type DocumentsResult
- type IDResult
- type IndexRange
- type RaftClusterSubmitter
- type ReadMetadata
- type ReadOptions
- type RoutedRaftClusterSubmitter
- type Scalar
- type Server
- type ServerOptions
- type Stats
- type WireError
Constants ¶
This section is empty.
Variables ¶
var ErrNilListener = fmt.Errorf("nativewire: nil listener: %w", net.ErrClosed)
ErrNilListener is returned when Serve is called with a nil listener. It wraps net.ErrClosed so callers that classify listener shutdown keep working.
var ErrServerClosed = errors.New("nativewire: server is closed")
ErrServerClosed reports that the server is closed or refusing connections.
Functions ¶
func AdmitClusterMutation ¶
func AdmitClusterMutation(ctx context.Context, submitter ClusterSubmitter) error
AdmitClusterMutation fails closed unless submitter is configured and, when it exposes admission state, the node is currently the leader.
func IsCatalogVersionMismatch ¶
IsCatalogVersionMismatch reports whether err is a remote catalog-version guard failure.
func WithExpectedCatalogVersion ¶
WithExpectedCatalogVersion attaches the catalog version guard to replicated mutations issued with ctx. When unset, the client reads or reuses the current version immediately before sending the mutation.
func WithIdempotencyKey ¶
WithIdempotencyKey attaches a caller-controlled idempotency key to replicated mutations issued with ctx. This lets callers retry the same logical mutation without the client generating a different key on each attempt.
Types ¶
type AckPolicy ¶
const ( AckVisible AckPolicy = iwire.AckVisible AckFlushed AckPolicy = iwire.AckFlushed AckSynced AckPolicy = iwire.AckSynced AckRaftCommitted AckPolicy = iwire.AckRaftCommitted )
type AppliedIndexReadBarrierProvider ¶
type AppliedIndexReadBarrierProvider interface {
LeaderReadBarrier(context.Context, ClusterReadRequest) (raftcluster.AppliedIndexReadBarrier, error)
}
AppliedIndexReadBarrierProvider supplies the applied-index target a leader_read must prove before nativewire serves local state.
type AppliedIndexReadCoordinator ¶
type AppliedIndexReadCoordinator struct {
BarrierProvider AppliedIndexReadBarrierProvider
Waiter raftcluster.AppliedIndexReadBarrierWaiter
ReadIndexTarget raftcluster.ReadIndexBarrier
ReadIndexProvider raftcluster.ReadIndexProvider
}
AppliedIndexReadCoordinator bridges nativewire leader_read requests to the raftcluster applied-index read barrier foundation. Linearizable reads require a configured read-index provider with production evidence and then wait for local apply through the proven read index. Lease reads remain unsupported until a lease proof exists.
func (AppliedIndexReadCoordinator) CoordinateRead ¶
func (c AppliedIndexReadCoordinator) CoordinateRead(ctx context.Context, request ClusterReadRequest) (ClusterReadResult, error)
type CatalogClusterRouteProvider ¶
type CatalogClusterRouteProvider struct {
// contains filtered or unexported fields
}
CatalogClusterRouteProvider adapts a validated raftplacement catalog to the nativewire route-preflight interface. It only returns catalog-derived metadata; it does not prove live leadership or submit routed commands.
func NewCatalogClusterRouteProvider ¶
func NewCatalogClusterRouteProvider(catalog raftplacement.ResolvedCatalogV1) CatalogClusterRouteProvider
NewCatalogClusterRouteProvider returns a route provider backed by a validated raftplacement catalog.
func (CatalogClusterRouteProvider) ClusterRoute ¶
func (p CatalogClusterRouteProvider) ClusterRoute(_ context.Context, request ClusterRouteRequest) (ClusterRouteTarget, error)
ClusterRoute resolves the request against the provider's catalog. Collection placements can satisfy collection, single-token, and token-batch requests with a collection target. Token/ring placements require a single token for submit targets; multi-token batches return classification metadata so preflight can fail closed before submit until split/fanout execution exists.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client serializes requests on one native-wire connection.
Byte slices returned by result APIs are immutable views into the client's response buffer. They remain valid until the next round trip on the same client; callers that need to keep them longer must copy them.
func NewInProcessClient ¶
func (*Client) CheckpointWithAck ¶
func (*Client) CloseCollection ¶
func (c *Client) CloseCollection(ctx context.Context, handle CollectionHandle) error
func (*Client) CreateCollection ¶
func (c *Client) CreateCollection(ctx context.Context, meta collections.CollectionMeta) (collections.CollectionMeta, error)
func (*Client) CreateIndex ¶
func (c *Client) CreateIndex(ctx context.Context, collection string, def collections.IndexDefinition) (collections.CollectionMeta, error)
func (*Client) CurrentCatalogVersion ¶
CurrentCatalogVersion returns the server-advertised catalog/schema version used by guarded replicated mutations.
func (*Client) CursorClose ¶
func (*Client) CursorNext ¶
func (c *Client) CursorNext(ctx context.Context, cursorID uint64, limits CursorLimits) (DocumentsResult, error)
CursorNext fetches the next cursor batch. Returned ID and document slices borrow the client's response buffer and remain valid until the next round trip.
func (*Client) CursorNextWithOptions ¶
func (c *Client) CursorNextWithOptions(ctx context.Context, cursorID uint64, limits CursorLimits, opts ReadOptions) (DocumentsResult, error)
func (*Client) DeleteBatch ¶
func (*Client) DropIndex ¶
func (c *Client) DropIndex(ctx context.Context, collection, index string) (collections.CollectionMeta, error)
func (*Client) FlushAllWithAck ¶
func (*Client) FlushCollection ¶
func (*Client) FlushCollectionWithAck ¶
func (*Client) GetMany ¶
func (c *Client) GetMany(ctx context.Context, collection string, ids [][]byte) ([][]byte, []bool, error)
GetMany fetches documents by ID. Returned document slices borrow the client's response buffer and remain valid until the next round trip on this client.
func (*Client) GetManyHandle ¶
func (c *Client) GetManyHandle(ctx context.Context, handle CollectionHandle, ids [][]byte) ([][]byte, []bool, error)
GetManyHandle fetches documents by ID through an open collection handle. Returned document slices borrow the client's response buffer and remain valid until the next round trip on this client.
func (*Client) GetManyHandleWithOptions ¶
func (c *Client) GetManyHandleWithOptions(ctx context.Context, handle CollectionHandle, ids [][]byte, opts ReadOptions) (DocumentsResult, error)
func (*Client) GetManyWithOptions ¶
func (c *Client) GetManyWithOptions(ctx context.Context, collection string, ids [][]byte, opts ReadOptions) (DocumentsResult, error)
func (*Client) IndexLookup ¶
func (c *Client) IndexLookup(ctx context.Context, collection, index string, value any, limits CursorLimits) ([][]byte, bool, error)
IndexLookup returns IDs matching an index value. Returned ID slices borrow the client's response buffer and remain valid until the next round trip.
func (*Client) IndexLookupWithOptions ¶
func (c *Client) IndexLookupWithOptions(ctx context.Context, collection, index string, value any, limits CursorLimits, opts ReadOptions) (IDResult, error)
func (*Client) IndexRange ¶
func (c *Client) IndexRange(ctx context.Context, collection, index string, opts IndexRange) ([][]byte, bool, error)
IndexRange returns IDs within an index range. Returned ID slices borrow the client's response buffer and remain valid until the next round trip.
func (*Client) IndexRangeWithOptions ¶
func (c *Client) IndexRangeWithOptions(ctx context.Context, collection, index string, opts IndexRange, readOpts ReadOptions) (IDResult, error)
func (*Client) InsertBatch ¶
func (c *Client) InsertBatch(ctx context.Context, collection string, format collections.DocumentFormat, ids, docs [][]byte, ack AckPolicy) ([][]byte, error)
func (*Client) InsertBatchHandle ¶
func (c *Client) InsertBatchHandle(ctx context.Context, handle CollectionHandle, format collections.DocumentFormat, ids, docs [][]byte, ack AckPolicy) ([][]byte, error)
func (*Client) InsertBatchHandleNoResult ¶
func (c *Client) InsertBatchHandleNoResult(ctx context.Context, handle CollectionHandle, format collections.DocumentFormat, ids, docs [][]byte, ack AckPolicy) error
func (*Client) InsertBatchNoResult ¶
func (c *Client) InsertBatchNoResult(ctx context.Context, collection string, format collections.DocumentFormat, ids, docs [][]byte, ack AckPolicy) error
func (*Client) ListCollections ¶
func (c *Client) ListCollections(ctx context.Context) ([]collections.CollectionMeta, error)
func (*Client) ListIndexes ¶
func (c *Client) ListIndexes(ctx context.Context, collection string) ([]collections.IndexDefinition, error)
func (*Client) OpenCollection ¶
func (*Client) OpenScan ¶
func (c *Client) OpenScan(ctx context.Context, collection string, limits CursorLimits) (DocumentsResult, error)
OpenScan starts a collection scan. Returned ID and document slices borrow the client's response buffer and remain valid until the next round trip.
func (*Client) OpenScanWithOptions ¶
func (c *Client) OpenScanWithOptions(ctx context.Context, collection string, limits CursorLimits, opts ReadOptions) (DocumentsResult, error)
func (*Client) ReplaceBatch ¶
func (c *Client) ReplaceBatch(ctx context.Context, collection string, format collections.DocumentFormat, ids, docs [][]byte, ack AckPolicy) (matched, modified int, err error)
func (*Client) UpdateBSONSet ¶
func (c *Client) UpdateBSONSet(ctx context.Context, collection string, id []byte, fields []collections.BSONSetField, ack AckPolicy) (matched, modified int, err error)
func (*Client) UpdateBSONSetHandle ¶
func (c *Client) UpdateBSONSetHandle(ctx context.Context, handle CollectionHandle, id []byte, fields []collections.BSONSetField, ack AckPolicy) (matched, modified int, err error)
type ClusterAdmissionProvider ¶
type ClusterAdmissionProvider interface {
ClusterAdmissionStatus(ctx context.Context) (ClusterAdmissionStatus, error)
}
ClusterAdmissionProvider exposes the node write-admission state backing a ClusterSubmitter. A configured cluster submitter that does not implement this interface fails closed as admission-unavailable.
type ClusterAdmissionStatus ¶
ClusterAdmissionStatus describes whether this node may accept cluster-owned writes. A provider must set Leader for write admission; the zero value fails closed as not-leader when returned by a configured provider.
func ClusterFollowerAdmission ¶
func ClusterFollowerAdmission(leaderHint, reason string) ClusterAdmissionStatus
ClusterFollowerAdmission returns a fail-closed not-leader status. leaderHint is optional and may carry a redirect target for callers that can use one.
func ClusterLeaderAdmission ¶
func ClusterLeaderAdmission() ClusterAdmissionStatus
ClusterLeaderAdmission returns an admitted leader status.
func ClusterUnavailableAdmission ¶
func ClusterUnavailableAdmission(reason string) ClusterAdmissionStatus
ClusterUnavailableAdmission returns a fail-closed cluster-unavailable status.
type ClusterReadCoordinator ¶
type ClusterReadCoordinator interface {
CoordinateRead(ctx context.Context, request ClusterReadRequest) (ClusterReadResult, error)
}
ClusterReadCoordinator proves cluster read barriers for native-wire reads. Implementations must fail closed: returning a strong ActualConsistency is the proof that the requested barrier was satisfied before the server reads local state.
type ClusterReadRequest ¶
type ClusterReadResult ¶
type ClusterReadResult struct {
ActualConsistency ConsistencyPolicy
ServingNode string
LeaderNode string
AppliedIndex uint64
HasAppliedIndex bool
}
type ClusterRequestMetadata ¶
type ClusterRequestMetadata = raftentry.RequestMetadataV1
ClusterRequestMetadata carries request-scoped fields that influence response policy but are intentionally excluded from deterministic command entry bytes.
type ClusterRouteProvider ¶
type ClusterRouteProvider interface {
ClusterRoute(ctx context.Context, request ClusterRouteRequest) (ClusterRouteTarget, error)
}
ClusterRouteProvider is an optional ClusterSubmitter extension for collection-level route preflight. Providers should use catalog-derived route decisions only; leader hints are metadata and are not live leadership proof.
type ClusterRouteRequest ¶
type ClusterRouteShape ¶
type ClusterRouteShape string
const ( ClusterRouteShapeCollection ClusterRouteShape = "collection" ClusterRouteShapeToken ClusterRouteShape = "token" ClusterRouteShapeTokenBatch ClusterRouteShape = "token_batch" )
type ClusterRouteTarget ¶
type ClusterRouteTarget struct {
GroupID string
Members []string
LeaderHint string
PlacementMode string
Reason string
Shape ClusterRouteShape
TokenKnown bool
Token uint64
PartitionID string
TokenBatchClass string
}
func PreflightClusterRoute ¶
func PreflightClusterRoute(ctx context.Context, submitter ClusterSubmitter, request ClusterRouteRequest) (ClusterRouteTarget, bool, error)
PreflightClusterRoute checks the optional cluster route provider. A missing provider preserves existing submitter behavior; a configured provider must return a supported route target with a group ID. Token/ring targets require an exactly-one-ID token route request; multi-ID token batches are classified only so adapters can fail closed until split/fanout execution exists.
type ClusterSubmitResult ¶
type ClusterSubmitResult struct {
ActualAck AckPolicy
CommittedRecoverable bool
ResponseSections []iwire.Section
// CatalogVersion is internal post-apply evidence. It lets response shaping
// omit response_meta without hiding catalog-cache progress from the server.
CatalogVersion uint64
HasCatalogVersion bool
}
ClusterSubmitResult is the submitter-owned response for an admitted command. CommittedRecoverable must only be true when AckRaftCommitted reflects a real consensus commit plus the serving node's selected local recoverability gate.
type ClusterSubmitter ¶
type ClusterSubmitter interface {
SubmitCommandEntryV1(ctx context.Context, entry []byte, metadata ClusterRequestMetadata) (ClusterSubmitResult, error)
}
ClusterSubmitter accepts deterministic native-wire CommandEntryV1 bytes for cluster-owned mutation admission. Submitters must copy entry bytes or response sections before retaining them after SubmitCommandEntryV1 returns.
type CollectionHandle ¶
type CollectionHandle uint64
type ConsistencyPolicy ¶
type ConsistencyPolicy = iwire.ConsistencyPolicy
const ( ConsistencyLocalStale ConsistencyPolicy = iwire.ConsistencyLocalStale ConsistencyLeaderRead ConsistencyPolicy = iwire.ConsistencyLeaderRead ConsistencyLinearizable ConsistencyPolicy = iwire.ConsistencyLinearizable ConsistencyLeaseRead ConsistencyPolicy = iwire.ConsistencyLeaseRead )
type CursorLimits ¶
type DocumentsResult ¶
type DocumentsResult struct {
IDs [][]byte
Docs [][]byte
Present []bool
Cursor CursorMeta
Truncated bool
ReadMeta ReadMetadata
}
DocumentsResult is a batched read result. ID and document slices returned by client APIs borrow the client's response buffer unless documented otherwise.
type IDResult ¶
type IDResult struct {
IDs [][]byte
Truncated bool
ReadMeta ReadMetadata
}
type IndexRange ¶
type RaftClusterSubmitter ¶
type RaftClusterSubmitter struct {
Bridge *raftcluster.SingleGroupSubmitter
Collections *collections.CollectionManager
}
RaftClusterSubmitter adapts the internal single-group raftcluster bridge to the public nativewire ClusterSubmitter contract.
func NewRaftClusterSubmitter ¶
func NewRaftClusterSubmitter(bridge *raftcluster.SingleGroupSubmitter, managers ...*collections.CollectionManager) *RaftClusterSubmitter
func (*RaftClusterSubmitter) ClusterAdmissionStatus ¶
func (s *RaftClusterSubmitter) ClusterAdmissionStatus(ctx context.Context) (ClusterAdmissionStatus, error)
func (*RaftClusterSubmitter) SubmitCommandEntryV1 ¶
func (s *RaftClusterSubmitter) SubmitCommandEntryV1(ctx context.Context, entry []byte, metadata ClusterRequestMetadata) (ClusterSubmitResult, error)
type ReadMetadata ¶
type ReadMetadata struct {
Valid bool
ActualConsistency ConsistencyPolicy
ServingNode string
LeaderNode string
AppliedIndex uint64
HasAppliedIndex bool
}
ReadMetadata is returned from native read responses when the server can label the read contract it actually served.
type ReadOptions ¶
type ReadOptions struct {
ConsistencyPolicy ConsistencyPolicy
}
ReadOptions carries native read policy controls. The zero value preserves the protocol default: serve locally and label the result local-stale.
type RoutedRaftClusterSubmitter ¶
type RoutedRaftClusterSubmitter struct {
*RaftClusterSubmitter
RouteProvider ClusterRouteProvider
}
RoutedRaftClusterSubmitter composes the concrete single-group Raft bridge with a catalog-backed route provider. The base RaftClusterSubmitter does not implement ClusterRouteProvider so existing no-provider behavior stays unchanged.
func NewRoutedRaftClusterSubmitter ¶
func NewRoutedRaftClusterSubmitter(bridge *raftcluster.SingleGroupSubmitter, provider ClusterRouteProvider, managers ...*collections.CollectionManager) *RoutedRaftClusterSubmitter
func (*RoutedRaftClusterSubmitter) ClusterRoute ¶
func (s *RoutedRaftClusterSubmitter) ClusterRoute(ctx context.Context, request ClusterRouteRequest) (ClusterRouteTarget, error)
type Scalar ¶
type Scalar struct {
Type collections.IndexValueType
Value any
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves native-wire control and command frames for TreeDB.
func NewServer ¶
func NewServer(opts ServerOptions) *Server
NewServer creates a native-wire server with defaulted limits and policies.
type ServerOptions ¶
type ServerOptions struct {
Limits iwire.Limits
MaxInFlight int
MaxConnections int
MaxCollectionHandles int
MaxCachedCollections int
MaxOpenCursors int
MaxCursorRetainedBytes int
MaxScanDocuments int
DefaultCursorBatchSize int
CursorIdleTimeout time.Duration
DefaultAckPolicy iwire.AckPolicy
MaxMetadataIdempotencyEntries int
InsertBatchCombineMaxBatch int
InsertBatchCombineDrainYields int
Collections *collections.CollectionManager
Backend *backenddb.DB
ClusterSubmitter ClusterSubmitter
ClusterReadCoordinator ClusterReadCoordinator
}
ServerOptions configures a native-wire server.
Source Files
¶
- client.go
- client_metadata.go
- client_mutation.go
- client_read.go
- cluster_raft_submitter.go
- cluster_read.go
- cluster_read_barrier.go
- cluster_route_provider.go
- cluster_submitter.go
- codec.go
- doc.go
- errors.go
- listener.go
- metadata.go
- mutation.go
- read.go
- server.go
- server_insert_combiner.go
- server_metadata.go
- server_mutation.go
- server_read.go
- stats.go