Skip to content

Commit

Permalink
HDFS-9837. BlockManager#countNodes should be able to detect duplicate…
Browse files Browse the repository at this point in the history
…d internal blocks. Contributed by Jing Zhao.
  • Loading branch information
Jing9 committed Feb 24, 2016
1 parent 954dd57 commit 47b92f2
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 156 deletions.
3 changes: 3 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ Trunk (Unreleased)
HDFS-9818. Correctly handle EC reconstruction work caused by not enough
racks. (jing9)

HDFS-9837. BlockManager#countNodes should be able to detect duplicated
internal blocks. (jing9)

BREAKDOWN OF HDFS-7285 SUBTASKS AND RELATED JIRAS

HDFS-7347. Configurable erasure coding policy for individual files and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.apache.hadoop.hdfs.util.StripedBlockUtil;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
* Subclass of {@link BlockInfo}, presenting a block group in erasure coding.
*
Expand Down Expand Up @@ -227,4 +230,47 @@ final boolean hasNoStorage() {
}
return true;
}

static class StorageAndBlockIndex {
final DatanodeStorageInfo storage;
final byte blockIndex;

StorageAndBlockIndex(DatanodeStorageInfo storage, byte blockIndex) {
this.storage = storage;
this.blockIndex = blockIndex;
}
}

public Iterable<StorageAndBlockIndex> getStorageAndIndexInfos() {
return new Iterable<StorageAndBlockIndex>() {
@Override
public Iterator<StorageAndBlockIndex> iterator() {
return new Iterator<StorageAndBlockIndex>() {
private int index = 0;

@Override
public boolean hasNext() {
while (index < getCapacity() && getStorageInfo(index) == null) {
index++;
}
return index < getCapacity();
}

@Override
public StorageAndBlockIndex next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
int i = index++;
return new StorageAndBlockIndex(storages[i], indices[i]);
}

@Override
public void remove() {
throw new UnsupportedOperationException("Remove is not supported");
}
};
}
};
}
}
Loading

0 comments on commit 47b92f2

Please sign in to comment.