mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-12-20 03:59:49 +08:00
Java: add retry on write
This commit is contained in:
@@ -29,11 +29,29 @@ public class SeaweedWrite {
|
|||||||
final byte[] bytes,
|
final byte[] bytes,
|
||||||
final long bytesOffset, final long bytesLength,
|
final long bytesOffset, final long bytesLength,
|
||||||
final String path) throws IOException {
|
final String path) throws IOException {
|
||||||
FilerProto.FileChunk.Builder chunkBuilder = writeChunk(
|
for (long waitTime = 1000L; waitTime < 10 * 1000; waitTime += waitTime / 2) {
|
||||||
replication, filerClient, offset, bytes, bytesOffset, bytesLength, path);
|
try {
|
||||||
synchronized (entry) {
|
FilerProto.FileChunk.Builder chunkBuilder = writeChunk(
|
||||||
entry.addChunks(chunkBuilder);
|
replication, filerClient, offset, bytes, bytesOffset, bytesLength, path);
|
||||||
|
lastException = null;
|
||||||
|
synchronized (entry) {
|
||||||
|
entry.addChunks(chunkBuilder);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
LOG.debug("writeData:{}", ioe);
|
||||||
|
lastException = ioe;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(waitTime);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lastException != null) {
|
||||||
|
throw lastException;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FilerProto.FileChunk.Builder writeChunk(final String replication,
|
public static FilerProto.FileChunk.Builder writeChunk(final String replication,
|
||||||
|
|||||||
Reference in New Issue
Block a user