// GetSegment returns a segment from storage. func GetSegment(e storage.Tx, domain string, id *uuid.UUID) (*Segment, error) { var ( bytes []byte err error key string ) key = fmt.Sprintf(segmentKey, id) if bytes, err = e.Get(domain, key); err != nil { return nil, err } if bytes == nil { return nil, nil } seg := Segment{ UUID: id, Domain: domain, } if err = unmarshalSegment(bytes, &seg); err != nil { return nil, err } return &seg, nil }
func SetBlock(e storage.Tx, domain string, id *uuid.UUID, idx int, bytes []byte) (int, error) { var key string key = fmt.Sprintf(blockKey, id, idx) return len(bytes), e.Set(domain, key, bytes) }
func GetLog(e storage.Tx, domain, name string) (*Log, error) { var ( bytes []byte err error key string ) key = fmt.Sprintf(logKey, name) if bytes, err = e.Get(domain, key); err != nil { return nil, err } if bytes == nil { return nil, nil } log := Log{ Domain: domain, Name: name, } if err = unmarshalLog(bytes, &log); err != nil { return nil, err } return &log, nil }
// GetBlock returns a block from storage. The lookup requires the domain, ID of the segment // the block is contained in, the index of the block in the segment, and the transaction // that processed the segment. func GetBlock(e storage.Tx, domain string, id *uuid.UUID, idx int) ([]byte, error) { var key string key = fmt.Sprintf(blockKey, id, idx) return e.Get(domain, key) }
func SetLog(e storage.Tx, domain string, log *Log) (int, error) { var ( bytes []byte err error key string ) if bytes, err = marshalLog(log); err != nil { return 0, err } key = fmt.Sprintf(logKey, log.Name) return len(bytes), e.Set(domain, key, bytes) }
func SetSegment(e storage.Tx, domain string, segment *Segment) (int, error) { var ( bytes []byte err error key string ) if bytes, err = marshalSegment(segment); err != nil { return 0, err } key = fmt.Sprintf(segmentKey, segment.UUID) return len(bytes), e.Set(domain, key, bytes) }
func DeleteLog(e storage.Tx, domain string, name string) error { key := fmt.Sprintf(logKey, name) return e.Delete(domain, key) }
func DeleteBlock(e storage.Tx, domain string, id *uuid.UUID, idx int) error { key := fmt.Sprintf(blockKey, id, idx) return e.Delete(domain, key) }
func DeleteSegment(e storage.Tx, domain string, id *uuid.UUID) error { key := fmt.Sprintf(segmentKey, id) return e.Delete(domain, key) }
// txid increments a global transaction ID. func txid(tx storage.Tx) (uint64, error) { return tx.Incr("origins", "tx") }