2010-02-08 15:30:06 +02:00
|
|
|
/*
|
|
|
|
* Licensed to Elastic Search and Shay Banon under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. Elastic Search 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.gateway;
|
|
|
|
|
2010-03-31 17:23:16 +03:00
|
|
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
2010-09-07 00:41:30 +03:00
|
|
|
import org.elasticsearch.index.CloseableIndexComponent;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit;
|
|
|
|
import org.elasticsearch.index.shard.IndexShardComponent;
|
|
|
|
import org.elasticsearch.index.translog.Translog;
|
|
|
|
|
|
|
|
/**
|
2010-04-08 19:28:41 +03:00
|
|
|
* @author kimchy (shay.banon)
|
2010-02-08 15:30:06 +02:00
|
|
|
*/
|
2010-03-31 22:45:46 +03:00
|
|
|
public interface IndexShardGateway extends IndexShardComponent, CloseableIndexComponent {
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2010-06-21 22:40:12 +03:00
|
|
|
String type();
|
|
|
|
|
2010-08-17 10:03:19 +03:00
|
|
|
/**
|
|
|
|
* The last / on going recovery status.
|
|
|
|
*/
|
2010-08-17 08:17:29 +03:00
|
|
|
RecoveryStatus recoveryStatus();
|
|
|
|
|
2010-08-17 10:03:19 +03:00
|
|
|
/**
|
|
|
|
* The last snapshot status performed. Can be <tt>null</tt>.
|
|
|
|
*/
|
|
|
|
SnapshotStatus lastSnapshotStatus();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current snapshot status being performed. Can be <tt>null</tt> indicating that no snapshot
|
|
|
|
* is being executed currently.
|
|
|
|
*/
|
|
|
|
SnapshotStatus currentSnapshotStatus();
|
|
|
|
|
2010-02-08 15:30:06 +02:00
|
|
|
/**
|
|
|
|
* Recovers the state of the shard from the gateway.
|
|
|
|
*/
|
2011-07-22 06:56:34 +03:00
|
|
|
void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Snapshots the given shard into the gateway.
|
|
|
|
*/
|
2010-06-21 22:40:12 +03:00
|
|
|
SnapshotStatus snapshot(Snapshot snapshot) throws IndexShardGatewaySnapshotFailedException;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2011-03-11 15:20:16 +02:00
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if snapshot is even required on this gateway (i.e. mainly handles recovery).
|
|
|
|
*/
|
|
|
|
boolean requiresSnapshot();
|
|
|
|
|
2010-02-08 15:30:06 +02:00
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if this gateway requires scheduling management for snapshot
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
boolean requiresSnapshotScheduling();
|
|
|
|
|
2010-11-06 23:27:46 +02:00
|
|
|
SnapshotLock obtainSnapshotLock() throws Exception;
|
|
|
|
|
|
|
|
public static interface SnapshotLock {
|
|
|
|
void release();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final SnapshotLock NO_SNAPSHOT_LOCK = new SnapshotLock() {
|
|
|
|
@Override public void release() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-31 17:23:16 +03:00
|
|
|
public static class Snapshot {
|
|
|
|
private final SnapshotIndexCommit indexCommit;
|
|
|
|
private final Translog.Snapshot translogSnapshot;
|
|
|
|
|
|
|
|
private final long lastIndexVersion;
|
|
|
|
private final long lastTranslogId;
|
2010-07-06 00:12:40 +03:00
|
|
|
private final long lastTranslogLength;
|
2010-08-23 14:48:49 +03:00
|
|
|
private final int lastTotalTranslogOperations;
|
2010-03-31 17:23:16 +03:00
|
|
|
|
2010-09-18 21:33:38 +02:00
|
|
|
public Snapshot(SnapshotIndexCommit indexCommit, Translog.Snapshot translogSnapshot, long lastIndexVersion, long lastTranslogId, long lastTranslogLength, int lastTotalTranslogOperations) {
|
2010-03-31 17:23:16 +03:00
|
|
|
this.indexCommit = indexCommit;
|
|
|
|
this.translogSnapshot = translogSnapshot;
|
|
|
|
this.lastIndexVersion = lastIndexVersion;
|
|
|
|
this.lastTranslogId = lastTranslogId;
|
2010-07-06 00:12:40 +03:00
|
|
|
this.lastTranslogLength = lastTranslogLength;
|
2010-08-23 14:48:49 +03:00
|
|
|
this.lastTotalTranslogOperations = lastTotalTranslogOperations;
|
2010-03-31 17:23:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the index has changed from the latest snapshot.
|
|
|
|
*/
|
|
|
|
public boolean indexChanged() {
|
|
|
|
return lastIndexVersion != indexCommit.getVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that a new transaction log has been created. Note check this <b>before</b> you
|
|
|
|
* check {@link #sameTranslogNewOperations()}.
|
|
|
|
*/
|
|
|
|
public boolean newTranslogCreated() {
|
|
|
|
return translogSnapshot.translogId() != lastTranslogId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that the same translog exists, but new operations have been appended to it. Throws
|
|
|
|
* {@link ElasticSearchIllegalStateException} if {@link #newTranslogCreated()} is <tt>true</tt>, so
|
|
|
|
* always check that first.
|
|
|
|
*/
|
|
|
|
public boolean sameTranslogNewOperations() {
|
|
|
|
if (newTranslogCreated()) {
|
|
|
|
throw new ElasticSearchIllegalStateException("Should not be called when there is a new translog");
|
|
|
|
}
|
2010-07-06 00:12:40 +03:00
|
|
|
return translogSnapshot.length() > lastTranslogLength;
|
2010-03-31 17:23:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public SnapshotIndexCommit indexCommit() {
|
|
|
|
return indexCommit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Translog.Snapshot translogSnapshot() {
|
|
|
|
return translogSnapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long lastIndexVersion() {
|
|
|
|
return lastIndexVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long lastTranslogId() {
|
|
|
|
return lastTranslogId;
|
|
|
|
}
|
|
|
|
|
2010-07-08 20:51:37 +03:00
|
|
|
public long lastTranslogLength() {
|
2010-07-06 00:12:40 +03:00
|
|
|
return lastTranslogLength;
|
2010-03-31 17:23:16 +03:00
|
|
|
}
|
2010-08-23 14:48:49 +03:00
|
|
|
|
|
|
|
public int lastTotalTranslogOperations() {
|
|
|
|
return this.lastTotalTranslogOperations;
|
|
|
|
}
|
2010-03-31 17:23:16 +03:00
|
|
|
}
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|