1 // A Volume is an interface representing a Keep back-end storage unit:
2 // for example, a single mounted disk, a RAID array, an Amazon S3 volume,
13 type Volume interface {
14 Get(loc string) ([]byte, error)
15 Put(loc string, block []byte) error
16 Touch(loc string) error
17 Mtime(loc string) (time.Time, error)
18 IndexTo(prefix string, writer io.Writer) error
19 Delete(loc string) error
20 Status() *VolumeStatus
25 // A VolumeManager tells callers which volumes can read, which volumes
26 // can write, and on which volume the next write should be attempted.
27 type VolumeManager interface {
28 // AllReadable returns all volumes.
29 AllReadable() []Volume
30 // AllWritable returns all volumes that aren't known to be in
31 // a read-only state. (There is no guarantee that a write to
32 // one will succeed, though.)
33 AllWritable() []Volume
34 // NextWritable returns the volume where the next new block
35 // should be written. A VolumeManager can select a volume in
36 // order to distribute activity across spindles, fill up disks
37 // with more free space, etc.
39 // Close shuts down the volume manager cleanly.
43 type RRVolumeManager struct {
49 func MakeRRVolumeManager(volumes []Volume) *RRVolumeManager {
50 vm := &RRVolumeManager{}
51 for _, v := range volumes {
52 vm.readables = append(vm.readables, v)
54 vm.writables = append(vm.writables, v)
60 func (vm *RRVolumeManager) AllReadable() []Volume {
64 func (vm *RRVolumeManager) AllWritable() []Volume {
68 func (vm *RRVolumeManager) NextWritable() Volume {
69 if len(vm.writables) == 0 {
72 i := atomic.AddUint32(&vm.counter, 1)
73 return vm.writables[i%uint32(len(vm.writables))]
76 func (vm *RRVolumeManager) Close() {