6
6
7
7
import alex .mojaki .s3upload .MultiPartOutputStream ;
8
8
import alex .mojaki .s3upload .StreamTransferManager ;
9
- import com .amazonaws .ClientConfiguration ;
10
- import com .amazonaws .auth .AWSStaticCredentialsProvider ;
11
- import com .amazonaws .auth .BasicAWSCredentials ;
12
- import com .amazonaws .client .builder .AwsClientBuilder ;
13
9
import com .amazonaws .services .s3 .AmazonS3 ;
14
- import com .amazonaws .services .s3 .AmazonS3ClientBuilder ;
15
10
import io .airbyte .commons .json .Jsons ;
16
11
import io .airbyte .commons .lang .Exceptions ;
17
12
import io .airbyte .db .jdbc .JdbcDatabase ;
18
13
import io .airbyte .integrations .destination .ExtendedNameTransformer ;
19
14
import io .airbyte .integrations .destination .jdbc .SqlOperations ;
20
15
import io .airbyte .integrations .destination .jdbc .StagingFilenameGenerator ;
21
16
import io .airbyte .integrations .destination .jdbc .copy .StreamCopier ;
17
+ import io .airbyte .integrations .destination .s3 .S3DestinationConfig ;
22
18
import io .airbyte .protocol .models .AirbyteRecordMessage ;
23
19
import io .airbyte .protocol .models .DestinationSyncMode ;
24
20
import java .io .IOException ;
@@ -43,10 +39,6 @@ public abstract class S3StreamCopier implements StreamCopier {
43
39
44
40
private static final int DEFAULT_UPLOAD_THREADS = 10 ; // The S3 cli uses 10 threads by default.
45
41
private static final int DEFAULT_QUEUE_CAPACITY = DEFAULT_UPLOAD_THREADS ;
46
- // The smallest part size is 5MB. An S3 upload can be maximally formed of 10,000 parts. This gives
47
- // us an upper limit of 10,000 * 10 / 1000 = 100 GB per table with a 10MB part size limit.
48
- // WARNING: Too large a part size can cause potential OOM errors.
49
- public static final int DEFAULT_PART_SIZE_MB = 10 ;
50
42
// It is optimal to write every 10,000,000 records (BATCH_SIZE * DEFAULT_PART) to a new file.
51
43
// The BATCH_SIZE is defined in CopyConsumerFactory.
52
44
// The average size of such a file will be about 1 GB.
@@ -57,7 +49,7 @@ public abstract class S3StreamCopier implements StreamCopier {
57
49
public static final int MAX_PARTS_PER_FILE = 1000 ;
58
50
59
51
protected final AmazonS3 s3Client ;
60
- protected final S3Config s3Config ;
52
+ protected final S3DestinationConfig s3Config ;
61
53
protected final String tmpTableName ;
62
54
private final DestinationSyncMode destSyncMode ;
63
55
protected final String schemaName ;
@@ -74,15 +66,15 @@ public abstract class S3StreamCopier implements StreamCopier {
74
66
private final StagingFilenameGenerator filenameGenerator ;
75
67
76
68
public S3StreamCopier (final String stagingFolder ,
77
- final DestinationSyncMode destSyncMode ,
78
- final String schema ,
79
- final String streamName ,
80
- final String s3FileName ,
81
- final AmazonS3 client ,
82
- final JdbcDatabase db ,
83
- final S3Config s3Config ,
84
- final ExtendedNameTransformer nameTransformer ,
85
- final SqlOperations sqlOperations ) {
69
+ final DestinationSyncMode destSyncMode ,
70
+ final String schema ,
71
+ final String streamName ,
72
+ final String s3FileName ,
73
+ final AmazonS3 client ,
74
+ final JdbcDatabase db ,
75
+ final S3DestinationConfig s3Config ,
76
+ final ExtendedNameTransformer nameTransformer ,
77
+ final SqlOperations sqlOperations ) {
86
78
this .destSyncMode = destSyncMode ;
87
79
this .schemaName = schema ;
88
80
this .streamName = streamName ;
@@ -231,58 +223,11 @@ private void closeAndWaitForUpload() throws IOException {
231
223
LOGGER .info ("All data for {} stream uploaded." , streamName );
232
224
}
233
225
234
- public static void attemptS3WriteAndDelete (final S3Config s3Config ) {
235
- attemptS3WriteAndDelete (s3Config , "" );
236
- }
237
-
238
- public static void attemptS3WriteAndDelete (final S3Config s3Config , final String bucketPath ) {
239
- final var prefix = bucketPath .isEmpty () ? "" : bucketPath + (bucketPath .endsWith ("/" ) ? "" : "/" );
240
- final String outputTableName = prefix + "_airbyte_connection_test_" + UUID .randomUUID ().toString ().replaceAll ("-" , "" );
241
- attemptWriteAndDeleteS3Object (s3Config , outputTableName );
242
- }
243
-
244
- private static void attemptWriteAndDeleteS3Object (final S3Config s3Config , final String outputTableName ) {
245
- final var s3 = getAmazonS3 (s3Config );
246
- final var s3Bucket = s3Config .getBucketName ();
247
-
248
- s3 .putObject (s3Bucket , outputTableName , "check-content" );
249
- s3 .deleteObject (s3Bucket , outputTableName );
250
- }
251
-
252
- public static AmazonS3 getAmazonS3 (final S3Config s3Config ) {
253
- final var endpoint = s3Config .getEndpoint ();
254
- final var region = s3Config .getRegion ();
255
- final var accessKeyId = s3Config .getAccessKeyId ();
256
- final var secretAccessKey = s3Config .getSecretAccessKey ();
257
-
258
- final var awsCreds = new BasicAWSCredentials (accessKeyId , secretAccessKey );
259
-
260
- if (endpoint .isEmpty ()) {
261
- return AmazonS3ClientBuilder .standard ()
262
- .withCredentials (new AWSStaticCredentialsProvider (awsCreds ))
263
- .withRegion (s3Config .getRegion ())
264
- .build ();
265
-
266
- } else {
267
-
268
- final ClientConfiguration clientConfiguration = new ClientConfiguration ();
269
- clientConfiguration .setSignerOverride ("AWSS3V4SignerType" );
270
-
271
- return AmazonS3ClientBuilder
272
- .standard ()
273
- .withEndpointConfiguration (new AwsClientBuilder .EndpointConfiguration (endpoint , region ))
274
- .withPathStyleAccessEnabled (true )
275
- .withClientConfiguration (clientConfiguration )
276
- .withCredentials (new AWSStaticCredentialsProvider (awsCreds ))
277
- .build ();
278
- }
279
- }
280
-
281
226
public abstract void copyS3CsvFileIntoTable (JdbcDatabase database ,
282
- String s3FileLocation ,
283
- String schema ,
284
- String tableName ,
285
- S3Config s3Config )
227
+ String s3FileLocation ,
228
+ String schema ,
229
+ String tableName ,
230
+ S3DestinationConfig s3Config )
286
231
throws SQLException ;
287
232
288
233
}
0 commit comments