153 lines
5.1 KiB
Java
Raw Normal View History

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;
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
*/
public interface IndexShardGateway extends IndexShardComponent, CloseableIndexComponent {
2010-02-08 15:30:06 +02:00
String type();
/**
* The last / on going recovery status.
*/
RecoveryStatus recoveryStatus();
/**
* 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.
*/
void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus) throws IndexShardGatewayRecoveryException;
2010-02-08 15:30:06 +02:00
/**
* Snapshots the given shard into the gateway.
*/
SnapshotStatus snapshot(Snapshot snapshot) throws IndexShardGatewaySnapshotFailedException;
2010-02-08 15:30:06 +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();
SnapshotLock obtainSnapshotLock() throws Exception;
public static interface SnapshotLock {
void release();
}
public static final SnapshotLock NO_SNAPSHOT_LOCK = new SnapshotLock() {
@Override public void release() {
}
};
public static class Snapshot {
private final SnapshotIndexCommit indexCommit;
private final Translog.Snapshot translogSnapshot;
private final long lastIndexVersion;
private final long lastTranslogId;
private final long lastTranslogLength;
private final int lastTotalTranslogOperations;
public Snapshot(SnapshotIndexCommit indexCommit, Translog.Snapshot translogSnapshot, long lastIndexVersion, long lastTranslogId, long lastTranslogLength, int lastTotalTranslogOperations) {
this.indexCommit = indexCommit;
this.translogSnapshot = translogSnapshot;
this.lastIndexVersion = lastIndexVersion;
this.lastTranslogId = lastTranslogId;
this.lastTranslogLength = lastTranslogLength;
this.lastTotalTranslogOperations = lastTotalTranslogOperations;
}
/**
* 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");
}
return translogSnapshot.length() > lastTranslogLength;
}
public SnapshotIndexCommit indexCommit() {
return indexCommit;
}
public Translog.Snapshot translogSnapshot() {
return translogSnapshot;
}
public long lastIndexVersion() {
return lastIndexVersion;
}
public long lastTranslogId() {
return lastTranslogId;
}
public long lastTranslogLength() {
return lastTranslogLength;
}
public int lastTotalTranslogOperations() {
return this.lastTotalTranslogOperations;
}
}
2010-02-08 15:30:06 +02:00
}