Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unexpected read retries #5199

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions pkg/chunk/cached_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,20 @@ func (store *cachedStore) put(key string, p *Page) error {
var (
reqID string
sc = object.DefaultStorageClass
st = time.Now()
)
return utils.WithTimeout(func() error {
err := utils.WithTimeout(func() error {
defer p.Release()
st := time.Now()
err := store.storage.Put(key, bytes.NewReader(p.Data), object.WithRequestID(&reqID), object.WithStorageClass(&sc))
used := time.Since(st)
logRequest("PUT", key, "", reqID, err, used)
store.objectDataBytes.WithLabelValues("PUT", sc).Add(float64(len(p.Data)))
store.objectReqsHistogram.WithLabelValues("PUT", sc).Observe(used.Seconds())
if err != nil {
store.objectReqErrors.Add(1)
}
return err
return store.storage.Put(key, bytes.NewReader(p.Data), object.WithRequestID(&reqID), object.WithStorageClass(&sc))
}, store.conf.PutTimeout)
used := time.Since(st)
logRequest("PUT", key, "", reqID, err, used)
store.objectDataBytes.WithLabelValues("PUT", sc).Add(float64(len(p.Data)))
store.objectReqsHistogram.WithLabelValues("PUT", sc).Observe(used.Seconds())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should record the actual duration for the request, not bounded by timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will leave it as is.

The reason for this update is - cachedStore.delete/cachedStore.load all measure duration bounded by timeout, why cachedStore.put differs from them?

if err != nil {
store.objectReqErrors.Add(1)
}
return err
}

func (store *cachedStore) delete(key string) error {
Expand Down Expand Up @@ -687,11 +687,14 @@ func (store *cachedStore) load(key string, page *Page, cache bool, forceCache bo
if store.downLimit != nil && !compressed {
store.downLimit.Wait(int64(len(page.Data)))
}
err = errors.New("Not downloaded")
var in io.ReadCloser
tried := 0
start := time.Now()
var p *Page
var (
in io.ReadCloser
n int
p *Page
reqID string
sc = object.DefaultStorageClass
start = time.Now()
)
if compressed {
c := NewOffPage(needed)
defer c.Release()
Expand All @@ -700,24 +703,10 @@ func (store *cachedStore) load(key string, page *Page, cache bool, forceCache bo
p = page
}
p.Acquire()
var n int
var (
reqID string
sc = object.DefaultStorageClass
)
err = utils.WithTimeout(func() error {
defer p.Release()
// it will be retried outside
for err != nil && tried < 2 {
time.Sleep(time.Second * time.Duration(tried*tried))
if tried > 0 {
logger.Warnf("GET %s: %s; retrying", key, err)
store.objectReqErrors.Add(1)
start = time.Now()
}
in, err = store.storage.Get(key, 0, -1, object.WithRequestID(&reqID), object.WithStorageClass(&sc))
tried++
}
// it will be retried in the upper layer.
in, err = store.storage.Get(key, 0, -1, object.WithRequestID(&reqID), object.WithStorageClass(&sc))
if err == nil {
n, err = io.ReadFull(in, p.Data)
_ = in.Close()
Expand All @@ -742,8 +731,7 @@ func (store *cachedStore) load(key string, page *Page, cache bool, forceCache bo
n, err = store.compressor.Decompress(page.Data, p.Data[:n])
}
if err != nil || n < len(page.Data) {
return fmt.Errorf("read %s fully: %s (%d < %d) after %s (tried %d)", key, err, n, len(page.Data),
used, tried)
return fmt.Errorf("read %s fully: %v (%d < %d) after %s", key, err, n, len(page.Data), used)
}
if cache {
store.bcache.cache(key, page, forceCache, !store.conf.OSCache)
Expand Down
Loading