[ARVADOS] updated: 1.1.0-192-g5a32827

Git user git at public.curoverse.com
Wed Nov 29 10:57:54 EST 2017


Summary of changes:
 sdk/go/httpserver/id_generator.go | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

       via  5a32827d1f5ada007f83f5d5bb9b2d12526f2755 (commit)
      from  062912dab12af62beab4d585584c0ccfc700af20 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 5a32827d1f5ada007f83f5d5bb9b2d12526f2755
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Wed Nov 29 10:56:44 2017 -0500

    12167: Use pseudo-random IDs instead of timestamps.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/go/httpserver/id_generator.go b/sdk/go/httpserver/id_generator.go
index c744691..d2c3a41 100644
--- a/sdk/go/httpserver/id_generator.go
+++ b/sdk/go/httpserver/id_generator.go
@@ -5,6 +5,7 @@
 package httpserver
 
 import (
+	"math/rand"
 	"net/http"
 	"strconv"
 	"sync"
@@ -18,21 +19,24 @@ type IDGenerator struct {
 	// Prefix is prepended to each returned ID.
 	Prefix string
 
-	lastID int64
-	mtx    sync.Mutex
+	mtx sync.Mutex
+	src rand.Source
 }
 
 // Next returns a new ID string. It is safe to call Next from multiple
 // goroutines.
 func (g *IDGenerator) Next() string {
-	id := time.Now().UnixNano()
 	g.mtx.Lock()
-	if id <= g.lastID {
-		id = g.lastID + 1
+	defer g.mtx.Unlock()
+	if g.src == nil {
+		g.src = rand.NewSource(time.Now().UnixNano())
 	}
-	g.lastID = id
-	g.mtx.Unlock()
-	return g.Prefix + strconv.FormatInt(id, 36)
+	a, b := g.src.Int63(), g.src.Int63()
+	id := strconv.FormatInt(a, 36) + strconv.FormatInt(b, 36)
+	for len(id) > 20 {
+		id = id[:20]
+	}
+	return g.Prefix + id
 }
 
 // AddRequestIDs wraps an http.Handler, adding an X-Request-Id header

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list