func newReplicatedCatalog(namespace auth.Namespace, conf *Config, replicator replication.Replicator) Catalog { logger := logging.GetLogger(module).WithFields(log.Fields{"namespace": namespace}) if conf == nil { conf = DefaultConfig } localMemberCatalog := newInMemoryCatalog(conf) if replicator == nil { return localMemberCatalog } rpc := &replicatedCatalog{ local: localMemberCatalog, replicator: replicator, notifyChannel: channels.NewChannelTimeout(256), logger: logger, } go rpc.handleMsgs() rpc.logger.Infof("Replicated-Catalog creation done") return rpc }
// New - Create a new replication instance func New(conf *Config) (Replication, error) { var lentry = logging.GetLogger(module) if conf == nil { err := fmt.Errorf("Nil conf") lentry.WithFields(log.Fields{ "error": err, }).Error("Failed to create replication server") return nil, err } if conf.Membership == nil || conf.Registrator == nil { err := fmt.Errorf("Nil cluster membership and/or registrator") lentry.WithFields(log.Fields{ "error": err, }).Error("Failed to create replication server") return nil, err } // Make sure that the listening port is free address := fmt.Sprintf("%s:%d", conf.Registrator.Self().IP(), conf.Registrator.Self().Port()) listener, err := net.Listen("tcp", address) if err != nil { lentry.WithFields(log.Fields{ "error": err, }).Error("Failed to create replication server") return nil, err } tr := &http.Transport{MaxIdleConnsPerHost: 1} hc := &http.Client{Transport: tr} logger := lentry.WithFields(log.Fields{"Member-ID": conf.Registrator.Self().ID()}) // Instantiate a server s := &server{ listener: listener, httpclient: hc, transport: tr, broadcast: channels.NewChannelTimeout(512), repair: channels.NewChannelTimeout(512), newPeers: make(chan *peer), closingPeers: make(chan *peer, 8), peers: make(map[cluster.MemberID]*peer), mux: http.NewServeMux(), replicators: make(map[auth.Namespace]*replicator), clients: make(map[cluster.MemberID]*client), selfID: conf.Registrator.Self().ID(), membership: conf.Membership, registrator: conf.Registrator, notifyChannel: make(chan *InMessage, 512), syncReqChannel: make(chan chan []byte, 8), health: newHealthChecker(), done: make(chan struct{}), logger: logger, } health.Register(module, s.health) logger.Info("Replication server created") return s, nil }