浏览代码

store: add 0 as padding for better lexicographic sorting.

Xiang Li 10 年之前
父节点
当前提交
a7b9bff939
共有 3 个文件被更改,包括 8 次插入8 次删除
  1. 4 4
      Documentation/api.md
  2. 3 3
      integration/v2_http_kv_test.go
  3. 1 1
      store/store.go

+ 4 - 4
Documentation/api.md

@@ -380,7 +380,7 @@ curl http://127.0.0.1:2379/v2/keys/queue -XPOST -d value=Job1
     "action": "create",
     "node": {
         "createdIndex": 6,
-        "key": "/queue/6",
+        "key": "/queue/00000000000000000006",
         "modifiedIndex": 6,
         "value": "Job1"
     }
@@ -399,7 +399,7 @@ curl http://127.0.0.1:2379/v2/keys/queue -XPOST -d value=Job2
     "action": "create",
     "node": {
         "createdIndex": 29,
-        "key": "/queue/29",
+        "key": "/queue/00000000000000000029",
         "modifiedIndex": 29,
         "value": "Job2"
     }
@@ -423,13 +423,13 @@ curl -s 'http://127.0.0.1:2379/v2/keys/queue?recursive=true&sorted=true'
         "nodes": [
             {
                 "createdIndex": 2,
-                "key": "/queue/2",
+                "key": "/queue/00000000000000000002",
                 "modifiedIndex": 2,
                 "value": "Job1"
             },
             {
                 "createdIndex": 3,
-                "key": "/queue/3",
+                "key": "/queue/00000000000000000003",
                 "modifiedIndex": 3,
                 "value": "Job2"
             }

+ 3 - 3
integration/v2_http_kv_test.go

@@ -541,7 +541,7 @@ func TestV2Unique(t *testing.T) {
 			http.StatusCreated,
 			map[string]interface{}{
 				"node": map[string]interface{}{
-					"key":   "/foo/4",
+					"key":   "/foo/00000000000000000004",
 					"value": "XXX",
 				},
 				"action": "create",
@@ -553,7 +553,7 @@ func TestV2Unique(t *testing.T) {
 			http.StatusCreated,
 			map[string]interface{}{
 				"node": map[string]interface{}{
-					"key":   "/foo/5",
+					"key":   "/foo/00000000000000000005",
 					"value": "XXX",
 				},
 				"action": "create",
@@ -565,7 +565,7 @@ func TestV2Unique(t *testing.T) {
 			http.StatusCreated,
 			map[string]interface{}{
 				"node": map[string]interface{}{
-					"key":   "/bar/6",
+					"key":   "/bar/00000000000000000006",
 					"value": "XXX",
 				},
 				"action": "create",

+ 1 - 1
store/store.go

@@ -495,7 +495,7 @@ func (s *store) internalCreate(nodePath string, dir bool, value string, unique,
 	currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
 
 	if unique { // append unique item under the node path
-		nodePath += "/" + strconv.FormatUint(nextIndex, 10)
+		nodePath += "/" + fmt.Sprintf("%020s", strconv.FormatUint(nextIndex, 10))
 	}
 
 	nodePath = path.Clean(path.Join("/", nodePath))