Skip to content

Commit

Permalink
Reset everything
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Jul 4, 2021
1 parent 4861b0d commit c55ac69
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 55 deletions.
4 changes: 2 additions & 2 deletions disk_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ func (d *diskPartition) selectDataPoints(metric string, labels []Label, start, e
}
decoder, err := newSeriesDecoder(r)
if err != nil {
return nil, fmt.Errorf("failed to generate decoder: %w", err)
return nil, fmt.Errorf("failed to generate decoder for metric %q in %q: %w", name, d.dirPath, err)
}

// TODO: Use binary search to select points on disk
points := make([]*DataPoint, 0, mt.NumDataPoints)
for i := 0; i < int(mt.NumDataPoints); i++ {
point := &DataPoint{}
if err := decoder.decodePoint(point); err != nil {
return nil, fmt.Errorf("failed to decode point: %w", err)
return nil, fmt.Errorf("failed to decode point of metric %q in %q: %w", name, d.dirPath, err)
}
if point.Timestamp < start {
continue
Expand Down
15 changes: 13 additions & 2 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,24 @@ func (e *gorillaEncoder) encodePoint(point *DataPoint) error {
}

// flush writes the buffered-bytes into the backend io.Writer
// and resets everything used for computation.
func (e *gorillaEncoder) flush() error {
// FIXME: Compress with ZStandard
_, err := e.w.Write(e.buf.bytes())
if err != nil {
return fmt.Errorf("failed to flush buffered bytes: %w", err)
}

e.buf.reset()
e.t0 = 0
e.t1 = 0
e.t = 0
e.tDelta = 0
e.v = 0
e.v = 0
e.leading = 0
e.trailing = 0

return nil
}

Expand Down Expand Up @@ -210,11 +221,11 @@ func (d *gorillaDecoder) decodePoint(dst *DataPoint) error {
if d.numRead == 0 {
t, err := binary.ReadVarint(&d.br)
if err != nil {
return err
return fmt.Errorf("failed to read Timestamp of T0: %w", err)
}
v, err := d.br.readBits(64)
if err != nil {
return err
return fmt.Errorf("failed to read Value of T0: %w", err)
}
d.t = t
d.v = math.Float64frombits(v)
Expand Down
102 changes: 51 additions & 51 deletions storage_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func ExampleStorage_Select_from_disk() {

storage, err := tstorage.NewStorage(
tstorage.WithDataPath(tmpDir),
tstorage.WithPartitionDuration(10*time.Second),
tstorage.WithPartitionDuration(100*time.Second),
tstorage.WithTimestampPrecision(tstorage.Seconds),
)
if err != nil {
Expand Down Expand Up @@ -417,56 +417,56 @@ func ExampleStorage_Select_from_disk() {
//Timestamp: 1600000048, Value: 0.1
//Timestamp: 1600000049, Value: 0.1
//Data points of metric2:
//Timestamp: 1600000050, Value: 0.2
//Timestamp: 1600000051, Value: 0.2
//Timestamp: 1600000052, Value: 0.2
//Timestamp: 1600000053, Value: 0.2
//Timestamp: 1600000054, Value: 0.2
//Timestamp: 1600000055, Value: 0.2
//Timestamp: 1600000056, Value: 0.2
//Timestamp: 1600000057, Value: 0.2
//Timestamp: 1600000058, Value: 0.2
//Timestamp: 1600000059, Value: 0.2
//Timestamp: 1600000060, Value: 0.2
//Timestamp: 1600000061, Value: 0.2
//Timestamp: 1600000062, Value: 0.2
//Timestamp: 1600000063, Value: 0.2
//Timestamp: 1600000064, Value: 0.2
//Timestamp: 1600000065, Value: 0.2
//Timestamp: 1600000066, Value: 0.2
//Timestamp: 1600000067, Value: 0.2
//Timestamp: 1600000068, Value: 0.2
//Timestamp: 1600000069, Value: 0.2
//Timestamp: 1600000070, Value: 0.2
//Timestamp: 1600000071, Value: 0.2
//Timestamp: 1600000072, Value: 0.2
//Timestamp: 1600000073, Value: 0.2
//Timestamp: 1600000074, Value: 0.2
//Timestamp: 1600000075, Value: 0.2
//Timestamp: 1600000076, Value: 0.2
//Timestamp: 1600000077, Value: 0.2
//Timestamp: 1600000078, Value: 0.2
//Timestamp: 1600000079, Value: 0.2
//Timestamp: 1600000080, Value: 0.2
//Timestamp: 1600000081, Value: 0.2
//Timestamp: 1600000082, Value: 0.2
//Timestamp: 1600000083, Value: 0.2
//Timestamp: 1600000084, Value: 0.2
//Timestamp: 1600000085, Value: 0.2
//Timestamp: 1600000086, Value: 0.2
//Timestamp: 1600000087, Value: 0.2
//Timestamp: 1600000088, Value: 0.2
//Timestamp: 1600000089, Value: 0.2
//Timestamp: 1600000090, Value: 0.2
//Timestamp: 1600000091, Value: 0.2
//Timestamp: 1600000092, Value: 0.2
//Timestamp: 1600000093, Value: 0.2
//Timestamp: 1600000094, Value: 0.2
//Timestamp: 1600000095, Value: 0.2
//Timestamp: 1600000096, Value: 0.2
//Timestamp: 1600000097, Value: 0.2
//Timestamp: 1600000098, Value: 0.2
//Timestamp: 1600000099, Value: 0.2
//Timestamp: 1600000000, Value: 0.2
//Timestamp: 1600000001, Value: 0.2
//Timestamp: 1600000002, Value: 0.2
//Timestamp: 1600000003, Value: 0.2
//Timestamp: 1600000004, Value: 0.2
//Timestamp: 1600000005, Value: 0.2
//Timestamp: 1600000006, Value: 0.2
//Timestamp: 1600000007, Value: 0.2
//Timestamp: 1600000008, Value: 0.2
//Timestamp: 1600000009, Value: 0.2
//Timestamp: 1600000010, Value: 0.2
//Timestamp: 1600000011, Value: 0.2
//Timestamp: 1600000012, Value: 0.2
//Timestamp: 1600000013, Value: 0.2
//Timestamp: 1600000014, Value: 0.2
//Timestamp: 1600000015, Value: 0.2
//Timestamp: 1600000016, Value: 0.2
//Timestamp: 1600000017, Value: 0.2
//Timestamp: 1600000018, Value: 0.2
//Timestamp: 1600000019, Value: 0.2
//Timestamp: 1600000020, Value: 0.2
//Timestamp: 1600000021, Value: 0.2
//Timestamp: 1600000022, Value: 0.2
//Timestamp: 1600000023, Value: 0.2
//Timestamp: 1600000024, Value: 0.2
//Timestamp: 1600000025, Value: 0.2
//Timestamp: 1600000026, Value: 0.2
//Timestamp: 1600000027, Value: 0.2
//Timestamp: 1600000028, Value: 0.2
//Timestamp: 1600000029, Value: 0.2
//Timestamp: 1600000030, Value: 0.2
//Timestamp: 1600000031, Value: 0.2
//Timestamp: 1600000032, Value: 0.2
//Timestamp: 1600000033, Value: 0.2
//Timestamp: 1600000034, Value: 0.2
//Timestamp: 1600000035, Value: 0.2
//Timestamp: 1600000036, Value: 0.2
//Timestamp: 1600000037, Value: 0.2
//Timestamp: 1600000038, Value: 0.2
//Timestamp: 1600000039, Value: 0.2
//Timestamp: 1600000040, Value: 0.2
//Timestamp: 1600000041, Value: 0.2
//Timestamp: 1600000042, Value: 0.2
//Timestamp: 1600000043, Value: 0.2
//Timestamp: 1600000044, Value: 0.2
//Timestamp: 1600000045, Value: 0.2
//Timestamp: 1600000046, Value: 0.2
//Timestamp: 1600000047, Value: 0.2
//Timestamp: 1600000048, Value: 0.2
//Timestamp: 1600000049, Value: 0.2
}

func ExampleStorage_InsertRows_concurrent() {
Expand Down

0 comments on commit c55ac69

Please sign in to comment.