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

KREST-3009 Add ability to update partition count on a topic #1084

Merged
merged 2 commits into from Nov 30, 2022

Conversation

ehumber
Copy link
Member

@ehumber ehumber commented Nov 22, 2022

Call looks like

curl -X PATCH http://localhost:8082/v3/clusters/3W-2oFuqSYuErBzrRrTKyw/topics/bob  -H "Content-Type: application/json" -d '{"partition_count":"10"}'  | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   688    0   664  100    24   6036    218 --:--:-- --:--:-- --:--:--  6254
{
  "kind": "KafkaTopic",
  "metadata": {
    "self": "http://localhost:8082/v3/clusters/3W-2oFuqSYuErBzrRrTKyw/topics/bob",
    "resource_name": "crn:///kafka=3W-2oFuqSYuErBzrRrTKyw/topic=bob"
  },
  "cluster_id": "3W-2oFuqSYuErBzrRrTKyw",
  "topic_name": "bob",
  "is_internal": false,
  "replication_factor": 1,
  "partitions_count": 10,
  "partitions": {
    "related": "http://localhost:8082/v3/clusters/3W-2oFuqSYuErBzrRrTKyw/topics/bob/partitions"
  },
  "configs": {
    "related": "http://localhost:8082/v3/clusters/3W-2oFuqSYuErBzrRrTKyw/topics/bob/configs"
  },
  "partition_reassignments": {
    "related": "http://localhost:8082/v3/clusters/3W-2oFuqSYuErBzrRrTKyw/topics/bob/partitions/-/reassignment"
  },
  "authorized_operations": []
}

Error messages are shown as returned by kafka

{"error_code":40002,"message":"Topic already has 2 partitions."}%  
{"error_code":40002,"message":"Topic currently has 2 partitions, which is higher than the requested 1."}% 

I don't think we have a PATCH call anywhere else in the code. I think it's right here - we are modifying but not fully replacing an existing topic object's information.

The flip of that could be that it should be a PUT as we are fully and idempotently replacing the whole of the topic's partition_count object, but patch felt more future safe, in case we add other things to the request body in future?

@msn-tldr
Copy link
Member

I don't think we have a PATCH call anywhere else in the code. I think it's right here - we are modifying but not fully replacing an existing topic object's information.

This does make sense.

Copy link
Member

@msn-tldr msn-tldr left a comment

Choose a reason for hiding this comment

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

Minor nits.

api/v3/openapi.yaml Show resolved Hide resolved
@@ -451,6 +454,8 @@ public class TopicManagerImplTest {

@Mock private DeleteTopicsResult deleteTopicsResult;

@Mock CreatePartitionsResult createPartitionsResult;
Copy link
Member

Choose a reason for hiding this comment

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

should this be private?

Copy link
Member

@dimitarndimitrov dimitarndimitrov left a comment

Choose a reason for hiding this comment

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

+1.
I think we should add a couple of integration tests and we'll be golden.

summary: 'Update partition count'
operationId: updatePartitionCountKafkaV3Topic
description: |-
[![Generally Available](https://img.shields.io/badge/Lifecycle%20Stage-Generally%20Available-%2345c6e8)](#section/Versioning/API-Lifecycle-Policy)
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest starting with a non-GA status initially, unless there are clear reasons why this should be immediately considered GA.

Copy link
Member Author

Choose a reason for hiding this comment

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

@axisc Thoughts? I think this is simple enough to go straight to GA, but it's safer to EA first. Do Terraform's requirements have an impact on this decision?

@@ -1112,6 +1135,7 @@ paths:
$ref: '#/components/responses/TooManyRequestsErrorResponse'
'5XX':
$ref: '#/components/responses/ServerErrorResponse'

Copy link
Member

Choose a reason for hiding this comment

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

nit: Redundant blank line.

Comment on lines 2453 to 2454
properties:
partition_count:
type: integer
Copy link
Member

Choose a reason for hiding this comment

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

nit: Specify that this should be a 32-bit int with format: int32.

topicManager
.get()
.getTopic(clusterId, topicName)
.thenApply(topic -> topic.orElseThrow(NotFoundException::new))
Copy link
Member

Choose a reason for hiding this comment

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

Is this practically guaranteed not to throw if the update operation succeeded? It should still stay there to address edge cases like racing delete and update, I just want to understand the failure path.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I did go through that thought process, it's borrowed straight from the get topic code but I thought to leave it matching. But you're right, there's only a really tiny timing window where the topic could be deleted. Overkill though, so happy to take it off.

@ehumber
Copy link
Member Author

ehumber commented Nov 22, 2022

+1. I think we should add a couple of integration tests and we'll be golden.

Yup, totally agree. Half written but fighting back atm. We may still need this PR in in a hurry, so will do it as a follow up.

@ehumber ehumber force-pushed the KREST-increase-partitions branch 5 times, most recently from 6c4eb63 to 8f94202 Compare November 29, 2022 14:54
Squashed commit so I can cherry pick more easily to the cloud release branch
@ehumber ehumber merged commit d9c6b78 into confluentinc:master Nov 30, 2022
@ehumber ehumber deleted the KREST-increase-partitions branch November 30, 2022 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants