-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[PIP-82] [pulsar-broker] incorporate review feedback #10201
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
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 |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ private Producer<byte[]> createProducer() throws PulsarClientException { | |
| final int sendTimeoutSecs = 10; | ||
|
|
||
| return pulsarClient.newProducer() | ||
| .topic(pulsarService.getConfig().getResourceUsageTransportPublishTopicName()) | ||
| .topic(RESOURCE_USAGE_TOPIC_NAME) | ||
| .batchingMaxPublishDelay(publishDelayMilliSecs, TimeUnit.MILLISECONDS) | ||
| .sendTimeout(sendTimeoutSecs, TimeUnit.SECONDS) | ||
| .blockIfQueueFull(false) | ||
|
|
@@ -113,11 +113,12 @@ public void close() throws Exception { | |
|
|
||
| private class ResourceUsageReader implements ReaderListener<byte[]>, AutoCloseable { | ||
| private final ResourceUsageInfo recdUsageInfo = new ResourceUsageInfo(); | ||
|
|
||
| private final Reader<byte[]> consumer; | ||
|
|
||
| public ResourceUsageReader() throws PulsarClientException { | ||
| consumer = pulsarClient.newReader() | ||
| .topic(pulsarService.getConfig().getResourceUsageTransportPublishTopicName()) | ||
| .topic(RESOURCE_USAGE_TOPIC_NAME) | ||
| .startMessageId(MessageId.latest) | ||
| .readerListener(this) | ||
| .create(); | ||
|
|
@@ -130,9 +131,19 @@ public void close() throws Exception { | |
|
|
||
| @Override | ||
| public void received(Reader<byte[]> reader, Message<byte[]> msg) { | ||
| try { | ||
| recdUsageInfo.parseFrom(Unpooled.wrappedBuffer(msg.getData()), msg.getData().length); | ||
| long publishTime = msg.getPublishTime(); | ||
| long currentTime = System.currentTimeMillis(); | ||
| long timeDelta = currentTime - publishTime; | ||
|
|
||
| recdUsageInfo.parseFrom(Unpooled.wrappedBuffer(msg.getData()), msg.getData().length); | ||
| if (timeDelta > TimeUnit.SECONDS.toMillis( | ||
| 2 * pulsarService.getConfig().getResourceUsageTransportPublishIntervalInSecs())) { | ||
| LOG.error("Stale resource usage msg from broker {} publish time {} current time{}", | ||
| recdUsageInfo.getBroker(), publishTime, currentTime); | ||
| staleMessageCount++; | ||
| return; | ||
| } | ||
| try { | ||
| recdUsageInfo.getUsageMapsList().forEach(ru -> { | ||
| ResourceUsageConsumer owner = consumerMap.get(ru.getOwner()); | ||
| if (owner != null) { | ||
|
|
@@ -150,6 +161,7 @@ public void received(Reader<byte[]> reader, Message<byte[]> msg) { | |
| } | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(ResourceUsageTransportManager.class); | ||
| public static final String RESOURCE_USAGE_TOPIC_NAME = "non-persistent://pulsar/system/resource-usage"; | ||
| private final PulsarService pulsarService; | ||
| private final PulsarClient pulsarClient; | ||
| private final ResourceUsageWriterTask pTask; | ||
|
|
@@ -159,9 +171,11 @@ public void received(Reader<byte[]> reader, Message<byte[]> msg) { | |
| private final Map<String, ResourceUsageConsumer> | ||
| consumerMap = new ConcurrentHashMap<String, ResourceUsageConsumer>(); | ||
|
|
||
| private long staleMessageCount = 0; | ||
|
Contributor
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. This variable doesn't seem to be used anywhere?
Contributor
Author
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. I added the variable with the intention of adding a unit test for it. But could not figure out a easy way to do so. I am open to ideas if you have suggestions on how I can add one. Else, I will remove this variable. |
||
|
|
||
| private void createTenantAndNamespace() throws PulsarServerException, PulsarAdminException { | ||
| // Create a public tenant and default namespace | ||
| TopicName topicName = TopicName.get(pulsarService.getConfig().getResourceUsageTransportPublishTopicName()); | ||
| TopicName topicName = TopicName.get(RESOURCE_USAGE_TOPIC_NAME); | ||
|
|
||
| PulsarAdmin admin = pulsarService.getAdminClient(); | ||
| ServiceConfiguration config = pulsarService.getConfig(); | ||
|
|
@@ -172,12 +186,26 @@ private void createTenantAndNamespace() throws PulsarServerException, PulsarAdmi | |
|
|
||
| List<String> tenantList = admin.tenants().getTenants(); | ||
| if (!tenantList.contains(tenant)) { | ||
| admin.tenants().createTenant(tenant, | ||
| new TenantInfo(Sets.newHashSet(config.getSuperUserRoles()), Sets.newHashSet(cluster))); | ||
| try { | ||
|
Contributor
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. To add try/catch is a good solution. |
||
| admin.tenants().createTenant(tenant, | ||
| new TenantInfo(Sets.newHashSet(config.getSuperUserRoles()), Sets.newHashSet(cluster))); | ||
| } catch (PulsarAdminException ex1) { | ||
| if (!(ex1 instanceof PulsarAdminException.ConflictException)) { | ||
| LOG.error("Unexpected exception {} when creating tenant {}", ex1, tenant); | ||
| throw ex1; | ||
| } | ||
| } | ||
| } | ||
| List<String> nsList = admin.namespaces().getNamespaces(tenant); | ||
| if (!nsList.contains(namespace)) { | ||
| admin.namespaces().createNamespace(namespace); | ||
| try { | ||
| admin.namespaces().createNamespace(namespace); | ||
| } catch (PulsarAdminException ex1) { | ||
| if (!(ex1 instanceof PulsarAdminException.ConflictException)) { | ||
| LOG.error("Unexpected exception {} when creating namespace {}", ex1, namespace); | ||
| throw ex1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
What was the rationale for making this not configurable?
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.
@jerrypeng while reviewing the previous PR(#10008), @codelipenghui and @315157973 gave feedback that the topic name is internal implementation detail that the user doesn't need to be exposed to. I did not have a strong reason to go the other way, so made this change. We can always make it configurable in the future, if we find that there is a use-case for it.