-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSANDRA-20245: Fix problems and race conditions with topology fetching #3842
Open
ifesdjeen
wants to merge
5
commits into
apache:cep-15-accord
Choose a base branch
from
ifesdjeen:CASSANDRA-20245
base: cep-15-accord
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85c4d9e
Fix problems and race conditions with topology fetching
ifesdjeen 6be92d2
Address Ariel's and David's comments
ifesdjeen 5bdd1fb
Address David's comments
ifesdjeen 9543c60
Document a change to configuration service
ifesdjeen ce7ba8e
Minor: fix CASTest
ifesdjeen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[submodule "modules/accord"] | ||
path = modules/accord | ||
url = https://github.com/apache/cassandra-accord.git | ||
branch = trunk | ||
url = https://github.com/ifesdjeen/cassandra-accord.git | ||
branch = CASSANDRA-20245 |
Submodule accord
updated
1 files
+3 −3 | accord-core/src/main/java/accord/impl/AbstractConfigurationService.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,7 @@ public EpochDiskState truncateTopologyUntil(long epoch, EpochDiskState diskState | |
} | ||
} | ||
|
||
//TODO (required): should not be public | ||
public final ChangeListener listener = new MetadataChangeListener(); | ||
private class MetadataChangeListener implements ChangeListener | ||
{ | ||
|
@@ -267,8 +268,6 @@ public synchronized void start() | |
Map<Node.Id, Long> removedNodes = mapping.removedNodes(); | ||
for (Map.Entry<Node.Id, Long> e : removedNodes.entrySet()) | ||
onNodeRemoved(e.getValue(), currentTopology(), e.getKey()); | ||
|
||
ClusterMetadataService.instance().log().addListener(listener); | ||
} | ||
|
||
@Override | ||
|
@@ -416,13 +415,36 @@ void maybeReportMetadata(ClusterMetadata metadata) | |
long epoch = metadata.epoch.getEpoch(); | ||
synchronized (epochs) | ||
{ | ||
if (epochs.maxEpoch() == 0) | ||
// On first boot, we have 2 options: | ||
// | ||
// - we can start listening to TCM _before_ we replay topologies | ||
// - we can start listening to TCM _after_ we replay topologies | ||
// | ||
// If we start listening to TCM _before_ we replay topologies from other nodes, | ||
// we may end up in a situation where TCM reports metadata that would create an | ||
// `epoch - 1` epoch state that is not associated with any topologies, and | ||
// therefore should not be listened upon. | ||
// | ||
// If we start listening to TCM _after_ we replay topologies, we may end up in a | ||
// situation where TCM reports metadata that is 1 (or more) epochs _ahead_ of the | ||
// last known epoch. Previous implementations were using TCM peer catch up, which | ||
// could have resulted in gaps. | ||
// | ||
// Current protocol solves both problems by _first_ replaying topologies form peers, | ||
// then subscribing to TCM _and_, if there are still any gaps, filling them again. | ||
// However, it still has a slight chance of creating an `epoch - 1` epoch state | ||
// not associated with any topologies, which under "right" circumstances could | ||
// have been waited upon with `epochReady`. This check precludes creation of this | ||
// epoch: by the time this code can be called, remote topology replay is already | ||
// done, so TCM listener will only report epochs that are _at least_ min epoch. | ||
if (epochs.maxEpoch() == 0 || epochs.minEpoch() == metadata.epoch.getEpoch()) | ||
{ | ||
getOrCreateEpochState(epoch); // touch epoch state so subsequent calls see it | ||
reportMetadata(metadata); | ||
return; | ||
} | ||
} | ||
|
||
getOrCreateEpochState(epoch - 1).acknowledged().addCallback(() -> reportMetadata(metadata)); | ||
} | ||
|
||
|
@@ -433,16 +455,25 @@ protected void fetchTopologyInternal(long epoch) | |
Stage.ACCORD_MIGRATION.execute(() -> { | ||
if (ClusterMetadata.current().epoch.getEpoch() < epoch) | ||
ClusterMetadataService.instance().fetchLogFromCMS(Epoch.create(epoch)); | ||
|
||
// In most cases, after fetching log from CMS, we will be caught up to the required epoch. | ||
// This TCM will also notify Accord via reportMetadata, so we do not need to fetch topologies. | ||
// If metadata has reported has skipped one or more epochs, and is _ahead_ of the requested epoch, | ||
// we need to fetch topologies from peers to fill in the gap. | ||
ClusterMetadata metadata = ClusterMetadata.current(); | ||
if (metadata.epoch.getEpoch() == epoch) | ||
return; | ||
|
||
try | ||
{ | ||
Set<InetAddressAndPort> peers = new HashSet<>(ClusterMetadata.current().directory.allJoinedEndpoints()); | ||
Set<InetAddressAndPort> peers = new HashSet<>(metadata.directory.allJoinedEndpoints()); | ||
peers.remove(FBUtilities.getBroadcastAddressAndPort()); | ||
if (peers.isEmpty()) | ||
return; | ||
Topology topology; | ||
while ((topology = FetchTopology.fetch(SharedContext.Global.instance, peers, epoch).get()) == null) | ||
{ | ||
} | ||
|
||
// TODO (required): fetch only _missing_ topologies. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one additional optimization... now that we waiting for TCM, TCM might have already informed us... we could check if accord has this epoch and avoid this. Maybe add a TODO for that? |
||
Topology topology = FetchTopology.fetch(SharedContext.Global.instance, peers, epoch).get(); | ||
Invariants.require(topology.epoch() == epoch); | ||
reportTopology(topology); | ||
} | ||
catch (InterruptedException e) | ||
|
@@ -461,6 +492,13 @@ protected void fetchTopologyInternal(long epoch) | |
}); | ||
} | ||
|
||
@Override | ||
public void reportTopology(Topology topology, boolean isLoad, boolean startSync) | ||
{ | ||
Invariants.require(topology.epoch() <= ClusterMetadata.current().epoch.getEpoch()); | ||
super.reportTopology(topology, isLoad, startSync); | ||
} | ||
|
||
@Override | ||
protected void localSyncComplete(Topology topology, boolean startSync) | ||
{ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RetrySpec
has the following constructorNothing stops us from adding
or a
create
method... I think i did things this way mostly because of repair but nothing is wrong withRetrySpec fetchRetry = RetrySpec.create(100);
IMOI am 100% fine with this class (assuming the ref test is fixed), I am also fine with creating new methods in
RetrySpec
to get the same behavior