Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit fa993ec

Browse files
authored
Merge pull request #541 from Azure/legacy-dev
Legacy dev
2 parents 979799e + 20d19f7 commit fa993ec

File tree

15 files changed

+179
-26
lines changed

15 files changed

+179
-26
lines changed

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2020.03.30 Version 8.6.3
2+
* Added the commitWriteOnInputStreamException option to BlobRequestOptions, which will allow the user to configure whether any data staged through openWrite when using the upload(InputStream, long) method will be committed upon failures in the InputStream.
3+
* Disabled httpsKeepAlive by default as it can introduce some perf issues.
4+
15
2020.03.18 Version 8.6.2
26
* Fixed a bug in the pom that disrupted the ability to download from maven central.
37

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
3939
<dependency>
4040
<groupId>com.microsoft.azure</groupId>
4141
<artifactId>azure-storage</artifactId>
42-
<version>8.6.2</version>
42+
<version>8.6.3</version>
4343
</dependency>
4444
```
4545

microsoft-azure-storage-samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.microsoft.azure</groupId>
2828
<artifactId>azure-storage</artifactId>
29-
<version>8.6.2</version>
29+
<version>8.6.3</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>com.microsoft.azure</groupId>

microsoft-azure-storage-samples/src/com/microsoft/azure/storage/logging/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.microsoft.azure</groupId>
2828
<artifactId>azure-storage</artifactId>
29-
<version>8.6.2</version>
29+
<version>8.6.3</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>com.microsoft.azure</groupId>

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,71 @@ public void testSkipEtagCheck() throws StorageException, IOException, URISyntaxE
27552755
stream.close();
27562756
}
27572757

2758+
private static class ExceptionInputStream extends InputStream {
2759+
private final byte[] data;
2760+
int index = 0;
2761+
boolean firstRead = true;
2762+
2763+
ExceptionInputStream(byte[] data) {
2764+
this.data = data;
2765+
}
2766+
2767+
@Override
2768+
public int read() throws IOException {
2769+
return 0;
2770+
}
2771+
2772+
@Override
2773+
public int read(byte[] arr, int offset, int len) throws IOException {
2774+
if (firstRead) {
2775+
// Fill either half the incoming buffer or use half the data, whichever is smaller.
2776+
// For safe partial write.
2777+
int size = Math.min(data.length, len) / 2;
2778+
if (len >= 0) System.arraycopy(data, index, arr, offset, size);
2779+
firstRead = false;
2780+
return size;
2781+
} else {
2782+
throw new IOException();
2783+
}
2784+
}
2785+
}
2786+
2787+
@Test
2788+
public void testCommitOnInputStreamException() throws StorageException, IOException, URISyntaxException {
2789+
final int blobSize = 2 * Constants.DEFAULT_MINIMUM_READ_SIZE_IN_BYTES; // so BlobInputStream doesn't read entire blob at once.
2790+
2791+
CloudBlobContainer container = BlobTestHelper.getRandomContainerReference();
2792+
container.createIfNotExists();
2793+
CloudBlockBlob blob = container.getBlockBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix(""));
2794+
2795+
BlobRequestOptions options = new BlobRequestOptions();
2796+
2797+
// Upload with no commit on failure.
2798+
byte[] data = TestHelper.getRandomBuffer(blobSize);
2799+
InputStream is = new ExceptionInputStream(data);
2800+
options.setCommitWriteOnInputStreamException(false);
2801+
2802+
try {
2803+
blob.upload(is, blobSize, null, null, options, null);
2804+
fail();
2805+
} catch(IOException e) {
2806+
assertFalse(blob.exists());
2807+
}
2808+
2809+
// Upload with commit on failure.
2810+
is = new ExceptionInputStream(data);
2811+
options = new BlobRequestOptions(); // Test the default. Should be true.
2812+
2813+
try {
2814+
blob.upload(is, blobSize, null, null, options, null);
2815+
fail();
2816+
} catch (IOException e) {
2817+
assertTrue(blob.exists());
2818+
}
2819+
2820+
container.delete();
2821+
}
2822+
27582823
@Test
27592824
public void testPutGetBlobCPK() throws URISyntaxException, StorageException, IOException {
27602825
// load CPK into options

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public static class HeaderConstants {
765765
/**
766766
* Specifies the value to use for UserAgent header.
767767
*/
768-
public static final String USER_AGENT_VERSION = "8.6.2";
768+
public static final String USER_AGENT_VERSION = "8.6.3";
769769

770770
/**
771771
* The default type for content-type and accept

microsoft-azure-storage/src/com/microsoft/azure/storage/RequestOptions.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected static void applyBaseDefaultsInternal(final RequestOptions modifiedOpt
108108
}
109109

110110
if (modifiedOptions.disableHttpsSocketKeepAlive() == null) {
111-
modifiedOptions.setDisableHttpsSocketKeepAlive(false);
111+
modifiedOptions.setDisableHttpsSocketKeepAlive(true);
112112
}
113113
}
114114

@@ -209,7 +209,7 @@ public Boolean requireEncryption() {
209209
* keep-alive; otherwise, <code>false</code>. For more information about disableHttpsSocketKeepAlive defaults, see
210210
* {@link ServiceClient#getDefaultRequestOptions()}
211211
*
212-
* @return A value to indicate whther https socket keep-alive should be disabled.
212+
* @return A value to indicate whether https socket keep-alive should be disabled.
213213
*/
214214
public Boolean disableHttpsSocketKeepAlive() {
215215
return this.disableHttpsSocketKeepAlive;
@@ -322,16 +322,16 @@ public void setRequireEncryption(Boolean requireEncryption) {
322322
* Sets a value to indicate whether https socket keep-alive should be disabled. Use <code>true</code> to disable
323323
* keep-alive; otherwise, <code>false</code>
324324
* <p>
325-
* The default is set in the client and is by default false, indicating that https socket keep-alive will be
326-
* enabled. You can change the value on this request by setting this property. You can also change the value on
325+
* The default is set in the client and is by default true, indicating that https socket keep-alive will be
326+
* disabled. You can change the value on this request by setting this property. You can also change the value on
327327
* on the {@link ServiceClient#getDefaultRequestOptions()} object so that all subsequent requests made via the
328328
* service client will use the appropriate value.
329329
* <p>
330330
* Setting keep-alive on https sockets is to work around a bug in the JVM where connection timeouts are not honored
331-
* on retried requests. In those cases, we use socket keep-alive as a fallback. Unfortunately, the timeout value
332-
* must be taken from a JVM property rather than configured locally. Therefore, in rare cases the JVM has configured
333-
* aggressively short keep-alive times, it may be beneficial to disable the use of keep-alives lest they interfere
334-
* with long running data transfer operations.
331+
* on retried requests. In those cases, you may choose to use socket keep-alive as a fallback. Unfortunately, the
332+
* timeout value must be taken from a JVM property rather than configured locally. Therefore, in rare cases the JVM
333+
* has configured aggressively short keep-alive times, it may not be beneficial to enable the use of keep-alives
334+
* lest they interfere with long running data transfer operations.
335335
*
336336
* @param disableHttpsSocketKeepAlive
337337
* A value to indicate whether https socket keep-alive should be disabled.

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobDecryptStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public void close() throws IOException
5959
this.cryptoStream.close();
6060
}
6161

62+
@Override
63+
void abort() throws IOException {
64+
// no-op. This method is used in the case of aborting uploads, and decrypt streams are on downloads.
65+
}
66+
6267
@Override
6368
public void write(byte[] data, int offset, int length) throws IOException {
6469
// Keep buffering until we have 16 bytes of IV.

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobEncryptStream.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ final class BlobEncryptStream extends BlobOutputStream {
4545
* Holds the cipher stream.
4646
*/
4747
private CipherOutputStream cipherStream;
48+
49+
private BlobOutputStreamInternal blobStream;
4850

4951
/**
5052
* Initializes a new instance of the BlobEncryptStream class for a CloudBlockBlob
@@ -70,8 +72,7 @@ protected BlobEncryptStream(final CloudBlockBlob blockBlob, final AccessConditio
7072
this.options = options;
7173

7274
this.options.setValidateEncryptionPolicy(false);
73-
BlobOutputStreamInternal blobStream =
74-
new BlobOutputStreamInternal(blockBlob, accessCondition, options, opContext);
75+
blobStream = new BlobOutputStreamInternal(blockBlob, accessCondition, options, opContext);
7576
this.cipherStream = new CipherOutputStream(blobStream, cipher);
7677
}
7778

@@ -159,4 +160,9 @@ public void close() throws IOException {
159160
this.cipherStream.close();
160161
}
161162

163+
@Override
164+
void abort() throws IOException {
165+
this.blobStream.abort();
166+
}
167+
162168
}

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStream.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ public void write(final byte[] data) throws IOException {
111111
@Override
112112
@DoesServiceRequest
113113
public abstract void close() throws IOException;
114+
115+
/**
116+
* Signals to the BlobOutputStream that it is being aborted and should not commit the data to the service on
117+
* closing, typically to be used in cases of errors or exceptions in the data source.
118+
*/
119+
abstract void abort() throws IOException;
114120
}

0 commit comments

Comments
 (0)