|
@@ -157,30 +157,37 @@ public class TestDirectoryScanner {
|
|
|
private void duplicateBlock(long blockId) throws IOException {
|
|
|
synchronized (fds) {
|
|
|
ReplicaInfo b = FsDatasetTestUtil.fetchReplicaInfo(fds, bpid, blockId);
|
|
|
- for (FsVolumeSpi v : fds.getVolumes()) {
|
|
|
- if (v.getStorageID().equals(b.getVolume().getStorageID())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Volume without a copy of the block. Make a copy now.
|
|
|
- File sourceBlock = b.getBlockFile();
|
|
|
- File sourceMeta = b.getMetaFile();
|
|
|
- String sourceRoot = b.getVolume().getBasePath();
|
|
|
- String destRoot = v.getBasePath();
|
|
|
-
|
|
|
- String relativeBlockPath = new File(sourceRoot).toURI().relativize(sourceBlock.toURI()).getPath();
|
|
|
- String relativeMetaPath = new File(sourceRoot).toURI().relativize(sourceMeta.toURI()).getPath();
|
|
|
-
|
|
|
- File destBlock = new File(destRoot, relativeBlockPath);
|
|
|
- File destMeta = new File(destRoot, relativeMetaPath);
|
|
|
-
|
|
|
- destBlock.getParentFile().mkdirs();
|
|
|
- FileUtils.copyFile(sourceBlock, destBlock);
|
|
|
- FileUtils.copyFile(sourceMeta, destMeta);
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences volumes =
|
|
|
+ fds.getFsVolumeReferences()) {
|
|
|
+ for (FsVolumeSpi v : volumes) {
|
|
|
+ if (v.getStorageID().equals(b.getVolume().getStorageID())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- if (destBlock.exists() && destMeta.exists()) {
|
|
|
- LOG.info("Copied " + sourceBlock + " ==> " + destBlock);
|
|
|
- LOG.info("Copied " + sourceMeta + " ==> " + destMeta);
|
|
|
+ // Volume without a copy of the block. Make a copy now.
|
|
|
+ File sourceBlock = b.getBlockFile();
|
|
|
+ File sourceMeta = b.getMetaFile();
|
|
|
+ String sourceRoot = b.getVolume().getBasePath();
|
|
|
+ String destRoot = v.getBasePath();
|
|
|
+
|
|
|
+ String relativeBlockPath =
|
|
|
+ new File(sourceRoot).toURI().relativize(sourceBlock.toURI())
|
|
|
+ .getPath();
|
|
|
+ String relativeMetaPath =
|
|
|
+ new File(sourceRoot).toURI().relativize(sourceMeta.toURI())
|
|
|
+ .getPath();
|
|
|
+
|
|
|
+ File destBlock = new File(destRoot, relativeBlockPath);
|
|
|
+ File destMeta = new File(destRoot, relativeMetaPath);
|
|
|
+
|
|
|
+ destBlock.getParentFile().mkdirs();
|
|
|
+ FileUtils.copyFile(sourceBlock, destBlock);
|
|
|
+ FileUtils.copyFile(sourceMeta, destMeta);
|
|
|
+
|
|
|
+ if (destBlock.exists() && destMeta.exists()) {
|
|
|
+ LOG.info("Copied " + sourceBlock + " ==> " + destBlock);
|
|
|
+ LOG.info("Copied " + sourceMeta + " ==> " + destMeta);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -209,58 +216,67 @@ public class TestDirectoryScanner {
|
|
|
|
|
|
/** Create a block file in a random volume*/
|
|
|
private long createBlockFile() throws IOException {
|
|
|
- List<? extends FsVolumeSpi> volumes = fds.getVolumes();
|
|
|
- int index = rand.nextInt(volumes.size() - 1);
|
|
|
long id = getFreeBlockId();
|
|
|
- File finalizedDir = volumes.get(index).getFinalizedDir(bpid);
|
|
|
- File file = new File(finalizedDir, getBlockFile(id));
|
|
|
- if (file.createNewFile()) {
|
|
|
- LOG.info("Created block file " + file.getName());
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences volumes = fds.getFsVolumeReferences()) {
|
|
|
+ int numVolumes = volumes.size();
|
|
|
+ int index = rand.nextInt(numVolumes - 1);
|
|
|
+ File finalizedDir = volumes.get(index).getFinalizedDir(bpid);
|
|
|
+ File file = new File(finalizedDir, getBlockFile(id));
|
|
|
+ if (file.createNewFile()) {
|
|
|
+ LOG.info("Created block file " + file.getName());
|
|
|
+ }
|
|
|
}
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
/** Create a metafile in a random volume*/
|
|
|
private long createMetaFile() throws IOException {
|
|
|
- List<? extends FsVolumeSpi> volumes = fds.getVolumes();
|
|
|
- int index = rand.nextInt(volumes.size() - 1);
|
|
|
long id = getFreeBlockId();
|
|
|
- File finalizedDir = volumes.get(index).getFinalizedDir(bpid);
|
|
|
- File file = new File(finalizedDir, getMetaFile(id));
|
|
|
- if (file.createNewFile()) {
|
|
|
- LOG.info("Created metafile " + file.getName());
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences refs = fds.getFsVolumeReferences()) {
|
|
|
+ int numVolumes = refs.size();
|
|
|
+ int index = rand.nextInt(numVolumes - 1);
|
|
|
+
|
|
|
+ File finalizedDir = refs.get(index).getFinalizedDir(bpid);
|
|
|
+ File file = new File(finalizedDir, getMetaFile(id));
|
|
|
+ if (file.createNewFile()) {
|
|
|
+ LOG.info("Created metafile " + file.getName());
|
|
|
+ }
|
|
|
}
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
/** Create block file and corresponding metafile in a rondom volume */
|
|
|
private long createBlockMetaFile() throws IOException {
|
|
|
- List<? extends FsVolumeSpi> volumes = fds.getVolumes();
|
|
|
- int index = rand.nextInt(volumes.size() - 1);
|
|
|
long id = getFreeBlockId();
|
|
|
- File finalizedDir = volumes.get(index).getFinalizedDir(bpid);
|
|
|
- File file = new File(finalizedDir, getBlockFile(id));
|
|
|
- if (file.createNewFile()) {
|
|
|
- LOG.info("Created block file " + file.getName());
|
|
|
-
|
|
|
- // Create files with same prefix as block file but extension names
|
|
|
- // such that during sorting, these files appear around meta file
|
|
|
- // to test how DirectoryScanner handles extraneous files
|
|
|
- String name1 = file.getAbsolutePath() + ".l";
|
|
|
- String name2 = file.getAbsolutePath() + ".n";
|
|
|
- file = new File(name1);
|
|
|
- if (file.createNewFile()) {
|
|
|
- LOG.info("Created extraneous file " + name1);
|
|
|
- }
|
|
|
|
|
|
- file = new File(name2);
|
|
|
- if (file.createNewFile()) {
|
|
|
- LOG.info("Created extraneous file " + name2);
|
|
|
- }
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences refs = fds.getFsVolumeReferences()) {
|
|
|
+ int numVolumes = refs.size();
|
|
|
+ int index = rand.nextInt(numVolumes - 1);
|
|
|
|
|
|
- file = new File(finalizedDir, getMetaFile(id));
|
|
|
+ File finalizedDir = refs.get(index).getFinalizedDir(bpid);
|
|
|
+ File file = new File(finalizedDir, getBlockFile(id));
|
|
|
if (file.createNewFile()) {
|
|
|
- LOG.info("Created metafile " + file.getName());
|
|
|
+ LOG.info("Created block file " + file.getName());
|
|
|
+
|
|
|
+ // Create files with same prefix as block file but extension names
|
|
|
+ // such that during sorting, these files appear around meta file
|
|
|
+ // to test how DirectoryScanner handles extraneous files
|
|
|
+ String name1 = file.getAbsolutePath() + ".l";
|
|
|
+ String name2 = file.getAbsolutePath() + ".n";
|
|
|
+ file = new File(name1);
|
|
|
+ if (file.createNewFile()) {
|
|
|
+ LOG.info("Created extraneous file " + name1);
|
|
|
+ }
|
|
|
+
|
|
|
+ file = new File(name2);
|
|
|
+ if (file.createNewFile()) {
|
|
|
+ LOG.info("Created extraneous file " + name2);
|
|
|
+ }
|
|
|
+
|
|
|
+ file = new File(finalizedDir, getMetaFile(id));
|
|
|
+ if (file.createNewFile()) {
|
|
|
+ LOG.info("Created metafile " + file.getName());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return id;
|