From 95d6eafeefe9314062fdc75e7ec10db0a289d232 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Tue, 18 Aug 2015 10:02:48 -0600 Subject: [PATCH] Fix measurement name being double-escaped during replication Fixes #3708 #3704 --- CHANGELOG.md | 3 +++ tsdb/points.go | 4 +++- tsdb/points_test.go | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de2f62541e..4652ed1b275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,9 @@ There are breaking changes in this release. Please see the *Features* section be - [#3673](https://github.com/influxdb/influxdb/pull/3673): Improve query performance by removing unnecessary tagset sorting. - [#3676](https://github.com/influxdb/influxdb/pull/3676): Improve query performance by memomizing mapper output keys. - [#3687](https://github.com/influxdb/influxdb/issues/3687): Fix panic: runtime error: makeslice: len out of range in hinted handoff +- [#3708](https://github.com/influxdb/influxdb/issues/3708): Fix double escaping measurement name during cluster replication +- [#3704](https://github.com/influxdb/influxdb/issues/3704): cluster replication issue for measurement name containing backslash + ## v0.9.2 [2015-07-24] diff --git a/tsdb/points.go b/tsdb/points.go index cc7d6d2e869..92e8e1c7dcf 100644 --- a/tsdb/points.go +++ b/tsdb/points.go @@ -946,7 +946,9 @@ func (p *point) Tags() Tags { } func MakeKey(name []byte, tags Tags) []byte { - return append(escape(name), tags.HashKey()...) + // unescape the name and then re-escape it to avoid double escaping. + // The key should always be stored in escaped form. + return append(escape(unescape(name)), tags.HashKey()...) } // SetTags replaces the tags for the point diff --git a/tsdb/points_test.go b/tsdb/points_test.go index 4efd97ce2a7..2e9f873a902 100644 --- a/tsdb/points_test.go +++ b/tsdb/points_test.go @@ -1216,3 +1216,22 @@ func TestNewPointUnhandledType(t *testing.T) { t.Errorf("NewPoint().String() mismatch.\ngot %v\nexp %v", pt.String(), exp) } } + +func TestMakeKeyEscaped(t *testing.T) { + if exp, got := `cpu\ load`, tsdb.MakeKey([]byte(`cpu\ load`), tsdb.Tags{}); string(got) != exp { + t.Errorf("MakeKey() mismatch.\ngot %v\nexp %v", got, exp) + } + + if exp, got := `cpu\ load`, tsdb.MakeKey([]byte(`cpu load`), tsdb.Tags{}); string(got) != exp { + t.Errorf("MakeKey() mismatch.\ngot %v\nexp %v", got, exp) + } + + if exp, got := `cpu\,load`, tsdb.MakeKey([]byte(`cpu\,load`), tsdb.Tags{}); string(got) != exp { + t.Errorf("MakeKey() mismatch.\ngot %v\nexp %v", got, exp) + } + + if exp, got := `cpu\,load`, tsdb.MakeKey([]byte(`cpu,load`), tsdb.Tags{}); string(got) != exp { + t.Errorf("MakeKey() mismatch.\ngot %v\nexp %v", got, exp) + } + +}