storage: add delete example

This commit is contained in:
Xiang Li 2015-05-15 19:33:59 -07:00
parent 4b0d9f69c7
commit 9575cc4258

View File

@ -62,5 +62,26 @@ func (s *store) Get(key []byte) []byte {
tx.Lock()
defer tx.Unlock()
vs := tx.UnsafeRange(keyBucketName, ibytes, nil, 0)
// TODO: the value will be an event type.
// TODO: copy out the bytes, decode it, return the value.
return vs[0]
}
func (s *store) Delete(key []byte) error {
now := s.now + 1
err := s.kvindex.Tombstone(key, now)
if err != nil {
return err
}
ibytes := make([]byte, 8)
binary.BigEndian.PutUint64(ibytes, now)
tx := s.b.BatchTx()
tx.Lock()
defer tx.Unlock()
// TODO: the value will be an event type.
// A tombstone is simple a "Delete" type event.
tx.UnsafePut(keyBucketName, key, []byte("tombstone"))
return nil
}