mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
storage: add delete example
This commit is contained in:
parent
4b0d9f69c7
commit
9575cc4258
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user