Skip to content

Commit

Permalink
Merge pull request #210 from ywk253100/231010_buffer
Browse files Browse the repository at this point in the history
Adjust the buffer size to avoid OOM
  • Loading branch information
shubham-pampattiwar authored Oct 10, 2023
2 parents d65ba53 + 800a4dd commit 371e238
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
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)
}

0 comments on commit 371e238

Please sign in to comment.