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);
}
}
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;
}
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;
}
Aggregations