-
Notifications
You must be signed in to change notification settings - Fork 568
/
compaction_cache.go
64 lines (57 loc) · 1.47 KB
/
compaction_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
package server
import (
"context"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"github.com/pachyderm/pachyderm/v2/src/internal/storage/fileset"
"google.golang.org/protobuf/types/known/anypb"
)
type cache struct {
driver *driver
tag string
}
func (d *driver) newCache(tag string) *cache {
return &cache{
driver: d,
tag: tag,
}
}
func (c *cache) Get(ctx context.Context, key string) (*anypb.Any, error) {
output, err := c.driver.getCache(ctx, key)
if err != nil {
return nil, err
}
return output, nil
}
func (c *cache) Put(ctx context.Context, key string, output *anypb.Any) error {
var fileSetIds []string
switch {
case output.MessageIs(&ShardTaskResult{}):
case output.MessageIs(&CompactTaskResult{}):
ct, err := deserializeCompactTaskResult(output)
if err != nil {
return err
}
fileSetIds = append(fileSetIds, ct.Id)
case output.MessageIs(&ConcatTaskResult{}):
ct, err := deserializeConcatTaskResult(output)
if err != nil {
return err
}
fileSetIds = append(fileSetIds, ct.Id)
case output.MessageIs(&ValidateTaskResult{}):
default:
return errors.Errorf("unrecognized any type (%v) in compaction cache", output.TypeUrl)
}
var fsids []fileset.ID
for _, id := range fileSetIds {
fsid, err := fileset.ParseID(id)
if err != nil {
return err
}
fsids = append(fsids, *fsid)
}
return c.driver.putCache(ctx, key, output, fsids, c.tag)
}
func (c *cache) clear(ctx context.Context) error {
return c.driver.clearCache(ctx, c.tag)
}