ringtest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ringtest holds CGo test helpers for the ring object.

They drive the C ring writer, hold extra references and link module configs to rings. Their C code is built by meson with the ring object archive's cache line size. Only tests import this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinkRing

func LinkRing(moduleConfigPtr unsafe.Pointer, name string) error

LinkRing links a module config, given as a raw pointer, to the named ring object.

It calls the C module link function directly.

func StressRecordValid

func StressRecordValid(seqno uint32, payload []byte) bool

StressRecordValid reports whether a payload is exactly the one the stress writer wrote for the given sequence number.

Types

type Reference

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

Reference is an extra reference to a published ring.

It plays the role of a live generation that has not retired yet.

func Hold

func Hold(agent *ffi.Agent, name string) (*Reference, error)

Hold adds an extra reference to the named ring in the agent's published generation.

Until Release, every attempt to free the ring fails.

func (*Reference) Release

func (m *Reference) Release()

Release drops the extra reference.

Later calls do nothing.

type Stress

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

Stress runs the C writer at full speed on its own OS thread.

The writer publishes by the ring's publish batch. Each record's length and bytes come from its sequence number, so a reader can detect a torn record.

func (*Stress) Done

func (m *Stress) Done() bool

Done reports whether the writer thread has finished.

func (*Stress) Wait

func (m *Stress) Wait()

Wait joins the writer thread and releases its state.

func (*Stress) Written

func (m *Stress) Written() uint64

Written returns the number of records the writer committed.

The value is final only after the writer has finished.

type Writer

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

Writer runs the C writer functions on one worker's ring.

It finds the ring through a raw object pointer.

func NewPublishedWriter

func NewPublishedWriter(agent *ffi.Agent, name string, workerIdx uint16) (*Writer, error)

NewPublishedWriter returns a Writer for one worker of the ring published under the given name.

It finds the ring the way the service that owns it publishes it.

func NewWriter

func NewWriter(objPtr unsafe.Pointer, workerIdx uint16) (*Writer, error)

NewWriter returns a Writer for one worker of a ring object, given as a raw pointer.

func (*Writer) CommitRecord

func (m *Writer) CommitRecord(payload []byte) (uint32, error)

CommitRecord adds one record to the unpublished batch and returns its sequence number.

Readers see the record after the next Publish. The ring may also publish the batch on its own: when this record fills the publish batch, or when the batch would grow too large. When the record does not fit the ring, CommitRecord returns an error and writes nothing, like the C writer.

func (*Writer) CorruptTotalLen

func (m *Writer) CorruptTotalLen(logicalOffset uint64, totalLen uint32)

CorruptTotalLen overwrites the length in the frame at a logical offset.

A test uses it to get a corrupt frame without a real race with the writer.

func (*Writer) Object

func (m *Writer) Object() unsafe.Pointer

Object returns the raw ring object pointer this writer uses.

func (*Writer) Publish

func (m *Writer) Publish()

Publish makes every record committed since the last publication visible to readers.

func (*Writer) SetIndices

func (m *Writer) SetIndices(write, readable uint64)

SetIndices sets the write and readable positions.

It sets both the writer's own copies and the published ones. A test uses it to start near the physical end or with a backlog, without writing records to get there.

func (*Writer) Source

func (m *Writer) Source() (cring.RecordSource, error)

Source returns the production record source of this writer's worker.

So a test reads records the same way a real reader does.

func (*Writer) StartStress

func (m *Writer) StartStress(records uint64) (*Stress, error)

StartStress starts writing the given number of records to the writer's worker ring.

The ring publishes them by its own publish batch. The writer stops early if the ring refuses a record.

func (*Writer) WriteRecord

func (m *Writer) WriteRecord(payload []byte) (uint32, error)

WriteRecord commits one record and publishes it.

It returns the sequence number stamped on the record. When the record does not fit the ring, it returns an error and writes nothing, like the C writer.

Jump to

Keyboard shortcuts

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