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
39 changes: 7 additions & 32 deletions benchmark/benchmark_gorums.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions cmd/benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,9 @@ func main() {
),
gorums.WithSendBufferSize(*sendBuffer),
}

mgr := benchmark.NewManager(dialOpts...)
defer mgr.Close()

cfg, err := benchmark.NewConfiguration(mgr, gorums.WithNodeList(remotes[:options.NumNodes]))
cfg, err := benchmark.NewConfig(gorums.WithNodeList(remotes[:options.NumNodes]), dialOpts...)
checkf("Failed to create configuration: %v", err)
defer cfg.Close()

results, err := benchmark.RunBenchmarks(benchReg, options, cfg)
checkf("Error running benchmarks: %v", err)
Expand Down
33 changes: 4 additions & 29 deletions cmd/protoc-gen-gorums/dev/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import gorums "github.com/relab/gorums"
// from user code already interacting with the generated code.
type (
Configuration = gorums.Configuration
Manager = gorums.Manager
Node = gorums.Node
NodeContext = gorums.NodeContext
ConfigContext = gorums.ConfigContext
Expand All @@ -16,43 +15,19 @@ type (
// This prevents users from defining message types with these names.
var (
_ = (*Configuration)(nil)
_ = (*Manager)(nil)
_ = (*Node)(nil)
_ = (*NodeContext)(nil)
_ = (*ConfigContext)(nil)
)

// NewManager returns a new Manager for managing connection to nodes added
// to the manager. This function accepts dial options used to configure
// various aspects of the manager.
func NewManager(opts ...gorums.DialOption) *Manager {
return gorums.NewManager(opts...)
}

// NewConfiguration returns a configuration based on the provided list of nodes.
// Nodes can be supplied using WithNodes or WithNodeList.
// A new configuration can also be created from an existing configuration
// using the Add, Union, Remove, Difference, Extend, and WithoutErrors methods.
func NewConfiguration(mgr *Manager, opt gorums.NodeListOption) (Configuration, error) {
return gorums.NewConfiguration(mgr, opt)
}

// NewConfig returns a new [Configuration] based on the provided [gorums.Option]s.
// It accepts exactly one [gorums.NodeListOption] and multiple [gorums.DialOption]s.
// You may use this function to create the initial configuration for a new manager.
// NewConfig returns a new [Configuration] based on the provided nodes and dial options.
//
// Example:
//
// cfg, err := NewConfig(
// gorums.WithNodeList([]string{"localhost:8080", "localhost:8081", "localhost:8082"}),
// gorums.WithDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
// gorums.WithDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
// )
//
// This is a convenience function for creating a configuration without explicitly
// creating a manager first. However, the manager can be accessed using the
// [Configuration.Manager] method. This method should only be used once since it
// creates a new manager; if a manager already exists, use [NewConfiguration]
// instead, and provide the existing manager as the first argument.
func NewConfig(opts ...gorums.Option) (Configuration, error) {
return gorums.NewConfig(opts...)
func NewConfig(nodes gorums.NodeListOption, opts ...gorums.DialOption) (Configuration, error) {
return gorums.NewConfig(nodes, opts...)
}
41 changes: 8 additions & 33 deletions cmd/protoc-gen-gorums/gengorums/template_static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 24 additions & 27 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,28 @@ func (c Configuration) Context(parent context.Context) *ConfigContext {
return &ConfigContext{Context: parent, cfg: c}
}

// NewConfiguration returns a configuration based on the provided list of nodes.
// Nodes can be supplied using WithNodes or WithNodeList.
// A new configuration can also be created from an existing configuration
// using the Add, Union, Remove, Difference, Extend, and WithoutErrors methods.
// Deprecated: Use [NewConfig] instead.
func NewConfiguration(mgr *Manager, opt NodeListOption) (nodes Configuration, err error) {
if opt == nil {
return nil, fmt.Errorf("config: missing required node list")
}
return opt.newConfig(mgr)
}

// NewConfig returns a new [Configuration] based on the provided [gorums.Option]s.
// It accepts exactly one [gorums.NodeListOption] and multiple [gorums.DialOption]s.
// You may use this function to create the initial configuration for a new manager.
// NewConfig returns a new [Configuration] based on the provided nodes and dial options.
//
// Example:
//
// cfg, err := NewConfig(
// gorums.WithNodeList([]string{"localhost:8080", "localhost:8081", "localhost:8082"}),
// gorums.WithDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
// gorums.WithDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
// )
//
// This is a convenience function for creating a configuration without explicitly
// creating a manager first. However, the manager can be accessed using the
// [Configuration.Manager] method. This method should only be used once since it
// creates a new manager; if a manager already exists, use [NewConfiguration]
// instead, and provide the existing manager as the first argument.
func NewConfig(opts ...Option) (Configuration, error) {
serverOptions, dialOpts, nodeListOption, err := splitOptions(opts)
if err != nil {
return nil, err
}
if len(serverOptions) > 0 {
return nil, fmt.Errorf("gorums: ServerOption not valid for NewConfig; pass it to NewSystem or NewLocalSystems instead")
}
if nodeListOption == nil {
func NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error) {
if nodes == nil {
return nil, fmt.Errorf("gorums: missing required NodeListOption")
}
mgr := NewManager(dialOpts...)
return NewConfiguration(mgr, nodeListOption)
mgr := newOutboundManager(opts...)
return NewConfiguration(mgr, nodes)
}

// Extend returns a new Configuration combining c with new nodes from the provided NodeListOption.
Expand All @@ -93,7 +75,7 @@ func (c Configuration) Extend(opt NodeListOption) (Configuration, error) {
if opt == nil {
return slices.Clone(c), nil
}
mgr := c.Manager()
mgr := c.mgr()
newNodes, err := opt.newConfig(mgr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -135,13 +117,28 @@ func (c Configuration) Equal(b Configuration) bool {

// Manager returns the Manager that manages this configuration's nodes.
// Returns nil if the configuration is empty.
//
// Deprecated: Use [Configuration.Close] to close the configuration instead.
func (c Configuration) Manager() *Manager {
return c.mgr()
}

// mgr returns the outboundManager for this configuration's nodes.
func (c Configuration) mgr() *outboundManager {
if len(c) == 0 {
return nil
}
return c[0].mgr
}

// Close closes all node connections managed by this configuration.
func (c Configuration) Close() error {
if mgr := c.mgr(); mgr != nil {
return mgr.Close()
}
return nil
}

// nextMsgID returns the next message ID from this client's manager.
func (c Configuration) nextMsgID() uint64 {
return c[0].msgIDGen()
Expand All @@ -158,7 +155,7 @@ func (c Configuration) Add(ids ...uint32) Configuration {
if len(c) == 0 {
return nil
}
mgr := c.Manager()
mgr := c.mgr()
nodes := slices.Clone(c)
// seenIDs is used to filter duplicate IDs and IDs already added
seenIDs := newSet(c.NodeIDs()...)
Expand Down
6 changes: 3 additions & 3 deletions examples/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func runClient(addresses []string) error {
if len(addresses) < 1 {
log.Fatalln("No addresses provided!")
}
mgr := proto.NewManager(
cfg, err := proto.NewConfig(gorums.WithNodeList(addresses),
gorums.WithDialOptions(
grpc.WithTransportCredentials(insecure.NewCredentials()), // disable TLS
),
)
cfg, err := proto.NewConfiguration(mgr, gorums.WithNodeList(addresses))
if err != nil {
log.Fatal(err)
}
Comment thread
meling marked this conversation as resolved.
return Repl(mgr, cfg)
defer cfg.Close()
return Repl(cfg)
}

// newestValue processes responses from a ReadQC call and returns the reply
Expand Down
39 changes: 7 additions & 32 deletions examples/storage/proto/storage_gorums.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading