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

[fix][broker] Fix UnsupportedOperationException when update topic properties. #20261

Merged
merged 3 commits into from
May 9, 2023
Merged

[fix][broker] Fix UnsupportedOperationException when update topic properties. #20261

merged 3 commits into from
May 9, 2023

Conversation

liangyepianzhou
Copy link
Contributor

Motivation

The branch master has an NPE check in the BrokerService::checkOwnershipAndCreatePersistentTopic, but it will lead to a UnsupportedOperationException. The returned map might be an unmodifiable Collections.emptyMap(). The call chain involved is as follows:

  1. BrokerService::checkOwnershipAndCreatePersistentTopic
  2. BrokerService::fetchTopicPropertiesAsync
  3. ManagedLedgerFactory::getManagedLedgerPropertiesAsync
  4. MetaStoreImpl::getManagedLedgerPropertiesAsync
  5. operationFailed
public void operationFailed(MetaStoreException e) {
    if (e instanceof MetadataNotFoundException) {
        result.complete(Collections.emptyMap());
    } else {
        result.completeExceptionally(e);
    }
}

Modifications

Make the getManagedLedgerPropertiesAsync return a modifiable map.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

…roperties.

## Motivation
The branch master has an NPE check in the `BrokerService::checkOwnershipAndCreatePersistentTopic`, but it will lead to a `UnsupportedOperationException`. The returned map might be an unmodifiable `Collections.emptyMap()`. The call chain involved is as follows:

1. `BrokerService::checkOwnershipAndCreatePersistentTopic`
2. `BrokerService::fetchTopicPropertiesAsync`
3. `ManagedLedgerFactory::getManagedLedgerPropertiesAsync`
4. `MetaStoreImpl::getManagedLedgerPropertiesAsync`
5. `operationFailed`

```java
public void operationFailed(MetaStoreException e) {
    if (e instanceof MetadataNotFoundException) {
        result.complete(Collections.emptyMap());
    } else {
        result.completeExceptionally(e);
    }
}
```
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label May 8, 2023
@Technoboy- Technoboy- merged commit 0b4c29d into apache:master May 9, 2023
@michaeljmarshall
Copy link
Member

@liangyepianzhou - would you mind sharing the stack trace for the UnsupportedOperationException? Thanks!

@poorbarcode
Copy link
Contributor

poorbarcode commented May 10, 2023

@liangyepianzhou

Why remove these labels?

截屏2023-05-11 01 07 47

@liangyepianzhou
Copy link
Contributor Author

@liangyepianzhou - would you mind sharing the stack trace for the UnsupportedOperationException? Thanks!

@michaeljmarshall Sure, of course.

Message: java.util.concurrent.CompletionException: java.lang.UnsupportedOperationException

Stacktrace:

org.apache.bookkeeper.mledger.ManagedLedgerException$MetaStoreException: java.util.concurrent.CompletionException: java.lang.UnsupportedOperationException
Caused by: java.util.concurrent.CompletionException: java.lang.UnsupportedOperationException
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:722)
	at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:482)
	at org.apache.bookkeeper.common.util.OrderedExecutor$TimedRunnable.run(OrderedExecutor.java:201)
	at org.apache.bookkeeper.common.util.SingleThreadSafeScheduledExecutorService$SafeRunnable.run(SingleThreadSafeScheduledExecutorService.java:46)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.UnsupportedOperationException
	at java.base/java.util.AbstractMap.put(AbstractMap.java:209)
	at java.base/java.util.AbstractMap.putAll(AbstractMap.java:281)
	at org.apache.pulsar.broker.admin.impl.PersistentTopicsBase$1.updatePropertiesComplete(PersistentTopicsBase.java:701)
	at org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl$26.operationComplete(ManagedLedgerImpl.java:4177)
	at org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl$26.operationComplete(ManagedLedgerImpl.java:4173)
	at org.apache.bookkeeper.mledger.impl.MetaStoreImpl.lambda$asyncUpdateLedgerIds$7(MetaStoreImpl.java:203)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	... 10 more


	at org.apache.pulsar.client.admin.PulsarAdminException.wrap(PulsarAdminException.java:252)
	at org.apache.pulsar.client.admin.internal.BaseResource.sync(BaseResource.java:352)
	at org.apache.pulsar.client.admin.internal.TopicsImpl.updateProperties(TopicsImpl.java:419)
	at org.apache.pulsar.broker.admin.TopicPoliciesTest.updatePropertiesForAutoCreatedTopicTest(TopicPoliciesTest.java:142)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
	at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
	at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
	at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969)
	at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
	at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:829)
	at org.testng.TestRunner.run(TestRunner.java:602)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
	at org.testng.SuiteRunner.run(SuiteRunner.java:330)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
	at org.testng.TestNG.runSuites(TestNG.java:1099)
	at org.testng.TestNG.run(TestNG.java:1067)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
	Suppressed: org.apache.pulsar.client.admin.PulsarAdminException$ServerSideErrorException: 
 --- An unexpected error occurred in the server ---

@liangyepianzhou
Copy link
Contributor Author

liangyepianzhou commented May 11, 2023

Why remove these labels?

@poorbarcode
Because this PR didn’t been cherry-picked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants