Skip to main content

etcd 0.2.0 - new API, new modules and tons of improvements

Today we released etcd 0.2.0 which introduces major features including an improved v2 API, two new modules for fair locking and leader election, and tons of new features.

Major Changes

v2 API

etcd 0.2.0 introduces a new API endpoint at /v2. This API has been built on all of the feedback we have gotten from the community of users who have been building projects on etcd. The major features of the new API include:

  • Simplified and consistent response format (example)
  • Compare-and-Swap (CAS) operations are now available so you can conditionally set values on keys (example)
  • Directories can be created and have a time-to-live (example)
  • Recursive GET requests to retrieve all data within a directory. (example)

The previous API from the 0.1 series of releases still works and can be found at /v1.

New Modules

One of the goals of etcd is to make building consistent and correct distributed systems easier for developers. In this release we have added two new modules that offer simple HTTP APIs to fair locks and leader elections.

The fair lock API can be used for things like ensuring only a single machine is running a cron job at a given time, for locking transactions across disparate data stores or as a building block for a larger distributed data structure. And you can do this from any language that can talk http:

On machine1 in your cluster you can protect job1:

curl -X POST 'http://127.0.0.1:4001/mod/v2/lock/job1?ttl=180?value=machine1'
# Do your work on job1
curl -X DELETE 'http://127.0.0.1:4001/mod/v2/lock/job1?value=machine1'

And on another machine you can protect job1:

curl -X POST 'http://127.0.0.1:4001/mod/v2/lock/job1?ttl=180&value=machine2'
# Do your work on job1 after machine1 has finished or timed out
curl -X DELETE 'http://127.0.0.1:4001/mod/v2/lock/job1?value=machine2'

Full docs for the lock are here.

The leader election module builds on top of the lock to provide a mechanism for doing a leader election on a set of candidate machines. We will do a blog post on how to wire this up to databases like Postgres for automatic failover. In the meantime you can find the docs here.

etcdctl improvements

etcdctl is a command line tool designed for use in scripts or for exploring the key space interactively and it has seen lots of improvements in this release.

  • exec-watch will execute a script everytime a key changes (example)
  • etcdctl ls can list directories recursively (example)
  • -o extended format for get/set for simple parsing from scripts (example)

Service Features

  • Configuration via command line, through environment variables, or by loading a configuration file.
  • Versioning of the internal protocol will allow you to run multiple versions of etcd in a cluster and perform rolling upgrades.
  • Bug fixes, internal refactoring and lots of tests added.

Getting Started

We will roll out 0.2.0 of etcd into CoreOS today. If you want to try it out in a Docker container or grab binary releases for Linux and OSX instruction are on the releases page.

Once you have etcd running the next step is reading through the extensive etcd manual and joining the mailing list or IRC channel.