Skip to content
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

[Broker] Fix NPEs and thread safety issue in PersistentReplicator #9763

Merged
merged 1 commit into from
Mar 1, 2021

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Mar 1, 2021

Fixes #9762

Motivation

NPEs occurs in PersistentReplicator, see #9762 for details.

Modifications

  • Make cursor field volatile since the field is updated asynchronously in another thread. -
  • Remove the unnecessary synchronization on openCursorAsync method since it's not needed.
  • Add null checks before accessing the cursor field since statistics might be updated before the cursor is available. Call comes from
    public synchronized void updateStats(
    ConcurrentOpenHashMap<String, ConcurrentOpenHashMap<String, ConcurrentOpenHashMap<String, Topic>>>
    topicsMap) {
    StatsOutputStream topicStatsStream = new StatsOutputStream(tempTopicStatsBuf);
    try {
    tempMetricsCollection.clear();
    bundleStats.clear();
    brokerOperabilityMetrics.reset();
    // Json begin
    topicStatsStream.startObject();
    topicsMap.forEach((namespaceName, bundles) -> {
    if (bundles.isEmpty()) {
    return;
    }
    try {
    topicStatsStream.startObject(namespaceName);
    nsStats.reset();
    bundles.forEach((bundle, topics) -> {
    NamespaceBundleStats currentBundleStats = bundleStats.computeIfAbsent(bundle,
    k -> new NamespaceBundleStats());
    currentBundleStats.reset();
    currentBundleStats.topics = topics.size();
    topicStatsStream.startObject(NamespaceBundle.getBundleRange(bundle));
    tempNonPersistentTopics.clear();
    // start persistent topic
    topicStatsStream.startObject("persistent");
    topics.forEach((name, topic) -> {
    if (topic instanceof PersistentTopic) {
    try {
    topic.updateRates(nsStats, currentBundleStats, topicStatsStream,
    clusterReplicationMetrics, namespaceName, exposePublisherStats);

@lhotari
Copy link
Member Author

lhotari commented Mar 1, 2021

/pulsarbot run-failure-checks

@merlimat merlimat added this to the 2.8.0 milestone Mar 1, 2021
@merlimat merlimat added type/bug The PR fixed a bug or issue reported a bug release/2.7.2 labels Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Broker] NullPointerExceptions in PersistentReplicator
4 participants