- Automatically add and rebalance cattle couchbase nodes using etcd as a discovery service
- Gracefull failover/remove node on container shutdown
- Survive ETCD outages
The Couchbase Node is responsible for starting up an instance of Couchbase server. In addition it is responsible for registering it's self as available for clustering
- Each cluster node is disposable when replication at a bucket level is enabled
- Each cluster node runs a disposable docker container activated by a systemd unit
- Every time the systemd unit recycles
- Starts the couchbase docker container.
- Attempts to acquire a scheduler lock from etcd
- Writes a label registering it's self with the backend store for initialization
- Listens to state change requests from the master scheduler
The scheduler is responsible for keeping the cluster balanced. Rebalancing the cluster as new cluster node are detected. Rebalancing when cluster nodes are no longer detected.
-
The scheduler runs a loop monitoring the current state of the cluster
-
The scheduler schedules actions upon detection of differences between node current state and the node desired state
- On acquiring a cluster wide master lock the scheduler is started
- The scheduler will elect a master node and set standard cluster settings like auto failure policy
- As nodes are detected desired actions are issued to nodes via etcd
- If the master goes down another cluster node aquires the master lock and begins the scheduler
-
As a container shuts down it will try issue a gracefull failover
-
The container will block and wait until the gracefull failover has completed
-
The container will then issue an asynchronous rebalance before exiting
-
Here is it important that the container is given enough time to gracefully shutdown
docker stop --time=120 couchbase
-
-
As a container starts it will try to add its self to the cluster
- If it is already a member of the cluster it will issue a 'setRecoveryType' to delta
- In any case it will finally trigger a rebalance
Currently the program sets auto failover to be 31 seconds.
The project requires a golang project structure
-
Build the Docker container
./src/github.com/andrewwebber/couchbase-array/couchbase-node/Docker/build.sh
-
Start etcd (below using boot2docker IPAddress)
go get github.com/coreos/etcd etcd --advertise-client-urls=http://172.16.237.1:4001,http://localhost:4001 --listen-client-urls=http://172.16.237.1:4001,http://localhost:4001
-
Start as many couchbase containers as you want
docker run -d --name couchbase1 -p 8091:8091 -e ETCDCTL_PEERS=http://172.16.237.1:4001 andrewwebber/couchbase-cloudarray docker run -d --name couchbase2 -e ETCDCTL_PEERS=http://172.16.237.1:4001 andrewwebber/couchbase-cloudarray docker run -d --name couchbase3 -e ETCDCTL_PEERS=http://172.16.237.1:4001 andrewwebber/couchbase-cloudarray
-
Browser to a node [http://172.16.237.103:8091] and login with Administrator password
-
Destroy and start containers at will
In production the docker arguments simply change to use --net="host"
- When a container starts it will rebalance of a master node
- When a container stop it will gracefully failover from the cluster and issue a rebalance on exit
Below is an example systemd service unit
[Service]
TimeoutSec=0
ExecStartPre=-/usr/bin/mkdir /home/core/couchbase
ExecStartPre=/usr/bin/chown 999:999 /home/core/couchbase
ExecStartPre=-/usr/bin/docker kill couchbase
ExecStartPre=-/usr/bin/docker rm -f couchbase
ExecStart=/usr/bin/docker run --name couchbase --net="host" -v /home/core/couchbase:/opt/couchbase/var -e ETCDCTL_PEERS=http://192.168.89.215:4001 --ulimit nofile=40960:40960 --ulimit core=100000000:100000000 --ulimit memlock=100000000:100000000 andrewwebber/couchbase-array
ExecStop=/usr/bin/docker kill --signal=SIGTERM couchbase
Restart=always
RestartSec=20
The direction of the project will be get as many arguments as possible from etcd including:
- Username and password
- Auto failover timeout in seconds
- Whether to issue a rebalance automatically upon graceful faillover
- Whether to issue a rebalance automatically upon new node detection
- Email alerts