VOL-1946: Use uuid to generate transaction ids for grpc request metadata to core instead of a running integer.
This will make it safe across restarts when core uses it to reserve transaction with etcd.
Change-Id: I0bac145f414327215e916857e2b2a936097876fb
diff --git a/afrouter/afrouter/backend.go b/afrouter/afrouter/backend.go
index 3db98c5..c597d49 100644
--- a/afrouter/afrouter/backend.go
+++ b/afrouter/afrouter/backend.go
@@ -87,7 +87,7 @@
r := &request{
// Create an outgoing context that includes the incoming metadata and that will cancel if the server's context is canceled
- ctx: metadata.AppendToOutgoingContext(metadata.NewOutgoingContext(serverStream.Context(), md.Copy()), "voltha_serial_number", strconv.FormatUint(nf.serialNo, 10)),
+ ctx: metadata.AppendToOutgoingContext(metadata.NewOutgoingContext(serverStream.Context(), md.Copy()), "voltha_serial_number", nf.serialNo),
streams: make(map[string]grpc.ClientStream),
responseErrChan: make(chan error, 1),
@@ -105,7 +105,7 @@
// TODO: Need to check if this is an active/active backend cluster
// with a serial number in the header.
- log.Debugf("Serial number for transaction allocated: %d", nf.serialNo)
+ log.Debugf("Serial number for transaction allocated: %s", nf.serialNo)
// If even one stream can be created then proceed. If none can be
// created then report an error because both the primary and redundant
// connections are non-existent.
diff --git a/afrouter/afrouter/binding-router.go b/afrouter/afrouter/binding-router.go
index 467b1e6..2602137 100644
--- a/afrouter/afrouter/binding-router.go
+++ b/afrouter/afrouter/binding-router.go
@@ -161,7 +161,6 @@
bindings: make(map[string]*backend),
//methodMap:make(map[string]byte),
currentBackend: &bptr,
- //serialNo:0,
}
// A binding association must exist
diff --git a/afrouter/afrouter/cluster.go b/afrouter/afrouter/cluster.go
index bb95183..859d92f 100644
--- a/afrouter/afrouter/cluster.go
+++ b/afrouter/afrouter/cluster.go
@@ -19,9 +19,9 @@
import (
"errors"
"fmt"
+ "github.com/google/uuid"
"github.com/opencord/voltha-go/common/log"
"google.golang.org/grpc"
- "sync/atomic"
)
var clusters = make(map[string]*cluster)
@@ -30,9 +30,8 @@
type cluster struct {
name string
//backends map[string]*backend
- backends []*backend
- backendIDMap map[*backend]int
- serialNoCounter uint64
+ backends []*backend
+ backendIDMap map[*backend]int
}
//TODO: Move the backend type (active/active etc) to the cluster
@@ -80,8 +79,8 @@
return nil
}
-func (c *cluster) allocateSerialNumber() uint64 {
- return atomic.AddUint64(&c.serialNoCounter, 1) - 1
+func (c *cluster) allocateSerialNumber() string {
+ return uuid.New().String()
}
func (c *cluster) nextBackend(be *backend, seq backendSequence) (*backend, error) {
diff --git a/afrouter/afrouter/codec.go b/afrouter/afrouter/codec.go
index 27f4619..278fc0a 100644
--- a/afrouter/afrouter/codec.go
+++ b/afrouter/afrouter/codec.go
@@ -53,7 +53,7 @@
connection *connection // optional, if the router preferred one connection over another
err error
methodInfo methodDetails
- serialNo uint64
+ serialNo string
metaKey string
metaVal string
}