Skip to content

Commit aa6d273

Browse files
committed
Adjust default values for replicas and partitions
Requests to create topics will fail if you supply assignments and partitions/replicas together. If you don't supply a value for partitions/replicas at all, default values of 1 will be used which also leads to topic creation failures. Here, the default values for the two settings are changed to -1 so that topic creations do not fail due to conflicting settings. Furthermore, this has the benefit of using the default values set inside the Kafka cluster. Related: - tulios/kafkajs#1305
1 parent 4966e07 commit aa6d273

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/clients/admin/admin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,9 @@ export class Admin extends Base<AdminOptions> {
444444
}
445445

446446
#createTopics (options: CreateTopicsOptions, callback: CallbackWithPromise<CreatedTopic[]>): void {
447-
const numPartitions = options.partitions ?? 1
448-
const replicationFactor = options.replicas ?? 1
447+
// -1 is required if manual assignments are used. If no manual assignments are used, -1 will default to broker settings.
448+
const numPartitions = options.partitions ?? -1
449+
const replicationFactor = options.replicas ?? -1
449450
const assignments: CreateTopicsRequestTopicAssignment[] = []
450451
const configs = options.configs ?? []
451452

test/clients/admin/admin.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,6 @@ test('createTopics using assignments', async t => {
439439
// Create a topic with a single partition - leader will be automatically assigned
440440
const created = await admin.createTopics({
441441
topics: [topicName],
442-
partitions: -1,
443-
replicas: -1,
444442
assignments: brokerIds.map((brokerId, i) => ({ partition: i, brokers: [brokerId] }))
445443
})
446444

0 commit comments

Comments
 (0)