Skip to content

Commit ed1b731

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 ed1b731

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/clients/admin/admin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ 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+
const numPartitions = options.partitions ?? -1
448+
const replicationFactor = options.replicas ?? -1
449449
const assignments: CreateTopicsRequestTopicAssignment[] = []
450450
const configs = options.configs ?? []
451451

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)