Cancelable cleanup actions.

Use case:

func () (*C, error) {
  a, err := AllocResourceA()
  if err != nil {
    return nil, err
  }

  cleanup := NewCleanup(func () { FreeA(a) })
  defer cleanup.Run()

  b, err := AllocResourceB()
  if err != nil {
    return nil, err
  }

  cleanup.Cancel()

  return &C{a, b}, nil
}

Change-Id: Ib92b0e8bdcacc349e7cb949acd7eed054c783067
Reviewed-on: http://review.couchbase.org/42939
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: John Liang <johliang00@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Adapt to goforestdb API changes.

Change-Id: I31c1a0cf0d5cad2fb7d4134d056d63197771c90b
Reviewed-on: http://review.couchbase.org/42940
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Sarath Lakshman <sarath@couchbase.com>
Fix license header (hopefully once and for all).

I left a reference to NorthScale there.

Change-Id: I852d72bbaa2ab746029f8f71236e59dce3633579
Reviewed-on: http://review.couchbase.org/42941
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Abstract BackoffTimer.

Change-Id: I0b29895d0bc76c51de1e3a158c1899148be68df5
Reviewed-on: http://review.couchbase.org/42942
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reverse setBallotInProg parameter meaning.

To reflect the name better.

Change-Id: I814b77097f52aff65d668bd43f2fc23ae998c97e
Reviewed-on: http://review.couchbase.org/42943
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Simplify setBallotInProg.

Change-Id: Ide637e24267cd654134f3b4ff0a6d946f3f86e60
Reviewed-on: http://review.couchbase.org/42944
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Remove unneeded intermediary variable.

Change-Id: Ied087c24411b1cfcb0855b50b6525d14e9f5f6f2
Reviewed-on: http://review.couchbase.org/42945
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Don't run timeout timer when there's no ballot.

Change-Id: I281c9e163c13c24a6e75fb921c3b4c19c6eb8b50
Reviewed-on: http://review.couchbase.org/42946
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Wait grace period after reaching quorum of votes for a leader.

During the grace period new votes are still accepted. If during this
time our idea of leader doesn't change, only then we declare it a
leader. This is what zookeeper also does to reduce the probability for
certain node to elect an incorrect leader which then causes
follower/leader synchronization to fail.

Change-Id: Ifa8715c5468972711d7b4b9c61f02586e17263eb
Reviewed-on: http://review.couchbase.org/42947
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Add CMakeList to build gometa along with Couchbase server