Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tsm1] Change timestamp from time.Time to unixnano #5522

Merged
merged 4 commits into from
Feb 4, 2016
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#5226](https://github.com/influxdata/influxdb/pull/5226): b\*1 to tsm1 shard conversion tool.
- [#5459](https://github.com/influxdata/influxdb/pull/5459): Create `/status` endpoint for health checks.
- [#5460](https://github.com/influxdata/influxdb/pull/5460): Prevent exponential growth in CLI history. Thanks @sczk!
- [#5522](https://github.com/influxdata/influxdb/pull/5522): Optimize tsm1 cache to reduce memory consumption and GC scan time.

### Bugfixes
- [#5129](https://github.com/influxdata/influxdb/pull/5129): Ensure precision flag is respected by CLI. Thanks @e-dard
Expand Down
10 changes: 10 additions & 0 deletions tsdb/engine/tsm1/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,13 @@ func mustMarshalEntry(entry WALEntry) (WalEntryType, []byte) {

return entry.Type(), snappy.Encode(b, b)
}

func BenchmarkCacheFloatEntries(b *testing.B) {
for i := 0; i < b.N; i++ {
cache := NewCache(10000)
for j := 0; j < 10000; j++ {
v := NewValue(time.Unix(1, 0), float64(j))
cache.Write("test", []Value{v})
}
}
}
57 changes: 29 additions & 28 deletions tsdb/engine/tsm1/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ type Value interface {
}

func NewValue(t time.Time, value interface{}) Value {
un := t.UnixNano()
switch v := value.(type) {
case int64:
return &Int64Value{time: t, value: v}
return &Int64Value{unixnano: un, value: v}
case float64:
return &FloatValue{time: t, value: v}
return &FloatValue{unixnano: un, value: v}
case bool:
return &BoolValue{time: t, value: v}
return &BoolValue{unixnano: un, value: v}
case string:
return &StringValue{time: t, value: v}
return &StringValue{unixnano: un, value: v}
}
return &EmptyValue{}
}
Expand Down Expand Up @@ -222,16 +223,16 @@ func (a Values) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Values) Less(i, j int) bool { return a[i].Time().UnixNano() < a[j].Time().UnixNano() }

type FloatValue struct {
time time.Time
value float64
unixnano int64
value float64
}

func (f *FloatValue) Time() time.Time {
return f.time
return time.Unix(0, f.unixnano)
}

func (f *FloatValue) UnixNano() int64 {
return f.time.UnixNano()
return f.unixnano
}

func (f *FloatValue) Value() interface{} {
Expand Down Expand Up @@ -308,10 +309,10 @@ func DecodeFloatBlock(block []byte, a []FloatValue) ([]FloatValue, error) {
ts := dec.Read()
v := iter.Values()
if i < len(a) {
a[i].time = ts
a[i].unixnano = ts.UnixNano()
a[i].value = v
} else {
a = append(a, FloatValue{ts, v})
a = append(a, FloatValue{ts.UnixNano(), v})
}
i++
}
Expand All @@ -329,20 +330,20 @@ func DecodeFloatBlock(block []byte, a []FloatValue) ([]FloatValue, error) {
}

type BoolValue struct {
time time.Time
value bool
unixnano int64
value bool
}

func (b *BoolValue) Time() time.Time {
return b.time
return time.Unix(0, b.unixnano)
}

func (b *BoolValue) Size() int {
return 9
}

func (b *BoolValue) UnixNano() int64 {
return b.time.UnixNano()
return b.unixnano
}

func (b *BoolValue) Value() interface{} {
Expand Down Expand Up @@ -410,10 +411,10 @@ func DecodeBoolBlock(block []byte, a []BoolValue) ([]BoolValue, error) {
ts := dec.Read()
v := vdec.Read()
if i < len(a) {
a[i].time = ts
a[i].unixnano = ts.UnixNano()
a[i].value = v
} else {
a = append(a, BoolValue{ts, v})
a = append(a, BoolValue{ts.UnixNano(), v})
}
i++
}
Expand All @@ -431,20 +432,20 @@ func DecodeBoolBlock(block []byte, a []BoolValue) ([]BoolValue, error) {
}

type Int64Value struct {
time time.Time
value int64
unixnano int64
value int64
}

func (v *Int64Value) Time() time.Time {
return v.time
return time.Unix(0, v.unixnano)
}

func (v *Int64Value) Value() interface{} {
return v.value
}

func (v *Int64Value) UnixNano() int64 {
return v.time.UnixNano()
return v.unixnano
}

func (v *Int64Value) Size() int {
Expand Down Expand Up @@ -500,10 +501,10 @@ func DecodeInt64Block(block []byte, a []Int64Value) ([]Int64Value, error) {
ts := tsDec.Read()
v := vDec.Read()
if i < len(a) {
a[i].time = ts
a[i].unixnano = ts.UnixNano()
a[i].value = v
} else {
a = append(a, Int64Value{ts, v})
a = append(a, Int64Value{ts.UnixNano(), v})
}
i++
}
Expand All @@ -521,20 +522,20 @@ func DecodeInt64Block(block []byte, a []Int64Value) ([]Int64Value, error) {
}

type StringValue struct {
time time.Time
value string
unixnano int64
value string
}

func (v *StringValue) Time() time.Time {
return v.time
return time.Unix(0, v.unixnano)
}

func (v *StringValue) Value() interface{} {
return v.value
}

func (v *StringValue) UnixNano() int64 {
return v.time.UnixNano()
return v.unixnano
}

func (v *StringValue) Size() int {
Expand Down Expand Up @@ -593,10 +594,10 @@ func DecodeStringBlock(block []byte, a []StringValue) ([]StringValue, error) {
ts := tsDec.Read()
v := vDec.Read()
if i < len(a) {
a[i].time = ts
a[i].unixnano = ts.UnixNano()
a[i].value = v
} else {
a = append(a, StringValue{ts, v})
a = append(a, StringValue{ts.UnixNano(), v})
}
i++
}
Expand Down
10 changes: 5 additions & 5 deletions tsdb/engine/tsm1/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,29 +462,29 @@ func (w *WriteWALEntry) UnmarshalBinary(b []byte) error {
}

for j := 0; j < nvals; j++ {
t := time.Unix(0, int64(btou64(b[i:i+8])))
un := int64(btou64(b[i : i+8]))
i += 8

switch typ {
case float64EntryType:
v := math.Float64frombits((btou64(b[i : i+8])))
i += 8
if fv, ok := values[j].(*FloatValue); ok {
fv.time = t
fv.unixnano = un
fv.value = v
}
case int64EntryType:
v := int64(btou64(b[i : i+8]))
i += 8
if fv, ok := values[j].(*Int64Value); ok {
fv.time = t
fv.unixnano = un
fv.value = v
}
case boolEntryType:
v := b[i]
i += 1
if fv, ok := values[j].(*BoolValue); ok {
fv.time = t
fv.unixnano = un
if v == 1 {
fv.value = true
} else {
Expand All @@ -501,7 +501,7 @@ func (w *WriteWALEntry) UnmarshalBinary(b []byte) error {
v := string(b[i : i+length])
i += length
if fv, ok := values[j].(*StringValue); ok {
fv.time = t
fv.unixnano = un
fv.value = v
}
default:
Expand Down