projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
12447: Remove .Bytes()
[arvados.git]
/
sdk
/
go
/
keepclient
/
block_cache.go
diff --git
a/sdk/go/keepclient/block_cache.go
b/sdk/go/keepclient/block_cache.go
index 7d03b68b9cac47a7fff8583851dc0c8100714615..1849fa2ce3f15f0387e000ceae4e07e14ca3eed7 100644
(file)
--- a/
sdk/go/keepclient/block_cache.go
+++ b/
sdk/go/keepclient/block_cache.go
@@
-1,7
+1,11
@@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
package keepclient
import (
package keepclient
import (
- "io
/ioutil
"
+ "io"
"sort"
"sync"
"time"
"sort"
"sync"
"time"
@@
-25,7
+29,7
@@
const defaultMaxBlocks = 4
// there are no more than MaxBlocks left.
func (c *BlockCache) Sweep() {
max := c.MaxBlocks
// there are no more than MaxBlocks left.
func (c *BlockCache) Sweep() {
max := c.MaxBlocks
- if max
< defaultMaxBlocks
{
+ if max
== 0
{
max = defaultMaxBlocks
}
c.mtx.Lock()
max = defaultMaxBlocks
}
c.mtx.Lock()
@@
-60,10
+64,15
@@
func (c *BlockCache) Get(kc *KeepClient, locator string) ([]byte, error) {
}
c.cache[cacheKey] = b
go func() {
}
c.cache[cacheKey] = b
go func() {
- rdr,
_
, _, err := kc.Get(locator)
+ rdr,
size
, _, err := kc.Get(locator)
var data []byte
if err == nil {
var data []byte
if err == nil {
- data, err = ioutil.ReadAll(rdr)
+ data := make([]byte, size, BLOCKSIZE)
+ _, err = io.ReadFull(rdr, data)
+ err2 := rdr.Close()
+ if err == nil {
+ err = err2
+ }
}
c.mtx.Lock()
b.data, b.err = data, err
}
c.mtx.Lock()
b.data, b.err = data, err
@@
-88,6
+97,12
@@
func (c *BlockCache) setup() {
c.cache = make(map[string]*cacheBlock)
}
c.cache = make(map[string]*cacheBlock)
}
+func (c *BlockCache) Clear() {
+ c.mtx.Lock()
+ c.setup()
+ c.mtx.Unlock()
+}
+
type timeSlice []time.Time
func (ts timeSlice) Len() int { return len(ts) }
type timeSlice []time.Time
func (ts timeSlice) Len() int { return len(ts) }