Implement stack-locking for multi-engine support

Implements a distributed stack lock using the database to avoid race
conditions when multiple engines are deployed.

Blueprint multiple-engines

Change-Id: If3c47dafcc5bc1b2188b7737205291bbab8bc231