Skip to content

Commit f27fed9

Browse files
author
Pawan Rawal
committed
Fingerprint and base36 encode Keys in TxnContext
1 parent c0a8c54 commit f27fed9

File tree

4 files changed

+6
-17
lines changed

4 files changed

+6
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project will adhere to [Semantic Versioning](http://semver.org/spec/v2.
1717
* Fix TLS flag parsing for Dgraph server and live loader.
1818
* Reduce dependencies for Go client.
1919
* `depth` and `loop` arguments should be inside @recurse().
20+
* Base36 encode keys that are part of TxnContext and are sent to the client.
2021

2122
## [0.9.1] - 2017-11-15
2223

dgraph/cmd/server/http.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package server
1919

2020
import (
2121
"context"
22-
"encoding/base64"
2322
"encoding/json"
2423
"fmt"
2524
"io/ioutil"
@@ -205,11 +204,6 @@ func mutationHandler(w http.ResponseWriter, r *http.Request) {
205204
e.Txn.Keys = e.Txn.Keys[:0]
206205
}
207206

208-
// base64 encode the keys
209-
for i, k := range e.Txn.Keys {
210-
e.Txn.Keys[i] = base64.StdEncoding.EncodeToString([]byte(k))
211-
}
212-
213207
response := map[string]interface{}{}
214208
response["extensions"] = e
215209
mp := map[string]interface{}{}
@@ -272,15 +266,6 @@ func commitHandler(w http.ResponseWriter, r *http.Request) {
272266
return
273267
}
274268

275-
// base64 decode keys
276-
for i, k := range encodedKeys {
277-
data, err := base64.StdEncoding.DecodeString(k)
278-
if err != nil {
279-
x.SetStatus(w, x.Error, "While base64 decoding keys header.")
280-
return
281-
}
282-
encodedKeys[i] = string(data)
283-
}
284269
tc.Keys = encodedKeys
285270

286271
cts, err := worker.CommitOverNetwork(context.Background(), tc)

dgraph/cmd/server/http_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestTransactionBasic(t *testing.T) {
153153
keys, mts, err := mutationWithTs(m1, false, ts)
154154
require.NoError(t, err)
155155
require.Equal(t, mts, ts)
156-
expected := []string{"AAAEbmFtZQAAAAAAAAAAAQ==", "AAAEbmFtZQAAAAAAAAAAAQ==", "AAAEbmFtZQIBYWxpY2U=", "AAAEbmFtZQIBYWxpY2U=", "AAAEbmFtZQIBYm9i", "AAAHYmFsYW5jZQAAAAAAAAAAAQ==", "AAAHYmFsYW5jZQAAAAAAAAAAAg==", "AAALX3ByZWRpY2F0ZV8AAAAAAAAAAAE=", "AAALX3ByZWRpY2F0ZV8AAAAAAAAAAAE=", "AAALX3ByZWRpY2F0ZV8AAAAAAAAAAAE=", "AAALX3ByZWRpY2F0ZV8AAAAAAAAAAAI="}
156+
expected := []string{"16zy665614irg", "1ep5ewu298spd", "2oz0ld779a6yh", "2oz0ld779a6yh", "321112eei4n9g", "321112eei4n9g", "3fk4wxiwz6h3r", "3mlibw7eeno0x", "u5ausuvjgdwg", "u5ausuvjgdwg", "u5ausuvjgdwg"}
157157
sort.Strings(expected)
158158
sort.Strings(keys)
159159
require.Equal(t, expected, keys)

posting/mvcc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import (
2222
"context"
2323
"math"
2424
"sort"
25+
"strconv"
2526
"sync"
2627
"sync/atomic"
2728
"time"
2829

2930
"github.com/dgraph-io/badger"
3031
"github.com/dgraph-io/dgraph/protos"
3132
"github.com/dgraph-io/dgraph/x"
33+
farm "github.com/dgryski/go-farm"
3234
)
3335

3436
var (
@@ -221,7 +223,8 @@ func (t *Txn) Fill(ctx *protos.TxnContext) {
221223
func (t *Txn) fill(ctx *protos.TxnContext) {
222224
ctx.StartTs = t.StartTs
223225
for _, d := range t.deltas {
224-
ctx.Keys = append(ctx.Keys, string(d.key))
226+
fp := farm.Fingerprint64(d.key)
227+
ctx.Keys = append(ctx.Keys, strconv.FormatUint(fp, 36))
225228
}
226229
}
227230

0 commit comments

Comments
 (0)