diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-07-20 15:35:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-20 15:35:47 +0800 |
| commit | 5850bb733936399babbe2d77f4b27cac312e2798 (patch) | |
| tree | 3966daffbb7b2633906f883e3047511772a4fdcf /other/java/hdfs3/src | |
| parent | b1616e93474246a624370ad18da98b8371c09ece (diff) | |
| parent | f90d2c93c9e34997a8e76aeefb438ec06b1cd093 (diff) | |
| download | seaweedfs-5850bb733936399babbe2d77f4b27cac312e2798.tar.xz seaweedfs-5850bb733936399babbe2d77f4b27cac312e2798.zip | |
Merge pull request #2 from chrislusf/master
sync
Diffstat (limited to 'other/java/hdfs3/src')
| -rw-r--r-- | other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedOutputStream.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedOutputStream.java b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedOutputStream.java index 9ea26776b..c602a0d81 100644 --- a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedOutputStream.java +++ b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedOutputStream.java @@ -216,12 +216,35 @@ public class SeaweedOutputStream extends OutputStream implements Syncable, Strea return; } - buffer.flip(); - int bytesLength = buffer.limit() - buffer.position(); - SeaweedWrite.writeData(entry, replication, filerGrpcClient, position, buffer.array(), buffer.position(), buffer.limit()); - // System.out.println(path + " saved [" + (position) + "," + ((position) + bytesLength) + ")"); - position += bytesLength; - buffer.clear(); + position += submitWriteBufferToService(buffer, position); + + buffer = ByteBufferPool.request(bufferSize); + + } + + private synchronized int submitWriteBufferToService(final ByteBuffer bufferToWrite, final long writePosition) throws IOException { + + bufferToWrite.flip(); + int bytesLength = bufferToWrite.limit() - bufferToWrite.position(); + + if (threadExecutor.getQueue().size() >= maxConcurrentRequestCount * 2) { + waitForTaskToComplete(); + } + final Future<Void> job = completionService.submit(() -> { + // System.out.println(path + " is going to save [" + (writePosition) + "," + ((writePosition) + bytesLength) + ")"); + SeaweedWrite.writeData(entry, replication, filerGrpcClient, writePosition, bufferToWrite.array(), bufferToWrite.position(), bufferToWrite.limit()); + // System.out.println(path + " saved [" + (writePosition) + "," + ((writePosition) + bytesLength) + ")"); + bufferToWrite.clear(); + ByteBufferPool.release(bufferToWrite); + return null; + }); + + writeOperations.add(new WriteOperation(job, writePosition, bytesLength)); + + // Try to shrink the queue + shrinkWriteOperationQueue(); + + return bytesLength; } |
