|
22 | 22 | import java.io.IOException; |
23 | 23 | import java.util.Iterator; |
24 | 24 |
|
| 25 | +import org.apache.hadoop.fs.FSDataOutputStream; |
| 26 | +import org.apache.hadoop.fs.Path; |
| 27 | +import org.apache.hadoop.hdfs.AppendTestUtil; |
| 28 | +import org.apache.hadoop.hdfs.protocol.Block; |
25 | 29 | import org.slf4j.Logger; |
26 | 30 | import org.slf4j.LoggerFactory; |
27 | 31 | import org.apache.hadoop.classification.InterfaceAudience; |
@@ -132,6 +136,23 @@ private CheckpointSignature runOperations() throws IOException { |
132 | 136 | DFSTestUtil.runOperations(cluster, dfs, cluster.getConfiguration(0), |
133 | 137 | dfs.getDefaultBlockSize(), 0); |
134 | 138 |
|
| 139 | + String client = "client"; |
| 140 | + String clientMachine = "clientMachine"; |
| 141 | + String src = "/test/testTruncate"; |
| 142 | + Path srcPath = new Path(src); |
| 143 | + byte[] contents = AppendTestUtil.initBuffer(512); |
| 144 | + FSDataOutputStream out = dfs.create(srcPath, true, 4, (short)3, |
| 145 | + dfs.getDefaultBlockSize()); |
| 146 | + out.write(contents, 0, 511); |
| 147 | + out.close(); |
| 148 | + |
| 149 | + INodesInPath iip = cluster.getNamesystem().getFSDirectory().getINodesInPath(src, FSDirectory.DirOp.WRITE); |
| 150 | + cluster.getNamesystem().writeLock(); |
| 151 | + Block truncateBlock = FSDirTruncateOp.prepareFileForTruncate(cluster.getNamesystem(), iip, |
| 152 | + client, clientMachine, 1, null); |
| 153 | + cluster.getNamesystem().getEditLog().logTruncate(src, client, clientMachine, truncateBlock.getNumBytes()-1, Time.now(), truncateBlock); |
| 154 | + cluster.getNamesystem().writeUnlock(); |
| 155 | + |
135 | 156 | // OP_ROLLING_UPGRADE_START |
136 | 157 | cluster.getNamesystem().getEditLog().logStartRollingUpgrade(Time.now()); |
137 | 158 | // OP_ROLLING_UPGRADE_FINALIZE |
|
0 commit comments