HDFS-12779. [READ] Allow cluster id to be specified to the Image generation tool
This commit is contained in:
parent
90d1b47a2a
commit
6cd80b2521
@ -160,6 +160,10 @@ public HAServiceState getState() {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setClusterID(String clusterID) {
|
||||||
|
this.clusterID = clusterID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return super.toString() + ";bpid=" + blockPoolID;
|
return super.toString() + ";bpid=" + blockPoolID;
|
||||||
|
@ -68,6 +68,7 @@ static Options options() {
|
|||||||
options.addOption("b", "blockclass", true, "Block output class");
|
options.addOption("b", "blockclass", true, "Block output class");
|
||||||
options.addOption("i", "blockidclass", true, "Block resolver class");
|
options.addOption("i", "blockidclass", true, "Block resolver class");
|
||||||
options.addOption("c", "cachedirs", true, "Max active dirents");
|
options.addOption("c", "cachedirs", true, "Max active dirents");
|
||||||
|
options.addOption("cid", "clusterID", true, "Cluster ID");
|
||||||
options.addOption("h", "help", false, "Print usage");
|
options.addOption("h", "help", false, "Print usage");
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
@ -112,6 +113,9 @@ public int run(String[] argv) throws Exception {
|
|||||||
case "c":
|
case "c":
|
||||||
opts.cache(Integer.parseInt(o.getValue()));
|
opts.cache(Integer.parseInt(o.getValue()));
|
||||||
break;
|
break;
|
||||||
|
case "cid":
|
||||||
|
opts.clusterID(o.getValue());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Internal error");
|
throw new UnsupportedOperationException("Internal error");
|
||||||
}
|
}
|
||||||
|
@ -126,13 +126,16 @@ public ImageWriter(Options opts) throws IOException {
|
|||||||
throw new IllegalStateException("Incompatible layout " +
|
throw new IllegalStateException("Incompatible layout " +
|
||||||
info.getLayoutVersion() + " (expected " + LAYOUT_VERSION);
|
info.getLayoutVersion() + " (expected " + LAYOUT_VERSION);
|
||||||
}
|
}
|
||||||
|
// set the cluster id, if given
|
||||||
|
if (opts.clusterID.length() > 0) {
|
||||||
|
info.setClusterID(opts.clusterID);
|
||||||
|
}
|
||||||
stor.format(info);
|
stor.format(info);
|
||||||
blockPoolID = info.getBlockPoolID();
|
blockPoolID = info.getBlockPoolID();
|
||||||
}
|
}
|
||||||
outdir = new Path(tmp, "current");
|
outdir = new Path(tmp, "current");
|
||||||
out = outfs.create(new Path(outdir, "fsimage_0000000000000000000"));
|
out = outfs.create(new Path(outdir, "fsimage_0000000000000000000"));
|
||||||
} else {
|
} else {
|
||||||
// XXX necessary? writing a NNStorage now...
|
|
||||||
outdir = null;
|
outdir = null;
|
||||||
outfs = null;
|
outfs = null;
|
||||||
out = opts.outStream;
|
out = opts.outStream;
|
||||||
@ -517,6 +520,7 @@ public static class Options implements Configurable {
|
|||||||
private UGIResolver ugis;
|
private UGIResolver ugis;
|
||||||
private Class<? extends UGIResolver> ugisClass;
|
private Class<? extends UGIResolver> ugisClass;
|
||||||
private BlockAliasMap<FileRegion> blocks;
|
private BlockAliasMap<FileRegion> blocks;
|
||||||
|
private String clusterID;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private Class<? extends BlockAliasMap> aliasMap;
|
private Class<? extends BlockAliasMap> aliasMap;
|
||||||
@ -543,6 +547,7 @@ public void setConf(Configuration conf) {
|
|||||||
NullBlockAliasMap.class, BlockAliasMap.class);
|
NullBlockAliasMap.class, BlockAliasMap.class);
|
||||||
blockIdsClass = conf.getClass(BLOCK_RESOLVER_CLASS,
|
blockIdsClass = conf.getClass(BLOCK_RESOLVER_CLASS,
|
||||||
FixedBlockResolver.class, BlockResolver.class);
|
FixedBlockResolver.class, BlockResolver.class);
|
||||||
|
clusterID = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -601,6 +606,10 @@ public Options blocks(Class<? extends BlockAliasMap> blocksClass) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Options clusterID(String clusterID) {
|
||||||
|
this.clusterID = clusterID;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -155,11 +155,18 @@ public void shutdown() throws Exception {
|
|||||||
|
|
||||||
void createImage(TreeWalk t, Path out,
|
void createImage(TreeWalk t, Path out,
|
||||||
Class<? extends BlockResolver> blockIdsClass) throws Exception {
|
Class<? extends BlockResolver> blockIdsClass) throws Exception {
|
||||||
|
createImage(t, out, blockIdsClass, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void createImage(TreeWalk t, Path out,
|
||||||
|
Class<? extends BlockResolver> blockIdsClass, String clusterID)
|
||||||
|
throws Exception {
|
||||||
ImageWriter.Options opts = ImageWriter.defaults();
|
ImageWriter.Options opts = ImageWriter.defaults();
|
||||||
opts.setConf(conf);
|
opts.setConf(conf);
|
||||||
opts.output(out.toString())
|
opts.output(out.toString())
|
||||||
.blocks(TextFileRegionAliasMap.class)
|
.blocks(TextFileRegionAliasMap.class)
|
||||||
.blockIds(blockIdsClass);
|
.blockIds(blockIdsClass)
|
||||||
|
.clusterID(clusterID);
|
||||||
try (ImageWriter w = new ImageWriter(opts)) {
|
try (ImageWriter w = new ImageWriter(opts)) {
|
||||||
for (TreePath e : t) {
|
for (TreePath e : t) {
|
||||||
w.accept(e);
|
w.accept(e);
|
||||||
@ -562,4 +569,19 @@ private void verifyFileLocation(int fileIndex)
|
|||||||
dnInfos[0].getDatanodeUuid());
|
dnInfos[0].getDatanodeUuid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetClusterID() throws Exception {
|
||||||
|
String clusterID = "PROVIDED-CLUSTER";
|
||||||
|
createImage(new FSTreeWalk(NAMEPATH, conf), NNDIRPATH,
|
||||||
|
FixedBlockResolver.class, clusterID);
|
||||||
|
// 2 Datanodes, 1 PROVIDED and other DISK
|
||||||
|
startCluster(NNDIRPATH, 2, null,
|
||||||
|
new StorageType[][] {
|
||||||
|
{StorageType.PROVIDED},
|
||||||
|
{StorageType.DISK}},
|
||||||
|
false);
|
||||||
|
NameNode nn = cluster.getNameNode();
|
||||||
|
assertEquals(clusterID, nn.getNamesystem().getClusterId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user