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: I7fba8808d8a4efbe7fd8fdff94fd9a53f3841c8b