Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(context, msg string)
- func Fatal(context, msg string, err error)
- func Info(context, action string)
- func ParseLevel(level string, defaultLevel zerolog.Level) zerolog.Level
- func ResponseHandler(w http.ResponseWriter, r *http.Request, data []byte)
- type Batch
- func (b *Batch) Abort()
- func (b *Batch) Commit() error
- func (b *Batch) Delete(id, topic []byte) error
- func (b *Batch) DeleteEntry(e *Entry) error
- func (b *Batch) Len() int
- func (b *Batch) Put(value []byte) error
- func (b *Batch) PutEntry(e *Entry) error
- func (b *Batch) Reset()
- func (b *Batch) SetOptions(opts *BatchOptions)
- func (b *Batch) Write() error
- type BatchGroup
- type BatchOptions
- type DB
- func (db *DB) Batch(fn func(*Batch, <-chan struct{}) error) error
- func (db *DB) Close() error
- func (db *DB) Count() int64
- func (db *DB) Delete(id, topic []byte) error
- func (db *DB) DeleteEntry(e *Entry) error
- func (db *DB) ExpireOldEntries()
- func (db *DB) FileSize() (int64, error)
- func (db *DB) Get(q *Query) (items [][]byte, err error)
- func (db *DB) HandleVarz(w http.ResponseWriter, r *http.Request)
- func (db *DB) Items(q *Query) (*ItemIterator, error)
- func (db *DB) LogSeq() uint64
- func (db *DB) NewBatchGroup() *BatchGroup
- func (db *DB) NewContract() (uint32, error)
- func (db *DB) NewID() []byte
- func (db *DB) Put(topic, value []byte) error
- func (db *DB) PutEntry(e *Entry) error
- func (db *DB) Seq() uint64
- func (db *DB) SetEntry(e *Entry, payload []byte) error
- func (db *DB) Varz() (*Varz, error)
- type Entry
- type Filter
- type Item
- type ItemIterator
- type Meter
- type Once
- type Options
- type Query
- type Varz
Constants ¶
const ( // MaxTopicLength is the maximum size of a topic in bytes. MaxTopicLength = 1 << 16 // MaxValueLength is the maximum size of a value in bytes. MaxValueLength = 1 << 30 // MaxKeys is the maximum numbers of keys in the DB. MaxKeys = math.MaxInt64 // MaxSeq is the maximum number of seq supported. MaxSeq = uint64(1<<56 - 1) )
Variables ¶
var DefaultBatchOptions = &BatchOptions{ Order: 0, Topic: nil, Contract: message.MasterContract, Encryption: false, AllowDuplicates: false, }
DefaultBatchOptions contains default options when writing batches to unitdb key-value store.
Functions ¶
func Debug ¶
func Debug(context, msg string)
Debug logs the debug message with tag if it is turned on.
func ParseLevel ¶
ParseLevel parses a string which represents a log level and returns a zerolog.Level.
func ResponseHandler ¶
func ResponseHandler(w http.ResponseWriter, r *http.Request, data []byte)
ResponseHandler handles responses for monitoring routes
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch is a write batch.
func (*Batch) Abort ¶
func (b *Batch) Abort()
Abort abort is a batch cleanup operation on batch complete
func (*Batch) Commit ¶
Commit commits changes to the DB. In batch operation commit is managed and client is not allowed to call Commit. On Commit complete batch operation signal to the cliend if the batch is fully commmited to DB.
func (*Batch) Delete ¶
Delete appends delete entry to batch for given key. It is safe to modify the contents of the argument after Delete returns but not before.
func (*Batch) DeleteEntry ¶
DeleteEntry appends entry for deletion to a batch for given key. It is safe to modify the contents of the argument after Delete returns but not before.
func (*Batch) Put ¶
Put adds entry to batch for given topic->key/value. Client must provide Topic to the BatchOptions. It is safe to modify the contents of the argument after Put returns but not before.
func (*Batch) PutEntry ¶
PutEntry appends entries to a bacth for given topic->key/value pair. It is safe to modify the contents of the argument after Put returns but not before.
func (*Batch) SetOptions ¶
func (b *Batch) SetOptions(opts *BatchOptions)
SetOptions sets batch options to defer default option and use options specified by client program
type BatchGroup ¶
type BatchGroup struct { *DB // contains filtered or unexported fields }
BatchGroup runs multiple batches concurrently without causing conflicts
func (*BatchGroup) Abort ¶
func (g *BatchGroup) Abort()
Abort abort is a batch cleanup operation on batch group complete
func (*BatchGroup) Add ¶
func (g *BatchGroup) Add(fn func(*Batch, <-chan struct{}) error)
Add adds a function to the Group. The function will be executed in its own goroutine when Run is called. Add must be called before Run.
func (*BatchGroup) Run ¶
func (g *BatchGroup) Run() error
Run exectues each function registered via Add in its own goroutine. Run blocks until all functions have returned. The first function to return will trigger the closure of the channel passed to each function, who should in turn, return. The return value from the first function to exit will be returned to the caller of Run.
type BatchOptions ¶
type BatchOptions struct { // In concurrent batch writes order determines how to handle conflicts Order int8 Topic []byte Contract uint32 Encryption bool AllowDuplicates bool }
BatchOptions is used to set options when using batch operation
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the message storage for topic->keys-values. All DB methods are safe for concurrent use by multiple goroutines.
func (*DB) Batch ¶
Batch executes a function within the context of a read-write managed transaction. If no error is returned from the function then the transaction is written. If an error is returned then the entire transaction is rolled back. Any error that is returned from the function or returned from the write is returned from the Batch() method.
Attempting to manually commit or rollback within the function will cause a panic.
func (*DB) Delete ¶
Delete sets entry for deletion. It is safe to modify the contents of the argument after Delete returns but not before.
func (*DB) DeleteEntry ¶
DeleteEntry deletes an entry from DB. you must provide an ID to delete an entry. It is safe to modify the contents of the argument after Delete returns but not before.
func (*DB) ExpireOldEntries ¶
func (db *DB) ExpireOldEntries()
ExpireOldEntries run expirer to delete entries from db if ttl was set on entries and it has expired
func (*DB) HandleVarz ¶
func (db *DB) HandleVarz(w http.ResponseWriter, r *http.Request)
HandleVarz will process HTTP requests for unitdb stats information.
func (*DB) Items ¶
func (db *DB) Items(q *Query) (*ItemIterator, error)
Items returns a new ItemIterator.
func (*DB) NewBatchGroup ¶
func (db *DB) NewBatchGroup() *BatchGroup
NewBatchGroup create new group to runs multiple batches concurrently without causing conflicts
func (*DB) NewContract ¶
NewContract generates a new Contract.
func (*DB) Put ¶
Put puts entry into DB. It uses default Contract to put entry into DB. It is safe to modify the contents of the argument after Put returns but not before.
func (*DB) PutEntry ¶
PutEntry puts entry into the DB, if Contract is not specified then it uses master Contract. It is safe to modify the contents of the argument after PutEntry returns but not before.
type Entry ¶
type Entry struct { ID []byte // The ID of the message Topic []byte // The topic of the message Payload []byte // The payload of the message ExpiresAt uint32 // The time expiry of the message Contract uint32 // The contract is used to as salt to hash topic parts and also used as prefix in the message Id // contains filtered or unexported fields }
Entry represents an entry which is stored into DB.
func (*Entry) SetContract ¶
SetContract sets contract on entry.
func (*Entry) SetPayload ¶
SetPayload sets payload to put entry into DB.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter filter is bloom filter generator
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item items returned by the iterator
type ItemIterator ¶
type ItemIterator struct {
// contains filtered or unexported fields
}
ItemIterator is an iterator over DB topic->key/value pairs. It iterates the items in an unspecified order.
func (*ItemIterator) Error ¶
func (it *ItemIterator) Error() error
Error returns any accumulated error. Exhausting all the key/value pairs is not considered to be an error. A memory iterator cannot encounter errors.
func (*ItemIterator) First ¶
func (it *ItemIterator) First()
First is similar to init. It query and loads window entries from trie/timeWindowBucket or summary file if available.
func (*ItemIterator) Item ¶
func (it *ItemIterator) Item() *Item
Item returns pointer to the current item. This item is only valid until it.Next() gets called.
func (*ItemIterator) Next ¶
func (it *ItemIterator) Next()
Next returns the next topic->key/value pair if available, otherwise it returns ErrIterationDone error.
func (*ItemIterator) Release ¶
func (it *ItemIterator) Release()
Release releases associated resources. Release should always succeed and can be called multiple times without causing error.
func (*ItemIterator) Valid ¶
func (it *ItemIterator) Valid() bool
Valid returns false when iteration is done.
type Meter ¶
type Meter struct { Metrics metrics.Metrics TimeSeries metrics.TimeSeries Gets metrics.Counter Puts metrics.Counter Leased metrics.Counter Syncs metrics.Counter Recovers metrics.Counter Dels metrics.Counter InMsgs metrics.Counter OutMsgs metrics.Counter InBytes metrics.Counter OutBytes metrics.Counter }
Meter meter provides various db statistics
func (*Meter) UnregisterAll ¶
func (m *Meter) UnregisterAll()
UnregisterAll unregister all metrics from meter
type Once ¶
type Once struct {
// contains filtered or unexported fields
}
Once is an object that will perform exactly one action until Reset is called. See http://golang.org/pkg/sync/#Once
func (*Once) Do ¶
func (o *Once) Do(f func())
Do simulates sync.Once.Do by executing the specified function only once, until Reset is called. See http://golang.org/pkg/sync/#Once
type Options ¶
type Options struct { // BackgroundSyncInterval sets the amount of time between background fsync() calls. // // Setting the value to 0 disables the automatic background synchronization. // Setting the value to -1 makes the DB call fsync() after every write operation. BackgroundSyncInterval time.Duration // BackgroundKeyExpiry sets flag to run key expirer BackgroundKeyExpiry bool // Encryption flag to encrypt keys Encryption bool // Encryption Key EncryptionKey []byte // Tiny Batch interval to group tiny batches and write into db on tiny batch interval // Setting the value to 0 immediately writes entries into db. TinyBatchWriteInterval time.Duration // DefaultQueryLimit limits maximum number of records to fetch if the DB Get or DB Iterator method does not specify a limit. DefaultQueryLimit int // MaxQueryLimit limits maximum number of records to fetch if the DB Get or DB Iterator method does not specify a limit or specify a limit larger than MaxQueryResults. MaxQueryLimit int // Size of buffer to use for pooling BufferSize int64 // Size of memory db MemdbSize int64 // Size of write ahead log LogSize int64 // Minimum freeblocks size before free blocks are allocated and reused. MinimumFreeBlocksSize int64 FileSystem fs.FileSystem }
Options holds the optional DB parameters.
type Query ¶
type Query struct { Topic []byte // The topic of the message Contract uint32 // The contract is used as prefix in the message Id Limit int // The maximum number of elements to return. // contains filtered or unexported fields }
Query represents a topic to query and optional contract information.
type Varz ¶
type Varz struct { Start time.Time `json:"start"` Now time.Time `json:"now"` Uptime string `json:"uptime"` Seq int64 `json:"seq"` Count int64 `json:"count"` Blocks int64 `json:"blocks"` Gets int64 `json:"gets"` Puts int64 `json:"puts"` Leased int64 `json:"leased"` Syncs int64 `json:"syncs"` Recovers int64 `json:"recovers"` Dels int64 `json:"Dels"` InMsgs int64 `json:"in_msgs"` OutMsgs int64 `json:"out_msgs"` InBytes int64 `json:"in_bytes"` OutBytes int64 `json:"out_bytes"` HMean float64 `json:"hmean"` // Event duration harmonic mean. P50 float64 `json:"p50"` // Event duration nth percentiles .. P75 float64 `json:"p75"` P95 float64 `json:"p95"` P99 float64 `json:"p99"` P999 float64 `json:"p999"` Long5p float64 `json:"long_5p"` // Average of the longest 5% event durations. Short5p float64 `json:"short_5p"` // Average of the shortest 5% event durations. Max float64 `json:"max"` // Highest event duration. Min float64 `json:"min"` // Lowest event duration. StdDev float64 `json:"stddev"` // Standard deviation. }
Varz outputs unitdb stats on the monitoring port at /varz.