Skip to content

Commit

Permalink
address review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SzyWilliam committed May 29, 2024
1 parent 205f3c8 commit 9c8b7b8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ private void setCurrentConf(RaftConfigurationImpl currentConf) {
}
}

synchronized void addConfiguration(RaftConfiguration conf, long commitIndex) {
synchronized void addConfiguration(RaftConfiguration conf) {
final long logIndex = conf.getLogEntryIndex();
final RaftConfiguration found = configurations.get(logIndex);
if (found != null && logIndex <= commitIndex) {
if (found != null) {
Preconditions.assertTrue(found.equals(conf));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,7 @@ CompletableFuture<Message> applyLogToStateMachine(ReferenceCountedObject<LogEntr
void notifyTruncatedLogEntry(LogEntryProto logEntry) {
if (logEntry.hasStateMachineLogEntry()) {
getTransactionManager().remove(TermIndex.valueOf(logEntry));
getState().truncate(logEntry.getIndex());

final ClientInvocationId invocationId = ClientInvocationId.valueOf(logEntry.getStateMachineLogEntry());
final CacheEntry cacheEntry = getRetryCache().getIfPresent(invocationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ void setRaftConf(LogEntryProto entry) {
}

void setRaftConf(RaftConfiguration conf) {
final long lastCommittedIndex = server.getState().log.isInitialized() ?
server.getRaftLog().getLastCommittedIndex() : RaftLog.INVALID_LOG_INDEX;
configurationManager.addConfiguration(conf, lastCommittedIndex);
configurationManager.addConfiguration(conf);
server.getServerRpc().addRaftPeers(conf.getAllPeers());
final Collection<RaftPeer> listeners = conf.getAllPeers(RaftPeerRole.LISTENER);
if (!listeners.isEmpty()) {
Expand All @@ -389,6 +387,10 @@ void setRaftConf(RaftConfiguration conf) {
LOG.trace("{}: {}", getMemberId(), configurationManager);
}

void truncate(long logIndex) {
configurationManager.removeConfigurations(logIndex);
}

void updateConfiguration(List<LogEntryProto> entries) {
if (entries != null && !entries.isEmpty()) {
configurationManager.removeConfigurations(entries.get(0).getIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private InstallSnapshotReplyProto installSnapshotImpl(InstallSnapshotRequestProt
if (request.hasLastRaftConfigurationLogEntryProto()) {
// Set the configuration included in the snapshot
final LogEntryProto proto = request.getLastRaftConfigurationLogEntryProto();
state.truncate(proto.getIndex());
if (!state.getRaftConf().equals(LogProtoUtils.toRaftConfiguration(proto))) {
LOG.info("{}: set new configuration {} from snapshot", getMemberId(), proto);
state.setRaftConf(proto);
Expand Down

0 comments on commit 9c8b7b8

Please sign in to comment.