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

PIP-187: Add API to analyze a subscription backlog and provide a accurate value #16545

Merged
merged 31 commits into from
Jul 30, 2022

Conversation

eolivelli
Copy link
Contributor

@eolivelli eolivelli commented Jul 12, 2022

PIP link: #16597
Also fixes #7623

Documentation

The new command is automatically documented for the REST API and for pulsar-admin

  • doc-not-needed

@codelipenghui
Copy link
Contributor

The related PR support the precise backlog #14958

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

I wonder if analise is a correct word in english, analyze should be the right verb

@eolivelli eolivelli force-pushed the impl/real-backlog branch from 8318f6f to ff182d0 Compare July 13, 2022 12:17
Copy link
Contributor Author

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoloboschi thanks for your review.
I have addressed your comments and also added one test about partitioned topics

@lhotari lhotari changed the title Issue 7623: Add API to analise a subscription backlog and provide a accurate value Issue 7623: Add API to analyse a subscription backlog and provide a accurate value Jul 13, 2022
Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, a couple of comments to address

@eolivelli eolivelli changed the title Issue 7623: Add API to analyse a subscription backlog and provide a accurate value PIP-187: Add API to analyse a subscription backlog and provide a accurate value Jul 14, 2022
@eolivelli eolivelli force-pushed the impl/real-backlog branch from ff182d0 to d15e6b8 Compare July 14, 2022 07:39
@eolivelli eolivelli requested review from nicoloboschi and dlg99 July 14, 2022 07:40
Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment on lines 79 to 80
} finally {
entry.release();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could be finally block of outer try (on line 74)

@eolivelli eolivelli changed the title PIP-187: Add API to analyse a subscription backlog and provide a accurate value PIP-187: Add API to analyze a subscription backlog and provide a accurate value Jul 15, 2022
@eolivelli eolivelli force-pushed the impl/real-backlog branch from d15e6b8 to 9cb51d1 Compare July 15, 2022 12:11
@eolivelli eolivelli force-pushed the impl/real-backlog branch from ba722e6 to 4c41c1b Compare July 18, 2022 07:52
@eolivelli eolivelli force-pushed the impl/real-backlog branch from 5ba6e19 to bb35022 Compare July 26, 2022 09:57
subscriptionBacklogScanMaxTimeMs=120000

# Maximum number of entries to be read within a Analise backlog operation
subscriptionBacklogScanMaxEntries=10000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can support these 2 options in the http endpoint, instead of support ns/topic polices.

Comment on lines 1838 to 1861
@Test(timeOut = 20000)
void testScanSingleEntry() throws Exception {
testScan(10,1);
}

@Test(timeOut = 30000)
void testScanBatchesWithSomeRemainder() throws Exception {
testScan(10,3);
}

@Test(timeOut = 30000)
void testScanBatches() throws Exception {
testScan(10,5);
}

@Test(timeOut = 30000)
void testScanBatchWholeLedger() throws Exception {
testScan(10,1000);
}

@Test(timeOut = 1000)
void testScanBatchEmptyLedger() throws Exception {
testScan(0,10);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add a data provider instead of separate methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.
I usually prefer this form while developing tests, because it is easier to run single combination of parameters and the method name explains the meaning of the test.

I have updated the patch

Comment on lines 20 to 37
/**
* 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.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated license header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I don't know how it happened. removed

@@ -1569,6 +1590,63 @@ private void internalDeleteSubscriptionForNonPartitionedTopic(AsyncResponse asyn
});
}

private void internalAnalyzeSubscriptionBacklogForNonPartitionedTopic(AsyncResponse asyncResponse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to return CompletableFuture here to avoid passing the AsyncResponse to the internal of implement, it will help us to understand the returned type without looking at the implementation details

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, but this whole class is coded this way.
I am not sure it is worth to change the code style only for one method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have changed most of the admin implements with future returned types.

Comment on lines 2474 to 2479
if (!topicName.isPartitioned() && getPartitionedTopicMetadata(topicName,
authoritative, false).partitions > 0) {
throw new RestException(Status.METHOD_NOT_ALLOWED,
"Analyze backlog on a partitioned topic is not allowed, "
+ "please try do it on specific topic partition");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check the topic is a partitioned topic or not first? If it's a partitioned topic, the ownership checking is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other methods check if the topic is partitioned in this same place.
if the broker is not the owner we will be redirected to another broker and we won't reach this point.

I notice that getPartitionedTopicMetadata is sync, I have reworked this part to make it fully async

class OpScan implements ReadEntriesCallback {
private final ManagedCursorImpl cursor;
private final ManagedLedgerImpl ledger;
private final PositionImpl startPosition;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks we can remove this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, removed

@eolivelli eolivelli force-pushed the impl/real-backlog branch from fa14b9b to 67873e0 Compare July 29, 2022 08:21
Copy link
Contributor Author

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codelipenghui I have addressed your comments and posted some answers.

thanks

class OpScan implements ReadEntriesCallback {
private final ManagedCursorImpl cursor;
private final ManagedLedgerImpl ledger;
private final PositionImpl startPosition;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, removed

Comment on lines 1838 to 1861
@Test(timeOut = 20000)
void testScanSingleEntry() throws Exception {
testScan(10,1);
}

@Test(timeOut = 30000)
void testScanBatchesWithSomeRemainder() throws Exception {
testScan(10,3);
}

@Test(timeOut = 30000)
void testScanBatches() throws Exception {
testScan(10,5);
}

@Test(timeOut = 30000)
void testScanBatchWholeLedger() throws Exception {
testScan(10,1000);
}

@Test(timeOut = 1000)
void testScanBatchEmptyLedger() throws Exception {
testScan(0,10);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.
I usually prefer this form while developing tests, because it is easier to run single combination of parameters and the method name explains the meaning of the test.

I have updated the patch

Comment on lines 20 to 37
/**
* 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.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I don't know how it happened. removed

@@ -1569,6 +1590,63 @@ private void internalDeleteSubscriptionForNonPartitionedTopic(AsyncResponse asyn
});
}

private void internalAnalyzeSubscriptionBacklogForNonPartitionedTopic(AsyncResponse asyncResponse,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, but this whole class is coded this way.
I am not sure it is worth to change the code style only for one method.

Comment on lines 2474 to 2479
if (!topicName.isPartitioned() && getPartitionedTopicMetadata(topicName,
authoritative, false).partitions > 0) {
throw new RestException(Status.METHOD_NOT_ALLOWED,
"Analyze backlog on a partitioned topic is not allowed, "
+ "please try do it on specific topic partition");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other methods check if the topic is partitioned in this same place.
if the broker is not the owner we will be redirected to another broker and we won't reach this point.

I notice that getPartitionedTopicMetadata is sync, I have reworked this part to make it fully async

@eolivelli
Copy link
Contributor Author

@Technoboy- I have updated ManagedCursorImpl.
I won't change the API implementation at the moment.
We can follow up

@Technoboy- Technoboy- merged commit 1af9695 into apache:master Jul 30, 2022
Gleiphir2769 pushed a commit to Gleiphir2769/pulsar that referenced this pull request Aug 4, 2022
@eolivelli eolivelli deleted the impl/real-backlog branch September 1, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker area/tool doc-not-needed Your PR changes do not impact docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a more accurate message backlog value
6 participants