Skip to content
代码片段 群组 项目
未验证 提交 ebf8a72d 编辑于 作者: Alok Thatikunta's avatar Alok Thatikunta 提交者: GitHub
浏览文件

KSTORAGE-972: Modify TopicIdPartition.toString() implementation to use ':' and...

KSTORAGE-972: Modify TopicIdPartition.toString() implementation to use ':' and '-' as delimiters (#2553)

* Modify toString method

* Address PR comments

* Fix write fencing file test method

* Address PR comments
上级 f3aa1909
无相关合并请求
......@@ -55,6 +55,6 @@ final public class TopicIdPartition {
@Override
public String toString() {
return topicIdAsBase64() + "-" + topic() + "-" + partition();
return topicIdAsBase64() + ":" + topic() + "-" + partition();
}
}
......@@ -133,7 +133,7 @@ public class RecoveryUtils {
/**
* Converts a list of formatted TopicIdPartition strings to a list of TopicIdPartition.
* Each item in the input list should be a CSV string with the following format:
* '<tiered_partition_topic_ID_base64_encoded>, <tiered_partition_topic_name>, <tiered_partition_name>'.
* '<tiered_partition_topic_ID_base64_encoded>:<tiered_partition_topic_name>-<tiered_partition_name>'.
*
* @param topicIdPartitionsStr the list of formatted TopicIdPartition strings
*
......@@ -142,10 +142,10 @@ public class RecoveryUtils {
public static List<TopicIdPartition> toTopicIdPartitions(List<String> topicIdPartitionsStr) {
final List<TopicIdPartition> partitions = new ArrayList<>();
for (String topicIdPartitionStr : topicIdPartitionsStr) {
final String[] components = topicIdPartitionStr.split(",");
if (components.length != 3) {
final String[] components = topicIdPartitionStr.split(":");
if (components.length != 2) {
throw new IllegalArgumentException(
String.format("'%s' does not contain 3 items.", topicIdPartitionStr));
String.format("'%s' does not contain one colon (':').", topicIdPartitionStr));
}
final UUID topicId;
......@@ -157,20 +157,34 @@ public class RecoveryUtils {
throw new IllegalArgumentException(msg, e);
}
final String topicName = components[1].trim();
final String suffixTopicNameAndPartitionName = topicIdPartitionStr
.substring(components[0].length() + 1).trim();
final int lastSplitIndex = suffixTopicNameAndPartitionName.lastIndexOf('-');
if (lastSplitIndex == -1) {
throw new IllegalArgumentException(
String.format("Item: '%s' does not contain at least one hyphen ('-').", topicIdPartitionStr));
}
final String topicName = suffixTopicNameAndPartitionName.substring(0, lastSplitIndex).trim();
if (topicName.isEmpty()) {
throw new IllegalArgumentException(
String.format(
"Item: '%s' cannot contain an empty topic name: '%s'",
topicIdPartitionStr, components[1]));
"Item: '%s' cannot contain an empty topic name: '%s'", topicIdPartitionStr, topicName));
}
final String partitionStr;
try {
partitionStr = suffixTopicNameAndPartitionName.substring(lastSplitIndex + 1).trim();
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(
String.format("Item: '%s' cannot contain an invalid partition number", topicIdPartitionStr));
}
final int partition;
try {
partition = Integer.parseInt(components[2].trim());
partition = Integer.parseInt(partitionStr);
} catch (NumberFormatException e) {
String msg = String.format(
"Item: '%s' has an illegal partition number: '%s'", topicIdPartitionStr, components[2]);
"Item: '%s' has an illegal partition number: '%s'", topicIdPartitionStr, partitionStr);
throw new IllegalArgumentException(msg, e);
}
if (partition < 0) {
......
......@@ -67,7 +67,7 @@ public class TierPartitionStateFencingTrigger {
" the tool. The format of the file is a newline separated list of information. Each line" +
" is a comma-separated value (CSV) containing information about a single tiered" +
" TopicIdPartition in the following format:" +
" '<tiered_partition_topic_ID_base64_encoded>, <tiered_partition_topic_name>, <tiered_partition_name>'.";
" '<tiered_partition_topic_ID_base64_encoded>:<tiered_partition_topic_name>-<tiered_partition_name>'.";
public static final String OUTPUT_CONFIG = "output.json";
public static final String OUTPUT_CONFIG_DOC = "The path where JSON containing the fenced "
......
......@@ -110,7 +110,7 @@ public class TierMessageFormatterTest {
Instant.ofEpochMilli(record.timestamp()), partitionRestore.toString());
assertEquals(expected, baos.toString());
assertEquals("TierPartitionForceRestore(version=0, "
+ "topicIdPartition=TaPDhhKMSPO9KowOTdyBxA-foo-0, "
+ "topicIdPartition=TaPDhhKMSPO9KowOTdyBxA:foo-0, "
+ "messageIdAsBase64=ca0LdNijSHq69rsVLY9w0w, "
+ "startOffset=1, endOffset=100, "
+ "stateOffsetAndEpoch=OffsetAndEpoch(offset=300, "
......
......@@ -9,7 +9,7 @@ object RecoveryTestUtils {
def writeFencingFile(file: File, tpIdsToBeFenced: List[TopicIdPartition]): Unit = {
val pw = new PrintWriter(file)
tpIdsToBeFenced.foreach(tpid => {
pw.write("%s,%s,%d".format(tpid.topicIdAsBase64(), tpid.topic(), tpid.partition()))
pw.write("%s:%s-%d".format(tpid.topicIdAsBase64(), tpid.topic(), tpid.partition()))
pw.println()
})
pw.close()
......
......@@ -145,7 +145,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
def testToTopicIdPartitionsWithEmptyTopicName(): Unit = {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
CoreUtils.generateUuidAsBase64(),
"",
"23")));
......@@ -153,7 +153,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
CoreUtils.generateUuidAsBase64(),
" ",
"23")));
......@@ -164,7 +164,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
def testToTopicIdPartitionsWithBadTopicId(): Unit = {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
"",
"foo",
"23")));
......@@ -172,7 +172,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
" ",
"foo",
"23")));
......@@ -181,7 +181,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
val badUuid = "badUuid"
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
badUuid,
"foo",
"23")));
......@@ -192,7 +192,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
def testToTopicIdPartitionsWithBadPartitionNumber(): Unit = {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
CoreUtils.generateUuidAsBase64(),
"foo",
"")));
......@@ -200,7 +200,7 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
CoreUtils.generateUuidAsBase64(),
"foo",
" ")));
......@@ -208,19 +208,11 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
Arrays.asList("%s:%s-%s".format(
CoreUtils.generateUuidAsBase64(),
"foo",
"abc")));
}
org.scalatest.Assertions.assertThrows[IllegalArgumentException]{
RecoveryUtils.toTopicIdPartitions(
Arrays.asList("%s,%s,%s".format(
CoreUtils.generateUuidAsBase64(),
"foo",
"-1")));
}
}
@Test
......@@ -229,11 +221,11 @@ class RecoveryUtilsTest extends IntegrationTestHarness {
val topicIdPartition2 = new TopicIdPartition("bar", UUID.randomUUID(), 97)
val result = RecoveryUtils.toTopicIdPartitions(
Arrays.asList(
"%s,%s,%d".format(
"%s:%s-%d".format(
CoreUtils.uuidToBase64(topicIdPartition1.topicId),
topicIdPartition1.topic,
topicIdPartition1.partition),
"%s,%s,%d".format(
"%s:%s-%d".format(
CoreUtils.uuidToBase64(topicIdPartition2.topicId),
topicIdPartition2.topic,
topicIdPartition2.partition)));
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册