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

Adjust the buffer size to avoid OOM #210

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions backupstoragelocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ spec:
# See https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs#about-block-blobs
# for more information on block blobs.
#
# Optional (defaults to 104857600, i.e. 100MB).
blockSizeInBytes: "104857600"
# Optional (defaults to 1048576, i.e. 1MB, maximum 104857600, i.e. 100MB).
blockSizeInBytes: "1048576"
```
12 changes: 9 additions & 3 deletions velero-plugin-for-microsoft-azure/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const (
blockSizeConfigKey = "blockSizeInBytes"
// blocks must be less than/equal to 100MB in size
// ref. https://docs.microsoft.com/en-us/rest/api/storageservices/put-block#uri-parameters
defaultBlockSize = 100 * 1024 * 1024
maxBlockSize = 100 * 1024 * 1024
defaultBlockSize = 1 * 1024 * 1024
)

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

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

if blockSize > maxBlockSize {
log.WithError(err).Warnf("Value provided for config.blockSizeInBytes (%d) is > the max size %d, using max block size of %d", blockSize, maxBlockSize, maxBlockSize)
return maxBlockSize
}

return blockSize
}

Expand Down
29 changes: 29 additions & 0 deletions velero-plugin-for-microsoft-azure/object_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -138,3 +139,31 @@ func (m *mockBlob) GetSASURI(ttl time.Duration, sharedKeyCredential *azblob.Shar
args := m.Called(ttl, sharedKeyCredential)
return args.String(0), args.Error(1)
}

func TestGetBlockSize(t *testing.T) {
logger := logrus.New()
config := map[string]string{}
// not specified
size := getBlockSize(logger, config)
assert.Equal(t, defaultBlockSize, size)

// invalid value specified
config[blockSizeConfigKey] = "invalid"
size = getBlockSize(logger, config)
assert.Equal(t, defaultBlockSize, size)

// value < 0 specified
config[blockSizeConfigKey] = "0"
size = getBlockSize(logger, config)
assert.Equal(t, defaultBlockSize, size)

// value > max size specified
config[blockSizeConfigKey] = "1048576000"
size = getBlockSize(logger, config)
assert.Equal(t, maxBlockSize, size)

// valid value specified
config[blockSizeConfigKey] = "1048570"
size = getBlockSize(logger, config)
assert.Equal(t, 1048570, size)
}
Loading