Repository: pingcap/tidb
File: pkg/objstore/s3store/client.go (Go)

Code before:
	input := &s3.CreateMultipartUploadInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(key),
	}
	if c.options.Acl != "" {
		input.ACL = types.ObjectCannedACL(c.options.Acl)
	}
	if c.options.Sse != "" {
		input.ServerSideEncryption = types.ServerSideEncryption(c.options.Sse)
	}
	if c.options.SseKmsKeyId != "" {
		input.SSEKMSKeyId = aws.String(c.options.SseKmsKeyId)
	}
	if c.options.StorageClass != "" {
		input.StorageClass = types.StorageClass(c.options.StorageClass)
	}

	resp, err := c.svc.CreateMultipartUpload(ctx, input)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &multipartWriter{
		svc:           c.svc,
		createOutput:  resp,
		completeParts: make([]types.CompletedPart, 0, 128),
		s3Compatible:  c.isKS3,
	}, nil
}

func (c *s3Client) MultipartUploader(name string, partSize int64, concurrency int) s3like.Uploader {
	up := manager.NewUploader(c.svc, func(u *manager.Uploader) {
		u.PartSize = partSize
		u.Concurrency = concurrency
		u.BufferProvider = manager.NewBufferedReadSeekerWriteToPool(concurrency * s3like.HardcodedChunkSize)
		if c.isKS3 {
			u.ClientOptions = append(u.ClientOptions, withContentMD5)
		}
	})
	return &multipartUploader{
		uploader:     up,
		BucketPrefix: c.BucketPrefix,
		key:          c.ObjectKey(name),
	}
}

// withContentMD5 removes all flexible checksum procecdures from an operation,
// instead computing an MD5 checksum for the request payload.
func withContentMD5(o *s3.Options) {
	o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
		_, _ = stack.Initialize.Remove("AWSChecksum:SetupInputContext")
		_, _ = stack.Build.Remove("AWSChecksum:RequestMetricsTracking")

Review comment (refactor):
The field name `s3Compatible` in the `multipartWriter` struct is inconsistent with the refactoring done in the `s3Client` struct where the field was renamed from `s3Compatible` to `isKS3`. For consistency and clarity, this field should also be renamed to `isKS3` to match the semantic change of this PR (narrowing the scope from "S3-compatible" to specifically "KS3").
```suggestion
		isKS3:         c.isKS3,
```

Code after:
	key := c.ObjectKey(name)
	input := &s3.CreateMultipartUploadInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(key),
	}
	if c.options.Acl != "" {
		input.ACL = types.ObjectCannedACL(c.options.Acl)
	}
	if c.options.Sse != "" {
		input.ServerSideEncryption = types.ServerSideEncryption(c.options.Sse)
	}
	if c.options.SseKmsKeyId != "" {
		input.SSEKMSKeyId = aws.String(c.options.SseKmsKeyId)
	}
	if c.options.StorageClass != "" {
		input.StorageClass = types.StorageClass(c.options.StorageClass)
	}

	resp, err := c.svc.CreateMultipartUpload(ctx, input)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &multipartWriter{
		svc:           c.svc,
		createOutput:  resp,
		completeParts: make([]types.CompletedPart, 0, 128),
		s3Compatible:  c.s3Compatible,
	}, nil
}

func (c *s3Client) MultipartUploader(name string, partSize int64, concurrency int) s3like.Uploader {
	up := manager.NewUploader(c.svc, func(u *manager.Uploader) {
		u.PartSize = partSize
		u.Concurrency = concurrency
		u.BufferProvider = manager.NewBufferedReadSeekerWriteToPool(concurrency * s3like.HardcodedChunkSize)
		if c.s3Compatible {
			u.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired
			u.ClientOptions = append(u.ClientOptions, withContentMD5)
		}
	})
	return &multipartUploader{
		uploader:     up,
		BucketPrefix: c.BucketPrefix,
		key:          c.ObjectKey(name),
	}
}

// withContentMD5 removes flexible checksum procedures from an operation,
// instead computing an MD5 checksum for the request payload.
func withContentMD5(o *s3.Options) {
	o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {