Documentation ¶
Index ¶
- func CompareChannels(expected *protoed.Channel, got *protoed.Channel, t *testing.T)
- func Initialize(access Access, path string) (err error)
- type Access
- type Descriptor
- type Env
- type Timestamp
- type Txn
- func (t *Txn) ChannelPage(page uint, perPage uint) (channels []*protoed.Channel, err error)
- func (t *Txn) CountChannels() (count uint64, err error)
- func (t *Txn) CountTimestamps() (count uint64, err error)
- func (t *Txn) GetChannel(descriptor string) (channel *protoed.Channel, err error)
- func (t *Txn) GetTimestamp(descriptor string) (Timestamp *Timestamp, err error)
- func (t *Txn) PutChannel(channel *protoed.Channel) (err error)
- func (t *Txn) PutTimestamp(descriptor Descriptor, Timestamp *Timestamp) (err error)
- func (t *Txn) RemoveChannel(descriptor string) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareChannels ¶
CompareChannels runs a deep comparison between two proto Channel messages, raising errors upon differences.
func Initialize ¶
Initialize initializes the database environment in the given directory. Initialize creates the expected database and should be called only once during the deployment.
Types ¶
type Access ¶
type Access int
Access enumerates different access rights for transactions on the database.
type Descriptor ¶
type Descriptor string
Descriptor is a key at which data is stored in the database.
func DecodeDescriptor ¶
func DecodeDescriptor(data []byte) Descriptor
DecodeDescriptor decodes an array of bytes to a descriptor.
func (Descriptor) Encode ¶
func (d Descriptor) Encode() []byte
Encode encodes the descriptor to an array of bytes.
type Env ¶
Env represents a database of channels.
func NewEnv ¶
NewEnv creates a new database environment object. The database directory is assumed to be already initialized.
type Timestamp ¶
type Timestamp uint64
Timestamp is a timestamp expressed as milliseconds from epoch in UTC.
func DecodeTimestamp ¶
DecodeTimestamp decodes the array of bytes to a timestamp.
func TimestampFromTime ¶
TimestampFromTime converts a time.Time to the corresponding timestamp in nanoseconds.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a transaction over the entries of the database.
func (*Txn) ChannelPage ¶
ChannelPage returns the requested `page` of the database entries.
Given the entire database as a list of channels, the elements starting from index `page*perPage` are inserted in the list sequentially until either the list contains `perPage` elements, or there are no more database entries.
If the database has less than `page*perPage` elements, an empty list is returned. ChannelPage requires: * t.access == ControlAccess
ChannelPage ensures: * err != nil || len(channels) <= int(perPage) * err != nil || !dbc.InTest || !(t.mustCountCh() <= uint64((page-1)*perPage) || len(channels) == 0) * err != nil || !dbc.InTest || !(t.mustCountCh() > uint64((page-1)*perPage) || len(channels) > 0) * err != nil || !dbc.InTest || !(t.mustCountCh() >= uint64(page*perPage) || len(channels) == int(perPage))
func (*Txn) CountChannels ¶
CountChannels returns the number of channels in the database.
CountChannels requires: * t.access == ControlAccess || t.access == RelayAccess
CountChannels ensures: * !dbc.InTest || err != nil || t.mustCountTs() <= count
func (*Txn) CountTimestamps ¶
CountTimestamps returns the number of timestamps in the database.
CountTimestamps requires: * t.access == ControlAccess || t.access == RelayAccess
func (*Txn) GetChannel ¶
GetChannel returns the channel associated with the descriptor in the database, if it exists; nil otherwise.
GetChannel requires: * t.access == ControlAccess || t.access == RelayAccess
GetChannel ensures: * err == nil || channel == nil || channel.Descriptor_ == descriptor * count positive if result: !dbc.InTest || !(err == nil && channel != nil) || t.mustCountCh() > 0 * empty response for empty database: !dbc.InTest || !(err == nil && t.mustCountCh() == 0) || channel == nil
func (*Txn) GetTimestamp ¶
GetTimestamp returns the Timestamp associated with the descriptor in the database, if it exists; nil otherwise.
GetTimestamp requires: * t.access == ControlAccess || t.access == RelayAccess
GetTimestamp ensures: * err == nil || Timestamp == nil || *Timestamp > 0 * !dbc.InTest || !(err == nil && Timestamp != nil) || t.mustCountTs() > 0 * empty response for empty database: !dbc.InTest || !(err == nil && t.mustCountTs() == 0) || Timestamp == nil
func (*Txn) PutChannel ¶
PutChannel inserts a channel in the database, keyed on its descriptor.
PutChannel requires: * t.access == ControlAccess * channel != nil
PutChannel preamble:
var oldHas bool oldCount := uint64(0) if dbc.InTest { oldCount = t.mustCountCh() oldHas = t.mustGetCh(channel.Descriptor_) != nil }
PutChannel ensures: * !dbc.InTest || err != nil || t.mustGetCh(channel.Descriptor_) != nil * !dbc.InTest || err != nil || oldHas || t.mustCountCh() == oldCount+1 * !dbc.InTest || err != nil || !oldHas || t.mustCountCh() == oldCount * !dbc.InTest || err != nil || t.mustGetCh(channel.Descriptor_) == nil || t.mustGetCh(channel.Descriptor_).MinPeriod == channel.MinPeriod || t.mustGetTs(channel.Descriptor_) == nil
func (*Txn) PutTimestamp ¶
func (t *Txn) PutTimestamp(descriptor Descriptor, Timestamp *Timestamp) (err error)
PutTimestamp inserts a Timestamp in the database, keyed on its descriptor.
PutTimestamp requires: * !dbc.InTest || t.access == RelayAccess * Timestamp != nil * *Timestamp > 0
PutTimestamp preamble:
var oldHas bool oldCount := uint64(0) if dbc.InTest { oldCount = t.mustCountTs() oldHas = t.mustGetTs(string(descriptor)) != nil }
PutTimestamp ensures: * !dbc.InTest || err != nil || t.mustGetTs(string(descriptor)) != nil * !dbc.InTest || err != nil || oldHas || t.mustCountTs() == oldCount+1 * !dbc.InTest || err != nil || !oldHas || t.mustCountTs() == oldCount
func (*Txn) RemoveChannel ¶
RemoveChannel removes a channel from the database.
RemoveChannel requires: * t.access == ControlAccess
RemoveChannel preamble:
var oldHasCh, oldHasTs bool oldCountCh := uint64(0) oldCountTs := uint64(0) if dbc.InTest { oldCountTs = t.mustCountTs() oldCountCh = t.mustCountCh() oldHasCh = t.mustGetCh(descriptor) != nil oldHasTs = t.mustGetTs(descriptor) != nil }
RemoveChannel ensures: * !dbc.InTest || err != nil || t.mustGetCh(descriptor) == nil && t.mustGetTs(descriptor) == nil * !dbc.InTest || err != nil || !oldHasCh || t.mustCountCh() == oldCountCh-1 * !dbc.InTest || err != nil || oldHasCh || t.mustCountCh() == oldCountCh * !dbc.InTest || err != nil || !oldHasTs || t.mustCountTs() == oldCountTs-1 * !dbc.InTest || err != nil || oldHasTs || t.mustCountTs() == oldCountTs