Fix dead lock in FSNamesystem.addSafeBlocks
@@ -7902,10 +7902,13 @@ QuotaUpdateManager getQuotaUpdateManager() {
* block to be added to safe blocks
* @throws IOException
*/
- private int addSafeBlock(final Long safeBlock) throws IOException {
- List<Long> safeBlocks = new ArrayList();
+ private int addSafeBlock(Long safeBlock) throws IOException {
+ final AtomicInteger added = new AtomicInteger(0);
+ List<Long> safeBlocks = new ArrayList<>();
safeBlocks.add(safeBlock);
- return addSafeBlocks(safeBlocks);
+ addSafeBlocksTX(safeBlocks, added);
+
+ return added.get();
}
/**
@@ -7926,20 +7929,7 @@ public Object performTask() throws IOException {
}.handle();
}
- /**
- * Update safe blocks in the database
- * @param safeBlocks
- * list of blocks to be added to safe blocks
- * @throws IOException
- */
- private int addSafeBlocks(final List<Long> safeBlocks) throws IOException {
- final AtomicInteger added = new AtomicInteger(0);
- try {
- Slicer.slice(safeBlocks.size(), slicerBatchSize, slicerNbThreads, fsOperationsExecutor,
- new Slicer.OperationHandler() {
- @Override
- public void handle(int startIndex, int endIndex) throws Exception {
- final List<Long> ids = safeBlocks.subList(startIndex, endIndex);
+ private void addSafeBlocksTX(final List<Long> safeBlocks, final AtomicInteger added) throws IOException {
new LightWeightRequestHandler(HDFSOperationType.ADD_SAFE_BLOCKS) {
@Override
public Object performTask() throws IOException {
@@ -7951,7 +7941,7 @@ public Object performTask() throws IOException {
SafeBlocksDataAccess da = (SafeBlocksDataAccess) HdfsStorageFactory
.getDataAccess(SafeBlocksDataAccess.class);
int before = da.countAll();
- da.insert(ids);
+ da.insert(safeBlocks);
connector.flush();
int after = da.countAll();
added.addAndGet(after - before);
@@ -7962,6 +7952,23 @@ public Object performTask() throws IOException {
}
}.handle();
}
+
+ /**
+ * Update safe blocks in the database
+ * @param safeBlocks
+ * list of blocks to be added to safe blocks
+ * @throws IOException
+ */
+ private int addSafeBlocks(final List<Long> safeBlocks) throws IOException {
+ final AtomicInteger added = new AtomicInteger(0);
+ try {
+ Slicer.slice(safeBlocks.size(), slicerBatchSize, slicerNbThreads, fsOperationsExecutor,
+ new Slicer.OperationHandler() {
+ @Override
+ public void handle(int startIndex, int endIndex) throws Exception {
+ final List<Long> ids = safeBlocks.subList(startIndex, endIndex);
+ addSafeBlocksTX(safeBlocks, added);
+ }
});
} catch (Exception e) {
if (e instanceof IOException) {
