Skip to content

Commit 1185d4e

Browse files
committed
Merge branch 'fielddata'
2 parents 7cfdd9e + c295211 commit 1185d4e

File tree

268 files changed

+22374
-15550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+22374
-15550
lines changed

src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ protected ShardClearIndicesCacheResponse shardOperation(ShardClearIndicesCacheRe
127127
if (request.fieldDataCache()) {
128128
clearedAtLeastOne = true;
129129
if (request.fields() == null || request.fields().length == 0) {
130-
service.cache().fieldData().clear("api");
130+
service.fieldData().clear();
131131
} else {
132132
for (String field : request.fields()) {
133-
service.cache().fieldData().clear("api", field);
133+
service.fieldData().clearField(field);
134134
}
135135
}
136136
}
@@ -142,7 +142,7 @@ protected ShardClearIndicesCacheResponse shardOperation(ShardClearIndicesCacheRe
142142
if (request.fields() != null && request.fields().length > 0) {
143143
// only clear caches relating to the specified fields
144144
for (String field : request.fields()) {
145-
service.cache().fieldData().clear("api", field);
145+
service.fieldData().clearField(field);
146146
}
147147
} else {
148148
service.cache().clear("api");
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to ElasticSearch and Shay Banon under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. ElasticSearch licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.common.lucene;
21+
22+
import org.apache.lucene.util.BytesRef;
23+
24+
/**
25+
* A wrapped to {@link BytesRef} that also caches the hashCode for it.
26+
*/
27+
public class HashedBytesRef {
28+
29+
public BytesRef bytes;
30+
public int hash;
31+
32+
public HashedBytesRef() {
33+
}
34+
35+
public HashedBytesRef(String bytes) {
36+
this(new BytesRef(bytes));
37+
}
38+
39+
public HashedBytesRef(BytesRef bytes) {
40+
this(bytes, bytes.hashCode());
41+
}
42+
43+
public HashedBytesRef(BytesRef bytes, int hash) {
44+
this.bytes = bytes;
45+
this.hash = hash;
46+
}
47+
48+
public HashedBytesRef resetHashCode() {
49+
this.hash = bytes.hashCode();
50+
return this;
51+
}
52+
53+
public HashedBytesRef reset(BytesRef bytes, int hash) {
54+
this.bytes = bytes;
55+
this.hash = hash;
56+
return this;
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
return hash;
62+
}
63+
64+
@Override
65+
public boolean equals(Object other) {
66+
if (other instanceof HashedBytesRef) {
67+
return bytes.equals(((HashedBytesRef) other).bytes);
68+
}
69+
return false;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return bytes.toString();
75+
}
76+
77+
public HashedBytesRef deepCopy() {
78+
return deepCopyOf(this);
79+
}
80+
81+
public static HashedBytesRef deepCopyOf(HashedBytesRef other) {
82+
BytesRef copy = new BytesRef();
83+
copy.copyBytes(other.bytes);
84+
return new HashedBytesRef(copy, other.hash);
85+
}
86+
}

src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.elasticsearch.common.logging.ESLogger;
3333
import org.elasticsearch.index.analysis.AnalyzerScope;
3434
import org.elasticsearch.index.analysis.NamedAnalyzer;
35-
import org.elasticsearch.index.field.data.FieldDataType;
35+
import org.elasticsearch.index.fielddata.IndexFieldData;
3636

3737
import java.io.IOException;
3838
import java.lang.reflect.Field;
@@ -215,7 +215,7 @@ public static void writeTopDocs(StreamOutput out, TopDocs topDocs, int from) thr
215215
out.writeString(sortField.getField());
216216
}
217217
if (sortField.getComparatorSource() != null) {
218-
writeSortType(out, ((FieldDataType.ExtendedFieldComparatorSource) sortField.getComparatorSource()).reducedType());
218+
writeSortType(out, ((IndexFieldData.XFieldComparatorSource) sortField.getComparatorSource()).reducedType());
219219
} else {
220220
writeSortType(out, sortField.getType());
221221
}

src/main/java/org/elasticsearch/index/cache/CacheStats.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,28 @@
3434
*/
3535
public class CacheStats implements Streamable, ToXContent {
3636

37-
long fieldEvictions;
3837
long filterEvictions;
3938
long filterCount;
40-
long fieldSize;
4139
long filterSize;
4240
long idCacheSize;
4341

4442
public CacheStats() {
4543
}
4644

47-
public CacheStats(long fieldEvictions, long filterEvictions, long fieldSize, long filterSize, long filterCount, long idCacheSize) {
48-
this.fieldEvictions = fieldEvictions;
45+
public CacheStats(long filterEvictions, long filterSize, long filterCount, long idCacheSize) {
4946
this.filterEvictions = filterEvictions;
50-
this.fieldSize = fieldSize;
5147
this.filterSize = filterSize;
5248
this.filterCount = filterCount;
5349
this.idCacheSize = idCacheSize;
5450
}
5551

5652
public void add(CacheStats stats) {
57-
this.fieldEvictions += stats.fieldEvictions;
5853
this.filterEvictions += stats.filterEvictions;
59-
this.fieldSize += stats.fieldSize;
6054
this.filterSize += stats.filterSize;
6155
this.filterCount += stats.filterCount;
6256
this.idCacheSize += stats.idCacheSize;
6357
}
6458

65-
public long fieldEvictions() {
66-
return this.fieldEvictions;
67-
}
68-
69-
public long getFieldEvictions() {
70-
return this.fieldEvictions();
71-
}
72-
7359
public long filterEvictions() {
7460
return this.filterEvictions;
7561
}
@@ -94,22 +80,6 @@ public long getFilterCount() {
9480
return filterCount;
9581
}
9682

97-
public long fieldSizeInBytes() {
98-
return this.fieldSize;
99-
}
100-
101-
public long getFieldSizeInBytes() {
102-
return fieldSizeInBytes();
103-
}
104-
105-
public ByteSizeValue fieldSize() {
106-
return new ByteSizeValue(fieldSize);
107-
}
108-
109-
public ByteSizeValue getFieldSize() {
110-
return this.fieldSize();
111-
}
112-
11383
public long filterSizeInBytes() {
11484
return this.filterSize;
11585
}
@@ -145,9 +115,6 @@ public ByteSizeValue getIdCacheSize() {
145115
@Override
146116
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
147117
builder.startObject(Fields.CACHE);
148-
builder.field(Fields.FIELD_EVICTIONS, fieldEvictions);
149-
builder.field(Fields.FIELD_SIZE, fieldSize().toString());
150-
builder.field(Fields.FIELD_SIZE_IN_BYTES, fieldSize);
151118
builder.field(Fields.FILTER_COUNT, filterCount);
152119
builder.field(Fields.FILTER_EVICTIONS, filterEvictions);
153120
builder.field(Fields.FILTER_SIZE, filterSize().toString());
@@ -160,9 +127,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
160127

161128
static final class Fields {
162129
static final XContentBuilderString CACHE = new XContentBuilderString("cache");
163-
static final XContentBuilderString FIELD_SIZE = new XContentBuilderString("field_size");
164-
static final XContentBuilderString FIELD_SIZE_IN_BYTES = new XContentBuilderString("field_size_in_bytes");
165-
static final XContentBuilderString FIELD_EVICTIONS = new XContentBuilderString("field_evictions");
166130
static final XContentBuilderString FILTER_EVICTIONS = new XContentBuilderString("filter_evictions");
167131
static final XContentBuilderString FILTER_COUNT = new XContentBuilderString("filter_count");
168132
static final XContentBuilderString FILTER_SIZE = new XContentBuilderString("filter_size");
@@ -179,19 +143,15 @@ public static CacheStats readCacheStats(StreamInput in) throws IOException {
179143

180144
@Override
181145
public void readFrom(StreamInput in) throws IOException {
182-
fieldEvictions = in.readVLong();
183146
filterEvictions = in.readVLong();
184-
fieldSize = in.readVLong();
185147
filterSize = in.readVLong();
186148
filterCount = in.readVLong();
187149
idCacheSize = in.readVLong();
188150
}
189151

190152
@Override
191153
public void writeTo(StreamOutput out) throws IOException {
192-
out.writeVLong(fieldEvictions);
193154
out.writeVLong(filterEvictions);
194-
out.writeVLong(fieldSize);
195155
out.writeVLong(filterSize);
196156
out.writeVLong(filterCount);
197157
out.writeVLong(idCacheSize);

src/main/java/org/elasticsearch/index/cache/IndexCache.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.common.unit.TimeValue;
3232
import org.elasticsearch.index.AbstractIndexComponent;
3333
import org.elasticsearch.index.Index;
34-
import org.elasticsearch.index.cache.field.data.FieldDataCache;
3534
import org.elasticsearch.index.cache.filter.FilterCache;
3635
import org.elasticsearch.index.cache.id.IdCache;
3736
import org.elasticsearch.index.cache.query.parser.QueryParserCache;
@@ -44,8 +43,6 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
4443

4544
private final FilterCache filterCache;
4645

47-
private final FieldDataCache fieldDataCache;
48-
4946
private final QueryParserCache queryParserCache;
5047

5148
private final IdCache idCache;
@@ -58,11 +55,9 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
5855
private CacheStats latestCacheStats;
5956

6057
@Inject
61-
public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, FieldDataCache fieldDataCache,
62-
QueryParserCache queryParserCache, IdCache idCache) {
58+
public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, QueryParserCache queryParserCache, IdCache idCache) {
6359
super(index, indexSettings);
6460
this.filterCache = filterCache;
65-
this.fieldDataCache = fieldDataCache;
6661
this.queryParserCache = queryParserCache;
6762
this.idCache = idCache;
6863

@@ -81,15 +76,15 @@ public void setClusterService(@Nullable ClusterService clusterService) {
8176

8277
public synchronized void invalidateCache() {
8378
FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats();
84-
latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes());
79+
latestCacheStats = new CacheStats(filterCache.evictions(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes());
8580
latestCacheStatsTimestamp = System.currentTimeMillis();
8681
}
8782

8883
public synchronized CacheStats stats() {
8984
long timestamp = System.currentTimeMillis();
9085
if ((timestamp - latestCacheStatsTimestamp) > refreshInterval.millis()) {
9186
FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats();
92-
latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes());
87+
latestCacheStats = new CacheStats(filterCache.evictions(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, idCache.sizeInBytes());
9388
latestCacheStatsTimestamp = timestamp;
9489
}
9590
return latestCacheStats;
@@ -99,10 +94,6 @@ public FilterCache filter() {
9994
return filterCache;
10095
}
10196

102-
public FieldDataCache fieldData() {
103-
return fieldDataCache;
104-
}
105-
10697
public IdCache idCache() {
10798
return this.idCache;
10899
}
@@ -114,7 +105,6 @@ public QueryParserCache queryParserCache() {
114105
@Override
115106
public void close() throws ElasticSearchException {
116107
filterCache.close();
117-
fieldDataCache.close();
118108
idCache.close();
119109
queryParserCache.close();
120110
if (clusterService != null) {
@@ -124,13 +114,11 @@ public void close() throws ElasticSearchException {
124114

125115
public void clear(IndexReader reader) {
126116
filterCache.clear(reader);
127-
fieldDataCache.clear(reader);
128117
idCache.clear(reader);
129118
}
130119

131120
public void clear(String reason) {
132121
filterCache.clear(reason);
133-
fieldDataCache.clear(reason);
134122
idCache.clear();
135123
queryParserCache.clear();
136124
}

src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.elasticsearch.common.inject.AbstractModule;
2323
import org.elasticsearch.common.settings.Settings;
24-
import org.elasticsearch.index.cache.field.data.FieldDataCacheModule;
2524
import org.elasticsearch.index.cache.filter.FilterCacheModule;
2625
import org.elasticsearch.index.cache.id.IdCacheModule;
2726
import org.elasticsearch.index.cache.query.parser.QueryParserCacheModule;
@@ -40,7 +39,6 @@ public IndexCacheModule(Settings settings) {
4039
@Override
4140
protected void configure() {
4241
new FilterCacheModule(settings).configure(binder());
43-
new FieldDataCacheModule(settings).configure(binder());
4442
new IdCacheModule(settings).configure(binder());
4543
new QueryParserCacheModule(settings).configure(binder());
4644

src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)