|
@@ -2169,6 +2169,8 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
|
|
private int maxRecoveryErrorCount = 5; // try block recovery 5 times
|
|
|
private volatile boolean appendChunk = false; // appending to existing partial block
|
|
|
private long initialFileSize = 0; // at time of file open
|
|
|
+ private Progressable progress;
|
|
|
+ private short blockReplication; // replication factor of file
|
|
|
|
|
|
private void setLastException(IOException e) {
|
|
|
if (lastException == null) {
|
|
@@ -2707,13 +2709,12 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Progressable progress;
|
|
|
-
|
|
|
private DFSOutputStream(String src, long blockSize, Progressable progress,
|
|
|
- int bytesPerChecksum) throws IOException {
|
|
|
+ int bytesPerChecksum, short replication) throws IOException {
|
|
|
super(new CRC32(), bytesPerChecksum, 4);
|
|
|
this.src = src;
|
|
|
this.blockSize = blockSize;
|
|
|
+ this.blockReplication = replication;
|
|
|
this.progress = progress;
|
|
|
if (progress != null) {
|
|
|
LOG.debug("Set non-null progress callback on DFSOutputStream "+src);
|
|
@@ -2737,7 +2738,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
|
|
DFSOutputStream(String src, FsPermission masked, boolean overwrite,
|
|
|
short replication, long blockSize, Progressable progress,
|
|
|
int buffersize, int bytesPerChecksum) throws IOException {
|
|
|
- this(src, blockSize, progress, bytesPerChecksum);
|
|
|
+ this(src, blockSize, progress, bytesPerChecksum, replication);
|
|
|
|
|
|
computePacketChunkSize(writePacketSize, bytesPerChecksum);
|
|
|
|
|
@@ -2759,7 +2760,7 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
|
|
DFSOutputStream(String src, int buffersize, Progressable progress,
|
|
|
LocatedBlock lastBlock, FileStatus stat,
|
|
|
int bytesPerChecksum) throws IOException {
|
|
|
- this(src, stat.getBlockSize(), progress, bytesPerChecksum);
|
|
|
+ this(src, stat.getBlockSize(), progress, bytesPerChecksum, stat.getReplication());
|
|
|
initialFileSize = stat.getLen(); // length of file when opened
|
|
|
|
|
|
//
|
|
@@ -3155,6 +3156,24 @@ public class DFSClient implements FSConstants, java.io.Closeable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the number of replicas of current block. This can be different
|
|
|
+ * from the designated replication factor of the file because the NameNode
|
|
|
+ * does not replicate the block to which a client is currently writing to.
|
|
|
+ * The client continues to write to a block even if a few datanodes in the
|
|
|
+ * write pipeline have failed. If the current block is full and the next
|
|
|
+ * block is not yet allocated, then this API will return 0 because there are
|
|
|
+ * no replicas in the pipeline.
|
|
|
+ */
|
|
|
+ public int getNumCurrentReplicas() throws IOException {
|
|
|
+ synchronized(dataQueue) {
|
|
|
+ if (nodes == null) {
|
|
|
+ return blockReplication;
|
|
|
+ }
|
|
|
+ return nodes.length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Waits till all existing data is flushed and confirmations
|
|
|
* received from datanodes.
|