Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
/ go-helix Public archive

A Go implementation of Apache Helix (currently the participant part only).

License

Notifications You must be signed in to change notification settings

uber-go/go-helix

Repository files navigation

go-helix GoDoc Build Status Coverage Status

A Go implementation of Apache Helix.

Currently the participant part only, compatible with the Apache Helix Java controller.

Installation

go get -u github.com/uber-go/go-helix

Quick Start

Init participant

participant, fatalErrChan := NewParticipant(
	zap.NewNop(),
	tally.NoopScope,
	"localhost:2181", // Zookeeper connect string
	"test_app", // application identifier
	"test_cluster", // helix cluster name
	"test_resource", // helix resource name
	"localhost", // participant host name
	123, // participant port
)

processor := NewStateModelProcessor()
processor.AddTransition("OFFLINE", "ONLINE", func(m *model.Message) (err error) {
    partitionNum, err := p.getPartitionNum(m)
    if err != nil {
        return err
    }
    // add logic here to save the owned partition and/or perform any actions for going online
})
processor.AddTransition("ONLINE", "OFFLINE", func(m *model.Message) (err error) {
   partitionNum, err := p.getPartitionNum(m)
   if err != nil {
       return err
   }
   // add logic here to remove the owned partition and/or perform any actions for going offline
})

participant.RegisterStateModel("OnlineOffline", processor)

err := participant.Connect() // initialization is complete if err is nil

// listen to the fatal error channel and handle the error by
// 1. recreate participant from scratch and connect, or
// 2. quit the program and restart
fatalErr := <- fatalErrChan

Use participant

Use the saved partitions to see if the partition should be handled by the participant.

Disconnect participant

participant.Disconnect()

Development Status: Beta

The APIs are functional. We do not expect, but there's no guarantee that no breaking changes will be made.

Contributing

We encourage and support an active, healthy community of contributors — including you! Details are in the contribution guide and the code of conduct. The go-helix maintainers keep an eye on issues and pull requests, but you can also report any negative conduct to oss-conduct@uber.com. That email list is a private, safe space; even the go-helix maintainers don't have access, so don't hesitate to hold us to a high standard.


Released under the MIT License.