|
42 | 42 | @ThreadSafe |
43 | 43 | final class CloudStorageReadChannel implements SeekableByteChannel { |
44 | 44 |
|
| 45 | + private final Storage gcsStorage; |
| 46 | + private final BlobId file; |
45 | 47 | private ReadChannel channel; |
46 | 48 | private long position; |
47 | 49 | private long size; |
48 | | - private Storage gcsStorage; |
49 | | - private BlobId file; |
50 | 50 | // max # of times we may reopen the file |
51 | 51 | private final int maxReopen; |
52 | 52 | // how many times we re-opened the file |
@@ -109,29 +109,23 @@ public int read(ByteBuffer dst) throws IOException { |
109 | 109 | } catch (StorageException exs) { |
110 | 110 | // this error isn't marked as retryable since the channel is closed; |
111 | 111 | // but here at this higher level we can retry it. |
112 | | - if (exs.getMessage().contains("Connection closed prematurely")) { |
113 | | - if (reopens < maxReopen) { |
114 | | - reopens++; |
115 | | - retryDelay(reopens); |
116 | | - innerOpen(); |
117 | | - continue; |
118 | | - } |
119 | | - } else if (exs.getCode() == 500) { |
| 112 | + if (exs.getMessage().contains("Connection closed prematurely") && reopens < maxReopen) { |
| 113 | + reopens++; |
| 114 | + retryDelay(reopens); |
| 115 | + innerOpen(); |
| 116 | + continue; |
| 117 | + } else if (exs.getCode() == 500 && retries < maxRetries) { |
120 | 118 | // server error. Not retryable yet retrying works in my experience. |
121 | | - if (retries < maxRetries) { |
122 | | - retries++; |
123 | | - retryDelay(retries); |
124 | | - continue; |
125 | | - } |
126 | | - } else if (exs.getCode() == 503) { |
| 119 | + retries++; |
| 120 | + retryDelay(retries); |
| 121 | + continue; |
| 122 | + } else if (exs.getCode() == 503 && retries < maxRetries) { |
127 | 123 | // server temporarily unavailable. Marked not retriable, |
128 | 124 | // yet retrying works in my experience. |
129 | | - if (retries < maxRetries) { |
130 | | - retries++; |
131 | | - // wait a bit more since this error suggests the server's busy |
132 | | - retryDelay(retries + 1); |
133 | | - continue; |
134 | | - } |
| 125 | + retries++; |
| 126 | + // wait a bit more since this error suggests the server's busy |
| 127 | + retryDelay(retries + 1); |
| 128 | + continue; |
135 | 129 | } |
136 | 130 | throw exs; |
137 | 131 | } |
|
0 commit comments