Search in sources :

Example 1 with LogEntryCorruptedException

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

the class V2Encoder method writeToByteArray.

private void writeToByteArray(final PBLogEntry pbLogEntry, final byte[] array, final int offset, final int len) {
    final CodedOutputStream output = CodedOutputStream.newInstance(array, offset, len);
    try {
        pbLogEntry.writeTo(output);
        output.checkNoSpaceLeft();
    } catch (final IOException e) {
        throw new LogEntryCorruptedException("Serializing PBLogEntry to a byte array threw an IOException (should never happen).", e);
    }
}
Also used : CodedOutputStream(com.google.protobuf.CodedOutputStream) IOException(java.io.IOException) LogEntryCorruptedException(io.dingodb.raft.error.LogEntryCorruptedException)

Example 2 with LogEntryCorruptedException

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

the class LogManagerImpl method getTermFromLogStorage.

private long getTermFromLogStorage(final long index) {
    final LogEntry entry = this.logStorage.getEntry(index);
    if (entry != null) {
        if (this.raftOptions.isEnableLogEntryChecksum() && entry.isCorrupted()) {
            // Report error to node and throw exception.
            final String msg = String.format("The log entry is corrupted, index=%d, term=%d, expectedChecksum=%d, realChecksum=%d", entry.getId().getIndex(), entry.getId().getTerm(), entry.getChecksum(), entry.checksum());
            reportError(RaftError.EIO.getNumber(), msg);
            throw new LogEntryCorruptedException(msg);
        }
        return entry.getId().getTerm();
    }
    return 0;
}
Also used : LogEntry(io.dingodb.raft.entity.LogEntry) LogEntryCorruptedException(io.dingodb.raft.error.LogEntryCorruptedException)

Example 3 with LogEntryCorruptedException

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

the class LogManagerImpl method getEntry.

@Override
public LogEntry getEntry(final long index) {
    this.readLock.lock();
    try {
        if (index > this.lastLogIndex || index < this.firstLogIndex) {
            return null;
        }
        final LogEntry entry = getEntryFromMemory(index);
        if (entry != null) {
            return entry;
        }
    } finally {
        this.readLock.unlock();
    }
    final LogEntry entry = this.logStorage.getEntry(index);
    if (entry == null) {
        reportError(RaftError.EIO.getNumber(), "Corrupted entry at index=%d, not found", index);
    }
    // Validate checksum
    if (entry != null && this.raftOptions.isEnableLogEntryChecksum() && entry.isCorrupted()) {
        String msg = String.format("Corrupted entry at index=%d, term=%d, expectedChecksum=%d, realChecksum=%d", index, entry.getId().getTerm(), entry.getChecksum(), entry.checksum());
        // Report error to node and throw exception.
        reportError(RaftError.EIO.getNumber(), msg);
        throw new LogEntryCorruptedException(msg);
    }
    return entry;
}
Also used : LogEntry(io.dingodb.raft.entity.LogEntry) LogEntryCorruptedException(io.dingodb.raft.error.LogEntryCorruptedException)

Aggregations

LogEntryCorruptedException (io.dingodb.raft.error.LogEntryCorruptedException)3 LogEntry (io.dingodb.raft.entity.LogEntry)2 CodedOutputStream (com.google.protobuf.CodedOutputStream)1 IOException (java.io.IOException)1