metacache: Make very small requests transient (#11109)

master
Klaus Post 4 years ago committed by GitHub
parent 5df61ab96b
commit e7d3b49a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/erasure-server-sets.go
  2. 14
      cmd/metacache-server-pool.go
  3. 14
      cmd/metacache-set.go

@ -707,7 +707,7 @@ func (z *erasureServerPools) ListObjectVersions(ctx context.Context, bucket, pre
// more objects matching the prefix. // more objects matching the prefix.
ri := logger.GetReqInfo(ctx) ri := logger.GetReqInfo(ctx)
if ri != nil && strings.Contains(ri.UserAgent, `1.0 Veeam/1.0 Backup`) && strings.HasSuffix(prefix, ".blk") { if ri != nil && strings.Contains(ri.UserAgent, `1.0 Veeam/1.0 Backup`) && strings.HasSuffix(prefix, ".blk") {
opts.singleObject = true opts.discardResult = true
opts.Transient = true opts.Transient = true
} }

@ -84,11 +84,21 @@ func (z *erasureServerPools) listPath(ctx context.Context, o listPathOptions) (e
o.ID = mustGetUUID() o.ID = mustGetUUID()
} }
o.BaseDir = baseDirFromPrefix(o.Prefix) o.BaseDir = baseDirFromPrefix(o.Prefix)
if o.singleObject { if o.discardResult {
// Override for single object. // Override for single object.
o.BaseDir = o.Prefix o.BaseDir = o.Prefix
} }
// For very small recursive listings, don't same cache.
// Attempts to avoid expensive listings to run for a long
// while when clients aren't interested in results.
// If the client DOES resume the listing a full cache
// will be generated due to the marker without ID and this check failing.
if o.Limit < 10 && o.Marker == "" && o.Create && o.Recursive {
o.discardResult = true
o.Transient = true
}
var cache metacache var cache metacache
// If we don't have a list id we must ask the server if it has a cache or create a new. // If we don't have a list id we must ask the server if it has a cache or create a new.
if o.Create { if o.Create {
@ -206,7 +216,9 @@ func (z *erasureServerPools) listPath(ctx context.Context, o listPathOptions) (e
} }
truncated := entries.len() > o.Limit || !allAtEOF truncated := entries.len() > o.Limit || !allAtEOF
entries.truncate(o.Limit) entries.truncate(o.Limit)
if !o.discardResult {
entries.listID = o.ID entries.listID = o.ID
}
if !truncated { if !truncated {
return entries, io.EOF return entries, io.EOF
} }

@ -95,8 +95,9 @@ type listPathOptions struct {
// A transient result will never be returned from the cache so knowing the list id is required. // A transient result will never be returned from the cache so knowing the list id is required.
Transient bool Transient bool
// singleObject will assume that prefix refers to an exact single object. // discardResult will not persist the cache to storage.
singleObject bool // When the initial results are returned listing will be canceled.
discardResult bool
} }
func init() { func init() {
@ -545,7 +546,7 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
o.debugf("listPath with options: %#v\n", o) o.debugf("listPath with options: %#v\n", o)
// See if we have the listing stored. // See if we have the listing stored.
if !o.Create && !o.singleObject { if !o.Create && !o.discardResult {
entries, err := er.streamMetadataParts(ctx, o) entries, err := er.streamMetadataParts(ctx, o)
if IsErr(err, []error{ if IsErr(err, []error{
nil, nil,
@ -627,6 +628,11 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
close(filterCh) close(filterCh)
} }
// Cancel listing on return if non-saved list.
if o.discardResult {
defer cancel()
}
go func() { go func() {
defer cancel() defer cancel()
// Save continuous updates // Save continuous updates
@ -658,7 +664,7 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
// Write results to disk. // Write results to disk.
bw := newMetacacheBlockWriter(cacheCh, func(b *metacacheBlock) error { bw := newMetacacheBlockWriter(cacheCh, func(b *metacacheBlock) error {
if o.singleObject { if o.discardResult {
// Don't save single object listings. // Don't save single object listings.
return nil return nil
} }

Loading…
Cancel
Save