2960: Refactor keepstore into a streaming server.
[arvados.git] / services / keepstore / volume.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package keepstore
6
7 import (
8         "context"
9         "io"
10         "time"
11
12         "git.arvados.org/arvados.git/sdk/go/arvados"
13         "github.com/sirupsen/logrus"
14 )
15
16 // volume is the interface to a back-end storage device.
17 type volume interface {
18         BlockRead(ctx context.Context, hash string, writeTo io.Writer) (int, error)
19         BlockWrite(ctx context.Context, hash string, data []byte) error
20         DeviceID() string
21         BlockTouch(hash string) error
22         BlockTrash(hash string) error
23         BlockUntrash(hash string) error
24         Index(ctx context.Context, prefix string, writeTo io.Writer) error
25         Mtime(hash string) (time.Time, error)
26         EmptyTrash()
27 }
28
29 type volumeDriver func(newVolumeParams) (volume, error)
30
31 type newVolumeParams struct {
32         UUID         string
33         Cluster      *arvados.Cluster
34         ConfigVolume arvados.Volume
35         Logger       logrus.FieldLogger
36         MetricsVecs  *volumeMetricsVecs
37         BufferPool   *bufferPool
38 }
39
40 // ioStats tracks I/O statistics for a volume or server
41 type ioStats struct {
42         Errors     uint64
43         Ops        uint64
44         CompareOps uint64
45         GetOps     uint64
46         PutOps     uint64
47         TouchOps   uint64
48         InBytes    uint64
49         OutBytes   uint64
50 }
51
52 type InternalStatser interface {
53         InternalStats() interface{}
54 }