Browse Source

Remove AlreadyExpiredException (#24857)

This is a relict from the TTL functionality that has been removed in #21670
Yannick Welsch 8 years ago
parent
commit
b5adb3cce9

+ 1 - 2
core/src/main/java/org/elasticsearch/ElasticsearchException.java

@@ -877,8 +877,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
                 org.elasticsearch.transport.ReceiveTimeoutTransportException::new, 83, UNKNOWN_VERSION_ADDED),
         NODE_DISCONNECTED_EXCEPTION(org.elasticsearch.transport.NodeDisconnectedException.class,
                 org.elasticsearch.transport.NodeDisconnectedException::new, 84, UNKNOWN_VERSION_ADDED),
-        ALREADY_EXPIRED_EXCEPTION(org.elasticsearch.index.AlreadyExpiredException.class,
-                org.elasticsearch.index.AlreadyExpiredException::new, 85, UNKNOWN_VERSION_ADDED),
+        // 85 used to be for AlreadyExpiredException
         AGGREGATION_EXECUTION_EXCEPTION(org.elasticsearch.search.aggregations.AggregationExecutionException.class,
                 org.elasticsearch.search.aggregations.AggregationExecutionException::new, 86, UNKNOWN_VERSION_ADDED),
         // 87 used to be for MergeMappingException

+ 0 - 91
core/src/main/java/org/elasticsearch/index/AlreadyExpiredException.java

@@ -1,91 +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;
-
-import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.index.engine.IgnoreOnRecoveryEngineException;
-
-import java.io.IOException;
-
-public class AlreadyExpiredException extends ElasticsearchException implements IgnoreOnRecoveryEngineException {
-    private String index;
-    private String type;
-    private String id;
-    private final long timestamp;
-    private final long ttl;
-    private final long now;
-
-    public AlreadyExpiredException(String index, String type, String id, long timestamp, long ttl, long now) {
-        super("already expired [" + index + "]/[" + type + "]/[" + id + "] due to expire at [" + (timestamp + ttl) + "] and was processed at [" + now + "]");
-        this.setIndex(index);
-        this.type = type;
-        this.id = id;
-        this.timestamp = timestamp;
-        this.ttl = ttl;
-        this.now = now;
-    }
-
-    public String index() {
-        return index;
-    }
-
-    public String type() {
-        return type;
-    }
-
-    public String id() {
-        return id;
-    }
-
-    public long timestamp() {
-        return timestamp;
-    }
-
-    public long ttl() {
-        return ttl;
-    }
-
-    public long now() {
-        return now;
-    }
-
-    public AlreadyExpiredException(StreamInput in) throws IOException{
-        super(in);
-        index = in.readOptionalString();
-        type = in.readOptionalString();
-        id = in.readOptionalString();
-        timestamp = in.readLong();
-        ttl = in.readLong();
-        now = in.readLong();
-    }
-
-    @Override
-    public void writeTo(StreamOutput out) throws IOException {
-        super.writeTo(out);
-        out.writeOptionalString(index);
-        out.writeOptionalString(type);
-        out.writeOptionalString(id);
-        out.writeLong(timestamp);
-        out.writeLong(ttl);
-        out.writeLong(now);
-    }
-}

+ 0 - 26
core/src/main/java/org/elasticsearch/index/engine/IgnoreOnRecoveryEngineException.java

@@ -1,26 +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.engine;
-
-/**
- * Exceptions implementing this interface will be ignored during recovery.
- */
-public interface IgnoreOnRecoveryEngineException {
-}

+ 33 - 55
core/src/main/java/org/elasticsearch/index/shard/TranslogRecoveryPerformer.java

@@ -24,12 +24,10 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.engine.Engine;
-import org.elasticsearch.index.engine.IgnoreOnRecoveryEngineException;
 import org.elasticsearch.index.mapper.DocumentMapperForType;
 import org.elasticsearch.index.mapper.MapperException;
 import org.elasticsearch.index.mapper.MapperService;
 import org.elasticsearch.index.mapper.Mapping;
-import org.elasticsearch.index.mapper.Uid;
 import org.elasticsearch.index.translog.Translog;
 import org.elasticsearch.rest.RestStatus;
 
