-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
disk_block_cache.go
237 lines (212 loc) · 7.25 KB
/
disk_block_cache.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/kbgitkbfs1/disk_block_cache.avdl
package kbgitkbfs1
import (
"fmt"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
"time"
)
type PrefetchStatus int
const (
PrefetchStatus_NO_PREFETCH PrefetchStatus = 0
PrefetchStatus_TRIGGERED_PREFETCH PrefetchStatus = 1
PrefetchStatus_FINISHED_PREFETCH PrefetchStatus = 2
)
func (o PrefetchStatus) DeepCopy() PrefetchStatus { return o }
var PrefetchStatusMap = map[string]PrefetchStatus{
"NO_PREFETCH": 0,
"TRIGGERED_PREFETCH": 1,
"FINISHED_PREFETCH": 2,
}
var PrefetchStatusRevMap = map[PrefetchStatus]string{
0: "NO_PREFETCH",
1: "TRIGGERED_PREFETCH",
2: "FINISHED_PREFETCH",
}
func (e PrefetchStatus) String() string {
if v, ok := PrefetchStatusRevMap[e]; ok {
return v
}
return fmt.Sprintf("%v", int(e))
}
// GetCachedBlockRes is the response from GetBlock.
type GetBlockRes struct {
Buf []byte `codec:"buf" json:"buf"`
ServerHalf []byte `codec:"serverHalf" json:"serverHalf"`
PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"`
}
func (o GetBlockRes) DeepCopy() GetBlockRes {
return GetBlockRes{
Buf: (func(x []byte) []byte {
if x == nil {
return nil
}
return append([]byte{}, x...)
})(o.Buf),
ServerHalf: (func(x []byte) []byte {
if x == nil {
return nil
}
return append([]byte{}, x...)
})(o.ServerHalf),
PrefetchStatus: o.PrefetchStatus.DeepCopy(),
}
}
// DeleteBlocksRes is the response from DeleteBlocks.
type DeleteBlocksRes struct {
NumRemoved int `codec:"numRemoved" json:"numRemoved"`
SizeRemoved int64 `codec:"sizeRemoved" json:"sizeRemoved"`
}
func (o DeleteBlocksRes) DeepCopy() DeleteBlocksRes {
return DeleteBlocksRes{
NumRemoved: o.NumRemoved,
SizeRemoved: o.SizeRemoved,
}
}
type GetBlockArg struct {
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
}
type GetPrefetchStatusArg struct {
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
}
type PutBlockArg struct {
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
Buf []byte `codec:"buf" json:"buf"`
ServerHalf []byte `codec:"serverHalf" json:"serverHalf"`
}
type DeleteBlocksArg struct {
BlockIDs [][]byte `codec:"blockIDs" json:"blockIDs"`
}
type UpdateBlockMetadataArg struct {
TlfID []byte `codec:"tlfID" json:"tlfID"`
BlockID []byte `codec:"blockID" json:"blockID"`
PrefetchStatus PrefetchStatus `codec:"prefetchStatus" json:"prefetchStatus"`
}
// DiskBlockCacheInterface specifies how to access a disk cache remotely.
type DiskBlockCacheInterface interface {
// GetBlock gets a block from the disk cache.
GetBlock(context.Context, GetBlockArg) (GetBlockRes, error)
// GetPrefetchStatus gets the prefetch status from the disk cache.
GetPrefetchStatus(context.Context, GetPrefetchStatusArg) (PrefetchStatus, error)
// PutBlock puts a block into the disk cache.
PutBlock(context.Context, PutBlockArg) error
// DeleteBlocks deletes a set of blocks from the disk cache.
DeleteBlocks(context.Context, [][]byte) (DeleteBlocksRes, error)
// UpdateBlockMetadata updates the metadata for a block in the disk cache.
UpdateBlockMetadata(context.Context, UpdateBlockMetadataArg) error
}
func DiskBlockCacheProtocol(i DiskBlockCacheInterface) rpc.Protocol {
return rpc.Protocol{
Name: "kbgitkbfs.1.DiskBlockCache",
Methods: map[string]rpc.ServeHandlerDescription{
"GetBlock": {
MakeArg: func() interface{} {
var ret [1]GetBlockArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetBlockArg)
if !ok {
err = rpc.NewTypeError((*[1]GetBlockArg)(nil), args)
return
}
ret, err = i.GetBlock(ctx, typedArgs[0])
return
},
},
"GetPrefetchStatus": {
MakeArg: func() interface{} {
var ret [1]GetPrefetchStatusArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetPrefetchStatusArg)
if !ok {
err = rpc.NewTypeError((*[1]GetPrefetchStatusArg)(nil), args)
return
}
ret, err = i.GetPrefetchStatus(ctx, typedArgs[0])
return
},
},
"PutBlock": {
MakeArg: func() interface{} {
var ret [1]PutBlockArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]PutBlockArg)
if !ok {
err = rpc.NewTypeError((*[1]PutBlockArg)(nil), args)
return
}
err = i.PutBlock(ctx, typedArgs[0])
return
},
},
"DeleteBlocks": {
MakeArg: func() interface{} {
var ret [1]DeleteBlocksArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]DeleteBlocksArg)
if !ok {
err = rpc.NewTypeError((*[1]DeleteBlocksArg)(nil), args)
return
}
ret, err = i.DeleteBlocks(ctx, typedArgs[0].BlockIDs)
return
},
},
"UpdateBlockMetadata": {
MakeArg: func() interface{} {
var ret [1]UpdateBlockMetadataArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]UpdateBlockMetadataArg)
if !ok {
err = rpc.NewTypeError((*[1]UpdateBlockMetadataArg)(nil), args)
return
}
err = i.UpdateBlockMetadata(ctx, typedArgs[0])
return
},
},
},
}
}
type DiskBlockCacheClient struct {
Cli rpc.GenericClient
}
// GetBlock gets a block from the disk cache.
func (c DiskBlockCacheClient) GetBlock(ctx context.Context, __arg GetBlockArg) (res GetBlockRes, err error) {
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.GetBlock", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
// GetPrefetchStatus gets the prefetch status from the disk cache.
func (c DiskBlockCacheClient) GetPrefetchStatus(ctx context.Context, __arg GetPrefetchStatusArg) (res PrefetchStatus, err error) {
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.GetPrefetchStatus", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
// PutBlock puts a block into the disk cache.
func (c DiskBlockCacheClient) PutBlock(ctx context.Context, __arg PutBlockArg) (err error) {
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.PutBlock", []interface{}{__arg}, nil, 0*time.Millisecond)
return
}
// DeleteBlocks deletes a set of blocks from the disk cache.
func (c DiskBlockCacheClient) DeleteBlocks(ctx context.Context, blockIDs [][]byte) (res DeleteBlocksRes, err error) {
__arg := DeleteBlocksArg{BlockIDs: blockIDs}
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.DeleteBlocks", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
// UpdateBlockMetadata updates the metadata for a block in the disk cache.
func (c DiskBlockCacheClient) UpdateBlockMetadata(ctx context.Context, __arg UpdateBlockMetadataArg) (err error) {
err = c.Cli.Call(ctx, "kbgitkbfs.1.DiskBlockCache.UpdateBlockMetadata", []interface{}{__arg}, nil, 0*time.Millisecond)
return
}