HDFS-15779. EC: fix NPE caused by StripedWriter.clearBuffers during reconstruct block. Contributed by Hongbing Wang

(cherry picked from commit 15a1f7adfc)
This commit is contained in:
Hui Fei 2021-02-04 09:19:51 +08:00
parent 96773ec81b
commit 164a4e63e0
1 changed files with 7 additions and 3 deletions

View File

@ -296,7 +296,8 @@ class StripedWriter {
*/
void clearBuffers() {
for (StripedBlockWriter writer : writers) {
ByteBuffer targetBuffer = writer.getTargetBuffer();
ByteBuffer targetBuffer =
writer != null ? writer.getTargetBuffer() : null;
if (targetBuffer != null) {
targetBuffer.clear();
}
@ -305,7 +306,8 @@ class StripedWriter {
void close() {
for (StripedBlockWriter writer : writers) {
ByteBuffer targetBuffer = writer.getTargetBuffer();
ByteBuffer targetBuffer =
writer != null ? writer.getTargetBuffer() : null;
if (targetBuffer != null) {
reconstructor.freeBuffer(targetBuffer);
writer.freeTargetBuffer();
@ -313,7 +315,9 @@ class StripedWriter {
}
for (int i = 0; i < targets.length; i++) {
writers[i].close();
if (writers[i] != null) {
writers[i].close();
}
}
}
}