You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/01/02 17:48:05 UTC
svn commit: r1226471 - in /lucene/dev/trunk: ./
lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
Author: mikemccand
Date: Mon Jan 2 16:48:05 2012
New Revision: 1226471
URL: http://svn.apache.org/viewvc?rev=1226471&view=rev
Log:
close in/out before deleting from cache
Modified:
lucene/dev/trunk/ (props changed)
lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java?rev=1226471&r1=1226470&r2=1226471&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NRTCachingDirectory.java Mon Jan 2 16:48:05 2012
@@ -282,35 +282,33 @@ public class NRTCachingDirectory extends
private void unCache(String fileName) throws IOException {
// Only let one thread uncache at a time; this only
// happens during commit() or close():
- IndexOutput out = null;
- IndexInput in = null;
- try {
- synchronized(uncacheLock) {
- if (VERBOSE) {
- System.out.println("nrtdir.unCache name=" + fileName);
- }
- if (!cache.fileExists(fileName)) {
- // Another thread beat us...
- return;
- }
- IOContext context = IOContext.DEFAULT;
- if (delegate.fileExists(fileName)) {
- throw new IOException("cannot uncache file=\"" + fileName + "\": it was separately also created in the delegate directory");
- }
- out = delegate.createOutput(fileName, context);
-
+ synchronized(uncacheLock) {
+ if (VERBOSE) {
+ System.out.println("nrtdir.unCache name=" + fileName);
+ }
+ if (!cache.fileExists(fileName)) {
+ // Another thread beat us...
+ return;
+ }
+ if (delegate.fileExists(fileName)) {
+ throw new IOException("cannot uncache file=\"" + fileName + "\": it was separately also created in the delegate directory");
+ }
+ final IOContext context = IOContext.DEFAULT;
+ final IndexOutput out = delegate.createOutput(fileName, context);
+ IndexInput in = null;
+ try {
in = cache.openInput(fileName, context);
in.copyBytes(out, in.length());
+ } finally {
+ IOUtils.close(in, out);
+ }
- // Lock order: uncacheLock -> this
- synchronized(this) {
- // Must sync here because other sync methods have
- // if (cache.fileExists(name)) { ... } else { ... }:
- cache.deleteFile(fileName);
- }
+ // Lock order: uncacheLock -> this
+ synchronized(this) {
+ // Must sync here because other sync methods have
+ // if (cache.fileExists(name)) { ... } else { ... }:
+ cache.deleteFile(fileName);
}
- } finally {
- IOUtils.close(in, out);
}
}
}