-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
132 lines (114 loc) · 4.65 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2015 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package storage
import (
"context"
"errors"
"go.chromium.org/luci/logdog/common/types"
)
var (
// ErrExists returned if an attempt is made to overwrite an existing record.
ErrExists = errors.New("storage: record exists")
// ErrDoesNotExist returned if an attempt is made to read a record that
// doesn't exist.
ErrDoesNotExist = errors.New("storage: record does not exist")
// ErrBadData is an error returned when the stored data is invalid.
ErrBadData = errors.New("storage: bad data")
// ErrReadOnly can be returned by Storage methods to indicate that the Storage
// is read-only.
ErrReadOnly = errors.New("storage: read only")
)
// PutRequest describes adding a single storage record to BigTable.
type PutRequest struct {
// Project is the project name of the stream.
Project string
// Path is the stream path to retrieve.
Path types.StreamPath
// Index is the entry's stream index.
Index types.MessageIndex
// Values are contiguous sequential records to add to the storage. The first
// index in values corresponds to Index.
Values [][]byte
}
// GetRequest is a request to retrieve a series of LogEntry records.
type GetRequest struct {
// Project is the project name of the stream.
Project string
// Path is the stream path to retrieve.
Path types.StreamPath
// Index is the entry's stream index.
Index types.MessageIndex
// Limit is the maximum number of records to return before stopping iteration.
// If <= 0, no maximum limit will be applied.
//
// The Storage instance may return fewer records than the supplied Limit as an
// implementation detail.
Limit int
// KeysOnly, if true, allows (but doesn't require) the Storage instance to
// omit entry data in its get callback. For scanning operations, this can be
// much cheaper/faster than full data queries.
KeysOnly bool
}
// GetCallback is invoked for each record in the Get request. If it returns
// false, iteration should stop.
//
// The MessageIndex may be -1 if the message index isn't known. In this case,
// the caller will have to unmarshal the log entry data to determine its index.
type GetCallback func(*Entry) bool
// ExpungeRequest is a request to expunge the data associated with this stream.
type ExpungeRequest struct {
// Project is the project name of the stream.
Project string
// Path is the stream path to remove from storage.
Path types.StreamPath
}
// Storage is an abstract LogDog storage implementation. Interfaces implementing
// this may be used to store and retrieve log records by the collection service
// layer.
//
// All of these methods must be synchronous and goroutine-safe.
//
// All methods may return errors.Transient errors if they encounter an error
// that may be transient.
type Storage interface {
// Close shuts down this instance, releasing any allocated resources.
Close()
// Writes log record data to storage.
//
// If the data already exists, ErrExists will be returned.
Put(context.Context, PutRequest) error
// Get invokes a callback over a range of sequential LogEntry records.
//
// These log entries will be returned in order (e.g., seq(Rn) < seq(Rn+1)),
// but, depending on ingest, may not be contiguous.
//
// The underlying Storage implementation may return fewer records than
// requested based on availability or implementation details; consequently,
// receiving fewer than requested records does not necessarily mean that more
// records are not available.
//
// Returns nil if retrieval executed successfully, ErrDoesNotExist if
// the requested stream does not exist, and an error if an error occurred
// during retrieval.
Get(context.Context, GetRequest, GetCallback) error
// Expunge removes all entries related to the given project/path.
Expunge(context.Context, ExpungeRequest) error
// Tail retrieves the latest log in the stream. If the stream has no logs, it
// will fail with ErrDoesNotExist.
//
// The MessageIndex may be -1 if the message index isn't known. In this case,
// the caller will have to unmarshal the log entry data to determine its
// index.
Tail(ctx context.Context, projectName string, stream types.StreamPath) (*Entry, error)
}