|
@@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.server.datanode.FinalizedReplica;
|
|
import org.apache.hadoop.hdfs.server.datanode.ReplicaHandler;
|
|
import org.apache.hadoop.hdfs.server.datanode.ReplicaHandler;
|
|
import org.apache.hadoop.hdfs.server.datanode.ReplicaInfo;
|
|
import org.apache.hadoop.hdfs.server.datanode.ReplicaInfo;
|
|
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
|
|
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
|
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.RoundRobinVolumeChoosingPolicy;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.RoundRobinVolumeChoosingPolicy;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
@@ -56,7 +57,6 @@ import org.mockito.stubbing.Answer;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -68,7 +68,6 @@ import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.fail;
|
|
import static org.junit.Assert.fail;
|
|
import static org.mockito.Matchers.any;
|
|
import static org.mockito.Matchers.any;
|
|
-import static org.mockito.Matchers.anyList;
|
|
|
|
import static org.mockito.Matchers.anyListOf;
|
|
import static org.mockito.Matchers.anyListOf;
|
|
import static org.mockito.Matchers.anyString;
|
|
import static org.mockito.Matchers.anyString;
|
|
import static org.mockito.Matchers.eq;
|
|
import static org.mockito.Matchers.eq;
|
|
@@ -124,6 +123,15 @@ public class TestFsDatasetImpl {
|
|
when(storage.getNumStorageDirs()).thenReturn(numDirs);
|
|
when(storage.getNumStorageDirs()).thenReturn(numDirs);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private int getNumVolumes() {
|
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences volumes =
|
|
|
|
+ dataset.getFsVolumeReferences()) {
|
|
|
|
+ return volumes.size();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Before
|
|
@Before
|
|
public void setUp() throws IOException {
|
|
public void setUp() throws IOException {
|
|
datanode = mock(DataNode.class);
|
|
datanode = mock(DataNode.class);
|
|
@@ -143,14 +151,14 @@ public class TestFsDatasetImpl {
|
|
dataset.addBlockPool(bpid, conf);
|
|
dataset.addBlockPool(bpid, conf);
|
|
}
|
|
}
|
|
|
|
|
|
- assertEquals(NUM_INIT_VOLUMES, dataset.getVolumes().size());
|
|
|
|
|
|
+ assertEquals(NUM_INIT_VOLUMES, getNumVolumes());
|
|
assertEquals(0, dataset.getNumFailedVolumes());
|
|
assertEquals(0, dataset.getNumFailedVolumes());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testAddVolumes() throws IOException {
|
|
public void testAddVolumes() throws IOException {
|
|
final int numNewVolumes = 3;
|
|
final int numNewVolumes = 3;
|
|
- final int numExistingVolumes = dataset.getVolumes().size();
|
|
|
|
|
|
+ final int numExistingVolumes = getNumVolumes();
|
|
final int totalVolumes = numNewVolumes + numExistingVolumes;
|
|
final int totalVolumes = numNewVolumes + numExistingVolumes;
|
|
Set<String> expectedVolumes = new HashSet<String>();
|
|
Set<String> expectedVolumes = new HashSet<String>();
|
|
List<NamespaceInfo> nsInfos = Lists.newArrayList();
|
|
List<NamespaceInfo> nsInfos = Lists.newArrayList();
|
|
@@ -172,13 +180,15 @@ public class TestFsDatasetImpl {
|
|
dataset.addVolume(loc, nsInfos);
|
|
dataset.addVolume(loc, nsInfos);
|
|
}
|
|
}
|
|
|
|
|
|
- assertEquals(totalVolumes, dataset.getVolumes().size());
|
|
|
|
|
|
+ assertEquals(totalVolumes, getNumVolumes());
|
|
assertEquals(totalVolumes, dataset.storageMap.size());
|
|
assertEquals(totalVolumes, dataset.storageMap.size());
|
|
|
|
|
|
Set<String> actualVolumes = new HashSet<String>();
|
|
Set<String> actualVolumes = new HashSet<String>();
|
|
- for (int i = 0; i < numNewVolumes; i++) {
|
|
|
|
- actualVolumes.add(
|
|
|
|
- dataset.getVolumes().get(numExistingVolumes + i).getBasePath());
|
|
|
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences volumes =
|
|
|
|
+ dataset.getFsVolumeReferences()) {
|
|
|
|
+ for (int i = 0; i < numNewVolumes; i++) {
|
|
|
|
+ actualVolumes.add(volumes.get(numExistingVolumes + i).getBasePath());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
assertEquals(actualVolumes.size(), expectedVolumes.size());
|
|
assertEquals(actualVolumes.size(), expectedVolumes.size());
|
|
assertTrue(actualVolumes.containsAll(expectedVolumes));
|
|
assertTrue(actualVolumes.containsAll(expectedVolumes));
|
|
@@ -204,7 +214,7 @@ public class TestFsDatasetImpl {
|
|
dataset.removeVolumes(volumesToRemove, true);
|
|
dataset.removeVolumes(volumesToRemove, true);
|
|
int expectedNumVolumes = dataDirs.length - 1;
|
|
int expectedNumVolumes = dataDirs.length - 1;
|
|
assertEquals("The volume has been removed from the volumeList.",
|
|
assertEquals("The volume has been removed from the volumeList.",
|
|
- expectedNumVolumes, dataset.getVolumes().size());
|
|
|
|
|
|
+ expectedNumVolumes, getNumVolumes());
|
|
assertEquals("The volume has been removed from the storageMap.",
|
|
assertEquals("The volume has been removed from the storageMap.",
|
|
expectedNumVolumes, dataset.storageMap.size());
|
|
expectedNumVolumes, dataset.storageMap.size());
|
|
|
|
|
|
@@ -231,7 +241,7 @@ public class TestFsDatasetImpl {
|
|
|
|
|
|
@Test(timeout = 5000)
|
|
@Test(timeout = 5000)
|
|
public void testRemoveNewlyAddedVolume() throws IOException {
|
|
public void testRemoveNewlyAddedVolume() throws IOException {
|
|
- final int numExistingVolumes = dataset.getVolumes().size();
|
|
|
|
|
|
+ final int numExistingVolumes = getNumVolumes();
|
|
List<NamespaceInfo> nsInfos = new ArrayList<>();
|
|
List<NamespaceInfo> nsInfos = new ArrayList<>();
|
|
for (String bpid : BLOCK_POOL_IDS) {
|
|
for (String bpid : BLOCK_POOL_IDS) {
|
|
nsInfos.add(new NamespaceInfo(0, CLUSTER_ID, bpid, 1));
|
|
nsInfos.add(new NamespaceInfo(0, CLUSTER_ID, bpid, 1));
|
|
@@ -247,14 +257,14 @@ public class TestFsDatasetImpl {
|
|
.thenReturn(builder);
|
|
.thenReturn(builder);
|
|
|
|
|
|
dataset.addVolume(loc, nsInfos);
|
|
dataset.addVolume(loc, nsInfos);
|
|
- assertEquals(numExistingVolumes + 1, dataset.getVolumes().size());
|
|
|
|
|
|
+ assertEquals(numExistingVolumes + 1, getNumVolumes());
|
|
|
|
|
|
when(storage.getNumStorageDirs()).thenReturn(numExistingVolumes + 1);
|
|
when(storage.getNumStorageDirs()).thenReturn(numExistingVolumes + 1);
|
|
when(storage.getStorageDir(numExistingVolumes)).thenReturn(sd);
|
|
when(storage.getStorageDir(numExistingVolumes)).thenReturn(sd);
|
|
Set<File> volumesToRemove = new HashSet<>();
|
|
Set<File> volumesToRemove = new HashSet<>();
|
|
volumesToRemove.add(loc.getFile());
|
|
volumesToRemove.add(loc.getFile());
|
|
dataset.removeVolumes(volumesToRemove, true);
|
|
dataset.removeVolumes(volumesToRemove, true);
|
|
- assertEquals(numExistingVolumes, dataset.getVolumes().size());
|
|
|
|
|
|
+ assertEquals(numExistingVolumes, getNumVolumes());
|
|
}
|
|
}
|
|
|
|
|
|
@Test(timeout = 5000)
|
|
@Test(timeout = 5000)
|
|
@@ -357,7 +367,10 @@ public class TestFsDatasetImpl {
|
|
DataNode dn = cluster.getDataNodes().get(0);
|
|
DataNode dn = cluster.getDataNodes().get(0);
|
|
|
|
|
|
FsDatasetImpl ds = (FsDatasetImpl) DataNodeTestUtils.getFSDataset(dn);
|
|
FsDatasetImpl ds = (FsDatasetImpl) DataNodeTestUtils.getFSDataset(dn);
|
|
- FsVolumeImpl vol = ds.getVolumes().get(0);
|
|
|
|
|
|
+ FsVolumeImpl vol;
|
|
|
|
+ try (FsDatasetSpi.FsVolumeReferences volumes = ds.getFsVolumeReferences()) {
|
|
|
|
+ vol = (FsVolumeImpl)volumes.get(0);
|
|
|
|
+ }
|
|
|
|
|
|
ExtendedBlock eb;
|
|
ExtendedBlock eb;
|
|
ReplicaInfo info;
|
|
ReplicaInfo info;
|