diff --git a/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java index 9bd1b7a9840..728e5a5d593 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -36,7 +35,6 @@ import java.util.Map; /** * */ -@Immutable public class AliasMetaData { private final String alias; diff --git a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index 0f7702e8fee..98486fd9d39 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -47,7 +46,6 @@ import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * */ -@Immutable public class IndexMetaData { private static ImmutableSet dynamicSettings = ImmutableSet.builder() diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 8c9f8c911ba..793cb22fa1b 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.common.xcontent.*; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; @@ -47,7 +46,6 @@ import static org.elasticsearch.common.settings.ImmutableSettings.*; /** * */ -@Immutable public class MetaData implements Iterable { private static ImmutableSet dynamicSettings = ImmutableSet.builder() diff --git a/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java index 8f7f0bb1cba..51bdaff0fc9 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java +++ b/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java @@ -27,7 +27,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.concurrent.Immutable; import java.io.IOException; import java.util.*; @@ -38,7 +37,6 @@ import static com.google.common.collect.Lists.newArrayList; /** * */ -@Immutable public class IndexRoutingTable implements Iterable { private final String index; diff --git a/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index ad9b57f235e..cf147fcc5e5 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; import java.util.HashMap; import java.util.Iterator; @@ -37,7 +36,6 @@ import static com.google.common.collect.Maps.newHashMap; /** * */ -@NotThreadSafe public class RoutingNodes implements Iterable { private final MetaData metaData; diff --git a/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index c5d7015414f..aae60b2305f 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndexMissingException; @@ -39,7 +38,6 @@ import static com.google.common.collect.Maps.newHashMap; /** * */ -@Immutable public class RoutingTable implements Iterable { public static final RoutingTable EMPTY_ROUTING_TABLE = builder().build(); diff --git a/src/main/java/org/elasticsearch/common/component/Lifecycle.java b/src/main/java/org/elasticsearch/common/component/Lifecycle.java index 7e0a01877a1..0c1cf02d7f3 100644 --- a/src/main/java/org/elasticsearch/common/component/Lifecycle.java +++ b/src/main/java/org/elasticsearch/common/component/Lifecycle.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.component; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.util.concurrent.ThreadSafe; /** * Lifecycle state. Allows the following transitions: @@ -57,10 +56,7 @@ import org.elasticsearch.common.util.concurrent.ThreadSafe; * // perofrm close logic here * } * - * - * */ -@ThreadSafe public class Lifecycle { public static enum State { diff --git a/src/main/java/org/elasticsearch/common/io/FastCharArrayWriter.java b/src/main/java/org/elasticsearch/common/io/FastCharArrayWriter.java index aa7e1a0ff44..991269a20e0 100644 --- a/src/main/java/org/elasticsearch/common/io/FastCharArrayWriter.java +++ b/src/main/java/org/elasticsearch/common/io/FastCharArrayWriter.java @@ -19,18 +19,13 @@ package org.elasticsearch.common.io; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; - import java.io.IOException; import java.io.Writer; import java.util.Arrays; /** * A similar class to {@link java.io.CharArrayWriter} allowing to get the underlying char[] buffer. - * - * */ -@NotThreadSafe public class FastCharArrayWriter extends Writer { /** diff --git a/src/main/java/org/elasticsearch/common/io/FastStringReader.java b/src/main/java/org/elasticsearch/common/io/FastStringReader.java index 6dbb87c083d..1c657eda208 100644 --- a/src/main/java/org/elasticsearch/common/io/FastStringReader.java +++ b/src/main/java/org/elasticsearch/common/io/FastStringReader.java @@ -19,18 +19,15 @@ package org.elasticsearch.common.io; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; - import java.io.IOException; import java.io.Reader; /** * A character stream whose source is a string that is not thread safe - * + *

* (shay.banon - * ) + * ) */ -@NotThreadSafe public class FastStringReader extends CharSequenceReader { private String str; diff --git a/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java b/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java index b5bf535a0e2..a3d3cc8f16a 100644 --- a/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java +++ b/src/main/java/org/elasticsearch/common/joda/FormatDateTimeFormatter.java @@ -19,16 +19,12 @@ package org.elasticsearch.common.joda; -import org.elasticsearch.common.util.concurrent.Immutable; import org.joda.time.format.DateTimeFormatter; /** * A simple wrapper around {@link DateTimeFormatter} that retains the * format that was used to create it. - * - * */ -@Immutable public class FormatDateTimeFormatter { private final String format; diff --git a/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java b/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java deleted file mode 100644 index 966989bfcf0..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMap.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.lucene.versioned; - -import org.elasticsearch.common.util.concurrent.ThreadSafe; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * An implementation of {@link VersionedMap} based on {@link ConcurrentHashMap}. - * - * - */ -@ThreadSafe -public class ConcurrentVersionedMap implements VersionedMap { - - private final ConcurrentHashMap map = new ConcurrentHashMap(); - - @Override - public boolean beforeVersion(int key, int versionToCheck) { - Integer result = map.get(key); - return result == null || versionToCheck < result; - } - - @Override - public void putVersion(int key, int version) { - map.put(key, version); - } - - @Override - public void putVersionIfAbsent(int key, int version) { - map.putIfAbsent(key, version); - } - - @Override - public void clear() { - map.clear(); - } -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java b/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java deleted file mode 100644 index 4f9a8875b98..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/versioned/ConcurrentVersionedMapLong.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.lucene.versioned; - -import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; -import org.elasticsearch.common.util.concurrent.ThreadSafe; - -/** - * An implementation of {@link VersionedMap} based on {@link org.elasticsearch.common.util.concurrent.ConcurrentMapLong}. - * - * - */ -@ThreadSafe -public class ConcurrentVersionedMapLong implements VersionedMap { - - private final ConcurrentMapLong map = ConcurrentCollections.newConcurrentMapLong(); - - @Override - public boolean beforeVersion(int key, int versionToCheck) { - Integer result = map.get(key); - return result == null || versionToCheck < result; - } - - @Override - public void putVersion(int key, int version) { - map.put(key, version); - } - - @Override - public void putVersionIfAbsent(int key, int version) { - map.putIfAbsent(key, version); - } - - @Override - public void clear() { - map.clear(); - } -} diff --git a/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java b/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java deleted file mode 100644 index 33899b3b5f5..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/versioned/NativeVersionedMap.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.lucene.versioned; - -import gnu.trove.impl.Constants; -import gnu.trove.map.hash.TIntIntHashMap; -import org.elasticsearch.common.util.concurrent.ThreadSafe; - -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -/** - * An implementation of {@link VersionedMap} based on trove. - * - * - */ -@ThreadSafe -public class NativeVersionedMap implements VersionedMap { - - /** - * Mask value for indexing into segments. The upper bits of a - * key's hash code are used to choose the segment. - */ - private final int segmentMask; - - /** - * Shift value for indexing within segments. - */ - private final int segmentShift; - - private final Segment[] segments; - - public NativeVersionedMap() { - this(16); - } - - public NativeVersionedMap(int concurrencyLevel) { - // Find power-of-two sizes best matching arguments - int sshift = 0; - int ssize = 1; - while (ssize < concurrencyLevel) { - ++sshift; - ssize <<= 1; - } - segmentShift = 32 - sshift; - segmentMask = ssize - 1; - this.segments = new Segment[ssize]; - for (int i = 0; i < segments.length; i++) { - segments[i] = new Segment(); - } - } - - @Override - public boolean beforeVersion(int key, int versionToCheck) { - Segment segment = segmentFor(hash(key)); - segment.rwl.readLock().lock(); - try { - int result = segment.map.get(key); - return result == -1 || versionToCheck < result; - } finally { - segment.rwl.readLock().unlock(); - } - } - - @Override - public void putVersion(int key, int version) { - Segment segment = segmentFor(hash(key)); - segment.rwl.writeLock().lock(); - try { - segment.map.put(key, version); - } finally { - segment.rwl.writeLock().unlock(); - } - } - - @Override - public void putVersionIfAbsent(int key, int version) { - Segment segment = segmentFor(hash(key)); - segment.rwl.writeLock().lock(); - try { - if (!segment.map.containsKey(key)) { - segment.map.put(key, version); - } - } finally { - segment.rwl.writeLock().unlock(); - } - } - - @Override - public void clear() { - for (Segment segment : segments) { - segment.rwl.writeLock().lock(); - try { - segment.map.clear(); - } finally { - segment.rwl.writeLock().unlock(); - } - } - } - - /** - * Applies a supplemental hash function to a given hashCode, which - * defends against poor quality hash functions. This is critical - * because ConcurrentHashMap uses power-of-two length hash tables, - * that otherwise encounter collisions for hashCodes that do not - * differ in lower or upper bits. - */ - private static int hash(int h) { - // Spread bits to regularize both segment and index locations, - // using variant of single-word Wang/Jenkins hash. - h += (h << 15) ^ 0xffffcd7d; - h ^= (h >>> 10); - h += (h << 3); - h ^= (h >>> 6); - h += (h << 2) + (h << 14); - return h ^ (h >>> 16); - } - - /** - * Returns the segment that should be used for key with given hash - * - * @param hash the hash code for the key - * @return the segment - */ - final Segment segmentFor(int hash) { - return segments[(hash >>> segmentShift) & segmentMask]; - } - - private static class Segment { - final ReadWriteLock rwl = new ReentrantReadWriteLock(); - final TIntIntHashMap map = new TIntIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, 0, -1); - - private Segment() { - - } - } -} diff --git a/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java b/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java deleted file mode 100644 index 92a6b09fcdd..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReader.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.lucene.versioned; - -import org.apache.lucene.index.*; -import org.elasticsearch.common.util.concurrent.ThreadSafe; - -import java.io.IOException; - -/** - * - */ -@ThreadSafe -public class VersionedIndexReader extends FilterIndexReader { - - protected final int version; - - protected final VersionedMap versionedMap; - - public VersionedIndexReader(IndexReader in, int version, VersionedMap versionedMap) { - super(in); - this.version = version; - this.versionedMap = versionedMap; - } - - @Override - public TermDocs termDocs() throws IOException { - return new VersionedTermDocs(in.termDocs()); - } - - @Override - public TermDocs termDocs(Term term) throws IOException { - return new VersionedTermDocs(in.termDocs(term)); - } - - @Override - public TermPositions termPositions() throws IOException { - return new VersionedTermPositions(in.termPositions()); - } - - @Override - public TermPositions termPositions(Term term) throws IOException { - return new VersionedTermPositions(in.termPositions(term)); - } - - - private class VersionedTermDocs extends FilterTermDocs { - - public VersionedTermDocs(TermDocs in) { - super(in); - } - - public boolean next() throws IOException { - while (in.next()) { - if (versionedMap.beforeVersion(in.doc(), version)) return true; - } - return false; - } - - public int read(final int[] docs, final int[] freqs) throws IOException { - int i = 0; - while (i < docs.length) { - if (!in.next()) return i; - - int doc = in.doc(); - if (versionedMap.beforeVersion(doc, version)) { - docs[i] = doc; - freqs[i] = in.freq(); - i++; - } - } - return i; - } - - public boolean skipTo(int i) throws IOException { - if (!in.skipTo(i)) return false; - if (versionedMap.beforeVersion(in.doc(), version)) return true; - - return next(); - } - } - - private class VersionedTermPositions extends VersionedTermDocs implements TermPositions { - final TermPositions _tp; - - public VersionedTermPositions(TermPositions in) { - super(in); - _tp = in; - } - - public int nextPosition() throws IOException { - return _tp.nextPosition(); - } - - public int getPayloadLength() { - return _tp.getPayloadLength(); - } - - public byte[] getPayload(byte[] data, int offset) throws IOException { - return _tp.getPayload(data, offset); - } - - public boolean isPayloadAvailable() { - return _tp.isPayloadAvailable(); - } - } - -} diff --git a/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java b/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java deleted file mode 100644 index 9f59e3d4dfb..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/versioned/VersionedMap.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.lucene.versioned; - -import org.elasticsearch.common.util.concurrent.ThreadSafe; - -/** - * A versioned map, allowing to put version numbers associated with specific - * keys. - *

- *

Note. versions can be assumed to be >= 0. - * - * - */ -@ThreadSafe -public interface VersionedMap { - - /** - * Returns true if the versionToCheck is smaller than the current version - * associated with the key. If there is no version associated with the key, then - * it should return true as well. - */ - boolean beforeVersion(int key, int versionToCheck); - - /** - * Puts (and replaces if it exists) the current key with the provided version. - */ - void putVersion(int key, int version); - - /** - * Puts the version with the key only if it is absent. - */ - void putVersionIfAbsent(int key, int version); - - /** - * Clears the map. - */ - void clear(); -} diff --git a/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java b/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java index 50ff49e3001..70f605a52eb 100644 --- a/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java +++ b/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java @@ -34,8 +34,6 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.Immutable; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import java.io.IOException; import java.io.InputStream; @@ -51,11 +49,7 @@ import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; /** * An immutable implementation of {@link Settings}. - * - * */ -@ThreadSafe -@Immutable public class ImmutableSettings implements Settings { private ImmutableMap settings; diff --git a/src/main/java/org/elasticsearch/common/settings/Settings.java b/src/main/java/org/elasticsearch/common/settings/Settings.java index 144cc43938f..cc05aa17b78 100644 --- a/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import java.util.Map; @@ -33,10 +32,8 @@ import java.util.Map; *

Using {@link ImmutableSettings#settingsBuilder()} in order to create a builder * which in turn can create an immutable implementation of settings. * - * * @see ImmutableSettings */ -@ThreadSafe public interface Settings { /** diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/CopyOnWriteMap.java b/src/main/java/org/elasticsearch/common/util/concurrent/CopyOnWriteMap.java deleted file mode 100644 index 2086d90b792..00000000000 --- a/src/main/java/org/elasticsearch/common/util/concurrent/CopyOnWriteMap.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.util.concurrent; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentMap; - -/** - * Provides the semantics of a thread safe copy on write map. - * - * - */ -@ThreadSafe -public class CopyOnWriteMap implements ConcurrentMap { - - private volatile Map map = new HashMap(); - - public void clear() { - map = new HashMap(); - } - - public boolean containsKey(Object key) { - return map.containsKey(key); - } - - public boolean containsValue(Object value) { - return map.containsValue(value); - } - - public Set> entrySet() { - return map.entrySet(); - } - - public V get(Object key) { - return map.get(key); - } - - public boolean isEmpty() { - return map.isEmpty(); - } - - public Set keySet() { - return map.keySet(); - } - - public V put(K key, V value) { - synchronized (this) { - Map copyMap = copyMap(); - V put = copyMap.put(key, value); - map = copyMap; - return put; - } - } - - public synchronized void putAll(Map t) { - Map copyMap = copyMap(); - copyMap.putAll(t); - map = copyMap; - } - - public synchronized V remove(Object key) { - Map copyMap = copyMap(); - V remove = copyMap.remove(key); - map = copyMap; - return remove; - } - - public int size() { - return map.size(); - } - - public Collection values() { - return map.values(); - } - - private Map copyMap() { - return new HashMap(map); - } - - public synchronized V putIfAbsent(K key, V value) { - V v = map.get(key); - if (v == null) { - Map copyMap = copyMap(); - copyMap.put(key, value); - map = copyMap; - } - return v; - } - - public synchronized boolean remove(Object key, Object value) { - V v = map.get(key); - if (v != null && v.equals(value)) { - Map copyMap = copyMap(); - copyMap.remove(key); - map = copyMap; - return true; - } - return false; - } - - public synchronized V replace(K key, V value) { - V v = map.get(key); - if (v != null) { - Map copyMap = copyMap(); - copyMap.put(key, value); - map = copyMap; - } - return v; - } - - public synchronized boolean replace(K key, V oldValue, V newValue) { - V v = map.get(key); - if (v != null && v.equals(oldValue)) { - Map copyMap = copyMap(); - copyMap.put(key, newValue); - map = copyMap; - return true; - } - return false; - } - -} diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/Immutable.java b/src/main/java/org/elasticsearch/common/util/concurrent/Immutable.java deleted file mode 100644 index 5bd6be661f9..00000000000 --- a/src/main/java/org/elasticsearch/common/util/concurrent/Immutable.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.util.concurrent; - -import java.lang.annotation.*; - -/** - * Immutable - *

- * The class to which this annotation is applied is immutable. This means that - * its state cannot be seen to change by callers. Of necessity this means that - * all public fields are final, and that all public final reference fields refer - * to other immutable objects, and that methods do not publish references to any - * internal state which is mutable by implementation even if not by design. - * Immutable objects may still have internal mutable state for purposes of - * performance optimization; some state variables may be lazily computed, so - * long as they are computed from immutable state and that callers cannot tell - * the difference. - *

- * Immutable objects are inherently thread-safe; they may be passed between - * threads or published without synchronization. - * - * - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.CLASS) -public @interface Immutable { -} diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/NotThreadSafe.java b/src/main/java/org/elasticsearch/common/util/concurrent/NotThreadSafe.java deleted file mode 100644 index d3a4116723d..00000000000 --- a/src/main/java/org/elasticsearch/common/util/concurrent/NotThreadSafe.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.util.concurrent; - -import java.lang.annotation.*; - -/** - * NotThreadSafe - *

- * The class to which this annotation is applied is not thread-safe. This - * annotation primarily exists for clarifying the non-thread-safety of a class - * that might otherwise be assumed to be thread-safe, despite the fact that it - * is a bad idea to assume a class is thread-safe without good reason. - * - * - * @see ThreadSafe - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.CLASS) -public @interface NotThreadSafe { -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/ThreadSafe.java b/src/main/java/org/elasticsearch/common/util/concurrent/ThreadSafe.java deleted file mode 100644 index 9197b3f7178..00000000000 --- a/src/main/java/org/elasticsearch/common/util/concurrent/ThreadSafe.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.common.util.concurrent; - -import java.lang.annotation.*; - -/** - * ThreadSafe - *

- * The class to which this annotation is applied is thread-safe. This means that - * no sequences of accesses (reads and writes to public fields, calls to public - * methods) may put the object into an invalid state, regardless of the - * interleaving of those actions by the runtime, and without requiring any - * additional synchronization or coordination on the part of the caller. - * - * - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.CLASS) -public @interface ThreadSafe { -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/Index.java b/src/main/java/org/elasticsearch/index/Index.java index 6a28462f5be..1d249da4b2b 100644 --- a/src/main/java/org/elasticsearch/index/Index.java +++ b/src/main/java/org/elasticsearch/index/Index.java @@ -22,7 +22,6 @@ package org.elasticsearch.index; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; -import org.elasticsearch.common.util.concurrent.Immutable; import java.io.IOException; import java.io.Serializable; @@ -30,7 +29,6 @@ import java.io.Serializable; /** * */ -@Immutable public class Index implements Serializable, Streamable { private String name; diff --git a/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java b/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java index b742d47eb40..3ec569d8227 100644 --- a/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java +++ b/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Fieldable; -import org.elasticsearch.common.util.concurrent.Immutable; import java.io.IOException; import java.io.Reader; @@ -30,10 +29,7 @@ import java.io.Reader; /** * Named analyzer is an analyzer wrapper around an actual analyzer ({@link #analyzer} that is associated * with a name ({@link #name()}. - * - * */ -@Immutable public final class NamedAnalyzer extends Analyzer { private final String name; diff --git a/src/main/java/org/elasticsearch/index/engine/Engine.java b/src/main/java/org/elasticsearch/index/engine/Engine.java index fe5c3be38d6..1fef90482dd 100644 --- a/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lucene.uid.UidField; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; import org.elasticsearch.index.mapper.DocumentMapper; @@ -48,7 +47,6 @@ import java.util.List; /** * */ -@ThreadSafe public interface Engine extends IndexShardComponent, CloseableComponent { static ByteSizeValue INACTIVE_SHARD_INDEXING_BUFFER = ByteSizeValue.parseBytesSizeValue("500kb"); diff --git a/src/main/java/org/elasticsearch/index/mapper/ContentPath.java b/src/main/java/org/elasticsearch/index/mapper/ContentPath.java index d53b67d5e10..337b6bd16c7 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ContentPath.java +++ b/src/main/java/org/elasticsearch/index/mapper/ContentPath.java @@ -19,12 +19,9 @@ package org.elasticsearch.index.mapper; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; - /** * */ -@NotThreadSafe public class ContentPath { public static enum Type { diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentFieldMappers.java b/src/main/java/org/elasticsearch/index/mapper/DocumentFieldMappers.java index d2cbb813c18..2087f33fbf9 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentFieldMappers.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentFieldMappers.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper; import com.google.common.collect.*; import org.apache.lucene.analysis.Analyzer; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.index.analysis.FieldNameAnalyzer; import java.util.Map; @@ -34,7 +33,6 @@ import static com.google.common.collect.Maps.newHashMap; /** * */ -@Immutable public class DocumentFieldMappers implements Iterable { private final ImmutableList fieldMappers; diff --git a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index 9a65077d6ba..b6802bbffb5 100644 --- a/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -26,18 +26,14 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.util.concurrent.Immutable; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.field.data.FieldDataType; import org.elasticsearch.index.query.QueryParseContext; /** * */ -@ThreadSafe public interface FieldMapper { - @Immutable public static class Names { private final String name; diff --git a/src/main/java/org/elasticsearch/index/mapper/FieldMappers.java b/src/main/java/org/elasticsearch/index/mapper/FieldMappers.java index a54e48a4c40..c8f21b56519 100644 --- a/src/main/java/org/elasticsearch/index/mapper/FieldMappers.java +++ b/src/main/java/org/elasticsearch/index/mapper/FieldMappers.java @@ -22,16 +22,12 @@ package org.elasticsearch.index.mapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; -import org.elasticsearch.common.util.concurrent.Immutable; import java.util.List; /** * A holder for several {@link FieldMapper}. - * - * */ -@Immutable public class FieldMappers implements Iterable { private final ImmutableList fieldMappers; diff --git a/src/main/java/org/elasticsearch/index/mapper/Mapper.java b/src/main/java/org/elasticsearch/index/mapper/Mapper.java index 74aea119868..e891f30797b 100644 --- a/src/main/java/org/elasticsearch/index/mapper/Mapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/Mapper.java @@ -23,8 +23,6 @@ import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.index.analysis.AnalysisService; @@ -34,12 +32,10 @@ import java.util.Map; /** * */ -@ThreadSafe public interface Mapper extends ToXContent { public static final Mapper[] EMPTY_ARRAY = new Mapper[0]; - @NotThreadSafe public static class BuilderContext { private final Settings indexSettings; private final ContentPath contentPath; @@ -59,7 +55,6 @@ public interface Mapper extends ToXContent { } } - @NotThreadSafe public static abstract class Builder { public String name; diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 4d58a7335b9..1a1b6facaa6 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XBooleanFilter; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.env.Environment; import org.elasticsearch.env.FailedToResolveConfigException; import org.elasticsearch.index.AbstractIndexComponent; @@ -65,7 +64,6 @@ import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder; /** * */ -@ThreadSafe public class MapperService extends AbstractIndexComponent implements Iterable { public static final String DEFAULT_MAPPING = "_default_"; diff --git a/src/main/java/org/elasticsearch/index/mapper/ObjectMappers.java b/src/main/java/org/elasticsearch/index/mapper/ObjectMappers.java index 69b60b3df81..0b641d1b6de 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ObjectMappers.java +++ b/src/main/java/org/elasticsearch/index/mapper/ObjectMappers.java @@ -22,15 +22,11 @@ package org.elasticsearch.index.mapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.index.mapper.object.ObjectMapper; /** * A holder for several {@link org.elasticsearch.index.mapper.object.ObjectMapper}. - * - * */ -@Immutable public class ObjectMappers implements Iterable { private final ImmutableList objectMappers; diff --git a/src/main/java/org/elasticsearch/index/mapper/ParseContext.java b/src/main/java/org/elasticsearch/index/mapper/ParseContext.java index 8538d47529d..958620e0406 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ParseContext.java +++ b/src/main/java/org/elasticsearch/index/mapper/ParseContext.java @@ -25,7 +25,6 @@ import org.apache.lucene.document.Field; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lucene.all.AllEntries; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.mapper.object.RootObjectMapper; @@ -38,7 +37,6 @@ import java.util.Map; /** * */ -@NotThreadSafe public class ParseContext { private final DocumentMapper docMapper; diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index 5ffe5fad3c8..53728501120 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.uid.UidField; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -52,7 +51,6 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parsePathType; /** * */ -@ThreadSafe public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { public static final String CONTENT_TYPE = "object"; diff --git a/src/main/java/org/elasticsearch/index/shard/ShardId.java b/src/main/java/org/elasticsearch/index/shard/ShardId.java index 05fb74a4fc4..fdcaa4e79e6 100644 --- a/src/main/java/org/elasticsearch/index/shard/ShardId.java +++ b/src/main/java/org/elasticsearch/index/shard/ShardId.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.shard; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; -import org.elasticsearch.common.util.concurrent.Immutable; import org.elasticsearch.index.Index; import java.io.IOException; @@ -30,10 +29,7 @@ import java.io.Serializable; /** * Allows for shard level components to be injected with the shard id. - * - * */ -@Immutable public class ShardId implements Serializable, Streamable { private Index index; diff --git a/src/main/java/org/elasticsearch/index/shard/service/IndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/IndexShard.java index 0457ad503ef..d39c6eb9fd1 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/IndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/IndexShard.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.shard.service; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.EngineException; import org.elasticsearch.index.flush.FlushStats; @@ -44,7 +43,6 @@ import org.elasticsearch.index.store.StoreStats; /** * */ -@ThreadSafe public interface IndexShard extends IndexShardComponent { ShardIndexingService indexingService(); diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 520be6b0a02..5590cfec71c 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -39,7 +39,6 @@ import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.aliases.IndexAliasesService; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.engine.*; @@ -77,7 +76,6 @@ import static org.elasticsearch.index.mapper.SourceToParse.source; /** * */ -@ThreadSafe public class InternalIndexShard extends AbstractIndexShardComponent implements IndexShard { private final ThreadPool threadPool; diff --git a/src/main/java/org/elasticsearch/index/translog/Translog.java b/src/main/java/org/elasticsearch/index/translog/Translog.java index 2fe122d8410..6fe28e42511 100644 --- a/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -29,8 +29,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.lease.Releasable; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexShardComponent; @@ -40,7 +38,6 @@ import java.io.InputStream; /** * */ -@ThreadSafe public interface Translog extends IndexShardComponent { public static final String TRANSLOG_ID_KEY = "translog_id"; @@ -145,7 +142,6 @@ public interface Translog extends IndexShardComponent { /** * A snapshot of the transaction log, allows to iterate over all the transaction log operations. */ - @NotThreadSafe static interface Snapshot extends Releasable { /** diff --git a/src/main/java/org/elasticsearch/indices/IndicesService.java b/src/main/java/org/elasticsearch/indices/IndicesService.java index d1328333dd8..aa911684e98 100644 --- a/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -22,7 +22,6 @@ package org.elasticsearch.indices; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.index.service.IndexService; import java.util.Set; @@ -30,7 +29,6 @@ import java.util.Set; /** * */ -@ThreadSafe public interface IndicesService extends Iterable, LifecycleComponent { /** diff --git a/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index d9eed2dad66..d15762f79b2 100644 --- a/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.inject.*; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.index.*; @@ -90,7 +89,6 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde /** * */ -@ThreadSafe public class InternalIndicesService extends AbstractLifecycleComponent implements IndicesService { private final NodeEnvironment nodeEnv; diff --git a/src/main/java/org/elasticsearch/script/ExecutableScript.java b/src/main/java/org/elasticsearch/script/ExecutableScript.java index f10a88071a7..0ce3e54b960 100644 --- a/src/main/java/org/elasticsearch/script/ExecutableScript.java +++ b/src/main/java/org/elasticsearch/script/ExecutableScript.java @@ -19,14 +19,9 @@ package org.elasticsearch.script; -import org.elasticsearch.common.util.concurrent.NotThreadSafe; - /** * An executable script, can't be used concurrently. - * - * */ -@NotThreadSafe public interface ExecutableScript { void setNextVar(String name, Object value); diff --git a/src/test/java/org/elasticsearch/benchmark/common/lucene/versioned/VersionedMapBenchmark.java b/src/test/java/org/elasticsearch/benchmark/common/lucene/versioned/VersionedMapBenchmark.java deleted file mode 100644 index 65c2127ffa1..00000000000 --- a/src/test/java/org/elasticsearch/benchmark/common/lucene/versioned/VersionedMapBenchmark.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.benchmark.common.lucene.versioned; - -import org.elasticsearch.common.StopWatch; -import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMap; -import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMapLong; -import org.elasticsearch.common.lucene.versioned.NativeVersionedMap; -import org.elasticsearch.common.lucene.versioned.VersionedMap; -import org.elasticsearch.common.unit.ByteSizeValue; - -import java.lang.management.ManagementFactory; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; - -/** - * - */ -public class VersionedMapBenchmark { - - private final VersionedMap versionedMap; - - private final int readerIterations; - - private final int writerIterations; - - private final CountDownLatch latch; - - private final Thread[] readerThreads; - - private final Thread[] writerThreads; - - private final CyclicBarrier barrier1; - private final CyclicBarrier barrier2; - - public VersionedMapBenchmark(VersionedMap versionedMap, - int numberOfReaders, int readerIterations, - int numberOfWriters, int writerIterations) { - this.versionedMap = versionedMap; - this.readerIterations = readerIterations; - this.writerIterations = writerIterations; - - readerThreads = new Thread[numberOfReaders]; - for (int i = 0; i < numberOfReaders; i++) { - readerThreads[i] = new Thread(new ReaderThread(), "reader[" + i + "]"); - } - - writerThreads = new Thread[numberOfWriters]; - for (int i = 0; i < numberOfWriters; i++) { - writerThreads[i] = new Thread(new WriterThread(), "writer[" + i + "]"); - } - - latch = new CountDownLatch(numberOfReaders + numberOfWriters); - barrier1 = new CyclicBarrier(numberOfReaders + numberOfWriters + 1); - barrier2 = new CyclicBarrier(numberOfReaders + numberOfWriters + 1); - - // now, warm up a bit - StopWatch stopWatch = new StopWatch("warmup"); - stopWatch.start(); - int warmupSize = 1000000; - for (int i = 0; i < warmupSize; i++) { - versionedMap.putVersion(i, i); - versionedMap.beforeVersion(i, i); - } - stopWatch.stop(); - System.out.println("Warmup up of [" + warmupSize + "]: " + stopWatch.totalTime()); - versionedMap.clear(); - } - - public void run() throws Exception { - for (int i = 0; i < 3; i++) { - System.gc(); - MILLISECONDS.sleep(100); - } - - long emptyUsed = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); - - for (Thread t : readerThreads) { - t.start(); - } - for (Thread t : writerThreads) { - t.start(); - } - barrier1.await(); - - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - barrier2.await(); - - latch.await(); - stopWatch.stop(); - - // verify that the writers wrote... - for (int i = 0; i < writerIterations; i++) { - if (versionedMap.beforeVersion(i, Integer.MAX_VALUE)) { - System.out.println("Wrong value for [" + i + ']'); - } - } - - System.out.println("Total:"); - System.out.println(" - [" + readerThreads.length + "] readers with [" + readerIterations + "] iterations"); - System.out.println(" - [" + writerThreads.length + "] writers with [" + writerIterations + "] iterations"); - System.out.println(" - Took: " + stopWatch.totalTime()); - - for (int i = 0; i < 3; i++) { - System.gc(); - MILLISECONDS.sleep(100); - } - - long bytesTaken = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() - emptyUsed; - System.out.println("Size of [" + writerIterations + "] entries is " + new ByteSizeValue(bytesTaken)); - } - - private class ReaderThread implements Runnable { - @Override - public void run() { - try { - barrier1.await(); - barrier2.await(); - } catch (Exception e) { - e.printStackTrace(); - } - for (int i = 0; i < readerIterations; i++) { - versionedMap.beforeVersion(i, i); - } - latch.countDown(); - } - } - - private class WriterThread implements Runnable { - @Override - public void run() { - try { - barrier1.await(); - barrier2.await(); - } catch (Exception e) { - e.printStackTrace(); - } - for (int i = 0; i < writerIterations; i++) { - versionedMap.putVersionIfAbsent(i, i); - } - latch.countDown(); - } - } - - // Some results: Two cores machine, general average across 5 runs - -// VersionedMapBenchmark benchmark = new VersionedMapBenchmark( -// versionedMap, 30, 2000000, 10, 2000000 -// ); - -// Running [native] type -// Took StopWatch '': running time = 11.9s -// ----------------------------------------- -// ms % Task name -// ----------------------------------------- -// 11909 100% -// -// Size of [2000000] entries is 17.9mb - -// Running [nb] type -// Took StopWatch '': running time = 6.1s -// ----------------------------------------- -// ms % Task name -// ----------------------------------------- -// 06134 100% -// -// Size of [2000000] entries is 77.6mb - - public static void main(String[] args) throws Exception { - String type = args.length > 0 ? args[0] : "nb"; - VersionedMap versionedMap; - if ("nb".equalsIgnoreCase(type)) { - versionedMap = new ConcurrentVersionedMapLong(); - } else if ("native".equalsIgnoreCase(type)) { - versionedMap = new NativeVersionedMap(); - } else if ("concurrent".equalsIgnoreCase(type)) { - versionedMap = new ConcurrentVersionedMap(); - } else { - throw new IllegalArgumentException("Type [" + type + "] unknown"); - } - System.out.println("Running [" + type + "] type"); - VersionedMapBenchmark benchmark = new VersionedMapBenchmark( - versionedMap, 30, 2000000, 10, 2000000 - ); - benchmark.run(); - } -} diff --git a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/AbstractVersionedMapTests.java b/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/AbstractVersionedMapTests.java deleted file mode 100644 index 05522b7b83c..00000000000 --- a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/AbstractVersionedMapTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.test.unit.common.lucene.versioned; - -import org.elasticsearch.common.lucene.versioned.VersionedMap; -import org.testng.annotations.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * - */ -public abstract class AbstractVersionedMapTests { - - protected abstract VersionedMap create(); - - @Test - public void testSimple() { - VersionedMap versionedMap = create(); - - assertThat(true, equalTo(versionedMap.beforeVersion(1, 1))); - assertThat(true, equalTo(versionedMap.beforeVersion(2, 2))); - - versionedMap.putVersion(1, 2); - assertThat(true, equalTo(versionedMap.beforeVersion(1, 1))); - assertThat(false, equalTo(versionedMap.beforeVersion(1, 2))); - assertThat(true, equalTo(versionedMap.beforeVersion(2, 2))); - - versionedMap.putVersionIfAbsent(1, 0); - assertThat(true, equalTo(versionedMap.beforeVersion(1, 1))); - assertThat(true, equalTo(versionedMap.beforeVersion(2, 2))); - - versionedMap.putVersion(2, 1); - assertThat(true, equalTo(versionedMap.beforeVersion(2, 0))); - assertThat(false, equalTo(versionedMap.beforeVersion(2, 1))); - assertThat(false, equalTo(versionedMap.beforeVersion(2, 2))); - assertThat(false, equalTo(versionedMap.beforeVersion(2, 3))); - } -} diff --git a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NativeVersionedMapTests.java b/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NativeVersionedMapTests.java deleted file mode 100644 index fd01e09c5b3..00000000000 --- a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NativeVersionedMapTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.test.unit.common.lucene.versioned; - -import org.elasticsearch.common.lucene.versioned.NativeVersionedMap; -import org.elasticsearch.common.lucene.versioned.VersionedMap; - -/** - * - */ -public class NativeVersionedMapTests extends AbstractVersionedMapTests { - - @Override - protected VersionedMap create() { - return new NativeVersionedMap(); - } -} \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NonBlockingVersionedMapTests.java b/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NonBlockingVersionedMapTests.java deleted file mode 100644 index fb09a2a5a17..00000000000 --- a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/NonBlockingVersionedMapTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.test.unit.common.lucene.versioned; - -import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMapLong; -import org.elasticsearch.common.lucene.versioned.VersionedMap; - -/** - * - */ -public class NonBlockingVersionedMapTests extends AbstractVersionedMapTests { - - @Override - protected VersionedMap create() { - return new ConcurrentVersionedMapLong(); - } -} diff --git a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/VersionedIndexReaderTests.java b/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/VersionedIndexReaderTests.java deleted file mode 100644 index 829cbdaef5a..00000000000 --- a/src/test/java/org/elasticsearch/test/unit/common/lucene/versioned/VersionedIndexReaderTests.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch 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.elasticsearch.test.unit.common.lucene.versioned; - -import org.apache.lucene.document.Document; -import org.apache.lucene.index.*; -import org.apache.lucene.store.RAMDirectory; -import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.lucene.versioned.ConcurrentVersionedMapLong; -import org.elasticsearch.common.lucene.versioned.VersionedIndexReader; -import org.elasticsearch.common.lucene.versioned.VersionedMap; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import static org.elasticsearch.common.lucene.DocumentBuilder.doc; -import static org.elasticsearch.common.lucene.DocumentBuilder.field; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * - */ -public class VersionedIndexReaderTests { - - private RAMDirectory dir; - private IndexReader indexReader; - private IndexWriter indexWriter; - private VersionedMap versionedMap; - - @BeforeClass - public void setUp() throws Exception { - versionedMap = new ConcurrentVersionedMapLong(); - dir = new RAMDirectory(); - indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.VERSION, Lucene.STANDARD_ANALYZER)); - indexWriter.addDocument(doc().add(field("value", "0")).build()); - indexWriter.addDocument(doc().add(field("value", "1")).build()); - indexWriter.addDocument(doc().add(field("value", "2")).build()); - indexWriter.addDocument(doc().add(field("value", "3")).build()); - indexWriter.commit(); - indexReader = IndexReader.open(dir, true); - } - - @AfterClass - public void tearDown() throws Exception { - indexWriter.close(); - indexReader.close(); - dir.close(); - } - - @Test - public void verifyExpected() throws Exception { - TermDocs termDocs; - Document doc = indexReader.document(0); - - assertThat(doc.getFieldable("value").stringValue(), equalTo("0")); - termDocs = indexReader.termDocs(new Term("value", "0")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - - doc = indexReader.document(1); - assertThat(doc.getFieldable("value").stringValue(), equalTo("1")); - termDocs = indexReader.termDocs(new Term("value", "1")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - - doc = indexReader.document(2); - assertThat(doc.getFieldable("value").stringValue(), equalTo("2")); - termDocs = indexReader.termDocs(new Term("value", "2")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - - doc = indexReader.document(3); - assertThat(doc.getFieldable("value").stringValue(), equalTo("3")); - termDocs = indexReader.termDocs(new Term("value", "3")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - } - - @Test - public void testSimple() throws Exception { - TermDocs termDocs; - // open a versioned index reader in version 0 - VersionedIndexReader versionedIndexReader = new VersionedIndexReader(indexReader, 0, versionedMap); - // delete doc 0 in version 1 - versionedMap.putVersion(0, 1); - - // we can see doc 0 still (versioned reader is on version 0) - termDocs = versionedIndexReader.termDocs(new Term("value", "0")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - // make sure we see doc 1, it was never deleted - termDocs = versionedIndexReader.termDocs(new Term("value", "1")); - assertThat(termDocs.next(), equalTo(true)); - assertThat(termDocs.next(), equalTo(false)); - - // delete doc 1 in version 2, we still - versionedMap.putVersion(1, 2); - // we can see doc 0 still (versioned reader is on version 0) - termDocs = versionedIndexReader.termDocs(new Term("value", "0")); - assertThat(termDocs.next(), equalTo(true)); - // we can see doc 1 still (versioned reader is on version 0) - termDocs = versionedIndexReader.termDocs(new Term("value", "1")); - assertThat(termDocs.next(), equalTo(true)); - - // move the versioned reader to 1 - versionedIndexReader = new VersionedIndexReader(indexReader, 1, versionedMap); - // we now can't see the deleted version 0 - termDocs = versionedIndexReader.termDocs(new Term("value", "0")); - assertThat(termDocs.next(), equalTo(false)); - // we can still see deleted version 1 - termDocs = versionedIndexReader.termDocs(new Term("value", "1")); - assertThat(termDocs.next(), equalTo(true)); - } -}