Skip to content

Commit 82de719

Browse files
authored
MINOR; Improve error message for the storage format command (#19210)
Minor improvement on the error output for the storage format command. Suggests changes for a valid storage format command. Reviewers: Justine Olshan <[email protected]>
1 parent a524fc6 commit 82de719

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,22 @@ private short effectiveKRaftFeatureLevel(Optional<Short> configuredKRaftVersionL
347347
if (configuredKRaftVersionLevel.isPresent()) {
348348
if (configuredKRaftVersionLevel.get() == 0) {
349349
if (hasDynamicQuorum()) {
350-
throw new FormatterException("Cannot set kraft.version to " +
351-
configuredKRaftVersionLevel.get() + " if KIP-853 configuration is present. " +
352-
"Try removing the --feature flag for kraft.version.");
350+
throw new FormatterException(
351+
"Cannot set kraft.version to " +
352+
configuredKRaftVersionLevel.get() +
353+
" if one of the flags --standalone, --initial-controllers, or --no-initial-controllers is used. " +
354+
"For dynamic controllers support, try removing the --feature flag for kraft.version."
355+
);
353356
}
354357
} else {
355358
if (!hasDynamicQuorum()) {
356-
throw new FormatterException("Cannot set kraft.version to " +
357-
configuredKRaftVersionLevel.get() + " unless KIP-853 configuration is present. " +
358-
"Try removing the --feature flag for kraft.version.");
359+
throw new FormatterException(
360+
"Cannot set kraft.version to " +
361+
configuredKRaftVersionLevel.get() +
362+
" unless one of the flags --standalone, --initial-controllers, or --no-initial-controllers is used. " +
363+
"For dynamic controllers support, try using one of --standalone, --initial-controllers, or " +
364+
"--no-initial-controllers."
365+
);
359366
}
360367
}
361368
return configuredKRaftVersionLevel.get();

metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java

+24-16
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,12 @@ public void testFormatWithInitialVotersFailsWithOlderKraftVersion() throws Excep
419419
formatter1.formatter.setInitialControllers(DynamicVoters.
420420
parse("1@localhost:8020:4znU-ou9Taa06bmEJxsjnw"));
421421
assertTrue(formatter1.formatter.hasDynamicQuorum());
422-
assertEquals("Cannot set kraft.version to 0 if KIP-853 configuration is present. " +
423-
"Try removing the --feature flag for kraft.version.",
424-
assertThrows(FormatterException.class,
425-
() -> formatter1.formatter.run()).getMessage());
422+
assertEquals(
423+
"Cannot set kraft.version to 0 if one of the flags --standalone, --initial-controllers, or " +
424+
"--no-initial-controllers is used. For dynamic controllers support, try removing the " +
425+
"--feature flag for kraft.version.",
426+
assertThrows(FormatterException.class, () -> formatter1.formatter.run()).getMessage()
427+
);
426428
}
427429
}
428430

@@ -433,10 +435,12 @@ public void testFormatWithoutInitialVotersFailsWithNewerKraftVersion() throws Ex
433435
formatter1.formatter.setFeatureLevel("kraft.version", (short) 1);
434436
formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
435437
assertFalse(formatter1.formatter.hasDynamicQuorum());
436-
assertEquals("Cannot set kraft.version to 1 unless KIP-853 configuration is present. " +
437-
"Try removing the --feature flag for kraft.version.",
438-
assertThrows(FormatterException.class,
439-
() -> formatter1.formatter.run()).getMessage());
438+
assertEquals(
439+
"Cannot set kraft.version to 1 unless one of the flags --standalone, --initial-controllers, or " +
440+
"--no-initial-controllers is used. For dynamic controllers support, try using one of " +
441+
"--standalone, --initial-controllers, or --no-initial-controllers.",
442+
assertThrows(FormatterException.class, () -> formatter1.formatter.run()).getMessage()
443+
);
440444
}
441445
}
442446

@@ -526,10 +530,12 @@ public void testFormatWithoutNoInitialControllersFailsWithNewerKraftVersion() th
526530
formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
527531
formatter1.formatter.setNoInitialControllersFlag(false);
528532
assertFalse(formatter1.formatter.hasDynamicQuorum());
529-
assertEquals("Cannot set kraft.version to 1 unless KIP-853 configuration is present. " +
530-
"Try removing the --feature flag for kraft.version.",
531-
assertThrows(FormatterException.class,
532-
formatter1.formatter::run).getMessage());
533+
assertEquals(
534+
"Cannot set kraft.version to 1 unless one of the flags --standalone, --initial-controllers, or " +
535+
"--no-initial-controllers is used. For dynamic controllers support, try using one of " +
536+
"--standalone, --initial-controllers, or --no-initial-controllers.",
537+
assertThrows(FormatterException.class, formatter1.formatter::run).getMessage()
538+
);
533539
}
534540
}
535541

@@ -541,10 +547,12 @@ public void testFormatWithNoInitialControllersFailsWithOlderKraftVersion() throw
541547
formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
542548
formatter1.formatter.setNoInitialControllersFlag(true);
543549
assertTrue(formatter1.formatter.hasDynamicQuorum());
544-
assertEquals("Cannot set kraft.version to 0 if KIP-853 configuration is present. " +
545-
"Try removing the --feature flag for kraft.version.",
546-
assertThrows(FormatterException.class,
547-
formatter1.formatter::run).getMessage());
550+
assertEquals(
551+
"Cannot set kraft.version to 0 if one of the flags --standalone, --initial-controllers, or " +
552+
"--no-initial-controllers is used. For dynamic controllers support, try removing the " +
553+
"--feature flag for kraft.version.",
554+
assertThrows(FormatterException.class, formatter1.formatter::run).getMessage()
555+
);
548556
}
549557
}
550558
}

0 commit comments

Comments
 (0)