From a91027503f74eeef12c3eddc0ceec7de7d1fa929 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 7 Dec 2017 12:21:16 -0500 Subject: [PATCH] Remove unused *Commit* classes These classes are not used anywhere. Relates #27606 --- .../common/lucene/IndexCommitDelegate.java | 98 --------- .../index/shard/CommitPoint.java | 145 ------------- .../index/shard/CommitPoints.java | 201 ------------------ .../index/shard/CommitPointsTests.java | 69 ------ 4 files changed, 513 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java delete mode 100644 core/src/main/java/org/elasticsearch/index/shard/CommitPoint.java delete mode 100644 core/src/main/java/org/elasticsearch/index/shard/CommitPoints.java delete mode 100644 core/src/test/java/org/elasticsearch/index/shard/CommitPointsTests.java diff --git a/core/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java b/core/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java deleted file mode 100644 index 7831a7568cf9e..0000000000000 --- a/core/src/main/java/org/elasticsearch/common/lucene/IndexCommitDelegate.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to Elasticsearch 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; - -import org.apache.lucene.index.IndexCommit; -import org.apache.lucene.store.Directory; - -import java.io.IOException; -import java.util.Collection; -import java.util.Map; - -/** - * A simple delegate that delegates all {@link IndexCommit} calls to a delegated - * {@link IndexCommit}. - * - * - */ -public abstract class IndexCommitDelegate extends IndexCommit { - - protected final IndexCommit delegate; - - /** - * Constructs a new {@link IndexCommit} that will delegate all calls - * to the provided delegate. - * - * @param delegate The delegate - */ - public IndexCommitDelegate(IndexCommit delegate) { - this.delegate = delegate; - } - - @Override - public String getSegmentsFileName() { - return delegate.getSegmentsFileName(); - } - - @Override - public Collection getFileNames() throws IOException { - return delegate.getFileNames(); - } - - @Override - public Directory getDirectory() { - return delegate.getDirectory(); - } - - @Override - public void delete() { - delegate.delete(); - } - - @Override - public boolean isDeleted() { - return delegate.isDeleted(); - } - - @Override - public int getSegmentCount() { - return delegate.getSegmentCount(); - } - - @Override - public boolean equals(Object other) { - return delegate.equals(other); - } - - @Override - public int hashCode() { - return delegate.hashCode(); - } - - @Override - public long getGeneration() { - return delegate.getGeneration(); - } - - @Override - public Map getUserData() throws IOException { - return delegate.getUserData(); - } -} diff --git a/core/src/main/java/org/elasticsearch/index/shard/CommitPoint.java b/core/src/main/java/org/elasticsearch/index/shard/CommitPoint.java deleted file mode 100644 index 03afc356f3168..0000000000000 --- a/core/src/main/java/org/elasticsearch/index/shard/CommitPoint.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to Elasticsearch 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.index.shard; - -import org.elasticsearch.common.Nullable; -import org.elasticsearch.index.store.StoreFileMetaData; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class CommitPoint { - - public static final CommitPoint NULL = new CommitPoint(-1, "_null_", Type.GENERATED, Collections.emptyList(), Collections.emptyList()); - - public static class FileInfo { - private final String name; - private final String physicalName; - private final long length; - private final String checksum; - - public FileInfo(String name, String physicalName, long length, String checksum) { - this.name = name; - this.physicalName = physicalName; - this.length = length; - this.checksum = checksum; - } - - public String name() { - return name; - } - - public String physicalName() { - return this.physicalName; - } - - public long length() { - return length; - } - - @Nullable - public String checksum() { - return checksum; - } - } - - public enum Type { - GENERATED, - SAVED - } - - private final long version; - - private final String name; - - private final Type type; - - private final List indexFiles; - - private final List translogFiles; - - public CommitPoint(long version, String name, Type type, List indexFiles, List translogFiles) { - this.version = version; - this.name = name; - this.type = type; - this.indexFiles = Collections.unmodifiableList(new ArrayList<>(indexFiles)); - this.translogFiles = Collections.unmodifiableList(new ArrayList<>(translogFiles)); - } - - public long version() { - return version; - } - - public String name() { - return this.name; - } - - public Type type() { - return this.type; - } - - public List indexFiles() { - return this.indexFiles; - } - - public List translogFiles() { - return this.translogFiles; - } - - public boolean containPhysicalIndexFile(String physicalName) { - return findPhysicalIndexFile(physicalName) != null; - } - - public CommitPoint.FileInfo findPhysicalIndexFile(String physicalName) { - for (FileInfo file : indexFiles) { - if (file.physicalName().equals(physicalName)) { - return file; - } - } - return null; - } - - public CommitPoint.FileInfo findNameFile(String name) { - CommitPoint.FileInfo fileInfo = findNameIndexFile(name); - if (fileInfo != null) { - return fileInfo; - } - return findNameTranslogFile(name); - } - - public CommitPoint.FileInfo findNameIndexFile(String name) { - for (FileInfo file : indexFiles) { - if (file.name().equals(name)) { - return file; - } - } - return null; - } - - public CommitPoint.FileInfo findNameTranslogFile(String name) { - for (FileInfo file : translogFiles) { - if (file.name().equals(name)) { - return file; - } - } - return null; - } -} diff --git a/core/src/main/java/org/elasticsearch/index/shard/CommitPoints.java b/core/src/main/java/org/elasticsearch/index/shard/CommitPoints.java deleted file mode 100644 index 12a310762280b..0000000000000 --- a/core/src/main/java/org/elasticsearch/index/shard/CommitPoints.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to Elasticsearch 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.index.shard; - -import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -public class CommitPoints implements Iterable { - - private final List commitPoints; - - public CommitPoints(List commitPoints) { - CollectionUtil.introSort(commitPoints, new Comparator() { - @Override - public int compare(CommitPoint o1, CommitPoint o2) { - return (o2.version() < o1.version() ? -1 : (o2.version() == o1.version() ? 0 : 1)); - } - }); - this.commitPoints = Collections.unmodifiableList(new ArrayList<>(commitPoints)); - } - - public List commits() { - return this.commitPoints; - } - - public boolean hasVersion(long version) { - for (CommitPoint commitPoint : commitPoints) { - if (commitPoint.version() == version) { - return true; - } - } - return false; - } - - public CommitPoint.FileInfo findPhysicalIndexFile(String physicalName) { - for (CommitPoint commitPoint : commitPoints) { - CommitPoint.FileInfo fileInfo = commitPoint.findPhysicalIndexFile(physicalName); - if (fileInfo != null) { - return fileInfo; - } - } - return null; - } - - public CommitPoint.FileInfo findNameFile(String name) { - for (CommitPoint commitPoint : commitPoints) { - CommitPoint.FileInfo fileInfo = commitPoint.findNameFile(name); - if (fileInfo != null) { - return fileInfo; - } - } - return null; - } - - @Override - public Iterator iterator() { - return commitPoints.iterator(); - } - - public static byte[] toXContent(CommitPoint commitPoint) throws Exception { - XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); - builder.startObject(); - builder.field("version", commitPoint.version()); - builder.field("name", commitPoint.name()); - builder.field("type", commitPoint.type().toString()); - - builder.startObject("index_files"); - for (CommitPoint.FileInfo fileInfo : commitPoint.indexFiles()) { - builder.startObject(fileInfo.name()); - builder.field("physical_name", fileInfo.physicalName()); - builder.field("length", fileInfo.length()); - if (fileInfo.checksum() != null) { - builder.field("checksum", fileInfo.checksum()); - } - builder.endObject(); - } - builder.endObject(); - - builder.startObject("translog_files"); - for (CommitPoint.FileInfo fileInfo : commitPoint.translogFiles()) { - builder.startObject(fileInfo.name()); - builder.field("physical_name", fileInfo.physicalName()); - builder.field("length", fileInfo.length()); - builder.endObject(); - } - builder.endObject(); - - builder.endObject(); - return BytesReference.toBytes(builder.bytes()); - } - - public static CommitPoint fromXContent(byte[] data) throws Exception { - // EMPTY is safe here because we never call namedObject - try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, data)) { - String currentFieldName = null; - XContentParser.Token token = parser.nextToken(); - if (token == null) { - // no data... - throw new IOException("No commit point data"); - } - long version = -1; - String name = null; - CommitPoint.Type type = null; - List indexFiles = new ArrayList<>(); - List translogFiles = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - List files = null; - if ("index_files".equals(currentFieldName) || "indexFiles".equals(currentFieldName)) { - files = indexFiles; - } else if ("translog_files".equals(currentFieldName) || "translogFiles".equals(currentFieldName)) { - files = translogFiles; - } else { - throw new IOException("Can't handle object with name [" + currentFieldName + "]"); - } - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - String fileName = currentFieldName; - String physicalName = null; - long size = -1; - String checksum = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token.isValue()) { - if ("physical_name".equals(currentFieldName) || "physicalName".equals(currentFieldName)) { - physicalName = parser.text(); - } else if ("length".equals(currentFieldName)) { - size = parser.longValue(); - } else if ("checksum".equals(currentFieldName)) { - checksum = parser.text(); - } - } - } - if (physicalName == null) { - throw new IOException("Malformed commit, missing physical_name for [" + fileName + "]"); - } - if (size == -1) { - throw new IOException("Malformed commit, missing length for [" + fileName + "]"); - } - files.add(new CommitPoint.FileInfo(fileName, physicalName, size, checksum)); - } - } - } else if (token.isValue()) { - if ("version".equals(currentFieldName)) { - version = parser.longValue(); - } else if ("name".equals(currentFieldName)) { - name = parser.text(); - } else if ("type".equals(currentFieldName)) { - type = CommitPoint.Type.valueOf(parser.text()); - } - } - } - - if (version == -1) { - throw new IOException("Malformed commit, missing version"); - } - if (name == null) { - throw new IOException("Malformed commit, missing name"); - } - if (type == null) { - throw new IOException("Malformed commit, missing type"); - } - - return new CommitPoint(version, name, type, indexFiles, translogFiles); - } - } -} diff --git a/core/src/test/java/org/elasticsearch/index/shard/CommitPointsTests.java b/core/src/test/java/org/elasticsearch/index/shard/CommitPointsTests.java deleted file mode 100644 index 6fd66f3fb73f6..0000000000000 --- a/core/src/test/java/org/elasticsearch/index/shard/CommitPointsTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to Elasticsearch 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.index.shard; - -import org.apache.logging.log4j.Logger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.test.ESTestCase; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; - -public class CommitPointsTests extends ESTestCase { - private final Logger logger = Loggers.getLogger(CommitPointsTests.class); - - public void testCommitPointXContent() throws Exception { - ArrayList indexFiles = new ArrayList<>(); - indexFiles.add(new CommitPoint.FileInfo("file1", "file1_p", 100, "ck1")); - indexFiles.add(new CommitPoint.FileInfo("file2", "file2_p", 200, "ck2")); - - ArrayList translogFiles = new ArrayList<>(); - translogFiles.add(new CommitPoint.FileInfo("t_file1", "t_file1_p", 100, null)); - translogFiles.add(new CommitPoint.FileInfo("t_file2", "t_file2_p", 200, null)); - - CommitPoint commitPoint = new CommitPoint(1, "test", CommitPoint.Type.GENERATED, indexFiles, translogFiles); - - byte[] serialized = CommitPoints.toXContent(commitPoint); - logger.info("serialized commit_point {}", new String(serialized, StandardCharsets.UTF_8)); - - CommitPoint desCp = CommitPoints.fromXContent(serialized); - assertThat(desCp.version(), equalTo(commitPoint.version())); - assertThat(desCp.name(), equalTo(commitPoint.name())); - - assertThat(desCp.indexFiles().size(), equalTo(commitPoint.indexFiles().size())); - for (int i = 0; i < desCp.indexFiles().size(); i++) { - assertThat(desCp.indexFiles().get(i).name(), equalTo(commitPoint.indexFiles().get(i).name())); - assertThat(desCp.indexFiles().get(i).physicalName(), equalTo(commitPoint.indexFiles().get(i).physicalName())); - assertThat(desCp.indexFiles().get(i).length(), equalTo(commitPoint.indexFiles().get(i).length())); - assertThat(desCp.indexFiles().get(i).checksum(), equalTo(commitPoint.indexFiles().get(i).checksum())); - } - - assertThat(desCp.translogFiles().size(), equalTo(commitPoint.translogFiles().size())); - for (int i = 0; i < desCp.indexFiles().size(); i++) { - assertThat(desCp.translogFiles().get(i).name(), equalTo(commitPoint.translogFiles().get(i).name())); - assertThat(desCp.translogFiles().get(i).physicalName(), equalTo(commitPoint.translogFiles().get(i).physicalName())); - assertThat(desCp.translogFiles().get(i).length(), equalTo(commitPoint.translogFiles().get(i).length())); - assertThat(desCp.translogFiles().get(i).checksum(), nullValue()); - } - } -}