You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/09/19 09:54:36 UTC

[servicecomb-kie] 01/01: [feat]return the same ID when input the same kvDoc request

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch sync
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git

commit 7efe3edfc0d13d81b47f592bee094808c741ea29
Author: little-cui <su...@qq.com>
AuthorDate: Mon Sep 19 17:53:53 2022 +0800

    [feat]return the same ID when input the same kvDoc request
---
 server/service/kv/kv_svc.go | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/server/service/kv/kv_svc.go b/server/service/kv/kv_svc.go
index 66a958b..3943888 100644
--- a/server/service/kv/kv_svc.go
+++ b/server/service/kv/kv_svc.go
@@ -19,16 +19,11 @@ package kv
 
 import (
 	"context"
+	"crypto/sha1"
 	"fmt"
+	"strings"
 	"time"
 
-	"github.com/go-chassis/cari/config"
-	"github.com/go-chassis/cari/pkg/errsvc"
-	"github.com/go-chassis/foundation/validator"
-	"github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
-	"github.com/go-chassis/openlog"
-	"github.com/gofrs/uuid"
-
 	"github.com/apache/servicecomb-kie/pkg/common"
 	"github.com/apache/servicecomb-kie/pkg/concurrency"
 	"github.com/apache/servicecomb-kie/pkg/model"
@@ -36,6 +31,11 @@ import (
 	"github.com/apache/servicecomb-kie/server/datasource"
 	"github.com/apache/servicecomb-kie/server/pubsub"
 	"github.com/apache/servicecomb-kie/server/service/sync"
+	"github.com/go-chassis/cari/config"
+	"github.com/go-chassis/cari/pkg/errsvc"
+	"github.com/go-chassis/foundation/validator"
+	"github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
+	"github.com/go-chassis/openlog"
 )
 
 var listSema = concurrency.NewSemaphore(concurrency.DefaultConcurrency)
@@ -131,11 +131,12 @@ func Create(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, *errsvc.Error)
 }
 
 func completeKV(kv *model.KVDoc, revision int64) error {
-	id, err := uuid.NewV4()
-	if err != nil {
-		return err
-	}
-	kv.ID = id.String()
+	kv.ID = fmt.Sprintf("%x", sha1.Sum([]byte(strings.Join([]string{
+		kv.Domain,
+		kv.Project,
+		kv.Key,
+		kv.LabelFormat,
+	}, "/"))))
 	kv.UpdateRevision = revision
 	kv.CreateRevision = revision
 	now := time.Now().Unix()