Skip to content

proposal: Auto commit mode for applying log iterator #957

Closed
@killme2008

Description

The current log Iterator is used to apply a batch of raft logs to state machine. After the batch is applied to state machine and returns from StateMachine#onApply method, these logs are considered committed.

And while iterating the logs in iterator:

  1. We can call Iteartor#setErrorAndRollback to rollback applied logs and halt the state machine.
  2. Or call Iteartor#commit to commit the logs already applied.

If we want to commit every log while applying, we should call commit method everytime:

while(it.hasNext()) {
    ByteBuffer data = it.getData();
    // apply data to state machine
   ......
   it.commit();
   it.next();
}

I think we can add an auto-commit mode to simplify the code:

// Enable auto-commit mode
it.setAutoCommit(true);

while(it.hasNext()) {
    ByteBuffer data = it.getData();
    // apply data to state machine
   ......
   it.next();
}

After enabling auto-commit mode by it.setAutoCommit(true), the iterator will call commit automatically when calling hasNext() that returns true.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions