|
@@ -483,6 +483,50 @@ public class VolumeScanner extends Thread {
|
|
return shouldScan;
|
|
return shouldScan;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get next block and check if it's needed to scan.
|
|
|
|
+ *
|
|
|
|
+ * @return the candidate block.
|
|
|
|
+ */
|
|
|
|
+ ExtendedBlock getNextBlockToScan() {
|
|
|
|
+ ExtendedBlock block;
|
|
|
|
+ try {
|
|
|
|
+ block = curBlockIter.nextBlock();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // There was an error listing the next block in the volume. This is a
|
|
|
|
+ // serious issue.
|
|
|
|
+ LOG.warn("{}: nextBlock error on {}", this, curBlockIter);
|
|
|
|
+ // On the next loop iteration, curBlockIter#eof will be set to true, and
|
|
|
|
+ // we will pick a different block iterator.
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (block == null) {
|
|
|
|
+ // The BlockIterator is at EOF.
|
|
|
|
+ LOG.info("{}: finished scanning block pool {}",
|
|
|
|
+ this, curBlockIter.getBlockPoolId());
|
|
|
|
+ saveBlockIterator(curBlockIter);
|
|
|
|
+ return null;
|
|
|
|
+ } else if (conf.skipRecentAccessed) {
|
|
|
|
+ // Check the access time of block file to avoid scanning recently
|
|
|
|
+ // changed blocks, reducing disk IO.
|
|
|
|
+ try {
|
|
|
|
+ BlockLocalPathInfo blockLocalPathInfo =
|
|
|
|
+ volume.getDataset().getBlockLocalPathInfo(block);
|
|
|
|
+ BasicFileAttributes attr = Files.readAttributes(
|
|
|
|
+ new File(blockLocalPathInfo.getBlockPath()).toPath(),
|
|
|
|
+ BasicFileAttributes.class);
|
|
|
|
+ if (System.currentTimeMillis() - attr.lastAccessTime().
|
|
|
|
+ to(TimeUnit.MILLISECONDS) < conf.scanPeriodMs) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException ioe) {
|
|
|
|
+ LOG.debug("Failed to get access time of block {}",
|
|
|
|
+ block, ioe);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return block;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Run an iteration of the VolumeScanner loop.
|
|
* Run an iteration of the VolumeScanner loop.
|
|
*
|
|
*
|
|
@@ -507,10 +551,10 @@ public class VolumeScanner extends Thread {
|
|
return 30000L;
|
|
return 30000L;
|
|
}
|
|
}
|
|
|
|
|
|
- // Find a usable block pool to scan.
|
|
|
|
if (suspectBlock != null) {
|
|
if (suspectBlock != null) {
|
|
block = suspectBlock;
|
|
block = suspectBlock;
|
|
} else {
|
|
} else {
|
|
|
|
+ // Find a usable block pool to scan.
|
|
if ((curBlockIter == null) || curBlockIter.atEnd()) {
|
|
if ((curBlockIter == null) || curBlockIter.atEnd()) {
|
|
long timeout = findNextUsableBlockIter();
|
|
long timeout = findNextUsableBlockIter();
|
|
if (timeout > 0) {
|
|
if (timeout > 0) {
|
|
@@ -528,40 +572,9 @@ public class VolumeScanner extends Thread {
|
|
}
|
|
}
|
|
return 0L;
|
|
return 0L;
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- block = curBlockIter.nextBlock();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- // There was an error listing the next block in the volume. This is a
|
|
|
|
- // serious issue.
|
|
|
|
- LOG.warn("{}: nextBlock error on {}", this, curBlockIter);
|
|
|
|
- // On the next loop iteration, curBlockIter#eof will be set to true, and
|
|
|
|
- // we will pick a different block iterator.
|
|
|
|
- return 0L;
|
|
|
|
- }
|
|
|
|
|
|
+ block = getNextBlockToScan();
|
|
if (block == null) {
|
|
if (block == null) {
|
|
- // The BlockIterator is at EOF.
|
|
|
|
- LOG.info("{}: finished scanning block pool {}",
|
|
|
|
- this, curBlockIter.getBlockPoolId());
|
|
|
|
- saveBlockIterator(curBlockIter);
|
|
|
|
- return 0;
|
|
|
|
- } else if (conf.skipRecentAccessed) {
|
|
|
|
- // Check the access time of block file to avoid scanning recently
|
|
|
|
- // changed blocks, reducing disk IO.
|
|
|
|
- try {
|
|
|
|
- BlockLocalPathInfo blockLocalPathInfo =
|
|
|
|
- volume.getDataset().getBlockLocalPathInfo(block);
|
|
|
|
- BasicFileAttributes attr = Files.readAttributes(
|
|
|
|
- new File(blockLocalPathInfo.getBlockPath()).toPath(),
|
|
|
|
- BasicFileAttributes.class);
|
|
|
|
- if (System.currentTimeMillis() - attr.lastAccessTime().
|
|
|
|
- to(TimeUnit.MILLISECONDS) < conf.scanPeriodMs) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (IOException ioe) {
|
|
|
|
- LOG.debug("Failed to get access time of block {}",
|
|
|
|
- block, ioe);
|
|
|
|
- }
|
|
|
|
|
|
+ return 0L;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (curBlockIter != null) {
|
|
if (curBlockIter != null) {
|