HDFS-15175. Multiple CloseOp shared block instance causes the standby namenode to crash when rolling editlog. Contributed by Wan Chang.
Reviewed-by: He Xiaoqiao <hexiaoqiao@apache.org> Reviewed-by: Stephen O'Donnell <sodonnel@apache.org>
This commit is contained in:
parent
3c8a48e681
commit
683feaa1d4
@ -412,6 +412,17 @@ private static List<XAttr> readXAttrsFromEditLog(DataInputStream in,
|
|||||||
return PBHelperClient.convertXAttrs(proto.getXAttrsList());
|
return PBHelperClient.convertXAttrs(proto.getXAttrsList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Block[] deepCopy(Block[] blocks) {
|
||||||
|
if (blocks == null || blocks.length == 0) {
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
Block[] copy = new Block[blocks.length];
|
||||||
|
for (int i = 0; i < blocks.length; ++i) {
|
||||||
|
copy[i] = blocks[i] == null ? null : new Block(blocks[i]);
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static abstract class AddCloseOp
|
static abstract class AddCloseOp
|
||||||
extends FSEditLogOp
|
extends FSEditLogOp
|
||||||
@ -500,7 +511,7 @@ <T extends AddCloseOp> T setBlocks(Block[] blocks) {
|
|||||||
throw new RuntimeException("Can't have more than " + MAX_BLOCKS +
|
throw new RuntimeException("Can't have more than " + MAX_BLOCKS +
|
||||||
" in an AddCloseOp.");
|
" in an AddCloseOp.");
|
||||||
}
|
}
|
||||||
this.blocks = blocks;
|
this.blocks = FSEditLogOp.deepCopy(blocks);
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,7 +989,7 @@ public String getPath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddBlockOp setPenultimateBlock(Block pBlock) {
|
AddBlockOp setPenultimateBlock(Block pBlock) {
|
||||||
this.penultimateBlock = pBlock;
|
this.penultimateBlock = pBlock == null ? null : new Block(pBlock);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -987,7 +998,7 @@ Block getPenultimateBlock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddBlockOp setLastBlock(Block lastBlock) {
|
AddBlockOp setLastBlock(Block lastBlock) {
|
||||||
this.lastBlock = lastBlock;
|
this.lastBlock = lastBlock == null ? null : new Block(lastBlock);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1090,7 +1101,7 @@ public String getPath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateBlocksOp setBlocks(Block[] blocks) {
|
UpdateBlocksOp setBlocks(Block[] blocks) {
|
||||||
this.blocks = blocks;
|
this.blocks = FSEditLogOp.deepCopy(blocks);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2881,7 +2892,8 @@ TruncateOp setTimestamp(long timestamp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TruncateOp setTruncateBlock(Block truncateBlock) {
|
TruncateOp setTruncateBlock(Block truncateBlock) {
|
||||||
this.truncateBlock = truncateBlock;
|
this.truncateBlock = truncateBlock == null ?
|
||||||
|
null : new Block(truncateBlock);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user