You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current version of NewConfiguration takes only a single variadic whose type is an empty interface. This makes the code fragile and it can break at runtime if passed an unrecognized type.
Below is a rewrite that should prevent the problem of passing an unrecognized type. Although, you can still "forget" to pass an implementation a QuorumSpec interface, which would break at runtime. Ideally, this should also be detected at compile time.
// NewConfiguration returns a configuration based on the provided list of nodes and// an optional quorum specification. The QuorumSpec is necessary for call types that// 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(cfg gorums.NodeListOption, qspec...QuorumSpec) (c*Configuration, errerror) {
iflen(qspec) >1 {
returnnil, fmt.Errorf("config: wrong number of options: %d", len(qspec))
}
iflen(qspec) ==0 {
// return an error if the QuorumSpec interface is not empty and no implementation was provided.vartestinterface{} =struct{}{}
if_, empty:=test.(QuorumSpec); !empty {
returnnil, fmt.Errorf("config: missing required QuorumSpec for quorum calls")
}
}
c=&Configuration{}
iflen(qspec) ==1 {
c.qspec=qspec[0]
}
c.RawConfiguration, err=gorums.NewRawConfiguration(m.RawManager, cfg)
iferr!=nil {
returnnil, err
}
// initialize the nodes slicec.nodes=make([]*Node, c.Size())
fori, n:=rangec.RawConfiguration {
c.nodes[i] =&Node{n}
}
returnc, nil
}
Another solution would be to generate different NewConfiguration signatures for the cases where the QuorumSpec is not needed (one-way communications like unicast and multicast). We would still have only one implementation in the generated code, but they would have different signatures. Alternatively, we could keep the same signature in all cases but make the QuorumSpec an empty interface for the one-way cases.
All of these solutions would break compatibility with existing code. Most uses of NewConfiguration actually pass the QuorumSpec as the first argument (but some does it the other way around). So either way, we will break someone. Since we haven't made an official release of version 1.0 yet, and I'm not aware of any production uses, I think it should be fine to do one of the above changes. Fixing it is trivial by swapping the order of the arguments.
The text was updated successfully, but these errors were encountered:
The current version of NewConfiguration takes only a single variadic whose type is an empty interface. This makes the code fragile and it can break at runtime if passed an unrecognized type.
Below is a rewrite that should prevent the problem of passing an unrecognized type. Although, you can still "forget" to pass an implementation a
QuorumSpec
interface, which would break at runtime. Ideally, this should also be detected at compile time.Another solution would be to generate different
NewConfiguration
signatures for the cases where theQuorumSpec
is not needed (one-way communications like unicast and multicast). We would still have only one implementation in the generated code, but they would have different signatures. Alternatively, we could keep the same signature in all cases but make theQuorumSpec
an empty interface for the one-way cases.All of these solutions would break compatibility with existing code. Most uses of
NewConfiguration
actually pass theQuorumSpec
as the first argument (but some does it the other way around). So either way, we will break someone. Since we haven't made an official release of version 1.0 yet, and I'm not aware of any production uses, I think it should be fine to do one of the above changes. Fixing it is trivial by swapping the order of the arguments.The text was updated successfully, but these errors were encountered: