Hello developers,
It's nice to meet you, I'm glad to hear that you are building a middleware
of open source project about Raft protocol,  I've forked the code into my
code repository, I really appreciate your contribution to the open source
community.

There are some questions made me confused

1. I created a class and extend to BaseStateMachine, and override the
method applyTransaction , below is the method code:

@Override
public CompletableFuture<Message> applyTransaction(TransactionContext trx) {
    final LogEntryProto entry = trx.getLogEntry();
    ByteString data = entry.getSmLogEntry().getData();
    final long index = entry.getIndex();
    byte[] bytes = data.toByteArray();
    String log = new String(bytes,Charset.forName("UTF-8"));
    System.out.println("applyTransaction::"+index);
    if(replicationTask.executeTransaction(log)){
        updateLastAppliedTermIndex(entry.getTerm(), index);
        return CompletableFuture.completedFuture(Message.valueOf("ok"));
    }
    return CompletableFuture.completedFuture(Message.valueOf("failed"));
}

My transaction is used to create or update a record into Mysql db, so the
entry log can be seen as a SQL bin log, so my question is, how to guarantee
my database record won't be duplicated when the machine is restarted and
then the snapshot replay.

2. how to physically delete the history logs when all machines SQL log is
executed successfully.

Looking forward to your reply.

Best regards,
Alan

Reply via email to