Skip to content

Commit 371e238

Browse files
Merge pull request #210 from ywk253100/231010_buffer
Adjust the buffer size to avoid OOM
2 parents d65ba53 + 800a4dd commit 371e238

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

backupstoragelocation.md

+2-2
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

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const (
4343
blockSizeConfigKey = "blockSizeInBytes"
4444
// blocks must be less than/equal to 100MB in size
4545
// ref. https://docs.microsoft.com/en-us/rest/api/storageservices/put-block#uri-parameters
46-
defaultBlockSize = 100 * 1024 * 1024
46+
maxBlockSize = 100 * 1024 * 1024
47+
defaultBlockSize = 1 * 1024 * 1024
4748
)
4849

4950
type containerGetter interface {
@@ -259,11 +260,16 @@ func getBlockSize(log logrus.FieldLogger, config map[string]string) int {
259260
return defaultBlockSize
260261
}
261262

262-
if blockSize <= 0 || blockSize > defaultBlockSize {
263-
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)
263+
if blockSize <= 0 {
264+
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is < 1, using default block size of %d", blockSize, defaultBlockSize)
264265
return defaultBlockSize
265266
}
266267

268+
if blockSize > maxBlockSize {
269+
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is > the max size %d, using max block size of %d", blockSize, maxBlockSize, maxBlockSize)
270+
return maxBlockSize
271+
}
272+
267273
return blockSize
268274
}
269275

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

+29
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
2525
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
2626
"github.com/pkg/errors"
27+
"github.com/sirupsen/logrus"
2728
"github.com/stretchr/testify/assert"
2829
"github.com/stretchr/testify/mock"
2930
"github.com/stretchr/testify/require"
@@ -138,3 +139,31 @@ func (m *mockBlob) GetSASURI(ttl time.Duration, sharedKeyCredential *azblob.Shar
138139
args := m.Called(ttl, sharedKeyCredential)
139140
return args.String(0), args.Error(1)
140141
}
142+
143+
func TestGetBlockSize(t *testing.T) {
144+
logger := logrus.New()
145+
config := map[string]string{}
146+
// not specified
147+
size := getBlockSize(logger, config)
148+
assert.Equal(t, defaultBlockSize, size)
149+
150+
// invalid value specified
151+
config[blockSizeConfigKey] = "invalid"
152+
size = getBlockSize(logger, config)
153+
assert.Equal(t, defaultBlockSize, size)
154+
155+
// value < 0 specified
156+
config[blockSizeConfigKey] = "0"
157+
size = getBlockSize(logger, config)
158+
assert.Equal(t, defaultBlockSize, size)
159+
160+
// value > max size specified
161+
config[blockSizeConfigKey] = "1048576000"
162+
size = getBlockSize(logger, config)
163+
assert.Equal(t, maxBlockSize, size)
164+
165+
// valid value specified
166+
config[blockSizeConfigKey] = "1048570"
167+
size = getBlockSize(logger, config)
168+
assert.Equal(t, 1048570, size)
169+
}

0 commit comments

Comments
 (0)