HBASE-7871 HBase can be stuck when closing regions concurrently (Ted Yu)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1464012 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ac97504dc5
commit
b16e84e632
|
@ -25,10 +25,13 @@ import org.apache.hadoop.metrics2.MetricsBuilder;
|
|||
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
||||
implements MetricsRegionAggregateSource {
|
||||
private final Log LOG = LogFactory.getLog(this.getClass());
|
||||
// lock to guard against concurrent access to regionSources
|
||||
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private final TreeSet<MetricsRegionSourceImpl> regionSources =
|
||||
new TreeSet<MetricsRegionSourceImpl>();
|
||||
|
@ -47,12 +50,22 @@ public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
|||
|
||||
@Override
|
||||
public void register(MetricsRegionSource source) {
|
||||
regionSources.add((MetricsRegionSourceImpl) source);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
regionSources.add((MetricsRegionSourceImpl) source);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(MetricsRegionSource source) {
|
||||
regionSources.remove(source);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
regionSources.remove(source);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,17 +79,20 @@ public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
|||
@Override
|
||||
public void getMetrics(MetricsBuilder metricsBuilder, boolean all) {
|
||||
|
||||
|
||||
MetricsRecordBuilder mrb = metricsBuilder.addRecord(metricsName)
|
||||
.setContext(metricsContext);
|
||||
|
||||
if (regionSources != null) {
|
||||
for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
|
||||
regionMetricSource.snapshot(mrb, all);
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
|
||||
regionMetricSource.snapshot(mrb, all);
|
||||
}
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
metricsRegistry.snapshot(mrb, all);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,14 @@ import org.apache.hadoop.metrics2.MetricsCollector;
|
|||
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
||||
implements MetricsRegionAggregateSource {
|
||||
|
||||
private final Log LOG = LogFactory.getLog(this.getClass());
|
||||
// lock to guard against concurrent access to regionSources
|
||||
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private final TreeSet<MetricsRegionSourceImpl> regionSources =
|
||||
new TreeSet<MetricsRegionSourceImpl>();
|
||||
|
@ -48,12 +51,22 @@ public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
|||
|
||||
@Override
|
||||
public void register(MetricsRegionSource source) {
|
||||
regionSources.add((MetricsRegionSourceImpl) source);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
regionSources.add((MetricsRegionSourceImpl) source);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(MetricsRegionSource source) {
|
||||
regionSources.remove(source);
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
regionSources.remove(source);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,8 +85,13 @@ public class MetricsRegionAggregateSourceImpl extends BaseSourceImpl
|
|||
.setContext(metricsContext);
|
||||
|
||||
if (regionSources != null) {
|
||||
for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
|
||||
regionMetricSource.snapshot(mrb, all);
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
for (MetricsRegionSourceImpl regionMetricSource : regionSources) {
|
||||
regionMetricSource.snapshot(mrb, all);
|
||||
}
|
||||
} finally {
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue