Documentation
¶
Overview ¶
Package microblob implements a thin layer above LevelDB to implement a key-value store.
Index ¶
- Constants
- Variables
- func Append(blobfn, fn string, backend Backend, kf KeyFunc) error
- func AppendBatchSize(blobfn, fn string, backend Backend, kf KeyFunc, size int) (err error)
- func IsAllZero(p []byte) bool
- func NewHandler(backend Backend, blobfile string) http.Handler
- func WithLastResponseTime(h http.Handler) http.Handler
- type Backend
- type BlobHandler
- type Counter
- type DebugBackend
- type Entry
- type EntryWriter
- type KeyExtractor
- type KeyFunc
- type LevelDBBackend
- type LineProcessor
- type ParsingExtractor
- type RegexpExtractor
- type UpdateHandler
Constants ¶
const Version = "0.2.3"
Version of application.
Variables ¶
var ErrInvalidValue = errors.New("invalid entry")
ErrInvalidValue if a value is corrupted.
Functions ¶
func Append ¶ added in v0.1.17
Append add a file to an existing blob file and adds their keys to the store.
func AppendBatchSize ¶ added in v0.1.17
AppendBatchSize uses a given batch size.
func NewHandler ¶ added in v0.2.0
NewHandler sets up routes for serving and stats.
Types ¶
type Backend ¶
type Backend interface { Get(key string) ([]byte, error) WriteEntries(entries []Entry) error Close() error }
Backend abstracts various implementations.
type BlobHandler ¶
type BlobHandler struct {
Backend Backend
}
BlobHandler serves blobs.
func (*BlobHandler) ServeHTTP ¶
func (h *BlobHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves HTTP.
type DebugBackend ¶
DebugBackend just writes the key, value and offsets to a given writer.
func (DebugBackend) Get ¶
func (b DebugBackend) Get(key string) ([]byte, error)
Get is a noop, always return nothing.
func (DebugBackend) WriteEntries ¶
func (b DebugBackend) WriteEntries(entries []Entry) error
WriteEntries write entries as TSV to the given writer.
type EntryWriter ¶
EntryWriter writes entries to some storage, e.g. a file or a database.
type KeyExtractor ¶
KeyExtractor extracts a string key from data.
type LevelDBBackend ¶
type LevelDBBackend struct { Blobfile string Filename string AllowEmptyValues bool // contains filtered or unexported fields }
LevelDBBackend writes entries into LevelDB.
func (*LevelDBBackend) Close ¶
func (b *LevelDBBackend) Close() error
Close closes database handle and blob file.
func (*LevelDBBackend) Count ¶ added in v0.1.20
func (b *LevelDBBackend) Count() (n int64, err error)
Count returns the number of documents added. LevelDB says: There is no way to implement Count more efficiently inside leveldb than outside.
func (*LevelDBBackend) Get ¶
func (b *LevelDBBackend) Get(key string) (data []byte, err error)
Get retrieves the data for a given key, using pread(2).
func (*LevelDBBackend) WriteEntries ¶
func (b *LevelDBBackend) WriteEntries(entries []Entry) error
WriteEntries writes entries as batch into LevelDB. The value is fixed 16 byte slice, first 8 bytes represents the offset, last 8 bytes the length. https://play.golang.org/p/xwX8BmWtVl
type LineProcessor ¶
type LineProcessor struct { BatchSize int // number of lines in a batch InitialOffset int64 // allow offsets beside zero // contains filtered or unexported fields }
LineProcessor reads a line, extracts the key and writes entries.
func NewLineProcessor ¶
func NewLineProcessor(r io.Reader, w EntryWriter, f KeyFunc) LineProcessor
NewLineProcessor reads lines from the given reader, extracts the key with the given key function and writes entries to the given entry writer.
func NewLineProcessorBatchSize ¶
func NewLineProcessorBatchSize(r io.Reader, w EntryWriter, f KeyFunc, size int) LineProcessor
NewLineProcessorBatchSize reads lines from the given reader, extracts the key with the given key function and writes entries to the given entry writer. Additionally, the number of lines per batch can be specified.
func (LineProcessor) Run ¶
func (p LineProcessor) Run() error
Run starts processing the input, sequential version. TODO(miku): Remove, since this is not used anymore.
func (LineProcessor) RunWithWorkers ¶
func (p LineProcessor) RunWithWorkers() error
RunWithWorkers start processing the input, uses multiple workers.
type ParsingExtractor ¶
type ParsingExtractor struct {
Key string
}
ParsingExtractor actually parses the JSON and extracts a top-level key at the given path. This is slower than for example regular expressions, but not too much.
func (ParsingExtractor) ExtractKey ¶
func (e ParsingExtractor) ExtractKey(b []byte) (s string, err error)
ExtractKey extracts the key. Fails, if key cannot be found in the document.
type RegexpExtractor ¶
RegexpExtractor extract a key via regular expression.
func (RegexpExtractor) ExtractKey ¶
func (e RegexpExtractor) ExtractKey(b []byte) (string, error)
ExtractKey returns the key found in a byte slice. Never fails, just might return unexpected values.
type UpdateHandler ¶ added in v0.1.17
UpdateHandler adds more data to the blob server.
func (UpdateHandler) ServeHTTP ¶ added in v0.1.17
func (u UpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP appends data from POST body to existing blob file.