@@ -149,59 +147,39 @@ public class TranslogRecoveryPerformer {
      *                            is encountered.
      */
     private void performRecoveryOperation(Engine engine, Translog.Operation operation, boolean allowMappingUpdates, Engine.Operation.Origin origin) throws IOException {
-
-        try {
-            switch (operation.opType()) {
-                case INDEX:
-                    Translog.Index index = (Translog.Index) operation;
-                    // we set canHaveDuplicates to true all the time such that we de-optimze the translog case and ensure that all
-                    // autoGeneratedID docs that are coming from the primary are updated correctly.
-                    Engine.Index engineIndex = IndexShard.prepareIndex(docMapper(index.type()),
-                        source(shardId.getIndexName(), index.type(), index.id(), index.source(), XContentFactory.xContentType(index.source()))
-                            .routing(index.routing()).parent(index.parent()), index.seqNo(), index.primaryTerm(),
-                            index.version(), index.versionType().versionTypeForReplicationAndRecovery(), origin, index.getAutoGeneratedIdTimestamp(), true);
-                    maybeAddMappingUpdate(engineIndex.type(), engineIndex.parsedDoc().dynamicMappingsUpdate(), engineIndex.id(), allowMappingUpdates);
-                    logger.trace("[translog] recover [index] op [({}, {})] of [{}][{}]", index.seqNo(), index.primaryTerm(), index.type(), index.id());
-                    index(engine, engineIndex);
-                    break;
-                case DELETE:
-                    Translog.Delete delete = (Translog.Delete) operation;
-                    logger.trace("[translog] recover [delete] op [({}, {})] of [{}][{}]", delete.seqNo(), delete.primaryTerm(), delete.type(), delete.id());
-                    final Engine.Delete engineDelete = new Engine.Delete(delete.type(), delete.id(), delete.uid(), delete.seqNo(),
-                            delete.primaryTerm(), delete.version(), delete.versionType().versionTypeForReplicationAndRecovery(),
-                            origin, System.nanoTime());
-                    delete(engine, engineDelete);
-                    break;
-                case NO_OP:
-                    final Translog.NoOp noOp = (Translog.NoOp) operation;
-                    final long seqNo = noOp.seqNo();
-                    final long primaryTerm = noOp.primaryTerm();
-                    final String reason = noOp.reason();
-                    logger.trace("[translog] recover [no_op] op [({}, {})] of [{}]", seqNo, primaryTerm, reason);
-                    final Engine.NoOp engineNoOp =
-                        new Engine.NoOp(seqNo, primaryTerm, origin, System.nanoTime(), reason);
-                    noOp(engine, engineNoOp);
-                    break;
-                default:
-                    throw new IllegalStateException("No operation defined for [" + operation + "]");
-            }
-        } catch (ElasticsearchException e) {
-            boolean hasIgnoreOnRecoveryException = false;
-            ElasticsearchException current = e;
-            while (true) {
-                if (current instanceof IgnoreOnRecoveryEngineException) {
-                    hasIgnoreOnRecoveryException = true;
-                    break;
-                }
-                if (current.getCause() instanceof ElasticsearchException) {
-                    current = (ElasticsearchException) current.getCause();
-                } else {
-                    break;
-                }
-            }
-            if (!hasIgnoreOnRecoveryException) {
-                throw e;
-            }
+        switch (operation.opType()) {
+            case INDEX:
+                Translog.Index index = (Translog.Index) operation;
+                // we set canHaveDuplicates to true all the time such that we de-optimze the translog case and ensure that all
+                // autoGeneratedID docs that are coming from the primary are updated correctly.
+                Engine.Index engineIndex = IndexShard.prepareIndex(docMapper(index.type()),
+                    source(shardId.getIndexName(), index.type(), index.id(), index.source(), XContentFactory.xContentType(index.source()))
+                        .routing(index.routing()).parent(index.parent()), index.seqNo(), index.primaryTerm(),
+                    index.version(), index.versionType().versionTypeForReplicationAndRecovery(), origin, index.getAutoGeneratedIdTimestamp(), true);
+                maybeAddMappingUpdate(engineIndex.type(), engineIndex.parsedDoc().dynamicMappingsUpdate(), engineIndex.id(), allowMappingUpdates);
+                logger.trace("[translog] recover [index] op [({}, {})] of [{}][{}]", index.seqNo(), index.primaryTerm(), index.type(), index.id());
+                index(engine, engineIndex);
+                break;
+            case DELETE:
+                Translog.Delete delete = (Translog.Delete) operation;
+                logger.trace("[translog] recover [delete] op [({}, {})] of [{}][{}]", delete.seqNo(), delete.primaryTerm(), delete.type(), delete.id());
+                final Engine.Delete engineDelete = new Engine.Delete(delete.type(), delete.id(), delete.uid(), delete.seqNo(),
+                    delete.primaryTerm(), delete.version(), delete.versionType().versionTypeForReplicationAndRecovery(),
+                    origin, System.nanoTime());
+                delete(engine, engineDelete);
+                break;
+            case NO_OP:
+                final Translog.NoOp noOp = (Translog.NoOp) operation;
+                final long seqNo = noOp.seqNo();
+                final long primaryTerm = noOp.primaryTerm();
+                final String reason = noOp.reason();
+                logger.trace("[translog] recover [no_op] op [({}, {})] of [{}]", seqNo, primaryTerm, reason);
+                final Engine.NoOp engineNoOp =
+                    new Engine.NoOp(seqNo, primaryTerm, origin, System.nanoTime(), reason);
+                noOp(engine, engineNoOp);
+                break;
+            default:
+                throw new IllegalStateException("No operation defined for [" + operation + "]");
         }
         operationProcessed();
     }

+ 1 - 20
core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java

@@ -56,7 +56,6 @@ import org.elasticsearch.common.util.set.Sets;
 import org.elasticsearch.common.xcontent.XContentLocation;
 import org.elasticsearch.discovery.DiscoverySettings;
 import org.elasticsearch.env.ShardLockObtainFailedException;
-import org.elasticsearch.index.AlreadyExpiredException;
 import org.elasticsearch.index.Index;
 import org.elasticsearch.index.engine.RecoveryEngineException;
 import org.elasticsearch.index.query.QueryShardException;
@@ -296,24 +295,6 @@ public class ExceptionSerializationTests extends ESTestCase {
         assertTrue(ex.getCause() instanceof NullPointerException);
     }
 
-    public void testAlreadyExpiredException() throws IOException {
-        AlreadyExpiredException alreadyExpiredException = serialize(new AlreadyExpiredException("index", "type", "id", 1, 2, 3));
-        assertEquals("index", alreadyExpiredException.getIndex().getName());
-        assertEquals("type", alreadyExpiredException.type());
-        assertEquals("id", alreadyExpiredException.id());
-        assertEquals(2, alreadyExpiredException.ttl());
-        assertEquals(1, alreadyExpiredException.timestamp());
-        assertEquals(3, alreadyExpiredException.now());
-
-        alreadyExpiredException = serialize(new AlreadyExpiredException(null, null, null, -1, -2, -3));
-        assertNull(alreadyExpiredException.getIndex());
-        assertNull(alreadyExpiredException.type());
-        assertNull(alreadyExpiredException.id());
-        assertEquals(-2, alreadyExpiredException.ttl());
-        assertEquals(-1, alreadyExpiredException.timestamp());
-        assertEquals(-3, alreadyExpiredException.now());
-    }
-
     public void testActionNotFoundTransportException() throws IOException {
         ActionNotFoundTransportException ex = serialize(new ActionNotFoundTransportException("AACCCTION"));
         assertEquals("AACCCTION", ex.action());
@@ -780,7 +761,7 @@ public class ExceptionSerializationTests extends ESTestCase {
         ids.put(82, org.elasticsearch.repositories.RepositoryException.class);
         ids.put(83, org.elasticsearch.transport.ReceiveTimeoutTransportException.class);
         ids.put(84, org.elasticsearch.transport.NodeDisconnectedException.class);
-        ids.put(85, org.elasticsearch.index.AlreadyExpiredException.class);
+        ids.put(85, null);
         ids.put(86, org.elasticsearch.search.aggregations.AggregationExecutionException.class);
         ids.put(88, org.elasticsearch.indices.InvalidIndexTemplateException.class);
         ids.put(90, org.elasticsearch.index.engine.RefreshFailedEngineException.class);