HDFS-11047. Remove deep copies of FinalizedReplica to alleviate heap consumption on DataNode. Contributed by Xiaobing Zhou
This commit is contained in:
parent
d0da47ad9f
commit
2848a27700
|
@ -596,14 +596,13 @@ public class DirectoryScanner implements Runnable {
|
||||||
diffs.put(bpid, diffRecord);
|
diffs.put(bpid, diffRecord);
|
||||||
|
|
||||||
statsRecord.totalBlocks = blockpoolReport.length;
|
statsRecord.totalBlocks = blockpoolReport.length;
|
||||||
List<FinalizedReplica> bl = dataset.getFinalizedBlocks(bpid);
|
final List<FinalizedReplica> bl = dataset.getFinalizedBlocks(bpid);
|
||||||
FinalizedReplica[] memReport = bl.toArray(new FinalizedReplica[bl.size()]);
|
Collections.sort(bl); // Sort based on blockId
|
||||||
Arrays.sort(memReport); // Sort based on blockId
|
|
||||||
|
|
||||||
int d = 0; // index for blockpoolReport
|
int d = 0; // index for blockpoolReport
|
||||||
int m = 0; // index for memReprot
|
int m = 0; // index for memReprot
|
||||||
while (m < memReport.length && d < blockpoolReport.length) {
|
while (m < bl.size() && d < blockpoolReport.length) {
|
||||||
FinalizedReplica memBlock = memReport[m];
|
FinalizedReplica memBlock = bl.get(m);
|
||||||
ScanInfo info = blockpoolReport[d];
|
ScanInfo info = blockpoolReport[d];
|
||||||
if (info.getBlockId() < memBlock.getBlockId()) {
|
if (info.getBlockId() < memBlock.getBlockId()) {
|
||||||
if (!dataset.isDeletingBlock(bpid, info.getBlockId())) {
|
if (!dataset.isDeletingBlock(bpid, info.getBlockId())) {
|
||||||
|
@ -650,8 +649,8 @@ public class DirectoryScanner implements Runnable {
|
||||||
++m;
|
++m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (m < memReport.length) {
|
while (m < bl.size()) {
|
||||||
FinalizedReplica current = memReport[m++];
|
FinalizedReplica current = bl.get(m++);
|
||||||
addDifference(diffRecord, statsRecord,
|
addDifference(diffRecord, statsRecord,
|
||||||
current.getBlockId(), current.getVolume());
|
current.getBlockId(), current.getVolume());
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,16 @@ public interface FsDatasetSpi<V extends FsVolumeSpi> extends FSDatasetMBean {
|
||||||
*/
|
*/
|
||||||
VolumeFailureSummary getVolumeFailureSummary();
|
VolumeFailureSummary getVolumeFailureSummary();
|
||||||
|
|
||||||
/** @return a list of finalized blocks for the given block pool. */
|
/**
|
||||||
|
* Gets a list of references to the finalized blocks for the given block pool.
|
||||||
|
* <p>
|
||||||
|
* Callers of this function should call
|
||||||
|
* {@link FsDatasetSpi#acquireDatasetLock} to avoid blocks' status being
|
||||||
|
* changed during list iteration.
|
||||||
|
* </p>
|
||||||
|
* @return a list of references to the finalized blocks for the given block
|
||||||
|
* pool.
|
||||||
|
*/
|
||||||
List<FinalizedReplica> getFinalizedBlocks(String bpid);
|
List<FinalizedReplica> getFinalizedBlocks(String bpid);
|
||||||
|
|
||||||
/** @return a list of finalized blocks for the given block pool. */
|
/** @return a list of finalized blocks for the given block pool. */
|
||||||
|
|
|
@ -1842,16 +1842,23 @@ class FsDatasetImpl implements FsDatasetSpi<FsVolumeImpl> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of finalized blocks from in-memory blockmap for a block pool.
|
* Gets a list of references to the finalized blocks for the given block pool.
|
||||||
|
* <p>
|
||||||
|
* Callers of this function should call
|
||||||
|
* {@link FsDatasetSpi#acquireDatasetLock} to avoid blocks' status being
|
||||||
|
* changed during list iteration.
|
||||||
|
* </p>
|
||||||
|
* @return a list of references to the finalized blocks for the given block
|
||||||
|
* pool.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<FinalizedReplica> getFinalizedBlocks(String bpid) {
|
public List<FinalizedReplica> getFinalizedBlocks(String bpid) {
|
||||||
try(AutoCloseableLock lock = datasetLock.acquire()) {
|
try(AutoCloseableLock lock = datasetLock.acquire()) {
|
||||||
ArrayList<FinalizedReplica> finalized =
|
final ArrayList<FinalizedReplica> finalized =
|
||||||
new ArrayList<FinalizedReplica>(volumeMap.size(bpid));
|
new ArrayList<FinalizedReplica>(volumeMap.size(bpid));
|
||||||
for (ReplicaInfo b : volumeMap.replicas(bpid)) {
|
for (ReplicaInfo b : volumeMap.replicas(bpid)) {
|
||||||
if (b.getState() == ReplicaState.FINALIZED) {
|
if (b.getState() == ReplicaState.FINALIZED) {
|
||||||
finalized.add(new FinalizedReplica((FinalizedReplica) b));
|
finalized.add((FinalizedReplica)b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return finalized;
|
return finalized;
|
||||||
|
|
Loading…
Reference in New Issue