You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2022 Shivaram Lingamneni <slingamn@cs.stanford.edu>
  2. // released under the MIT license
  3. package datastore
  4. import (
  5. "time"
  6. "github.com/ergochat/ergo/irc/utils"
  7. )
  8. type Table uint16
  9. // XXX these are persisted and must remain stable;
  10. // do not reorder, when deleting use _ to ensure that the deleted value is skipped
  11. const (
  12. TableMetadata Table = iota
  13. TableChannels
  14. TableChannelPurges
  15. )
  16. type KV struct {
  17. UUID utils.UUID
  18. Value []byte
  19. }
  20. // A Datastore provides the following abstraction:
  21. // 1. Tables, each keyed on a UUID (the implementation is free to merge
  22. // the table name and the UUID into a single key as long as the rest of
  23. // the contract can be satisfied). Table names are [a-z0-9_]+
  24. // 2. The ability to efficiently enumerate all uuid-value pairs in a table
  25. // 3. Gets, sets, and deletes for individual (table, uuid) keys
  26. type Datastore interface {
  27. Backoff() time.Duration
  28. GetAll(table Table) ([]KV, error)
  29. // This is rarely used because it would typically lead to TOCTOU races
  30. Get(table Table, key utils.UUID) (value []byte, err error)
  31. Set(table Table, key utils.UUID, value []byte, expiration time.Time) error
  32. // Note that deleting a nonexistent key is not considered an error
  33. Delete(table Table, key utils.UUID) error
  34. }