Skip to content
104 changes: 53 additions & 51 deletions benchmark/benchmark_gorums.pb.go

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

22 changes: 11 additions & 11 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func (mockSrv) Test(_ ServerCtx, _ *mock.Request) (*mock.Response, error) {
return nil, nil
}

func dummyMgr() *RawManager {
return NewRawManager(
func dummyMgr() *manager {
return newManager(
WithGrpcDialOptions(
grpc.WithTransportCredentials(insecure.NewCredentials()),
),
Expand All @@ -27,7 +27,7 @@ func dummyMgr() *RawManager {

var handlerName = "mock.Server.Test"

func dummySrv() *Server {
func newDummySrv() *Server {
mockSrv := &mockSrv{}
srv := NewServer()
srv.RegisterHandler(handlerName, func(ctx ServerCtx, in *Message, finished chan<- *Message) {
Expand Down Expand Up @@ -66,20 +66,20 @@ func TestChannelCreation(t *testing.T) {

func TestChannelSuccessfulConnection(t *testing.T) {
addrs, teardown := TestSetup(t, 1, func(_ int) ServerIface {
return dummySrv()
return newDummySrv()
})
defer teardown()
mgr := dummyMgr()
defer mgr.Close()
defer mgr.close()
node, err := NewRawNode(addrs[0])
if err != nil {
t.Fatal(err)
}

if err = mgr.AddNode(node); err != nil {
if err = mgr.addNode(node); err != nil {
t.Fatal(err)
}
if len(mgr.Nodes()) < 1 {
if len(mgr.getNodes()) < 1 {
t.Fatal("the node was not added to the configuration")
}
if !node.channel.isConnected() {
Expand All @@ -92,18 +92,18 @@ func TestChannelSuccessfulConnection(t *testing.T) {

func TestChannelUnsuccessfulConnection(t *testing.T) {
mgr := dummyMgr()
defer mgr.Close()
defer mgr.close()
// no servers are listening on the given address
node, err := NewRawNode("127.0.0.1:5000")
if err != nil {
t.Fatal(err)
}

// the node should still be added to the configuration
if err = mgr.AddNode(node); err != nil {
if err = mgr.addNode(node); err != nil {
t.Fatal(err)
}
if len(mgr.Nodes()) < 1 {
if len(mgr.getNodes()) < 1 {
t.Fatal("the node was not added to the configuration")
}
if node.conn == nil {
Expand All @@ -114,7 +114,7 @@ func TestChannelUnsuccessfulConnection(t *testing.T) {
func TestChannelReconnection(t *testing.T) {
srvAddr := "127.0.0.1:5000"
// wait to start the server
startServer, stopServer := testServerSetup(t, srvAddr, dummySrv())
startServer, stopServer := testServerSetup(t, srvAddr, newDummySrv())
node, err := NewRawNode(srvAddr)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 2 additions & 4 deletions cmd/benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ func main() {
gorums.WithSendBufferSize(*sendBuffer),
}

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

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

results, err := benchmark.RunBenchmarks(benchReg, options, cfg, options.QuorumSize)
checkf("Error running benchmarks: %v", err)
Expand Down
60 changes: 52 additions & 8 deletions cmd/protoc-gen-gorums/dev/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,70 @@ type Configuration struct {
gorums.RawConfiguration
}

// ConfigurationFromRaw returns a new Configuration from the given raw configuration and QuorumSpec.
//
// This function may for example be used to "clone" a configuration but install a different QuorumSpec:
// NewConfiguration returns a configuration based on the provided list of nodes (required)
// and an optional quorum specification. The QuorumSpec is necessary for call types that
// must process replies. For configurations only used for unicast or multicast call types,
// a QuorumSpec is not needed.
// Nodes can be supplied using WithNodeMap or WithNodeList.
// Using any other type of NodeListOption will not work.
// The ManagerOption list controls how the nodes in the configuration are created.
func NewConfiguration(cfg gorums.NodeListOption, opts ...gorums.ManagerOption) (c *Configuration, err error) {
c = &Configuration{}
c.RawConfiguration, err = gorums.NewRawConfiguration(cfg, opts...)
if err != nil {
return nil, err
}
return c, nil
}

// ConfigurationFromRaw returns a new configuration from the given raw configuration.
//
// cfg1, err := mgr.NewConfiguration(qspec1, opts...)
// cfg2 := ConfigurationFromRaw(cfg1.RawConfig, qspec2)
// cfg1, err := pb.NewConfiguration(nodeList, opts...)
// cfg2 := ConfigurationFromRaw(cfg1.RawConfig)
func ConfigurationFromRaw(rawCfg gorums.RawConfiguration) (*Configuration, error) {
newCfg := &Configuration{
RawConfiguration: rawCfg,
}
return newCfg, nil
}

// Nodes returns a slice of each available node. IDs are returned in the same
// order as they were provided in the creation of the Manager.
// SubConfiguration allows for making a new Configuration from the ManagerOption list and
// node list of another configuration,
// Nodes can be supplied using WithNodeMap or WithNodeList, or WithNodeIDs.
// A new configuration can also be created from an existing configuration,
// using the And, WithNewNodes, Except, and WithoutNodes methods.
func (c *Configuration) SubConfiguration(cfg gorums.NodeListOption) (subCfg *Configuration, err error) {
subCfg = &Configuration{}
subCfg.RawConfiguration, err = c.SubRawConfiguration(cfg)
if err != nil {
return nil, err
}
return subCfg, nil
}

// Close closes the nodes which aren't used by other subconfigurations
func (c *Configuration) Close() error {
return c.RawConfiguration.Close()
}

// Nodes returns a slice of the configuration nodes. Sorted by node id.
//
// NOTE: mutating the returned slice is not supported.
func (c *Configuration) Nodes() []*Node {
nodes := make([]*Node, c.Size())
for i, n := range c.RawConfiguration {
for i, n := range c.RawConfiguration.RawNodes {
nodes[i] = &Node{n}
}
return nodes
}

// AllNodes returns a slice of each available node of all subconfigurations. Sorted by node id.
//
// NOTE: mutating the returned slice is not supported.
func (c *Configuration) AllNodes() []*Node {
rawNodes := c.RawConfiguration.AllNodes()
nodes := make([]*Node, len(rawNodes))
for i, n := range rawNodes {
nodes[i] = &Node{n}
}
return nodes
Expand Down
42 changes: 0 additions & 42 deletions cmd/protoc-gen-gorums/dev/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,3 @@ func init() {
encoding.RegisterCodec(gorums.NewCodec())
}
}

// Manager maintains a connection pool of nodes on
// which quorum calls can be performed.
type Manager struct {
*gorums.RawManager
}

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

// NewConfiguration returns a configuration based on the provided list of nodes (required)
// and an optional quorum specification. The QuorumSpec is necessary for call types that
// must process replies. For configurations only used for unicast or multicast call types,
// a QuorumSpec is not needed. The QuorumSpec interface is also a ConfigOption.
// Nodes can be supplied using WithNodeMap or WithNodeList, or WithNodeIDs.
// A new configuration can also be created from an existing configuration,
// using the And, WithNewNodes, Except, and WithoutNodes methods.
func (m *Manager) NewConfiguration(nodeList gorums.NodeListOption) (c *Configuration, err error) {
c = &Configuration{}
c.RawConfiguration, err = gorums.NewRawConfiguration(m.RawManager, nodeList)
if err != nil {
return nil, err
}
return c, nil
}

// Nodes returns a slice of available nodes on this manager.
// IDs are returned in the order they were added at creation of the manager.
func (m *Manager) Nodes() []*Node {
gorumsNodes := m.RawManager.Nodes()
nodes := make([]*Node, len(gorumsNodes))
for i, n := range gorumsNodes {
nodes[i] = &Node{n}
}
return nodes
}
2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_client_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_multicast_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_quorumcall_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_rpc_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_server_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/dev/zorums_unicast_gorums.pb.go

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

Loading
Loading