Java Code Examples for org.apache.ratis.proto.RaftProtos.LogEntryProto#hasMetadataEntry()

The following examples show how to use org.apache.ratis.proto.RaftProtos.LogEntryProto#hasMetadataEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RaftLog.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
/**
 * Validate the term and index of entry w.r.t RaftLog
 */
protected void validateLogEntry(LogEntryProto entry) {
  if (entry.hasMetadataEntry()) {
    return;
  }
  long latestSnapshotIndex = getSnapshotIndex();
  TermIndex lastTermIndex = getLastEntryTermIndex();
  if (lastTermIndex != null) {
    long lastIndex = lastTermIndex.getIndex() > latestSnapshotIndex ?
        lastTermIndex.getIndex() : latestSnapshotIndex;
    Preconditions.assertTrue(entry.getTerm() >= lastTermIndex.getTerm(),
        "Entry term less than RaftLog's last term: %d, entry: %s", lastTermIndex.getTerm(), entry);
    Preconditions.assertTrue(entry.getIndex() == lastIndex + 1,
        "Difference between entry index and RaftLog's last index %d (or snapshot index %d) " +
            "is greater than 1, entry: %s",
        lastTermIndex.getIndex(), latestSnapshotIndex, entry);
  } else {
    Preconditions.assertTrue(entry.getIndex() == latestSnapshotIndex + 1,
        "Difference between entry index and RaftLog's latest snapshot index %d is greater than 1 " +
            "and in between log entries are not present, entry: %s",
        latestSnapshotIndex, entry);
  }
}
 
Example 2
Source File: RaftTestUtil.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
static List<LogEntryProto> getStateMachineLogEntries(RaftLog log) {
  final List<LogEntryProto> entries = new ArrayList<>();
  for (LogEntryProto e : getLogEntryProtos(log)) {
    final String s = ServerProtoUtils.toString(e);
    if (e.hasStateMachineLogEntry()) {
      LOG.info(s + ", " + e.getStateMachineLogEntry().toString().trim().replace("\n", ", "));
      entries.add(e);
    } else if (e.hasConfigurationEntry()) {
      LOG.info("Found {}, ignoring it.", s);
    } else if (e.hasMetadataEntry()) {
      LOG.info("Found {}, ignoring it.", s);
    } else {
      throw new AssertionError("Unexpected LogEntryBodyCase " + e.getLogEntryBodyCase() + " at " + s);
    }
  }
  return entries;
}
 
Example 3
Source File: RaftTestUtil.java    From ratis with Apache License 2.0 6 votes vote down vote up
static void assertLogEntries(RaftLog log, long expectedTerm, SimpleMessage... expectedMessages) {
  final List<LogEntryProto> entries = new ArrayList<>(expectedMessages.length);
  for(LogEntryProto e : getLogEntryProtos(log)) {
    final String s = ServerProtoUtils.toString(e);
    if (e.hasStateMachineLogEntry()) {
      LOG.info(s + ", " + e.getStateMachineLogEntry().toString().trim().replace("\n", ", "));
      entries.add(e);
    } else if (e.hasConfigurationEntry()) {
      LOG.info("Found {}, ignoring it.", s);
    } else if (e.hasMetadataEntry()) {
      LOG.info("Found {}, ignoring it.", s);
    } else {
      throw new AssertionError("Unexpected LogEntryBodyCase " + e.getLogEntryBodyCase() + " at " + s);
    }
  }

  try {
    assertLogEntries(entries, expectedTerm, expectedMessages);
  } catch(Throwable t) {
    throw new AssertionError("entries: " + entries, t);
  }
}
 
Example 4
Source File: ParseRatisLog.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private void processLogEntry(LogEntryProto proto) {
  if (proto.hasConfigurationEntry()) {
    numConfEntries++;
  } else if (proto.hasMetadataEntry()) {
    numMetadataEntries++;
  } else if (proto.hasStateMachineLogEntry()) {
    numStateMachineEntries++;
  } else {
    System.out.println("Found invalid entry" + proto.toString());
    numInvalidEntries++;
  }

  String str = ServerProtoUtils.toLogEntryString(proto, smLogToString);
  System.out.println(str);
}
 
Example 5
Source File: RaftLogMetrics.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public void onLogEntryCommit(LogEntryProto proto) {
  if (proto.hasConfigurationEntry()) {
    registry.counter(CONFIG_LOG_ENTRY_COUNT).inc();
  } else if (proto.hasMetadataEntry()) {
    registry.counter(METADATA_LOG_ENTRY_COUNT).inc();
  } else if (proto.hasStateMachineLogEntry()) {
    registry.counter(STATE_MACHINE_LOG_ENTRY_COUNT).inc();
  }
}
 
Example 6
Source File: RaftLog.java    From ratis with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the term and index of entry w.r.t RaftLog
 */
void validateLogEntry(LogEntryProto entry) {
  if (entry.hasMetadataEntry()) {
    return;
  }
  TermIndex lastTermIndex = getLastEntryTermIndex();
  if (lastTermIndex != null) {
    Preconditions.assertTrue(entry.getTerm() >= lastTermIndex.getTerm(),
        "Entry term less than RaftLog's last term: %d, entry: %s", lastTermIndex.getTerm(), entry);
    Preconditions.assertTrue(entry.getIndex() == lastTermIndex.getIndex() + 1,
        "Difference between entry index and RaftLog's last index %d greater than 1, entry: %s", lastTermIndex.getIndex(), entry);
  }
}