-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsdb.go
84 lines (66 loc) · 1.99 KB
/
tsdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package tsdb
import (
"fmt"
"os"
"sync"
)
const (
ASC = "asc"
DESC = "desc"
)
type BoltDBConfig struct {
Path string
Mode os.FileMode
}
type TimeEntry struct {
Time int64
Value []byte
}
type Query struct {
Series string
From int64
To int64
//Sorting order:
//Possible values are ASC and DESC
//ASC : The time Series will have the oldest data first
//DESC: The time Series will have the latest data first.
Sort string
//Number of entries to be returned per page. This is used for pagination.
// The next sequence is found out using NextEntry variable of a query response.
MaxEntries int
}
type TimeSeries []TimeEntry
type TSDB interface {
//Create a new bucket
Create(name string) error
//This function adds the senml records
Add(name string, timeseries TimeSeries) error
//Get the senml records
Query(q Query) (timeSeries TimeSeries, nextEntry *int64, err error)
QueryOnChannel(q Query) (timeseries <-chan TimeEntry, nextEntry chan *int64, err chan error)
//Get the total pages for a particular query.
// This helps for any client to call multiple queries
GetPages(q Query) (seriesList []int64, count int, err error)
//Get the senml records
Get(series string) (timeSeries TimeSeries, err error)
//Returns two channels, one for Time entries and one for error.
//This avoids the usage of an extra buffer by the database
//Caution: first read the channel and then read the error. Error channel shall be written only after the timeseries channel is closed
GetOnChannel(series string) (timeseries <-chan TimeEntry, err chan error)
//Delete a complete Series
Delete(series string) error
//Close the database
Close() error
}
var ds TSDB //will be used as a singleton db object
var once sync.Once //make thread safe singleton
func Open(config interface{}) (TSDB, error) {
switch config.(type) {
case BoltDBConfig:
retDB := new(Boltdb)
err := retDB.open(config.(BoltDBConfig))
return retDB, err
default:
return nil, fmt.Errorf("Unsupported storage Configuration")
}
}