Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c ConfigContext) Configuration() Configuration {
// resp, err := paxos.Prepare(cfgCtx, req)
func (c Configuration) Context(parent context.Context) *ConfigContext {
if len(c) == 0 {
panic("gorums: Context called with empty configuration")
panic("gorums: Context called on an empty configuration")
}
return &ConfigContext{Context: parent, cfg: c}
}
Expand All @@ -52,7 +52,7 @@ func (c Configuration) Context(parent context.Context) *ConfigContext {
// )
func NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error) {
if nodes == nil {
return nil, fmt.Errorf("config: missing required node list")
return nil, fmt.Errorf("gorums: missing required node list")
}
mgr := newOutboundManager(opts...)
cfg, err := nodes.newConfig(mgr)
Expand All @@ -66,7 +66,7 @@ func NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error)
// Extend returns a new Configuration combining c with new nodes from the provided NodeListOption.
func (c Configuration) Extend(opt NodeListOption) (Configuration, error) {
if len(c) == 0 {
return nil, fmt.Errorf("config: cannot extend empty configuration")
return nil, fmt.Errorf("gorums: cannot extend empty configuration")
}
if opt == nil {
return slices.Clone(c), nil
Expand Down
12 changes: 6 additions & 6 deletions config_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (nodeMap[T]) isOption() {}

func (nm nodeMap[T]) newConfig(registry nodeRegistry) (Configuration, error) {
if len(nm) == 0 {
return nil, fmt.Errorf("config: missing required node map")
return nil, fmt.Errorf("gorums: missing required node map")
}
builder := newNodeBuilder(registry, len(nm))
// Sort IDs to ensure deterministic processing order
Expand All @@ -66,7 +66,7 @@ func (nodeList) isOption() {}

func (nl nodeList) newConfig(registry nodeRegistry) (Configuration, error) {
if len(nl) == 0 {
return nil, fmt.Errorf("config: missing required node addresses")
return nil, fmt.Errorf("gorums: missing required node addresses")
}
builder := newNodeBuilder(registry, len(nl))
nextID := builder.nextID()
Expand Down Expand Up @@ -113,25 +113,25 @@ func newNodeBuilder(registry nodeRegistry, capacity int) *nodeBuilder {
// add creates or reuses a node with the given ID and address.
func (b *nodeBuilder) add(id uint32, addr string) error {
if id == 0 {
return fmt.Errorf("config: node 0 is reserved")
return fmt.Errorf("gorums: node 0 is reserved")
}
normalizedAddr, err := normalizeAddr(addr)
if err != nil {
return fmt.Errorf("config: invalid address %q: %w", addr, err)
return fmt.Errorf("gorums: invalid address %q: %w", addr, err)
}

// If ID already exists, verify address matches
if existingNode, found := b.idToNode[id]; found {
if existingNode.Address() != normalizedAddr {
return fmt.Errorf("config: node %d already in use by %q", id, existingNode.Address())
return fmt.Errorf("gorums: node %d already in use by %q", id, existingNode.Address())
}
b.nodes = append(b.nodes, existingNode)
return nil
}

// Check for duplicate address
if existingID, exists := b.addrToID[normalizedAddr]; exists {
return fmt.Errorf("config: address %q already in use by node %d", normalizedAddr, existingID)
return fmt.Errorf("gorums: address %q already in use by node %d", normalizedAddr, existingID)
}

b.addrToID[normalizedAddr] = id
Expand Down
22 changes: 11 additions & 11 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,52 @@ func TestNewConfig(t *testing.T) {
{
name: "WithNodeList/Reject/EmptyNodeList",
opt: gorums.WithNodeList([]string{}),
wantErr: "config: missing required node addresses",
wantErr: "gorums: missing required node addresses",
},
{
name: "WithNodes/Reject/EmptyNodeMap",
opt: gorums.WithNodes(map[uint32]testNode{}),
wantErr: "config: missing required node map",
wantErr: "gorums: missing required node map",
},
{
name: "WithNodes/Reject/ZeroID",
opt: gorums.WithNodes(map[uint32]testNode{
0: {addr: "127.0.0.1:9080"}, // ID 0 should be rejected
1: {addr: "127.0.0.1:9081"},
}),
wantErr: "config: node 0 is reserved",
wantErr: "gorums: node 0 is reserved",
},
{
name: "WithNodes/Reject/DuplicateAddress",
opt: gorums.WithNodes(map[uint32]testNode{
1: {addr: "127.0.0.1:9081"},
2: {addr: "127.0.0.1:9081"}, // Duplicate address
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
{
name: "WithNodeList/Reject/DuplicateAddress",
opt: gorums.WithNodeList([]string{
"127.0.0.1:9081",
"127.0.0.1:9081", // Duplicate address
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
{
name: "WithNodes/Reject/NormalizedDuplicateAddress",
opt: gorums.WithNodes(map[uint32]testNode{
1: {addr: "localhost:9081"},
2: {addr: "127.0.0.1:9081"}, // Same resolved address
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
{
name: "WithNodeList/Reject/NormalizedDuplicateAddress",
opt: gorums.WithNodeList([]string{
"localhost:9081",
"127.0.0.1:9081", // Same resolved address
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -155,31 +155,31 @@ func TestConfigurationExtend(t *testing.T) {
extendOpt: gorums.WithNodes(map[uint32]testNode{
0: {addr: "127.0.0.1:9090"}, // ID 0 should be rejected
}),
wantErr: "config: node 0 is reserved",
wantErr: "gorums: node 0 is reserved",
},
{
name: "WithNodes/Reject/IDConflict",
initialNodes: nodes12,
extendOpt: gorums.WithNodes(map[uint32]testNode{
2: {addr: "127.0.0.1:9090"}, // ID 2 already exists, rejected
}),
wantErr: `config: node 2 already in use by "127.0.0.1:9082"`,
wantErr: `gorums: node 2 already in use by "127.0.0.1:9082"`,
},
{
name: "WithNodes/Reject/AddressConflict",
initialNodes: nodes12,
extendOpt: gorums.WithNodes(map[uint32]testNode{
3: {addr: "127.0.0.1:9081"}, // Same address as ID 1
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
{
name: "WithNodes/Reject/NormalizedAddressConflict",
initialNodes: nodes12,
extendOpt: gorums.WithNodes(map[uint32]testNode{
3: {addr: "localhost:9081"}, // Resolves to same as existing node 1
}),
wantErr: `config: address "127.0.0.1:9081" already in use by node 1`,
wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`,
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion correctable.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *Correctable[Resp]) update(reply Resp, level int, done bool, err error)
c.mu.Lock()
defer c.mu.Unlock()
if c.done {
panic("update(...) called on a done correctable")
panic("gorums: update(...) called on a completed correctable")
}
c.reply, c.level, c.err, c.done = reply, level, err, done
if done {
Expand Down
4 changes: 2 additions & 2 deletions doc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ Without `Release()`, the server would block all other inbound messages until the
func (s *storageServer) ReadNestedQC(ctx gorums.ServerCtx, req *pb.ReadRequest) (*pb.ReadResponse, error) {
config := ctx.Config()
if len(config) == 0 {
return nil, fmt.Errorf("ReadNestedQC requires a server peer configuration")
return nil, fmt.Errorf("read_nested_qc: requires a server peer configuration")
}
// Release the handler lock before making nested outbound calls to avoid
// blocking inbound message processing on this server.
Expand Down Expand Up @@ -1520,7 +1520,7 @@ The handler reads `ctx.ClientConfig()` to reach all currently connected client p
func (s *storageServer) ReadNestedQC(ctx gorums.ServerCtx, req *pb.ReadRequest) (*pb.ReadResponse, error) {
config := ctx.ClientConfig()
if len(config) == 0 {
return nil, fmt.Errorf("ReadNestedQC: no client peers connected")
return nil, fmt.Errorf("read_nested_qc: no client peers connected")
}
ctx.Release()
return newestValue(pb.ReadQC(config.Context(ctx), req))
Expand Down
4 changes: 2 additions & 2 deletions inbound_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gorums
import (
"cmp"
"context"
"errors"
"fmt"
"maps"
"slices"
"sync"
Expand Down Expand Up @@ -263,7 +263,7 @@ func (im *inboundManager) acceptClient(streamCtx context.Context, inboundStream
im.mu.Lock()
defer im.mu.Unlock()
if im.nextClientID == ^uint32(0) {
return nil, func() {}, errors.New("gorums: dynamic client ID space exhausted")
return nil, func() {}, fmt.Errorf("gorums: dynamic client ID space exhausted")
}
id := im.nextClientID
im.nextClientID++
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (c *Channel) isConnected() bool {
// Combining them would cause double delivery on the response channel.
func (c *Channel) Enqueue(req Request) {
if req.WaitSendDone && req.Streaming {
panic("stream: WaitSendDone and Streaming are mutually exclusive")
panic("gorums: WaitSendDone and Streaming are mutually exclusive")
}
if c.isLocal() {
c.router.DispatchLocalRequest(c.id, req)
Expand Down
2 changes: 1 addition & 1 deletion mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (m *outboundManager) addNode(node *Node) {

func (m *outboundManager) newNode(id uint32, addr string) (*Node, error) {
if _, found := m.Node(id); found {
return nil, fmt.Errorf("node %d already exists", id)
return nil, fmt.Errorf("gorums: node %d already exists", id)
}
// Use a local (in-process) node when this ID is our own local node
// and a handler is configured (symmetric peer configuration).
Expand Down
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Node struct {
// resp, err := service.GRPCCall(nodeCtx, req)
func (n *Node) Context(parent context.Context) *NodeContext {
if n == nil {
panic("gorums: Context called with nil node")
panic("gorums: Context called on nil node")
}
return &NodeContext{Context: parent, node: n}
}
Expand Down
26 changes: 13 additions & 13 deletions opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ import (
// a panic when the caller invokes the nil function.
func TestSplitOptionsTypedNil(t *testing.T) {
tests := []struct {
name string
opts []Option
wantSrvLen int
name string
opts []Option
wantSrvLen int
wantDialLen int
}{
{
name: "UntypedNil",
opts: []Option{nil},
wantSrvLen: 0,
name: "UntypedNil",
opts: []Option{nil},
wantSrvLen: 0,
wantDialLen: 0,
},
{
name: "NilDialOption",
opts: []Option{DialOption(nil)},
wantSrvLen: 0,
name: "NilDialOption",
opts: []Option{DialOption(nil)},
wantSrvLen: 0,
wantDialLen: 0,
},
{
name: "NilServerOption",
opts: []Option{ServerOption(nil)},
wantSrvLen: 0,
name: "NilServerOption",
opts: []Option{ServerOption(nil)},
wantSrvLen: 0,
wantDialLen: 0,
},
{
Expand All @@ -44,7 +44,7 @@ func TestSplitOptionsTypedNil(t *testing.T) {
ServerOption(nil),
WithReceiveBufferSize(0),
},
wantSrvLen: 1,
wantSrvLen: 1,
wantDialLen: 1,
},
}
Expand Down
4 changes: 2 additions & 2 deletions testopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (to *testOptions) serverFunc(srvFn func(i int) ServerIface) func(i int) Ser
}
if len(to.serverOpts) > 0 {
// You need to pass nil as the server function to use server options with the default server
panic("gorums: cannot use server options with a custom server function; use nil to use the default test server")
panic("gorums: cannot use server options with a custom server function")
}
return srvFn
}
Expand Down Expand Up @@ -107,7 +107,7 @@ type stopFuncProvider struct {
// This option is intended for testing purposes only.
func WithStopFunc(_ testing.TB, fn *func(...int)) TestOption {
if fn == nil {
panic("gorums: WithStopFunc called with nil pointer")
panic("gorums: WithStopFunc called with nil function pointer")
}
return stopFuncProvider{stopFunc: fn}
}
Expand Down
Loading