From a7fa6e348afe98b71ff9fe2e4663c656e54f9add Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Wed, 9 Jan 2013 20:32:49 +0000 Subject: [PATCH] HBASE-7515 Store.loadStoreFiles should close opened files if there's an exception (Ted Yu) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1431045 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/HStore.java | 62 ++++++++++++------- .../hadoop/hbase/regionserver/StoreFile.java | 11 +++- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index 528ac02b068..84052d4e946 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.regionserver; import java.io.IOException; +import java.io.InterruptedIOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -429,26 +430,38 @@ public class HStore implements Store, StoreConfiguration { totalValidStoreFile++; } + IOException ioe = null; try { for (int i = 0; i < totalValidStoreFile; i++) { - Future future = completionService.take(); - StoreFile storeFile = future.get(); - long length = storeFile.getReader().length(); - this.storeSize += length; - this.totalUncompressedBytes += - storeFile.getReader().getTotalUncompressedBytes(); - if (LOG.isDebugEnabled()) { - LOG.debug("loaded " + storeFile.toStringDetailed()); - } - results.add(storeFile); - } - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { - throw new IOException(e.getCause()); + try { + Future future = completionService.take(); + StoreFile storeFile = future.get(); + long length = storeFile.getReader().length(); + this.storeSize += length; + this.totalUncompressedBytes += + storeFile.getReader().getTotalUncompressedBytes(); + if (LOG.isDebugEnabled()) { + LOG.debug("loaded " + storeFile.toStringDetailed()); + } + results.add(storeFile); + } catch (InterruptedException e) { + if (ioe == null) ioe = new InterruptedIOException(e.getMessage()); + } catch (ExecutionException e) { + if (ioe == null) ioe = new IOException(e.getCause()); + } + } } finally { storeFileOpenerThreadPool.shutdownNow(); } + if (ioe != null) { + // close StoreFile readers + try { + for (StoreFile file : results) { + if (file != null) file.closeReader(true); + } + } catch (IOException e) { } + throw ioe; + } return results; } @@ -645,18 +658,25 @@ public class HStore implements Store, StoreConfiguration { }); } + IOException ioe = null; try { for (int i = 0; i < result.size(); i++) { - Future future = completionService.take(); - future.get(); + try { + Future future = completionService.take(); + future.get(); + } catch (InterruptedException e) { + if (ioe == null) { + ioe = new InterruptedIOException(); + ioe.initCause(e); + } + } catch (ExecutionException e) { + if (ioe == null) ioe = new IOException(e.getCause()); + } } - } catch (InterruptedException e) { - throw new IOException(e); - } catch (ExecutionException e) { - throw new IOException(e.getCause()); } finally { storeFileCloserThreadPool.shutdownNow(); } + if (ioe != null) throw ioe; } LOG.info("Closed " + this); return result; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java index 012b9fba1b9..ca0dd90393e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java @@ -624,7 +624,16 @@ public class StoreFile { */ public Reader createReader() throws IOException { if (this.reader == null) { - this.reader = open(); + try { + this.reader = open(); + } catch (IOException e) { + try { + this.closeReader(true); + } catch (IOException ee) { + } + throw e; + } + } return this.reader; }