func (c *copyCatImpl) SubscribeToDataStructure(id *ID, provider SnapshotProvider) (chan<- []byte, <-chan []byte, <-chan error, SnapshotConsumer, error) {
	var interactiveBackend *raftBackend
	var err error
	var remoteRaftPeers []*pb.RaftPeer
	var remoteRaftPeer *pb.RaftPeer

	remoteRaftPeer, _ = c.membership.onePeerForDataStructureId(id)
	if remoteRaftPeer == nil {
		c.logger.Infof("Can't find data structure [%s] anywhere. Starting new raft group...", id)
		// TODO: revisit the concept of number of replicas
		// In my mind the number of replicas is just a proxy for how paranoid you are...
		// Maybe it's easier for the user to fhink about it as different use cases.
		// Meh, paranoia and consistency vs real consistency
		remoteRaftPeers, err = c.membership.startNewRaftGroup(id, 2)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}

		interactiveBackend, err = c.subscribeToExistingRaftGroup(id, c.config, remoteRaftPeers[0], provider)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}
	} else {
		c.logger.Infof("Found data structure [%s] on peer: %s", id, remoteRaftPeer.String())
		interactiveBackend, err = c.subscribeToExistingRaftGroup(id, c.config, remoteRaftPeer, provider)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}
	}

	return interactiveBackend.proposeChan, interactiveBackend.commitChan, interactiveBackend.errorChan, func() ([]byte, error) { return interactiveBackend.snapshot() }, nil
}
// takes a data structure id, joins the raft group as learner, assembles and exposes the raft log
takes a data structure id, joins the raft group as learner, assembles and exposes the raft log
// takes a data structure id joins the raft group as learner assembles and exposes the raft log
func (c *copyCatImpl) SubscribeToDataStructure(id *ID, provider SnapshotProvider) (chan<- []byte, <-chan []byte, <-chan error, SnapshotConsumer, error) {
	var interactiveBackend *raftBackend
	var err error
	var remoteRaftPeers []*pb.RaftPeer
	var remoteRaftPeer *pb.RaftPeer
	remoteRaftPeer, _ = c.membership.onePeerForDataStructureId(id)
	if remoteRaftPeer == nil {
		c.logger.Infof("Can't find data structure [%s] anywhere. Starting new raft group...", id)
		remoteRaftPeers, err = c.membership.startNewRaftGroup(id, 2)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}
		interactiveBackend, err = c.subscribeToExistingRaftGroup(id, c.config, remoteRaftPeers[0], provider)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}
	} else {
		c.logger.Infof("Found data structure [%s] on peer: %s", id, remoteRaftPeer.String())
		interactiveBackend, err = c.subscribeToExistingRaftGroup(id, c.config, remoteRaftPeer, provider)
		if err != nil {
			c.logger.Errorf("Can't connect to data structure [%s]: %s", id, err.Error())
			return nil, nil, nil, nil, err
		}
	}
	return interactiveBackend.proposeChan, interactiveBackend.commitChan, interactiveBackend.errorChan, func() ([]byte, error) { return interactiveBackend.snapshot() }, nil
}
func ( c * copyCatImpl ) SubscribeToDataStructure ( id * ID , provider SnapshotProvider ) ( chan <- [ ] byte , <- chan [ ] byte , <- chan error , SnapshotConsumer , error ) { var interactiveBackend * raftBackend var err error var remoteRaftPeers [ ] * pb . RaftPeer var remoteRaftPeer * pb . RaftPeer remoteRaftPeer , _ = c . membership . onePeerForDataStructureId ( id ) if remoteRaftPeer == nil { c . logger . Infof ( " " , id ) remoteRaftPeers , err = c . membership . startNewRaftGroup ( id , 2 ) if err != nil { c . logger . Errorf ( " " , id , err . Error ( ) ) return nil , nil , nil , nil , err } interactiveBackend , err = c . subscribeToExistingRaftGroup ( id , c . config , remoteRaftPeers [ 0 ] , provider ) if err != nil { c . logger . Errorf ( " " , id , err . Error ( ) ) return nil , nil , nil , nil , err } } else { c . logger . Infof ( " " , id , remoteRaftPeer . String ( ) ) interactiveBackend , err = c . subscribeToExistingRaftGroup ( id , c . config , remoteRaftPeer , provider ) if err != nil { c . logger . Errorf ( " " , id , err . Error ( ) ) return nil , nil , nil , nil , err } } return interactiveBackend . proposeChan , interactiveBackend . commitChan , interactiveBackend . errorChan , func ( ) ( [ ] byte , error ) { return interactiveBackend . snapshot ( ) } , nil }
takes a data structure id, joins the raft group as learner, assembles and exposes the raft log
takes a data structure id joins the raft group as learner assembles and exposes the raft log
// TODO: revisit the concept of number of replicas // In my mind the number of replicas is just a proxy for how paranoid you are... // Maybe it's easier for the user to fhink about it as different use cases. // Meh, paranoia and consistency vs real consistency