VOL-1497 : Add more control to kv/memory access
- Added kv locking mechanism (etcd only)
- (watch) control path access whenever possible
- (watch) use a transaction for updates and merge with memory
- cleaned up vendoring
- misc changes to fix exceptions found along the way
Amendments:
- Copyright header got removed in auto-generated file
- Changed default locking to false for KV list operation
- Updated backend api to allow the passing of locking parameter
Change-Id: Ie1a55d3ca8b9d92ae71a85ce42bb22fcf1419e2c
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index af717ef..b321f22 100644
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -140,7 +140,7 @@
// getDeviceWithoutLock is a helper function to be used ONLY by any device agent function AFTER it has acquired the device lock.
// This function is meant so that we do not have duplicate code all over the device agent functions
func (agent *DeviceAgent) getDeviceWithoutLock() (*voltha.Device, error) {
- if device := agent.clusterDataProxy.Get("/devices/"+agent.deviceId, 0, false, ""); device != nil {
+ if device := agent.clusterDataProxy.Get("/devices/"+agent.deviceId, 0, true, ""); device != nil {
if d, ok := device.(*voltha.Device); ok {
cloned := proto.Clone(d).(*voltha.Device)
return cloned, nil
diff --git a/rw_core/core/transaction.go b/rw_core/core/transaction.go
index 397299e..e7125d3 100644
--- a/rw_core/core/transaction.go
+++ b/rw_core/core/transaction.go
@@ -178,7 +178,7 @@
// Add a timeout here in case we miss an event from the KV
case <-time.After(time.Duration(duration) * time.Millisecond):
// In case of missing events, let's check the transaction key
- kvp, err := ctx.kvClient.Get(c.txnKey, ctx.kvOperationTimeout)
+ kvp, err := ctx.kvClient.Get(c.txnKey, ctx.kvOperationTimeout, false)
if err == nil && kvp == nil {
log.Debug("missed-deleted-event")
res = ABANDONED_BY_OTHER
@@ -228,16 +228,16 @@
log.Debugw("schedule-key-deletion", log.Fields{"key": c.txnKey})
time.Sleep(time.Duration(ctx.timeToDeleteCompletedKeys) * time.Second)
log.Debugw("background-key-deletion", log.Fields{"key": c.txnKey})
- ctx.kvClient.Delete(c.txnKey, ctx.kvOperationTimeout)
+ ctx.kvClient.Delete(c.txnKey, ctx.kvOperationTimeout, false)
}
func (c *KVTransaction) Close() error {
log.Debugw("close", log.Fields{"key": c.txnKey})
- return ctx.kvClient.Put(c.txnKey, TRANSACTION_COMPLETE, ctx.kvOperationTimeout)
+ return ctx.kvClient.Put(c.txnKey, TRANSACTION_COMPLETE, ctx.kvOperationTimeout, false)
}
func (c *KVTransaction) Delete() error {
log.Debugw("delete", log.Fields{"key": c.txnKey})
- err := ctx.kvClient.Delete(c.txnKey, ctx.kvOperationTimeout)
+ err := ctx.kvClient.Delete(c.txnKey, ctx.kvOperationTimeout, false)
return err
}