hide decrement and update close logic to call decrement

This commit is contained in:
fjy 2013-08-01 13:24:56 -07:00
parent e92e0c35a4
commit dc169d9fcd
2 changed files with 14 additions and 4 deletions

View File

@ -56,6 +56,7 @@ import com.metamx.emitter.service.ServiceMetricEvent;
import org.joda.time.Interval; import org.joda.time.Interval;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -191,7 +192,12 @@ public class ServerManager implements QuerySegmentWalker
dataSourceCounts.add(dataSource, -1L); dataSourceCounts.add(dataSource, -1L);
} }
oldQueryable.decrement(); try {
oldQueryable.close();
}
catch (IOException e) {
throw new SegmentLoadingException(e, "Unable to close segment %s", segment.getIdentifier());
}
} else { } else {
log.info( log.info(
"Told to delete a queryable on dataSource[%s] for interval[%s] and version [%s] that I don't have.", "Told to delete a queryable on dataSource[%s] for interval[%s] and version [%s] that I don't have.",

View File

@ -112,11 +112,15 @@ public class ReferenceCountingSegment implements Segment
{ {
synchronized (lock) { synchronized (lock) {
if (!isClosed) { if (!isClosed) {
if (numReferences > 0) {
decrement();
} else {
baseSegment.close(); baseSegment.close();
isClosed = true; isClosed = true;
} }
} }
} }
}
public Closeable increment() public Closeable increment()
{ {
@ -140,7 +144,7 @@ public class ReferenceCountingSegment implements Segment
} }
} }
public void decrement() private void decrement()
{ {
synchronized (lock) { synchronized (lock) {
if (!isClosed) { if (!isClosed) {