5050import org .apache .hadoop .hdds .scm .XceiverClientFactory ;
5151import org .apache .hadoop .hdds .scm .XceiverClientManager ;
5252import org .apache .hadoop .hdds .scm .client .ClientTrustManager ;
53+ import org .apache .hadoop .hdds .scm .storage .ByteBufferStreamOutput ;
5354import org .apache .hadoop .hdds .security .x509 .certificate .client .CACertificateProvider ;
5455import org .apache .hadoop .hdds .scm .client .HddsClientUtils ;
5556import org .apache .hadoop .hdds .scm .pipeline .Pipeline ;
@@ -1959,11 +1960,16 @@ public OzoneOutputStream createMultipartKey(
19591960 long size , int partNumber , String uploadID ) throws IOException {
19601961 final OpenKeySession openKey = newMultipartOpenKey (
19611962 volumeName , bucketName , keyName , size , partNumber , uploadID , false );
1963+ return createMultipartOutputStream (openKey , uploadID , partNumber );
1964+ }
1965+
1966+ private OzoneOutputStream createMultipartOutputStream (
1967+ OpenKeySession openKey , String uploadID , int partNumber
1968+ ) throws IOException {
19621969 KeyOutputStream keyOutputStream = createKeyOutputStream (openKey )
19631970 .setMultipartNumber (partNumber )
19641971 .setMultipartUploadID (uploadID )
19651972 .setIsMultipartKey (true )
1966- .setAtomicKeyCreation (isS3GRequest .get ())
19671973 .build ();
19681974 return createOutputStream (openKey , keyOutputStream );
19691975 }
@@ -1979,29 +1985,25 @@ public OzoneDataStreamOutput createMultipartStreamKey(
19791985 throws IOException {
19801986 final OpenKeySession openKey = newMultipartOpenKey (
19811987 volumeName , bucketName , keyName , size , partNumber , uploadID , true );
1982- // Amazon S3 never adds partial objects, So for S3 requests we need to
1983- // set atomicKeyCreation to true
1984- // refer: https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
1985- KeyDataStreamOutput keyOutputStream =
1986- new KeyDataStreamOutput .Builder ()
1987- .setHandler (openKey )
1988- .setXceiverClientManager (xceiverClientManager )
1989- .setOmClient (ozoneManagerClient )
1990- .setReplicationConfig (openKey .getKeyInfo ().getReplicationConfig ())
1991- .setMultipartNumber (partNumber )
1992- .setMultipartUploadID (uploadID )
1993- .setIsMultipartKey (true )
1994- .enableUnsafeByteBufferConversion (unsafeByteBufferConversion )
1995- .setConfig (clientConfig )
1996- .setAtomicKeyCreation (isS3GRequest .get ())
1997- .build ();
1998- keyOutputStream
1999- .addPreallocateBlocks (
2000- openKey .getKeyInfo ().getLatestVersionLocations (),
2001- openKey .getOpenVersion ());
2002- final OzoneOutputStream out = createSecureOutputStream (
2003- openKey , keyOutputStream , null );
2004- return new OzoneDataStreamOutput (out != null ? out : keyOutputStream );
1988+ final ByteBufferStreamOutput out ;
1989+ ReplicationConfig replicationConfig = openKey .getKeyInfo ().getReplicationConfig ();
1990+ if (replicationConfig .getReplicationType () == HddsProtos .ReplicationType .RATIS ) {
1991+ KeyDataStreamOutput keyOutputStream = newKeyOutputStreamBuilder ()
1992+ .setHandler (openKey )
1993+ .setReplicationConfig (replicationConfig )
1994+ .setMultipartNumber (partNumber )
1995+ .setMultipartUploadID (uploadID )
1996+ .setIsMultipartKey (true )
1997+ .build ();
1998+ keyOutputStream .addPreallocateBlocks (
1999+ openKey .getKeyInfo ().getLatestVersionLocations (),
2000+ openKey .getOpenVersion ());
2001+ final OzoneOutputStream secureOut = createSecureOutputStream (openKey , keyOutputStream , null );
2002+ out = secureOut != null ? secureOut : keyOutputStream ;
2003+ } else {
2004+ out = createMultipartOutputStream (openKey , uploadID , partNumber );
2005+ }
2006+ return new OzoneDataStreamOutput (out );
20052007 }
20062008
20072009 @ Override
@@ -2403,25 +2405,33 @@ private OzoneDataStreamOutput createDataStreamOutput(OpenKeySession openKey)
24032405 throws IOException {
24042406 final ReplicationConfig replicationConfig
24052407 = openKey .getKeyInfo ().getReplicationConfig ();
2408+ final ByteBufferStreamOutput out ;
2409+ if (replicationConfig .getReplicationType () == HddsProtos .ReplicationType .RATIS ) {
2410+ KeyDataStreamOutput keyOutputStream = newKeyOutputStreamBuilder ()
2411+ .setHandler (openKey )
2412+ .setReplicationConfig (replicationConfig )
2413+ .build ();
2414+ keyOutputStream .addPreallocateBlocks (
2415+ openKey .getKeyInfo ().getLatestVersionLocations (),
2416+ openKey .getOpenVersion ());
2417+ final OzoneOutputStream secureOut = createSecureOutputStream (openKey , keyOutputStream , null );
2418+ out = secureOut != null ? secureOut : keyOutputStream ;
2419+ } else {
2420+ out = createOutputStream (openKey );
2421+ }
2422+ return new OzoneDataStreamOutput (out );
2423+ }
2424+
2425+ private KeyDataStreamOutput .Builder newKeyOutputStreamBuilder () {
24062426 // Amazon S3 never adds partial objects, So for S3 requests we need to
24072427 // set atomicKeyCreation to true
24082428 // refer: https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
2409- KeyDataStreamOutput keyOutputStream =
2410- new KeyDataStreamOutput .Builder ()
2411- .setHandler (openKey )
2412- .setXceiverClientManager (xceiverClientManager )
2413- .setOmClient (ozoneManagerClient )
2414- .setReplicationConfig (replicationConfig )
2415- .enableUnsafeByteBufferConversion (unsafeByteBufferConversion )
2416- .setConfig (clientConfig )
2417- .setAtomicKeyCreation (isS3GRequest .get ())
2418- .build ();
2419- keyOutputStream
2420- .addPreallocateBlocks (openKey .getKeyInfo ().getLatestVersionLocations (),
2421- openKey .getOpenVersion ());
2422- final OzoneOutputStream out = createSecureOutputStream (
2423- openKey , keyOutputStream , null );
2424- return new OzoneDataStreamOutput (out != null ? out : keyOutputStream );
2429+ return new KeyDataStreamOutput .Builder ()
2430+ .setXceiverClientManager (xceiverClientManager )
2431+ .setOmClient (ozoneManagerClient )
2432+ .enableUnsafeByteBufferConversion (unsafeByteBufferConversion )
2433+ .setConfig (clientConfig )
2434+ .setAtomicKeyCreation (isS3GRequest .get ());
24252435 }
24262436
24272437 private OzoneOutputStream createOutputStream (OpenKeySession openKey )
0 commit comments