Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6426: [Backport 0.26] Use always new appender r=Zelldon a=Zelldon ## Description Backports #6392 > Previous if the leader close transition took to long and the broker become leader again it could happen that the new appender was used by the old log storage appender. This is now prevented by not using a supplier. It requests the appender once on leader transition and always uses the same object. > > @deepthidevaki you mentioned that you want to prevent stuff based on different term. I think it is already something checked in the ZeebePartition regarding that. If this is not enough for your we can create a follow up issue. <!-- Please explain the changes you made here. --> There were some changes necessary since here the journal changes are not available, which means we need to use the ZeebeIndexMapping etc. ## Related issues <!-- Which issues are closed by this PR or are related --> closes #6346 ## Definition of Done _Not all items need to be done depending on the issue and the pull request._ Code changes: * [ ] The changes are backwards compatibility with previous versions * [ ] If it fixes a bug then PRs are created to [backport](https://github.com/zeebe-io/zeebe/compare/stable/0.24...develop?expand=1&template=backport_template.md&title=[Backport%200.24]) the fix to the last two minor versions. You can trigger a backport by assigning labels (e.g. `backport stable/0.25`) to the PR, in case that fails you need to create backports manually. Testing: * [ ] There are unit/integration tests that verify all acceptance criterias of the issue * [ ] New tests are written to ensure backwards compatibility with further versions * [ ] The behavior is tested manually * [ ] The change has been verified by a QA run * [ ] The impact of the changes is verified by a benchmark Documentation: * [ ] The documentation is updated (e.g. BPMN reference, configuration, examples, get-started guides, etc.) * [ ] New content is added to the [release announcement](https://drive.google.com/drive/u/0/folders/1DTIeswnEEq-NggJ25rm2BsDjcCQpDape) Co-authored-by: Christopher Zell <zelldon91@googlemail.com>
- Loading branch information
Showing
11 changed files
with
135 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...main/java/io/zeebe/broker/system/partitions/impl/steps/AtomixLogStoragePartitionStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.0. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.0. | ||
*/ | ||
package io.zeebe.broker.system.partitions.impl.steps; | ||
|
||
import io.zeebe.broker.system.partitions.PartitionContext; | ||
import io.zeebe.broker.system.partitions.PartitionStep; | ||
import io.zeebe.logstreams.storage.atomix.AtomixLogStorage; | ||
import io.zeebe.util.sched.future.ActorFuture; | ||
import io.zeebe.util.sched.future.CompletableActorFuture; | ||
|
||
public class AtomixLogStoragePartitionStep implements PartitionStep { | ||
private static final String WRONG_TERM_ERROR_MSG = | ||
"Expected that current term '%d' is same as raft term '%d', but was not. Failing installation of 'AtomixLogStoragePartitionStep' on partition %d."; | ||
|
||
@Override | ||
public ActorFuture<Void> open(final long currentTerm, final PartitionContext context) { | ||
final var openFuture = new CompletableActorFuture<Void>(); | ||
final var server = context.getRaftPartition().getServer(); | ||
|
||
final var appenderOptional = server.getAppender(); | ||
appenderOptional.ifPresentOrElse( | ||
logAppender -> { | ||
final var raftTerm = server.getTerm(); | ||
|
||
if (raftTerm != currentTerm) { | ||
openFuture.completeExceptionally( | ||
new IllegalStateException( | ||
String.format( | ||
WRONG_TERM_ERROR_MSG, currentTerm, raftTerm, context.getPartitionId()))); | ||
} else { | ||
context.setAtomixLogStorage( | ||
AtomixLogStorage.ofPartition( | ||
context.getZeebeIndexMapping(), server::openReader, logAppender)); | ||
openFuture.complete(null); | ||
} | ||
}, | ||
() -> | ||
openFuture.completeExceptionally( | ||
new IllegalStateException("Not leader of partition " + context.getPartitionId()))); | ||
|
||
return openFuture; | ||
} | ||
|
||
@Override | ||
public ActorFuture<Void> close(final PartitionContext context) { | ||
context.setAtomixLogStorage(null); | ||
return CompletableActorFuture.completed(null); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "AtomixLogStorage"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.