|
@@ -29,6 +29,10 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.MutableBlockCollection;
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.MutableBlockCollection;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.snapshot.INodeFileUnderConstructionWithLink;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.snapshot.INodeFileWithLink;
|
|
|
|
+
|
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
|
|
|
/**
|
|
/**
|
|
* I-node for file being written.
|
|
* I-node for file being written.
|
|
@@ -45,6 +49,28 @@ public class INodeFileUnderConstruction extends INodeFile implements MutableBloc
|
|
return (INodeFileUnderConstruction)file;
|
|
return (INodeFileUnderConstruction)file;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /** Convert the given file to an {@link INodeFileUnderConstruction}. */
|
|
|
|
+ public static INodeFileUnderConstruction toINodeFileUnderConstruction(
|
|
|
|
+ INodeFile file,
|
|
|
|
+ String clientName,
|
|
|
|
+ String clientMachine,
|
|
|
|
+ DatanodeDescriptor clientNode) {
|
|
|
|
+ Preconditions.checkArgument(!(file instanceof INodeFileUnderConstruction),
|
|
|
|
+ "file is already an INodeFileUnderConstruction");
|
|
|
|
+ final INodeFileUnderConstruction uc = new INodeFileUnderConstruction(
|
|
|
|
+ file.getLocalNameBytes(),
|
|
|
|
+ file.getFileReplication(),
|
|
|
|
+ file.getModificationTime(),
|
|
|
|
+ file.getPreferredBlockSize(),
|
|
|
|
+ file.getBlocks(),
|
|
|
|
+ file.getPermissionStatus(),
|
|
|
|
+ clientName,
|
|
|
|
+ clientMachine,
|
|
|
|
+ clientNode);
|
|
|
|
+ return file instanceof INodeFileWithLink?
|
|
|
|
+ new INodeFileUnderConstructionWithLink(uc): uc;
|
|
|
|
+ }
|
|
|
|
+
|
|
private String clientName; // lease holder
|
|
private String clientName; // lease holder
|
|
private final String clientMachine;
|
|
private final String clientMachine;
|
|
private final DatanodeDescriptor clientNode; // if client is a cluster node too.
|
|
private final DatanodeDescriptor clientNode; // if client is a cluster node too.
|
|
@@ -56,11 +82,8 @@ public class INodeFileUnderConstruction extends INodeFile implements MutableBloc
|
|
String clientName,
|
|
String clientName,
|
|
String clientMachine,
|
|
String clientMachine,
|
|
DatanodeDescriptor clientNode) {
|
|
DatanodeDescriptor clientNode) {
|
|
- super(permissions.applyUMask(UMASK), BlockInfo.EMPTY_ARRAY, replication,
|
|
|
|
- modTime, modTime, preferredBlockSize);
|
|
|
|
- this.clientName = clientName;
|
|
|
|
- this.clientMachine = clientMachine;
|
|
|
|
- this.clientNode = clientNode;
|
|
|
|
|
|
+ this(null, replication, modTime, preferredBlockSize, BlockInfo.EMPTY_ARRAY,
|
|
|
|
+ permissions.applyUMask(UMASK), clientName, clientMachine, clientNode);
|
|
}
|
|
}
|
|
|
|
|
|
INodeFileUnderConstruction(byte[] name,
|
|
INodeFileUnderConstruction(byte[] name,
|
|
@@ -78,6 +101,13 @@ public class INodeFileUnderConstruction extends INodeFile implements MutableBloc
|
|
this.clientMachine = clientMachine;
|
|
this.clientMachine = clientMachine;
|
|
this.clientNode = clientNode;
|
|
this.clientNode = clientNode;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ protected INodeFileUnderConstruction(INodeFileUnderConstruction that) {
|
|
|
|
+ super(that);
|
|
|
|
+ this.clientName = that.clientName;
|
|
|
|
+ this.clientMachine = that.clientMachine;
|
|
|
|
+ this.clientNode = that.clientNode;
|
|
|
|
+ }
|
|
|
|
|
|
String getClientName() {
|
|
String getClientName() {
|
|
return clientName;
|
|
return clientName;
|
|
@@ -103,30 +133,26 @@ public class INodeFileUnderConstruction extends INodeFile implements MutableBloc
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- //
|
|
|
|
- // converts a INodeFileUnderConstruction into a INodeFile
|
|
|
|
- // use the modification time as the access time
|
|
|
|
- //
|
|
|
|
- INodeFile convertToInodeFile(long mtime) {
|
|
|
|
- assert allBlocksComplete() : "Can't finalize inode " + this
|
|
|
|
- + " since it contains non-complete blocks! Blocks are "
|
|
|
|
- + Arrays.asList(getBlocks());
|
|
|
|
- //TODO SNAPSHOT: may convert to INodeFileWithLink
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Converts an INodeFileUnderConstruction to an INodeFile.
|
|
|
|
+ * The original modification time is used as the access time.
|
|
|
|
+ * The new modification is the specified mtime.
|
|
|
|
+ */
|
|
|
|
+ protected INodeFile toINodeFile(long mtime) {
|
|
|
|
+ assertAllBlocksComplete();
|
|
return new INodeFile(getLocalNameBytes(), getPermissionStatus(),
|
|
return new INodeFile(getLocalNameBytes(), getPermissionStatus(),
|
|
mtime, getModificationTime(),
|
|
mtime, getModificationTime(),
|
|
getBlocks(), getFileReplication(), getPreferredBlockSize());
|
|
getBlocks(), getFileReplication(), getPreferredBlockSize());
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @return true if all of the blocks in this file are marked as completed.
|
|
|
|
- */
|
|
|
|
- private boolean allBlocksComplete() {
|
|
|
|
- for (BlockInfo b : getBlocks()) {
|
|
|
|
- if (!b.isComplete()) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ /** Assert all blocks are complete. */
|
|
|
|
+ protected void assertAllBlocksComplete() {
|
|
|
|
+ final BlockInfo[] blocks = getBlocks();
|
|
|
|
+ for (int i = 0; i < blocks.length; i++) {
|
|
|
|
+ Preconditions.checkState(blocks[i].isComplete(), "Failed to finalize"
|
|
|
|
+ + " %s %s since blocks[%s] is non-complete, where blocks=%s.",
|
|
|
|
+ getClass().getSimpleName(), this, i, Arrays.asList(getBlocks()));
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|