zookeeper

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package zookeeper - Common Zookeeper subsystem. The zookeeper subsystem provides a Zookeeper client that is common across all of Burrow, and can be used by other subsystems to store metadata or coordinate operations between multiple Burrow instances. It is used primarily to assure that only one Burrow instance is sending notifications at any time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

type Coordinator struct {
	App *protocol.ApplicationContext
	Log *zap.Logger
	// contains filtered or unexported fields
}

Coordinator (zookeeper) manages a single Zookeeper connection for other coordinators and modules to make use of in order to store metadata for Burrow itself. This is not required to connect to the same Zookeeper ensemble as any specific Kafka cluster. The ZookeeperClient is stored in the application context, as well as the root path that any modules should create their metadata underneath.

The coordinator monitors the connection state transitions and signals when the session is expired, and then when it reconnects. Code that must be aware of session expirations, such as code that makes use of watches, should have a structure as in the example.

Example (StateMonitoring)

Example for the Coordinator docs on how to do connection state monitoring

// Ignore me - needed to make the example clean
app := &protocol.ApplicationContext{}

for {
	// Wait for the Zookeeper connection to be connected
	for !app.ZookeeperConnected {
		// Sleep before looping around to prevent a tight loop
		time.Sleep(100 * time.Millisecond)
		continue
	}

	// Zookeeper is connected
	// Do all the work you need to do setting up watches, locks, etc.

	// Wait on the condition that signals that the session has expired
	app.ZookeeperExpired.L.Lock()
	app.ZookeeperExpired.Wait()
	app.ZookeeperExpired.L.Unlock()

	// The Zookeeper session has been lost
	// Do any work that you need to in order to clean up, or stop work that was happening inside a lock

	// Loop around to wait for the Zookeeper session to be established again
}
Output:

func (*Coordinator) Configure

func (zc *Coordinator) Configure()

Configure validates that the configuration has a list of servers provided for the Zookeeper ensemble, of the form host:port. It also checks the provided root path, using a default of "/burrow" if none has been provided.

func (*Coordinator) Start

func (zc *Coordinator) Start() error

Start creates the connection to the Zookeeper ensemble, and assures that the root path exists. Once that is done, it sets the ZookeeperConnected flag in the application context to true, and creates the ZookeeperExpired condition flag. It then starts a main loop to watch for connection state changes.

func (*Coordinator) Stop

func (zc *Coordinator) Stop() error

Stop closes the connection to the Zookeeper ensemble and waits for the connection state monitor to exit (which it will because the event channel will be closed).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL