-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[feat][broker]PIP-180 Shadow Topic - Part V - Support shadow topic creation. #17711
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.bookkeeper.mledger.impl; | ||
|
||
import java.util.function.Supplier; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.bookkeeper.client.BookKeeper; | ||
import org.apache.bookkeeper.common.util.OrderedScheduler; | ||
import org.apache.bookkeeper.mledger.ManagedLedgerConfig; | ||
import org.apache.pulsar.common.naming.TopicName; | ||
|
||
/** | ||
* Working in progress until <a href="https://github.com/apache/pulsar/issues/16153">PIP-180</a> is finished. | ||
* Currently, it works nothing different with ManagedLedgerImpl. | ||
*/ | ||
@Slf4j | ||
public class ShadowManagedLedgerImpl extends ManagedLedgerImpl { | ||
|
||
private final TopicName shadowSource; | ||
private final String sourceMLName; | ||
|
||
public ShadowManagedLedgerImpl(ManagedLedgerFactoryImpl factory, BookKeeper bookKeeper, | ||
MetaStore store, ManagedLedgerConfig config, | ||
OrderedScheduler scheduledExecutor, | ||
String name, final Supplier<Boolean> mlOwnershipChecker) { | ||
super(factory, bookKeeper, store, config, scheduledExecutor, name, mlOwnershipChecker); | ||
this.shadowSource = TopicName.get(config.getShadowSource()); | ||
this.sourceMLName = shadowSource.getPersistenceNamingEncoding(); | ||
} | ||
|
||
@Override | ||
synchronized void initialize(ManagedLedgerInitializeLedgerCallback callback, Object ctx) { | ||
// TODO: ShadowManagedLedger has different initialize process from normal ManagedLedger, | ||
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. we should avoid TODOs and try to implement full PR or make it extendable PR. 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.
@rdhabalia This would make PIP-180 a very huge PR and very hard to review. The next PR is coming up and have implemented this. |
||
// which is complicated and will be implemented in the next PRs. | ||
super.initialize(callback, ctx); | ||
} | ||
|
||
public TopicName getShadowSource() { | ||
return shadowSource; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.pulsar.broker.service.persistent; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.bookkeeper.mledger.impl.ShadowManagedLedgerImpl; | ||
import org.apache.pulsar.broker.service.BrokerTestBase; | ||
import org.apache.pulsar.common.naming.TopicName; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
@Slf4j | ||
public class ShadowTopicTest extends BrokerTestBase { | ||
|
||
@BeforeClass(alwaysRun = true) | ||
@Override | ||
protected void setup() throws Exception { | ||
baseSetup(); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
@Override | ||
protected void cleanup() throws Exception { | ||
internalCleanup(); | ||
} | ||
|
||
@Test() | ||
public void testNonPartitionedShadowTopicSetup() throws Exception { | ||
String sourceTopic = "persistent://prop/ns-abc/source"; | ||
String shadowTopic = "persistent://prop/ns-abc/shadow"; | ||
//1. test shadow topic setting in topic creation. | ||
admin.topics().createNonPartitionedTopic(sourceTopic); | ||
admin.topics().createShadowTopic(shadowTopic, sourceTopic); | ||
PersistentTopic brokerShadowTopic = | ||
(PersistentTopic) pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get(); | ||
Assert.assertTrue(brokerShadowTopic.getManagedLedger() instanceof ShadowManagedLedgerImpl); | ||
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().get().toString(), sourceTopic); | ||
Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), sourceTopic); | ||
|
||
//2. test shadow topic could be properly loaded after unload. | ||
admin.namespaces().unload("prop/ns-abc"); | ||
Assert.assertTrue(pulsar.getBrokerService().getTopicReference(shadowTopic).isEmpty()); | ||
Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), sourceTopic); | ||
brokerShadowTopic = (PersistentTopic) pulsar.getBrokerService().getTopicIfExists(shadowTopic).get().get(); | ||
Assert.assertTrue(brokerShadowTopic.getManagedLedger() instanceof ShadowManagedLedgerImpl); | ||
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().get().toString(), sourceTopic); | ||
} | ||
|
||
@Test() | ||
public void testPartitionedShadowTopicSetup() throws Exception { | ||
String sourceTopic = "persistent://prop/ns-abc/source-p"; | ||
String shadowTopic = "persistent://prop/ns-abc/shadow-p"; | ||
String shadowTopicPartition = TopicName.get(shadowTopic).getPartition(0).toString(); | ||
|
||
//1. test shadow topic setting in topic creation. | ||
admin.topics().createPartitionedTopic(sourceTopic, 2); | ||
admin.topics().createShadowTopic(shadowTopic, sourceTopic); | ||
pulsarClient.newProducer().topic(shadowTopic).create().close();//trigger loading partitions. | ||
PersistentTopic brokerShadowTopic = (PersistentTopic) pulsar.getBrokerService() | ||
.getTopicIfExists(shadowTopicPartition).get().get(); | ||
Assert.assertTrue(brokerShadowTopic.getManagedLedger() instanceof ShadowManagedLedgerImpl); | ||
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().get().toString(), sourceTopic); | ||
Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), sourceTopic); | ||
Jason918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//2. test shadow topic could be properly loaded after unload. | ||
admin.namespaces().unload("prop/ns-abc"); | ||
Assert.assertTrue(pulsar.getBrokerService().getTopicReference(shadowTopic).isEmpty()); | ||
|
||
Assert.assertEquals(admin.topics().getShadowSource(shadowTopic), sourceTopic); | ||
brokerShadowTopic = | ||
(PersistentTopic) pulsar.getBrokerService().getTopicIfExists(shadowTopicPartition).get().get(); | ||
Assert.assertTrue(brokerShadowTopic.getManagedLedger() instanceof ShadowManagedLedgerImpl); | ||
Assert.assertEquals(brokerShadowTopic.getShadowSourceTopic().get().toString(), sourceTopic); | ||
} | ||
|
||
|
||
} |
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.
Uppercase or lowercase? I remember the replicator being lowercase. But I'm not sure which is better.
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.
This would appear in topic property. I think uppercase should cause less conflict.