Documentation
¶
Overview ¶
Package btrdb implements bindings to interface with a running instance of the Berkeley Tree Database (BTrDB).
The main abstraction provided is a BTrDBConnection, which represents a single connection to a BTrDB.
Example usage:
import ( "gopkg.in/btrdb.v3" "github.com/pborman/uuid" ) func main() { var myuuid uuid.UUID var err error var bc *btrdb.BTrDBConnection var version uint64 var versionchan chan uint64 var svchan chan btrdb.StandardValue var sv btrdb.StandardValue var points []btrdb.StandardValue var statcode chan string var strstatcode string var asyncerr chan string bc, err = btrdb.NewBTrDBConnection("localhost:4410") if err != nil { /* Fatal error */ } /* UUID of the stream into which to insert/query */ myuuid = uuid.NewRandom() /* Points to insert */ points = []btrdb.StandardValue{ btrdb.StandardValue{Time: 1, Value: 2.0}, btrdb.StandardValue{Time: 4, Value: 7.5}, btrdb.StandardValue{Time: 6, Value: 2.5}, btrdb.StandardValue{Time: 13, Value: 8.0}, btrdb.StandardValue{Time: 15, Value: 6.0}, } /* Insert */ statcode, err = bc.InsertValues(myuuid, points, true) strstatcode = <- statcode if err != nil || "ok" != strstatcode { /* Error */ } /* Standard Values Query */ svchan, versionchan, asyncerr, err = bc.QueryStandardValues(myuuid, 0, 16, 0) if err != nil { /* Error */ } for sv = range svchan { /* Handle Point */ } /* Get the version used to satisfy the query */ version = <- versionchan }
Index ¶
- Constants
- Variables
- type BTrDBConnection
- func (bc *BTrDBConnection) Close() error
- func (bc *BTrDBConnection) DeleteValues(uuid uuid.UUID, start_time int64, end_time int64) (chan string, error)
- func (bc *BTrDBConnection) InsertValues(uuid uuid.UUID, points []StandardValue, sync bool) (chan string, error)
- func (bc *BTrDBConnection) QueryChangedRanges(uuid uuid.UUID, from_generation uint64, to_generation uint64, resolution uint8) (chan TimeRange, chan uint64, chan string, error)
- func (bc *BTrDBConnection) QueryNearestValue(uuid uuid.UUID, time int64, backward bool, version uint64) (chan StandardValue, chan uint64, chan string, error)
- func (bc *BTrDBConnection) QueryStandardValues(uuid uuid.UUID, start_time int64, end_time int64, version uint64) (chan StandardValue, chan uint64, chan string, error)
- func (bc *BTrDBConnection) QueryStatisticalValues(uuid uuid.UUID, start_time int64, end_time int64, point_width uint8, ...) (chan StatisticalValue, chan uint64, chan string, error)
- func (bc *BTrDBConnection) QueryVersion(uuids []uuid.UUID) (chan uint64, chan string, error)
- func (bc *BTrDBConnection) QueryWindowValues(uuid uuid.UUID, start_time int64, end_time int64, width uint64, depth uint8, ...) (chan StatisticalValue, chan uint64, chan string, error)
- type StandardValue
- type StatisticalValue
- type TimeRange
Constants ¶
const BUFFER_LEN = 1024
Variables ¶
var ERR_CLOSED = errors.New("Connection closed")
Error if the connection to BTrDB is lost
Functions ¶
This section is empty.
Types ¶
type BTrDBConnection ¶
type BTrDBConnection struct {
// contains filtered or unexported fields
}
BTrDBConnection abstracts a single connection to a BTrDB. A single BTrDBConnection supports multiple concurrent requests to BTrDB.
func NewBTrDBConnection ¶
func NewBTrDBConnection(addr string) (*BTrDBConnection, error)
Creates a connection to the BTrDB at the provided address, and returns a BTrDBConnection to represent the connection.
func (*BTrDBConnection) Close ¶
func (bc *BTrDBConnection) Close() error
Releases the resources associated with this BTrDBConnection. It is undefined behavior to call this while there are outstanding requests on the connection.
func (*BTrDBConnection) DeleteValues ¶
func (bc *BTrDBConnection) DeleteValues(uuid uuid.UUID, start_time int64, end_time int64) (chan string, error)
Delete values from the specified stream in the specified time range.
Return values are the same as in InsertValues.
func (*BTrDBConnection) InsertValues ¶
func (bc *BTrDBConnection) InsertValues(uuid uuid.UUID, points []StandardValue, sync bool) (chan string, error)
Inserts the points specified in the points slice into the stream corresponding to the specified UUID. If the sync parameter is true, then the BTrDB will commit the points to disk, before sending an acknowledgment; otherwise, it will return an acknowledgment and an OK will be received immediately, but the data will not be immediately queryable.
Returns a channel with the status code of the operation, and an error in case the request could not be sent. When the acknowledgment is received from the BTrDB, the status code will appear on the channel as a string; 'ok' is the value corresponding to success.
func (*BTrDBConnection) QueryChangedRanges ¶
func (bc *BTrDBConnection) QueryChangedRanges(uuid uuid.UUID, from_generation uint64, to_generation uint64, resolution uint8) (chan TimeRange, chan uint64, chan string, error)
Makes a Changed Ranges Query for ranges of time at the specified resolution that correspond to data that changed between the specified versions in the specified stream.
Return values are the same as in QueryStandardValues.
func (*BTrDBConnection) QueryNearestValue ¶
func (bc *BTrDBConnection) QueryNearestValue(uuid uuid.UUID, time int64, backward bool, version uint64) (chan StandardValue, chan uint64, chan string, error)
Makes a Nearest Value Query for the nearest point in the specified stream, at the specified version, nearest to the specified time, in the specified direction. A version number of 0 means to use the latest version of the stream.
Return values are the same as in QueryStandardValues.
func (*BTrDBConnection) QueryStandardValues ¶
func (bc *BTrDBConnection) QueryStandardValues(uuid uuid.UUID, start_time int64, end_time int64, version uint64) (chan StandardValue, chan uint64, chan string, error)
Makes a Standard Values Query for data in the specified stream, at the specified version, in the specified time range. A version number of 0 means to use the latest version of the stream.
Returns three channels and an error. The first channel contains the points satisfying the query. The second channel contains a single value, which is the version of the stream used to satisfy the query. In case BTrDB returns an error code, the third channel will contain a string describing the error. If the operation completes successfully, nothing is sent on this channel; it remains open until all points are consumed from the first channel. The fourth value returned is an error, used if the request cannot be sent to the database.
func (*BTrDBConnection) QueryStatisticalValues ¶
func (bc *BTrDBConnection) QueryStatisticalValues(uuid uuid.UUID, start_time int64, end_time int64, point_width uint8, version uint64) (chan StatisticalValue, chan uint64, chan string, error)
Makes a Statistical Values Query. Data in the specified stream, at the specified version, in the specified time range, is broken up into time intervals, each 1 << point_width nanoseconds in size. For each time interval, a statistical aggregate of the data in the interval is generated containing the number of data points in the interval, and the minimum, mean, and maximum values of data in the interval. A version number of 0 means to use the latest version of the stream.
Should the start and end times not line up with the sizes of the intervals, they are rounded down before making the query. The point_width parameter must be an integer in the interval [0, 62].
Return values are the same as in QueryStandardValues.
func (*BTrDBConnection) QueryVersion ¶
Makes a Version Query for the version corresponding to each of the streams specified by the provided UUIDs.
Returns two channels and an error. The first channel contains the version numbers of the streams, in the same order as they were queried. In case BTrDB returns an error code, the third channel will contain a string describing the error (if the operation completes successfully, nothing is sent on this channel). The fourth value returned is an error, used if the request cannot be sent to the database.
func (*BTrDBConnection) QueryWindowValues ¶
func (bc *BTrDBConnection) QueryWindowValues(uuid uuid.UUID, start_time int64, end_time int64, width uint64, depth uint8, version uint64) (chan StatisticalValue, chan uint64, chan string, error)
Makes a Statistical Values Query. Data in the specified stream, at the specified version, in the specified time range, is broken up into time intervals, of the specified width, in nanoseconds. For each time interval, a statistical aggregate of the data in the interval is generated containing the number of data points in the interval, and the minimum, mean, and maximum values of data in the interval. The endpoints of the intervals are precise up to 1 << depth nanoseconds; the query is more performant for larger values of depth. A version number of 0 means to use the latest version of the stream.
Should the start and end times not line up with the sizes of the intervals, they are rounded down before making the query. The depth parameter must be an integer in the interval [0, 62].
Return values are the same as in QueryStandardValues.
type StandardValue ¶
Represents a single data point.
type StatisticalValue ¶
Represents statistics over a range of data.