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
This commit is contained in:
Zhihong Yu 2013-01-09 20:32:49 +00:00
parent 485cf1a3ce
commit a7fa6e348a
2 changed files with 51 additions and 22 deletions

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.hbase.regionserver; package org.apache.hadoop.hbase.regionserver;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -429,26 +430,38 @@ public class HStore implements Store, StoreConfiguration {
totalValidStoreFile++; totalValidStoreFile++;
} }
IOException ioe = null;
try { try {
for (int i = 0; i < totalValidStoreFile; i++) { for (int i = 0; i < totalValidStoreFile; i++) {
Future<StoreFile> future = completionService.take(); try {
StoreFile storeFile = future.get(); Future<StoreFile> future = completionService.take();
long length = storeFile.getReader().length(); StoreFile storeFile = future.get();
this.storeSize += length; long length = storeFile.getReader().length();
this.totalUncompressedBytes += this.storeSize += length;
storeFile.getReader().getTotalUncompressedBytes(); this.totalUncompressedBytes +=
if (LOG.isDebugEnabled()) { storeFile.getReader().getTotalUncompressedBytes();
LOG.debug("loaded " + storeFile.toStringDetailed()); if (LOG.isDebugEnabled()) {
} LOG.debug("loaded " + storeFile.toStringDetailed());
results.add(storeFile); }
} results.add(storeFile);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new IOException(e); if (ioe == null) ioe = new InterruptedIOException(e.getMessage());
} catch (ExecutionException e) { } catch (ExecutionException e) {
throw new IOException(e.getCause()); if (ioe == null) ioe = new IOException(e.getCause());
}
}
} finally { } finally {
storeFileOpenerThreadPool.shutdownNow(); 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; return results;
} }
@ -645,18 +658,25 @@ public class HStore implements Store, StoreConfiguration {
}); });
} }
IOException ioe = null;
try { try {
for (int i = 0; i < result.size(); i++) { for (int i = 0; i < result.size(); i++) {
Future<Void> future = completionService.take(); try {
future.get(); Future<Void> 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 { } finally {
storeFileCloserThreadPool.shutdownNow(); storeFileCloserThreadPool.shutdownNow();
} }
if (ioe != null) throw ioe;
} }
LOG.info("Closed " + this); LOG.info("Closed " + this);
return result; return result;

View File

@ -624,7 +624,16 @@ public class StoreFile {
*/ */
public Reader createReader() throws IOException { public Reader createReader() throws IOException {
if (this.reader == null) { 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; return this.reader;
} }