concourse/atc — pull request #2 by luan (2014-10-29 19:51:39+00:00)
Title: Ensure that only the most recent version detected from a given check feeds into auto-triggered builds

This adds a `locks` table. The way this works is by adding a row per lock. Currently we use it for resources here, each lock has a (unique) name.
The current name scheme is: `resource: %s`, where %s is filled in with the resource name, we lazily create the locking rows, but never clean them up, that's something we might need to do in the future too.

The idea here is to start a simple way of having a generic global locking system across multiple ATCs (or any component that uses that DB table for that matter.
I added two functions to the DB, `AcquireReadLock(names []string)` and `AcquireWriteLock(names []string)` the work, respectively, with `SELECT 1 FROM

FOR SHARE` and `SELECT 1 FROM

FOR UPDATE` giving you flexibility on the locking there. There are a few tests added for theses methods, they might add quite a few seconds to the unit test times, we can reconsider those too if necessary.

Finally, I added read locking on inputs while scheduling builds and write locking where checking resources for new versions.

https://www.pivotaltracker.com/story/show/79242754