Repository: incubator-blur Updated Branches: refs/heads/master dc96edb67 -> f9d8e405f
Removing a reference to IndexInput that holds on to instances in a ThreadLocal var. Can cause memory issues. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/f9d8e405 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/f9d8e405 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/f9d8e405 Branch: refs/heads/master Commit: f9d8e405f3612d0c3aa0dec55adca2ac044768e7 Parents: dc96edb Author: Aaron McCurry <[email protected]> Authored: Sun Aug 24 10:50:27 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Sun Aug 24 10:50:27 2014 -0400 ---------------------------------------------------------------------- .../blur/lucene/codec/CachedDecompressor.java | 8 ++-- .../cachevalue/UnsafeCacheValue.java | 12 +----- .../org/apache/blur/store/util/UnsafeUtil.java | 42 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f9d8e405/blur-store/src/main/java/org/apache/blur/lucene/codec/CachedDecompressor.java ---------------------------------------------------------------------- diff --git a/blur-store/src/main/java/org/apache/blur/lucene/codec/CachedDecompressor.java b/blur-store/src/main/java/org/apache/blur/lucene/codec/CachedDecompressor.java index e837efc..18c4cc1 100644 --- a/blur-store/src/main/java/org/apache/blur/lucene/codec/CachedDecompressor.java +++ b/blur-store/src/main/java/org/apache/blur/lucene/codec/CachedDecompressor.java @@ -72,22 +72,22 @@ public class CachedDecompressor extends Decompressor { } static class Entry { - IndexInput _indexInput; String _name; long _filePointer = -1; BytesRef _cache = new BytesRef(); + int _indexInputHashCode; void setup(IndexInput indexInput, String name, long filePointer) { - _indexInput = indexInput; + _indexInputHashCode = System.identityHashCode(indexInput); _name = name; _filePointer = filePointer; } boolean isValid(IndexInput indexInput, String name, long filePointer) { - if (_indexInput != indexInput) { + if (_indexInputHashCode != System.identityHashCode(indexInput)) { return false; } - if (!name.equals(_name)) { + if (!_name.equals(name)) { return false; } if (_filePointer != filePointer) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f9d8e405/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java ---------------------------------------------------------------------- diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java index 6f230fd..ddff81f 100644 --- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java +++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/cachevalue/UnsafeCacheValue.java @@ -21,10 +21,10 @@ import static org.apache.blur.metrics.MetricsConstants.JVM; import static org.apache.blur.metrics.MetricsConstants.OFF_HEAP_MEMORY; import static org.apache.blur.metrics.MetricsConstants.ORG_APACHE_BLUR; -import java.lang.reflect.Field; import java.util.concurrent.atomic.AtomicLong; import org.apache.blur.metrics.AtomicLongGauge; +import org.apache.blur.store.util.UnsafeUtil; import sun.misc.Unsafe; @@ -33,19 +33,11 @@ import com.yammer.metrics.core.MetricName; public class UnsafeCacheValue extends BaseCacheValue { - private static final String JAVA_NIO_BITS = "java.nio.Bits"; private static final Unsafe _unsafe; private static final AtomicLong _offHeapMemorySize = new AtomicLong(); static { - try { - Class<?> clazz = Class.forName(JAVA_NIO_BITS); - Field field = clazz.getDeclaredField("unsafe"); - field.setAccessible(true); - _unsafe = (Unsafe) field.get(null); - } catch (Exception e) { - throw new RuntimeException(e); - } + _unsafe = UnsafeUtil.getUnsafe(); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, OFF_HEAP_MEMORY), new AtomicLongGauge(_offHeapMemorySize)); } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/f9d8e405/blur-store/src/main/java/org/apache/blur/store/util/UnsafeUtil.java ---------------------------------------------------------------------- diff --git a/blur-store/src/main/java/org/apache/blur/store/util/UnsafeUtil.java b/blur-store/src/main/java/org/apache/blur/store/util/UnsafeUtil.java new file mode 100644 index 0000000..abaf2ff --- /dev/null +++ b/blur-store/src/main/java/org/apache/blur/store/util/UnsafeUtil.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.blur.store.util; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +public class UnsafeUtil { + private static final String JAVA_NIO_BITS = "java.nio.Bits"; + private static final Unsafe _unsafe; + + static { + try { + Class<?> clazz = Class.forName(JAVA_NIO_BITS); + Field field = clazz.getDeclaredField("unsafe"); + field.setAccessible(true); + _unsafe = (Unsafe) field.get(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static Unsafe getUnsafe() { + return _unsafe; + } + +}
