add global lock to handle replication