Skip to content

Commit af5ae8e

Browse files
committed
Adjust the buffer size to avoid OOM
Adjust the buffer size to avoid OOM Fixes vmware-tanzu/velero#6847 Signed-off-by: Wenkai Yin(尹文开) <[email protected]>
1 parent af0f844 commit af5ae8e

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

backupstoragelocation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ spec:
7070
# See https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs#about-block-blobs
7171
# for more information on block blobs.
7272
#
73-
# Optional (defaults to 104857600, i.e. 100MB).
74-
blockSizeInBytes: "104857600"
73+
# Optional (defaults to 1048576, i.e. 1MB, maximum 104857600, i.e. 100MB).
74+
blockSizeInBytes: "1048576"
7575
```

velero-plugin-for-microsoft-azure/object_store.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const (
5555

5656
// blocks must be less than/equal to 100MB in size
5757
// ref. https://docs.microsoft.com/en-us/rest/api/storageservices/put-block#uri-parameters
58-
defaultBlockSize = 100 * 1024 * 1024
58+
maxBlockSize = 100 * 1024 * 1024
59+
defaultBlockSize = 1 * 1024 * 1024
5960
)
6061

6162
type containerGetter interface {
@@ -412,11 +413,16 @@ func getBlockSize(log logrus.FieldLogger, config map[string]string) int {
412413
return defaultBlockSize
413414
}
414415

415-
if blockSize <= 0 || blockSize > defaultBlockSize {
416-
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is outside the allowed range of 1 to %d, using default block size of %d", blockSize, defaultBlockSize, defaultBlockSize)
416+
if blockSize <= 0 {
417+
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is < 1, using default block size of %d", blockSize, defaultBlockSize)
417418
return defaultBlockSize
418419
}
419420

421+
if blockSize > maxBlockSize {
422+
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is > the max size %d, using max block size of %d", blockSize, maxBlockSize, maxBlockSize)
423+
return maxBlockSize
424+
}
425+
420426
return blockSize
421427
}
422428

velero-plugin-for-microsoft-azure/object_store_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
2727
azcontainer "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
2828
"github.com/pkg/errors"
29+
"github.com/sirupsen/logrus"
2930
"github.com/stretchr/testify/assert"
3031
"github.com/stretchr/testify/mock"
3132
"github.com/stretchr/testify/require"
@@ -163,3 +164,31 @@ func (m *mockContainer) ListBlobsHierarchy(delimiter string, listOptions *azcont
163164
args := m.Called(delimiter, listOptions)
164165
return args.Get(0).(*runtime.Pager[azcontainer.ListBlobsHierarchyResponse])
165166
}
167+
168+
func TestGetBlockSize(t *testing.T) {
169+
logger := logrus.New()
170+
config := map[string]string{}
171+
// not specified
172+
size := getBlockSize(logger, config)
173+
assert.Equal(t, defaultBlockSize, size)
174+
175+
// invalid value specified
176+
config[blockSizeConfigKey] = "invalid"
177+
size = getBlockSize(logger, config)
178+
assert.Equal(t, defaultBlockSize, size)
179+
180+
// value < 0 specified
181+
config[blockSizeConfigKey] = "0"
182+
size = getBlockSize(logger, config)
183+
assert.Equal(t, defaultBlockSize, size)
184+
185+
// value > max size specified
186+
config[blockSizeConfigKey] = "1048576000"
187+
size = getBlockSize(logger, config)
188+
assert.Equal(t, maxBlockSize, size)
189+
190+
// valid value specified
191+
config[blockSizeConfigKey] = "1048570"
192+
size = getBlockSize(logger, config)
193+
assert.Equal(t, 1048570, size)
194+
}

0 commit comments

Comments
 (0)