Skip to content

Commit 934a3e4

Browse files
ferhatelmasfenos
andauthored
fix: configurable part size (#1116)
Co-authored-by: Fabrizio <fabri.feno@gmail.com> Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent d87675c commit 934a3e4

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { SignJWT } from 'jose'
44

55
export type StorageBackendType = 'file' | 's3'
66
export type IcebergCatalogAuthType = 'sigv4' | 'token'
7+
const DEFAULT_S3_UPLOAD_PART_SIZE = 16 * 1024 * 1024
8+
const MIN_S3_UPLOAD_PART_SIZE = 5 * 1024 * 1024
9+
710
export enum MultitenantMigrationStrategy {
811
PROGRESSIVE = 'progressive',
912
ON_REQUEST = 'on_request',
@@ -68,6 +71,7 @@ type StorageConfigType = {
6871
storageS3InternalTracesEnabled?: boolean
6972
storageS3MaxSockets: number
7073
storageS3DisableChecksum: boolean
74+
storageS3UploadPartSize: number
7175
storageS3UploadQueueSize: number
7276
storageS3Bucket: string
7377
storageS3Endpoint?: string
@@ -374,6 +378,11 @@ export function getConfig(options?: { reload?: boolean }): StorageConfigType {
374378
10
375379
),
376380
storageS3DisableChecksum: getOptionalConfigFromEnv('STORAGE_S3_DISABLE_CHECKSUM') === 'true',
381+
storageS3UploadPartSize: Math.max(
382+
envNumber(getOptionalConfigFromEnv('STORAGE_S3_UPLOAD_PART_SIZE')) ??
383+
DEFAULT_S3_UPLOAD_PART_SIZE,
384+
MIN_S3_UPLOAD_PART_SIZE
385+
),
377386
storageS3UploadQueueSize:
378387
envNumber(getOptionalConfigFromEnv('STORAGE_S3_UPLOAD_QUEUE_SIZE')) ?? 2,
379388
storageS3InternalTracesEnabled:

src/storage/backend/s3/adapter.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { getConfig } from '../../../config'
88
import { withOptionalVersion } from '../adapter'
99
import { MAX_PUT_OBJECT_SIZE, S3Backend } from './adapter'
1010

11+
const DEFAULT_S3_UPLOAD_PART_SIZE = 16 * 1024 * 1024
12+
1113
vi.mock('@aws-sdk/client-s3', async () => {
1214
const originalModule =
1315
await vi.importActual<typeof import('@aws-sdk/client-s3')>('@aws-sdk/client-s3')
@@ -35,6 +37,7 @@ vi.mock('@aws-sdk/s3-request-presigner', () => ({
3537
}))
3638

3739
type UploadOptionsShape = {
40+
partSize?: number
3841
queueSize?: number
3942
}
4043

@@ -322,6 +325,8 @@ describe('S3Backend', () => {
322325
)
323326

324327
expect(Upload).toHaveBeenCalledTimes(1)
328+
expect(getConfig().storageS3UploadPartSize).toBe(DEFAULT_S3_UPLOAD_PART_SIZE)
329+
expect(uploadInstances[0].options.partSize).toBe(getConfig().storageS3UploadPartSize)
325330
expect(uploadInstances[0].options.queueSize).toBe(getConfig().storageS3UploadQueueSize)
326331
expect(mockSend).toHaveBeenCalledTimes(1)
327332
expect(mockSend.mock.calls[0][0]).toBeInstanceOf(HeadObjectCommand)
@@ -348,6 +353,8 @@ describe('S3Backend', () => {
348353
)
349354

350355
expect(Upload).toHaveBeenCalledTimes(1)
356+
expect(getConfig().storageS3UploadPartSize).toBe(DEFAULT_S3_UPLOAD_PART_SIZE)
357+
expect(uploadInstances[0].options.partSize).toBe(getConfig().storageS3UploadPartSize)
351358
expect(uploadInstances[0].options.queueSize).toBe(getConfig().storageS3UploadQueueSize)
352359
expect(mockSend).not.toHaveBeenCalled()
353360
expect(result).toMatchObject({

src/storage/backend/s3/adapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from './../adapter'
3636

3737
const {
38+
storageS3UploadPartSize,
3839
storageS3UploadQueueSize,
3940
tracingFeatures,
4041
storageS3MaxSockets,
@@ -249,6 +250,7 @@ export class S3Backend implements StorageBackendAdapter {
249250

250251
const upload = new Upload({
251252
client: this.client,
253+
partSize: storageS3UploadPartSize,
252254
queueSize: storageS3UploadQueueSize,
253255
params: {
254256
Bucket: bucketName,

0 commit comments

Comments
 (0)