kv.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package storage
  2. import (
  3. "io"
  4. "github.com/coreos/etcd/storage/storagepb"
  5. )
  6. type KV interface {
  7. // Range gets the keys in the range at rangeRev.
  8. // If rangeRev <=0, range gets the keys at currentRev.
  9. // If `end` is nil, the request returns the key.
  10. // If `end` is not nil, it gets the keys in range [key, range_end).
  11. // Limit limits the number of keys returned.
  12. // If the required rev is compacted, ErrCompacted will be returned.
  13. Range(key, end []byte, limit, rangeRev int64) (kvs []storagepb.KeyValue, rev int64, err error)
  14. // Put puts the given key,value into the store.
  15. // A put also increases the rev of the store, and generates one event in the event history.
  16. Put(key, value []byte) (rev int64)
  17. // DeleteRange deletes the given range from the store.
  18. // A deleteRange increases the rev of the store if any key in the range exists.
  19. // The number of key deleted will be returned.
  20. // It also generates one event for each key delete in the event history.
  21. // if the `end` is nil, deleteRange deletes the key.
  22. // if the `end` is not nil, deleteRange deletes the keys in range [key, range_end).
  23. DeleteRange(key, end []byte) (n, rev int64)
  24. // TnxBegin begins a tnx. Only Tnx prefixed operation can be executed, others will be blocked
  25. // until tnx ends. Only one on-going tnx is allowed.
  26. // TnxBegin returns an int64 tnx ID.
  27. // All tnx prefixed operations with same tnx ID will be done with the same rev.
  28. TnxBegin() int64
  29. // TnxEnd ends the on-going tnx with tnx ID. If the on-going tnx ID is not matched, error is returned.
  30. TnxEnd(tnxID int64) error
  31. TnxRange(tnxID int64, key, end []byte, limit, rangeRev int64) (kvs []storagepb.KeyValue, rev int64, err error)
  32. TnxPut(tnxID int64, key, value []byte) (rev int64, err error)
  33. TnxDeleteRange(tnxID int64, key, end []byte) (n, rev int64, err error)
  34. Compact(rev int64) error
  35. // Write a snapshot to the given io writer
  36. Snapshot(w io.Writer) (int64, error)
  37. Restore() error
  38. Close() error
  39. }