HDFS-11267. Avoid redefinition of storageDirs in NNStorage and cleanup its accessors in Storage. (Manoj Govindassamy via lei)

This commit is contained in:
Lei Xu 2016-12-29 16:57:40 +08:00
parent e9f1396834
commit a4f66655ec
6 changed files with 21 additions and 19 deletions

View File

@ -125,7 +125,7 @@ public interface StorageDirType {
} }
protected List<StorageDirectory> storageDirs = protected List<StorageDirectory> storageDirs =
new CopyOnWriteArrayList<StorageDirectory>(); new CopyOnWriteArrayList<>();
private class DirIterator implements Iterator<StorageDirectory> { private class DirIterator implements Iterator<StorageDirectory> {
final StorageDirType dirType; final StorageDirType dirType;
@ -939,6 +939,10 @@ public int getNumStorageDirs() {
return storageDirs.size(); return storageDirs.size();
} }
public List<StorageDirectory> getStorageDirs() {
return storageDirs;
}
public StorageDirectory getStorageDir(int idx) { public StorageDirectory getStorageDir(int idx) {
return storageDirs.get(idx); return storageDirs.get(idx);
} }

View File

@ -295,7 +295,7 @@ private void format(StorageDirectory bpSdir, NamespaceInfo nsInfo) throws IOExce
void remove(File absPathToRemove) { void remove(File absPathToRemove) {
Preconditions.checkArgument(absPathToRemove.isAbsolute()); Preconditions.checkArgument(absPathToRemove.isAbsolute());
LOG.info("Removing block level storage: " + absPathToRemove); LOG.info("Removing block level storage: " + absPathToRemove);
for (Iterator<StorageDirectory> it = this.storageDirs.iterator(); for (Iterator<StorageDirectory> it = getStorageDirs().iterator();
it.hasNext(); ) { it.hasNext(); ) {
StorageDirectory sd = it.next(); StorageDirectory sd = it.next();
if (sd.getRoot().getAbsoluteFile().equals(absPathToRemove)) { if (sd.getRoot().getAbsoluteFile().equals(absPathToRemove)) {
@ -788,7 +788,7 @@ String getRestoreDirectory(File blockFile) {
*/ */
public void clearTrash() { public void clearTrash() {
final List<File> trashRoots = new ArrayList<>(); final List<File> trashRoots = new ArrayList<>();
for (StorageDirectory sd : storageDirs) { for (StorageDirectory sd : getStorageDirs()) {
File trashRoot = getTrashRootDir(sd); File trashRoot = getTrashRootDir(sd);
if (trashRoot.exists() && sd.getPreviousDir().exists()) { if (trashRoot.exists() && sd.getPreviousDir().exists()) {
LOG.error("Trash and PreviousDir shouldn't both exist for storage " LOG.error("Trash and PreviousDir shouldn't both exist for storage "
@ -826,7 +826,7 @@ public void stopTrashCleaner() {
/** trash is enabled if at least one storage directory contains trash root */ /** trash is enabled if at least one storage directory contains trash root */
@VisibleForTesting @VisibleForTesting
public boolean trashEnabled() { public boolean trashEnabled() {
for (StorageDirectory sd : storageDirs) { for (StorageDirectory sd : getStorageDirs()) {
if (getTrashRootDir(sd).exists()) { if (getTrashRootDir(sd).exists()) {
return true; return true;
} }

View File

@ -181,11 +181,11 @@ public boolean trashEnabled(String bpid) {
} }
public void setRollingUpgradeMarker(String bpid) throws IOException { public void setRollingUpgradeMarker(String bpid) throws IOException {
getBPStorage(bpid).setRollingUpgradeMarkers(storageDirs); getBPStorage(bpid).setRollingUpgradeMarkers(getStorageDirs());
} }
public void clearRollingUpgradeMarker(String bpid) throws IOException { public void clearRollingUpgradeMarker(String bpid) throws IOException {
getBPStorage(bpid).clearRollingUpgradeMarkers(storageDirs); getBPStorage(bpid).clearRollingUpgradeMarkers(getStorageDirs());
} }
/** /**
@ -493,7 +493,7 @@ synchronized void removeVolumes(
} }
StringBuilder errorMsgBuilder = new StringBuilder(); StringBuilder errorMsgBuilder = new StringBuilder();
for (Iterator<StorageDirectory> it = this.storageDirs.iterator(); for (Iterator<StorageDirectory> it = getStorageDirs().iterator();
it.hasNext(); ) { it.hasNext(); ) {
StorageDirectory sd = it.next(); StorageDirectory sd = it.next();
StorageLocation sdLocation = sd.getStorageLocation(); StorageLocation sdLocation = sd.getStorageLocation();
@ -988,7 +988,7 @@ void finalizeUpgrade(String bpID) throws IOException {
// To handle finalizing a snapshot taken at datanode level while // To handle finalizing a snapshot taken at datanode level while
// upgrading to federation, if datanode level snapshot previous exists, // upgrading to federation, if datanode level snapshot previous exists,
// then finalize it. Else finalize the corresponding BP. // then finalize it. Else finalize the corresponding BP.
for (StorageDirectory sd : storageDirs) { for (StorageDirectory sd : getStorageDirs()) {
File prevDir = sd.getPreviousDir(); File prevDir = sd.getPreviousDir();
if (prevDir.exists()) { if (prevDir.exists()) {
// data node level storage finalize // data node level storage finalize

View File

@ -172,8 +172,6 @@ public NNStorage(Configuration conf,
throws IOException { throws IOException {
super(NodeType.NAME_NODE); super(NodeType.NAME_NODE);
storageDirs = new CopyOnWriteArrayList<>();
// this may modify the editsDirs, so copy before passing in // this may modify the editsDirs, so copy before passing in
setStorageDirectories(imageDirs, setStorageDirectories(imageDirs,
Lists.newArrayList(editsDirs), Lists.newArrayList(editsDirs),
@ -212,7 +210,7 @@ public boolean isPreUpgradableLayout(StorageDirectory sd) throws IOException {
@Override // Closeable @Override // Closeable
public void close() throws IOException { public void close() throws IOException {
unlockAll(); unlockAll();
storageDirs.clear(); getStorageDirs().clear();
} }
/** /**
@ -295,7 +293,7 @@ synchronized void setStorageDirectories(Collection<URI> fsNameDirs,
Collection<URI> fsEditsDirs, Collection<URI> fsEditsDirs,
Collection<URI> sharedEditsDirs) Collection<URI> sharedEditsDirs)
throws IOException { throws IOException {
this.storageDirs.clear(); getStorageDirs().clear();
this.removedStorageDirs.clear(); this.removedStorageDirs.clear();
// Add all name dirs with appropriate NameNodeDirType // Add all name dirs with appropriate NameNodeDirType
@ -873,7 +871,7 @@ private void reportErrorsOnDirectory(StorageDirectory sd) {
+ sd.getRoot().getPath(), e); + sd.getRoot().getPath(), e);
} }
if (this.storageDirs.remove(sd)) { if (getStorageDirs().remove(sd)) {
this.removedStorageDirs.add(sd); this.removedStorageDirs.add(sd);
} }
@ -928,7 +926,7 @@ public void reportErrorOnFile(File f) {
// getCanonicalPath may need to call stat() or readlink() and it's likely // getCanonicalPath may need to call stat() or readlink() and it's likely
// those calls would fail due to the same underlying IO problem. // those calls would fail due to the same underlying IO problem.
String absPath = f.getAbsolutePath(); String absPath = f.getAbsolutePath();
for (StorageDirectory sd : storageDirs) { for (StorageDirectory sd : getStorageDirs()) {
String dirPath = sd.getRoot().getAbsolutePath(); String dirPath = sd.getRoot().getAbsolutePath();
if (!dirPath.endsWith(File.separator)) { if (!dirPath.endsWith(File.separator)) {
dirPath += File.separator; dirPath += File.separator;
@ -1140,14 +1138,14 @@ public void updateNameDirSize() {
@Override @Override
public void writeAll() throws IOException { public void writeAll() throws IOException {
this.layoutVersion = getServiceLayoutVersion(); this.layoutVersion = getServiceLayoutVersion();
for (StorageDirectory sd : storageDirs) { for (StorageDirectory sd : getStorageDirs()) {
try { try {
writeProperties(sd); writeProperties(sd);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error during write properties to the VERSION file to " + LOG.warn("Error during write properties to the VERSION file to " +
sd.toString(), e); sd.toString(), e);
reportErrorsOnDirectory(sd); reportErrorsOnDirectory(sd);
if (storageDirs.isEmpty()) { if (getStorageDirs().isEmpty()) {
throw new IOException("All the storage failed while writing " + throw new IOException("All the storage failed while writing " +
"properties to VERSION file"); "properties to VERSION file");
} }

View File

@ -33,7 +33,7 @@ public static StorageDirectory spyOnStorageDirectory(
Storage s, int idx) { Storage s, int idx) {
StorageDirectory dir = Mockito.spy(s.getStorageDir(idx)); StorageDirectory dir = Mockito.spy(s.getStorageDir(idx));
s.storageDirs.set(idx, dir); s.getStorageDirs().set(idx, dir);
return dir; return dir;
} }
} }

View File

@ -50,7 +50,7 @@ private static class StubBlockPoolSliceStorage extends BlockPoolSliceStorage {
String clusterId) { String clusterId) {
super(namespaceID, bpID, cTime, clusterId); super(namespaceID, bpID, cTime, clusterId);
addStorageDir(new StorageDirectory(new File("/tmp/dontcare/" + bpID))); addStorageDir(new StorageDirectory(new File("/tmp/dontcare/" + bpID)));
assertThat(storageDirs.size(), is(1)); assertThat(getStorageDirs().size(), is(1));
} }
} }