HDFS-14104. Review getImageTxIdToRetain. Contributed by David Mollitor.
This commit is contained in:
parent
f600fbb6c4
commit
ffca734c62
@ -184,27 +184,26 @@ public class NNStorageRetentionManager {
|
|||||||
* @return the transaction ID corresponding to the oldest checkpoint
|
* @return the transaction ID corresponding to the oldest checkpoint
|
||||||
* that should be retained.
|
* that should be retained.
|
||||||
*/
|
*/
|
||||||
private long getImageTxIdToRetain(FSImageTransactionalStorageInspector inspector) {
|
private long getImageTxIdToRetain(
|
||||||
|
FSImageTransactionalStorageInspector inspector) {
|
||||||
List<FSImageFile> images = inspector.getFoundImages();
|
|
||||||
TreeSet<Long> imageTxIds = Sets.newTreeSet();
|
final List<FSImageFile> images = inspector.getFoundImages();
|
||||||
|
if (images.isEmpty()) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeSet<Long> imageTxIds = Sets.newTreeSet(Collections.reverseOrder());
|
||||||
for (FSImageFile image : images) {
|
for (FSImageFile image : images) {
|
||||||
imageTxIds.add(image.getCheckpointTxId());
|
imageTxIds.add(image.getCheckpointTxId());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Long> imageTxIdsList = Lists.newArrayList(imageTxIds);
|
List<Long> imageTxIdsList = Lists.newArrayList(imageTxIds);
|
||||||
if (imageTxIdsList.isEmpty()) {
|
int toRetain = Math.min(numCheckpointsToRetain, imageTxIdsList.size());
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.reverse(imageTxIdsList);
|
|
||||||
int toRetain = Math.min(numCheckpointsToRetain, imageTxIdsList.size());
|
|
||||||
long minTxId = imageTxIdsList.get(toRetain - 1);
|
long minTxId = imageTxIdsList.get(toRetain - 1);
|
||||||
LOG.info("Going to retain " + toRetain + " images with txid >= " +
|
LOG.info("Going to retain {} images with txid >= {}", toRetain, minTxId);
|
||||||
minTxId);
|
|
||||||
return minTxId;
|
return minTxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface responsible for disposing of old checkpoints and edit logs.
|
* Interface responsible for disposing of old checkpoints and edit logs.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user