HDFS-9781. FsDatasetImpl#getBlockReports can occasionally throw NullPointerException. Contributed by Manoj Govindassamy.
This commit is contained in:
parent
f6ea9be547
commit
07650bc37a
|
@ -1827,13 +1827,24 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
||||||
Map<String, BlockListAsLongs.Builder> builders =
|
Map<String, BlockListAsLongs.Builder> builders =
|
||||||
new HashMap<String, BlockListAsLongs.Builder>();
|
new HashMap<String, BlockListAsLongs.Builder>();
|
||||||
|
|
||||||
List<FsVolumeImpl> curVolumes = volumes.getVolumes();
|
List<FsVolumeImpl> curVolumes = null;
|
||||||
for (FsVolumeSpi v : curVolumes) {
|
|
||||||
builders.put(v.getStorageID(), BlockListAsLongs.builder(maxDataLength));
|
|
||||||
}
|
|
||||||
|
|
||||||
try (AutoCloseableLock lock = datasetLock.acquire()) {
|
try (AutoCloseableLock lock = datasetLock.acquire()) {
|
||||||
|
curVolumes = volumes.getVolumes();
|
||||||
|
for (FsVolumeSpi v : curVolumes) {
|
||||||
|
builders.put(v.getStorageID(), BlockListAsLongs.builder(maxDataLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> missingVolumesReported = new HashSet<>();
|
||||||
for (ReplicaInfo b : volumeMap.replicas(bpid)) {
|
for (ReplicaInfo b : volumeMap.replicas(bpid)) {
|
||||||
|
String volStorageID = b.getVolume().getStorageID();
|
||||||
|
if (!builders.containsKey(volStorageID)) {
|
||||||
|
if (!missingVolumesReported.contains(volStorageID)) {
|
||||||
|
LOG.warn("Storage volume: " + volStorageID + " missing for the"
|
||||||
|
+ " replica block: " + b + ". Probably being removed!");
|
||||||
|
missingVolumesReported.add(volStorageID);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch(b.getState()) {
|
switch(b.getState()) {
|
||||||
case FINALIZED:
|
case FINALIZED:
|
||||||
case RBW:
|
case RBW:
|
||||||
|
|
|
@ -590,8 +590,15 @@ public class TestFsDatasetImpl {
|
||||||
final ExtendedBlock eb = new ExtendedBlock(BLOCK_POOL_IDS[0], 0);
|
final ExtendedBlock eb = new ExtendedBlock(BLOCK_POOL_IDS[0], 0);
|
||||||
final CountDownLatch startFinalizeLatch = new CountDownLatch(1);
|
final CountDownLatch startFinalizeLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch brReceivedLatch = new CountDownLatch(1);
|
final CountDownLatch brReceivedLatch = new CountDownLatch(1);
|
||||||
|
final CountDownLatch volRemovedLatch = new CountDownLatch(1);
|
||||||
class BlockReportThread extends Thread {
|
class BlockReportThread extends Thread {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// Lets wait for the volume remove process to start
|
||||||
|
try {
|
||||||
|
volRemovedLatch.await();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.info("Unexpected exception when waiting for vol removal:", e);
|
||||||
|
}
|
||||||
LOG.info("Getting block report");
|
LOG.info("Getting block report");
|
||||||
dataset.getBlockReports(eb.getBlockPoolId());
|
dataset.getBlockReports(eb.getBlockPoolId());
|
||||||
LOG.info("Successfully received block report");
|
LOG.info("Successfully received block report");
|
||||||
|
@ -599,18 +606,27 @@ public class TestFsDatasetImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BlockReportThread brt = new BlockReportThread();
|
|
||||||
class ResponderThread extends Thread {
|
class ResponderThread extends Thread {
|
||||||
public void run() {
|
public void run() {
|
||||||
try (ReplicaHandler replica = dataset
|
try (ReplicaHandler replica = dataset
|
||||||
.createRbw(StorageType.DEFAULT, eb, false)) {
|
.createRbw(StorageType.DEFAULT, eb, false)) {
|
||||||
LOG.info("createRbw finished");
|
LOG.info("CreateRbw finished");
|
||||||
startFinalizeLatch.countDown();
|
startFinalizeLatch.countDown();
|
||||||
|
|
||||||
// Slow down while we're holding the reference to the volume
|
// Slow down while we're holding the reference to the volume.
|
||||||
Thread.sleep(1000);
|
// As we finalize a block, the volume is removed in parallel.
|
||||||
|
// Ignore any interrupts coming out of volume shutdown.
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
LOG.info("Ignoring ", ie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lets wait for the other thread finish getting block report
|
||||||
|
brReceivedLatch.await();
|
||||||
|
|
||||||
dataset.finalizeBlock(eb);
|
dataset.finalizeBlock(eb);
|
||||||
LOG.info("finalizeBlock finished");
|
LOG.info("FinalizeBlock finished");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Exception caught. This should not affect the test", e);
|
LOG.warn("Exception caught. This should not affect the test", e);
|
||||||
}
|
}
|
||||||
|
@ -621,13 +637,28 @@ public class TestFsDatasetImpl {
|
||||||
res.start();
|
res.start();
|
||||||
startFinalizeLatch.await();
|
startFinalizeLatch.await();
|
||||||
|
|
||||||
|
// Verify if block report can be received
|
||||||
|
// when volume is being removed
|
||||||
|
final BlockReportThread brt = new BlockReportThread();
|
||||||
|
brt.start();
|
||||||
|
|
||||||
Set<File> volumesToRemove = new HashSet<>();
|
Set<File> volumesToRemove = new HashSet<>();
|
||||||
volumesToRemove.add(
|
volumesToRemove.add(
|
||||||
StorageLocation.parse(dataset.getVolume(eb).getBasePath()).getFile());
|
StorageLocation.parse(dataset.getVolume(eb).getBasePath()).getFile());
|
||||||
LOG.info("Removing volume " + volumesToRemove);
|
/**
|
||||||
// Verify block report can be received during this
|
* TODO: {@link FsDatasetImpl#removeVolumes(Set, boolean)} is throwing
|
||||||
brt.start();
|
* IllegalMonitorStateException when there is a parallel reader/writer
|
||||||
dataset.removeVolumes(volumesToRemove, true);
|
* to the volume. Remove below try/catch block after fixing HDFS-10830.
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
LOG.info("Removing volume " + volumesToRemove);
|
||||||
|
dataset.removeVolumes(volumesToRemove, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.info("Unexpected issue while removing volume: ", e);
|
||||||
|
} finally {
|
||||||
|
volRemovedLatch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
LOG.info("Volumes removed");
|
LOG.info("Volumes removed");
|
||||||
brReceivedLatch.await();
|
brReceivedLatch.await();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue