VOL-1775 VOL-1779 VOL-1780 : Fix several issues with overall stability

- Apply changes as reported by golang race utility
- Added version attribute in KV object
- Added context object to db/model api
- Carrying timestamp info through context to help in the
  decision making when applying a revision change
- Replaced proxy access control mechanism with etcd reservation mechanism

Change-Id: If3d142a73b1da0d64fa6a819530f297dbfada2d3
diff --git a/db/model/branch.go b/db/model/branch.go
index 5502e63..3389291 100644
--- a/db/model/branch.go
+++ b/db/model/branch.go
@@ -26,7 +26,7 @@
 
 // Branch structure is used to classify a collection of transaction based revisions
 type Branch struct {
-	sync.RWMutex
+	mutex      sync.RWMutex
 	Node       *node
 	Txid       string
 	Origin     Revision
@@ -85,8 +85,8 @@
 
 // SetLatest assigns the latest revision for this branch
 func (b *Branch) SetLatest(latest Revision) {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.Lock()
+	defer b.mutex.Unlock()
 
 	if b.Latest != nil {
 		log.Debugw("updating-latest-revision", log.Fields{"current": b.Latest.GetHash(), "new": latest.GetHash()})
@@ -119,16 +119,16 @@
 
 // GetLatest retrieves the latest revision of the branch
 func (b *Branch) GetLatest() Revision {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.RLock()
+	defer b.mutex.RUnlock()
 
 	return b.Latest
 }
 
 // GetOrigin retrieves the original revision of the branch
 func (b *Branch) GetOrigin() Revision {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.RLock()
+	defer b.mutex.RUnlock()
 
 	return b.Origin
 }
@@ -142,8 +142,8 @@
 
 // GetRevision pulls a revision entry at the specified hash
 func (b *Branch) GetRevision(hash string) Revision {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.RLock()
+	defer b.mutex.RUnlock()
 
 	if revision, ok := b.Revisions[hash]; ok {
 		return revision
@@ -154,16 +154,16 @@
 
 // SetRevision updates a revision entry at the specified hash
 func (b *Branch) SetRevision(hash string, revision Revision) {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.Lock()
+	defer b.mutex.Unlock()
 
 	b.Revisions[hash] = revision
 }
 
 // DeleteRevision removes a revision with the specified hash
 func (b *Branch) DeleteRevision(hash string) {
-	b.Lock()
-	defer b.Unlock()
+	b.mutex.Lock()
+	defer b.mutex.Unlock()
 
 	if _, ok := b.Revisions[hash]; ok {
 		delete(b.Revisions, hash)