DataStorage extends Storage { @VisibleForTesting synchronized List<StorageDirectory> addStorageLocations(DataNode datanode, NamespaceInfo nsInfo, Collection<StorageLocation> dataDirs, StartupOption startOpt) throws IOException { final int numThreads = getParallelVolumeLoadThreadsNum( dataDirs.size(), datanode.getConf()); final ExecutorService executor = Executors.newFixedThreadPool(numThreads); try { final List<StorageLocation> successLocations = loadDataStorage( datanode, nsInfo, dataDirs, startOpt, executor); if (successLocations.isEmpty()) { return Lists.newArrayList(); } return loadBlockPoolSliceStorage( datanode, nsInfo, successLocations, startOpt, executor); } finally { executor.shutdown(); } } DataStorage();  DataStorage(StorageInfo storageInfo); BlockPoolSliceStorage getBPStorage(String bpid); String getDatanodeUuid(); void setDatanodeUuid(String newDatanodeUuid); static boolean createStorageID(
      StorageDirectory sd, boolean regenerateStorageIds, Configuration conf); void enableTrash(String bpid); void clearTrash(String bpid); boolean trashEnabled(String bpid); void setRollingUpgradeMarker(String bpid); void clearRollingUpgradeMarker(String bpid); String getTrashDirectoryForReplica(String bpid, ReplicaInfo info); VolumeBuilder prepareVolume(DataNode datanode,
      StorageLocation location, List<NamespaceInfo> nsInfos); @Override boolean isPreUpgradableLayout(StorageDirectory sd); @Deprecated static boolean fullyDelete(final File dir); final static String BLOCK_SUBDIR_PREFIX; final static String STORAGE_DIR_RBW; final static String STORAGE_DIR_FINALIZED; final static String STORAGE_DIR_LAZY_PERSIST; final static String STORAGE_DIR_TMP; }
@Test public void testAddStorageDirectories() throws IOException, URISyntaxException { final int numLocations = 3; final int numNamespace = 3; List<StorageLocation> locations = createStorageLocations(numLocations); List<NamespaceInfo> namespaceInfos = createNamespaceInfos(numNamespace); for (NamespaceInfo ni : namespaceInfos) { storage.addStorageLocations(mockDN, ni, locations, START_OPT); for (StorageLocation sl : locations) { checkDir(new File(sl.getUri())); checkDir(new File(sl.getUri()), ni.getBlockPoolID()); } } assertEquals(numLocations, storage.getNumStorageDirs()); locations = createStorageLocations(numLocations); List<StorageDirectory> addedLocation = storage.addStorageLocations(mockDN, namespaceInfos.get(0), locations, START_OPT); assertTrue(addedLocation.isEmpty()); assertEquals(numLocations, storage.getNumStorageDirs()); locations = createStorageLocations(6); storage.addStorageLocations(mockDN, nsInfo, locations, START_OPT); assertEquals(6, storage.getNumStorageDirs()); }
@Test public void testAddStorageDirectoriesFailure() throws IOException { final int numLocations = 1; List<StorageLocation> locations = createStorageLocations(numLocations); assertEquals(numLocations, locations.size()); NamespaceInfo namespaceInfo = new NamespaceInfo(0, CLUSTER_ID, DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); List<StorageDirectory> successLocations = storage.addStorageLocations( mockDN, namespaceInfo, locations, START_OPT); assertEquals(1, successLocations.size()); storage.unlockAll(); DataNode newMockDN = Mockito.mock(DataNode.class); Mockito.when(newMockDN.getConf()).thenReturn(new HdfsConfiguration()); DataStorage newStorage = new DataStorage(); NamespaceInfo newNamespaceInfo = new NamespaceInfo(0, CLUSTER_ID2, DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); successLocations = newStorage.addStorageLocations( newMockDN, newNamespaceInfo, locations, START_OPT); assertEquals(0, successLocations.size()); newStorage.unlockAll(); newMockDN.shutdown(); }
@Test public void testMissingVersion() throws IOException, URISyntaxException { final int numLocations = 1; final int numNamespace = 1; List<StorageLocation> locations = createStorageLocations(numLocations); StorageLocation firstStorage = locations.get(0); Storage.StorageDirectory sd = new Storage.StorageDirectory(firstStorage); File currentDir = new File(sd.getCurrentDir(), "BP-787466439-172.26.24.43-1462305406642"); assertTrue("unable to mkdir " + currentDir.getName(), currentDir.mkdirs()); List<NamespaceInfo> namespaceInfos = createNamespaceInfos(numNamespace); for (NamespaceInfo ni : namespaceInfos) { storage.addStorageLocations(mockDN, ni, locations, START_OPT); } assertTrue("Storage directory was formatted", currentDir.exists()); }