Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ type Key struct {
// Namespace is an optional cache namespace.
Namespace string

// MaxResultRows must contain `max_result_rows` query arg
MaxResultRows string

// Extremes must contain `extremes` query arg
Extremes string

// ResultOverflowMode must contain `result_overflow_mode` query arg
ResultOverflowMode string

// UserParamsHash must contain hashed value of users params
UserParamsHash uint32
}

// String returns string representation of the key.
func (k *Key) String() string {
s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; UserParams=%d",
cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace, k.UserParamsHash)
s := fmt.Sprintf("V%d; Query=%q; AcceptEncoding=%q; DefaultFormat=%q; Database=%q; Compress=%q; EnableHTTPCompression=%q; Namespace=%q; MaxResultRows=%q; Extremes=%q; ResultOverflowMode=%q; UserParams=%d",
cacheVersion, k.Query, k.AcceptEncoding, k.DefaultFormat, k.Database, k.Compress, k.EnableHTTPCompression, k.Namespace,
k.MaxResultRows, k.Extremes, k.ResultOverflowMode, k.UserParamsHash)
h := sha256.Sum256([]byte(s))

// The first 16 bytes of the hash should be enough
Expand Down
12 changes: 6 additions & 6 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ func TestKeyString(t *testing.T) {
key: &Key{
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
},
expected: "b84443ea3b7651f8eed84ad70cc17d55",
expected: "bebe3382e36ffdeea479b45d827b208a",
},
{
key: &Key{
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
AcceptEncoding: "gzip",
},
expected: "baece3cc15d1aa1516e2729409ece703",
expected: "498c1af30fb94280fd7c7225c0c8fb39",
},
{
key: &Key{
Query: []byte("SELECT 1 FROM system.numbers LIMIT 10"),
AcceptEncoding: "gzip",
DefaultFormat: "JSON",
},
expected: "c238bde938f93419e93b5b7b0341f1ef",
expected: "720292aa0647cc5e53e0b6e6033eef34",
},
{
key: &Key{
Expand All @@ -72,7 +72,7 @@ func TestKeyString(t *testing.T) {
DefaultFormat: "JSON",
Database: "foobar",
},
expected: "e55de3951f08688a34e589caaeed437f",
expected: "5c6a70736d71e570faca739c4557780c",
},
{
key: &Key{
Expand All @@ -82,7 +82,7 @@ func TestKeyString(t *testing.T) {
Database: "foobar",
Namespace: "ns123",
},
expected: "a8676b65119982a1fa135005e0583a07",
expected: "08b4baf6825e53bbd18136a88abda4f8",
},
{
key: &Key{
Expand All @@ -93,7 +93,7 @@ func TestKeyString(t *testing.T) {
Compress: "1",
Namespace: "ns123",
},
expected: "9a2ad211524d5c8983d43784fd59677d",
expected: "0e043f23ccd1b9039b33623b3b7c114a",
},
}

Expand Down
3 changes: 3 additions & 0 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ func (rp *reverseProxy) serveFromCache(s *scope, srw *statResponseWriter, req *h
Compress: origParams.Get("compress"),
EnableHTTPCompression: origParams.Get("enable_http_compression"),
Namespace: origParams.Get("cache_namespace"),
Extremes: origParams.Get("extremes"),
MaxResultRows: origParams.Get("max_result_rows"),
ResultOverflowMode: origParams.Get("result_overflow_mode"),
UserParamsHash: paramsHash,
}

Expand Down
6 changes: 6 additions & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ var allowedParams = []string{
"decompress",
// compress the result if the client over HTTP said that it understands data compressed by gzip or deflate.
"enable_http_compression",
// limit on the number of rows in the result
"max_result_rows",
// whether to count extreme values
"extremes",
// what to do if the volume of the result exceeds one of the limits
"result_overflow_mode",
}

// This regexp must match params needed to describe a way to use external data
Expand Down