NAME

Vayne::Zk - Vayne Zk control modual

SYNOPSIS

use Vayne::Zk;
my $zk = Vayne::Zk->new();
my %region = $zk->meta;

DESCRIPTION

DATA STRUCTURE

# we have three regions and 'vayne' is the namespace.
[zk: localhost:2181(CONNECTED) 0] ls /vayne
[region-foo, region-bar, region-first]

# region-first's redis(message system) info.
[zk: localhost:2181(CONNECTED) 1] get /vayne/region-first
---
password: xxxxxxxxxx
server: 127.0.0.1:6379

# real servers belong to the region 'region-fist'.
[zk: localhost:2181(CONNECTED) 2] ls /vayne/region-first
[vayne1.foo.bar.net, vayne2.foo.bar.net]

# workers in vayne1.foo.bar.net.
[zk: localhost:2181(CONNECTED) 3] ls /vayne/region-first/vayne1.foo.bar.net
[tcp, dump, track]

# we have two tcp workers running on vayne1.foo.bar.net belongs to region-first and pids are 52749 52757.
[zk: localhost:2181(CONNECTED) 4] ls /vayne/region-first/vayne1.foo.bar.net/tcp
[52749, 52757]

The node '/vayne/region-first/vayne1.foo.bar.net/tcp/52749' is registered when the worker tcp start.

METHODS FOR CONTROLLING VAYNE SYSTEM

$zk->meta

Get all meta info under zookeeper NAMESPACE.

$zk->define($region, {server=>$redis_server, password=>$redis_pwd})

Define a new region.

$zk->switch($region, $host)

Switch a host to region

$zk->delete($host)

Delete a host.

$zk->delete_region($region)

Delete a region.

METHODS USED BY WORKER

$zk->register(@names)

Register worker. How to write a worker, please see Vayne::Worker.

$zk->queue

Get region's queue(redis) info.

$zk->check

Worker will verify the register info periodically. Worker will go die when registered path changed. More details see Vayne::Worker.