Search in sources :

Example 1 with LogNotFoundException

use of io.dingodb.raft.error.LogNotFoundException in project dingo by dingodb.

the class NodeImpl method readCommittedUserLog.

@Override
public UserLog readCommittedUserLog(final long index) {
    if (index <= 0) {
        throw new LogIndexOutOfBoundsException("Request index is invalid: " + index);
    }
    final long savedLastAppliedIndex = this.fsmCaller.getLastAppliedIndex();
    if (index > savedLastAppliedIndex) {
        throw new LogIndexOutOfBoundsException("Request index " + index + " is greater than lastAppliedIndex: " + savedLastAppliedIndex);
    }
    long curIndex = index;
    LogEntry entry = this.logManager.getEntry(curIndex);
    if (entry == null) {
        throw new LogNotFoundException("User log is deleted at index: " + index);
    }
    do {
        if (entry.getType() == EnumOutter.EntryType.ENTRY_TYPE_DATA) {
            return new UserLog(curIndex, entry.getData());
        } else {
            curIndex++;
        }
        if (curIndex > savedLastAppliedIndex) {
            throw new IllegalStateException("No user log between index:" + index + " and last_applied_index:" + savedLastAppliedIndex);
        }
        entry = this.logManager.getEntry(curIndex);
    } while (entry != null);
    throw new LogNotFoundException("User log is deleted at index: " + curIndex);
}
Also used : UserLog(io.dingodb.raft.entity.UserLog) LogIndexOutOfBoundsException(io.dingodb.raft.error.LogIndexOutOfBoundsException) LogNotFoundException(io.dingodb.raft.error.LogNotFoundException) LogEntry(io.dingodb.raft.entity.LogEntry)

Aggregations

LogEntry (io.dingodb.raft.entity.LogEntry)1 UserLog (io.dingodb.raft.entity.UserLog)1 LogIndexOutOfBoundsException (io.dingodb.raft.error.LogIndexOutOfBoundsException)1 LogNotFoundException (io.dingodb.raft.error.LogNotFoundException)1