Skip to content

Commit

Permalink
HDFS-8792. BlockManager#postponedMisreplicatedBlocks should use a Lig…
Browse files Browse the repository at this point in the history
…htWeightHashSet to save memory (Yi Liu via Colin P. McCabe)
  • Loading branch information
Colin Patrick Mccabe committed Aug 17, 2015
1 parent e535e0f commit c77bd6a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
3 changes: 3 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Expand Up @@ -807,6 +807,9 @@ Release 2.8.0 - UNRELEASED
HDFS-7433. Optimize performance of DatanodeManager's node map. HDFS-7433. Optimize performance of DatanodeManager's node map.
(daryn via kihwal) (daryn via kihwal)


HDFS-8792. BlockManager#postponedMisreplicatedBlocks should use a
LightWeightHashSet to save memory (Yi Liu via Colin P. McCabe)

BUG FIXES BUG FIXES


HDFS-7501. TransactionsSinceLastCheckpoint can be negative on SBNs. HDFS-7501. TransactionsSinceLastCheckpoint can be negative on SBNs.
Expand Down
Expand Up @@ -85,6 +85,7 @@
import org.apache.hadoop.hdfs.server.protocol.KeyUpdateCommand; import org.apache.hadoop.hdfs.server.protocol.KeyUpdateCommand;
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo; import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo;
import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks; import org.apache.hadoop.hdfs.server.protocol.StorageReceivedDeletedBlocks;
import org.apache.hadoop.hdfs.util.LightWeightHashSet;
import org.apache.hadoop.hdfs.util.LightWeightLinkedSet; import org.apache.hadoop.hdfs.util.LightWeightLinkedSet;
import org.apache.hadoop.metrics2.util.MBeans; import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.net.Node; import org.apache.hadoop.net.Node;
Expand All @@ -95,7 +96,6 @@


import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;


import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -196,7 +196,8 @@ public int getPendingDataNodeMessageCount() {
* notified of all block deletions that might have been pending * notified of all block deletions that might have been pending
* when the failover happened. * when the failover happened.
*/ */
private final Set<Block> postponedMisreplicatedBlocks = Sets.newHashSet(); private final LightWeightHashSet<Block> postponedMisreplicatedBlocks =
new LightWeightHashSet<>();


/** /**
* Maps a StorageID to the set of blocks that are "extra" for this * Maps a StorageID to the set of blocks that are "extra" for this
Expand Down
Expand Up @@ -527,12 +527,13 @@ public void printDetails(final PrintStream out) {
} }


private class LinkedSetIterator implements Iterator<T> { private class LinkedSetIterator implements Iterator<T> {
/** The starting modification for fail-fast. */ /** The current modification epoch. */
private final int startModification = modification; private int expectedModification = modification;
/** The current index of the entry array. */ /** The current index of the entry array. */
private int index = -1; private int index = -1;
/** The next element to return. */ /** The next element to return. */
private LinkedElement<T> next = nextNonemptyEntry(); private LinkedElement<T> next = nextNonemptyEntry();
private LinkedElement<T> current;


private LinkedElement<T> nextNonemptyEntry() { private LinkedElement<T> nextNonemptyEntry() {
for (index++; index < entries.length && entries[index] == null; index++); for (index++; index < entries.length && entries[index] == null; index++);
Expand All @@ -546,13 +547,14 @@ public boolean hasNext() {


@Override @Override
public T next() { public T next() {
if (modification != startModification) { if (modification != expectedModification) {
throw new ConcurrentModificationException("modification=" throw new ConcurrentModificationException("modification="
+ modification + " != startModification = " + startModification); + modification + " != expectedModification = " + expectedModification);
} }
if (next == null) { if (next == null) {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
current = next;
final T e = next.element; final T e = next.element;
// find the next element // find the next element
final LinkedElement<T> n = next.next; final LinkedElement<T> n = next.next;
Expand All @@ -562,7 +564,16 @@ public T next() {


@Override @Override
public void remove() { public void remove() {
throw new UnsupportedOperationException("Remove is not supported."); if (current == null) {
throw new NoSuchElementException();
}
if (modification != expectedModification) {
throw new ConcurrentModificationException("modification="
+ modification + " != expectedModification = " + expectedModification);
}
LightWeightHashSet.this.removeElem(current.element);
current = null;
expectedModification = modification;
} }
} }


Expand Down
Expand Up @@ -190,6 +190,33 @@ public void testRemoveAll() {
LOG.info("Test remove all - DONE"); LOG.info("Test remove all - DONE");
} }


@Test
public void testRemoveAllViaIterator() {
LOG.info("Test remove all via iterator");
for (Integer i : list) {
assertTrue(set.add(i));
}
for (Iterator<Integer> iter = set.iterator(); iter.hasNext(); ) {
int e = iter.next();
// element should be there before removing
assertTrue(set.contains(e));
iter.remove();
// element should not be there now
assertFalse(set.contains(e));
}

// the deleted elements should not be there
for (int i = 0; i < NUM; i++) {
assertFalse(set.contains(list.get(i)));
}

// iterator should not have next
Iterator<Integer> iter = set.iterator();
assertFalse(iter.hasNext());
assertTrue(set.isEmpty());
LOG.info("Test remove all via iterator - DONE");
}

@Test @Test
public void testPollAll() { public void testPollAll() {
LOG.info("Test poll all"); LOG.info("Test poll all");
Expand Down Expand Up @@ -470,4 +497,4 @@ public boolean equals(Object obj) {
} }
} }


} }

0 comments on commit c77bd6a

Please sign in to comment.