|
@@ -59,6 +59,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
|
import org.apache.hadoop.hdfs.util.Canceler;
|
|
|
import org.apache.hadoop.hdfs.util.MD5FileUtils;
|
|
|
import org.apache.hadoop.io.MD5Hash;
|
|
|
+import org.apache.hadoop.util.IdGenerator;
|
|
|
import org.apache.hadoop.util.Time;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DFSUtil;
|
|
@@ -92,6 +93,7 @@ public class FSImage implements Closeable {
|
|
|
final private Configuration conf;
|
|
|
|
|
|
protected NNStorageRetentionManager archivalManager;
|
|
|
+ protected IdGenerator blockIdGenerator;
|
|
|
|
|
|
/**
|
|
|
* Construct an FSImage
|
|
@@ -137,6 +139,9 @@ public class FSImage implements Closeable {
|
|
|
Preconditions.checkState(fileCount == 1,
|
|
|
"FSImage.format should be called with an uninitialized namesystem, has " +
|
|
|
fileCount + " files");
|
|
|
+ // BlockIdGenerator is defined during formatting
|
|
|
+ // currently there is only one BlockIdGenerator
|
|
|
+ blockIdGenerator = createBlockIdGenerator(fsn);
|
|
|
NamespaceInfo ns = NNStorage.newNamespaceInfo();
|
|
|
ns.clusterID = clusterId;
|
|
|
|
|
@@ -253,6 +258,7 @@ public class FSImage implements Closeable {
|
|
|
doRollback();
|
|
|
break;
|
|
|
case REGULAR:
|
|
|
+ default:
|
|
|
// just load the image
|
|
|
}
|
|
|
|
|
@@ -737,6 +743,9 @@ public class FSImage implements Closeable {
|
|
|
FSImageFormat.Loader loader = new FSImageFormat.Loader(
|
|
|
conf, target);
|
|
|
loader.load(curFile);
|
|
|
+ // BlockIdGenerator is determined after loading image
|
|
|
+ // currently there is only one BlockIdGenerator
|
|
|
+ blockIdGenerator = createBlockIdGenerator(target);
|
|
|
target.setBlockPoolId(this.getBlockPoolID());
|
|
|
|
|
|
// Check that the image digest we loaded matches up with what
|
|
@@ -1165,4 +1174,12 @@ public class FSImage implements Closeable {
|
|
|
public synchronized long getMostRecentCheckpointTxId() {
|
|
|
return storage.getMostRecentCheckpointTxId();
|
|
|
}
|
|
|
+
|
|
|
+ public long getUniqueBlockId() {
|
|
|
+ return blockIdGenerator.nextValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ public IdGenerator createBlockIdGenerator(FSNamesystem fsn) {
|
|
|
+ return new RandomBlockIdGenerator(fsn);
|
|
|
+ }
|
|
|
}
|