Skip to content

Commit 152ee1d

Browse files
authored
Fixed the Chinese logger of schema (#17721)
1 parent 329fa10 commit 152ee1d

2 files changed

Lines changed: 104 additions & 5 deletions

File tree

iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class DataNodeSchemaMessages {
3030
"更新模板 {} 在 schemaRegion {} 中的子树测点计数失败";
3131
public static final String RECOVER_SPEND = "恢复 [{}] 耗时:{} ms";
3232
public static final String SCHEMA_REGION_FAILED_TO_RECOVER =
33-
"StorageGroup [%s] 中的 SchemaRegion [%d] 恢复失败。";
33+
"SchemaRegion [%d] 在 StorageGroup [%s] 中恢复失败。";
3434
public static final String SCHEMA_REGION_ALREADY_DELETED =
3535
"SchemaRegion(id = {}) 已被删除,已跳过";
3636
public static final String FAILED_TO_GET_TABLE_FOR_TIMESERIES_COUNT =
@@ -104,7 +104,7 @@ public final class DataNodeSchemaMessages {
104104

105105
public static final String CANNOT_FORCE_MLOG = "无法将 {} 的 mlog 强制写入 schema region";
106106
public static final String SPEND_TIME_DESERIALIZE_MTREE =
107-
"从 mlog.bin 反序列化 {} 的 mtree 耗时 {} ms";
107+
"从 mlog.bin 反序列化 MTree 耗时 {} ms,对应路径 {}";
108108
public static final String FAILED_TO_PARSE_MLOG = "解析 ";
109109
public static final String MLOG_BIN_SUFFIX = " mlog.bin 失败";
110110
public static final String PARSE_MLOG_ERROR = "在行号 {} 处解析 mlog 出错:";
@@ -116,7 +116,7 @@ public final class DataNodeSchemaMessages {
116116
public static final String MLOG_RECOVERY_CHECK_POINT = "MLog 恢复检查点:{}";
117117
public static final String CANNOT_GET_MLOG_CHECKPOINT =
118118
"无法从 MLogDescription 文件获取检查点,原因:{},使用默认值 0。";
119-
public static final String FAILED_TO_SKIP_MLOG = " {} 跳过 {} 失败";
119+
public static final String FAILED_TO_SKIP_MLOG = "跳过 {} 失败,schemaRegion 目录为 {}";
120120
public static final String UPDATE_MLOG_DESCRIPTION_FAILED = "更新 {} 失败,原因:{}";
121121
public static final String DIRECT_BUFFER_MEMORY_EXCEEDED =
122122
"直接缓冲区的总分配内存将达到 ";
@@ -162,7 +162,7 @@ public final class DataNodeSchemaMessages {
162162
public static final String ERROR_DURING_INIT_SCHEMA_REGION =
163163
"初始化 schemaRegion {} 过程中发生错误";
164164
public static final String FAILED_TO_RECOVER_TAG_INDEX =
165-
"在 schemaRegion {} 中恢复 {} 的 tagIndex 失败。";
165+
"恢复 {} 的 tagIndex 失败,schemaRegion 为 {}。";
166166
public static final String FAILED_TO_READ_TAG_ATTRIBUTE =
167167
"读取 tag 和 attribute 信息失败:{}";
168168

@@ -556,7 +556,7 @@ public final class DataNodeSchemaMessages {
556556
// ======================== CachedMTreeStore / Scheduler 相关消息 ========================
557557

558558
public static final String MTREE_FLUSH_COST =
559-
"在 SchemaRegion {} 中刷写 MTree 耗时 {}ms";
559+
"MTree 刷写耗时 {}ms,SchemaRegion 为 {}";
560560

561561
// ======================== DataNodeTableCache 相关消息 ========================
562562

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.i18n;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.slf4j.helpers.MessageFormatter;
25+
26+
import java.io.IOException;
27+
import java.net.URISyntaxException;
28+
import java.nio.charset.StandardCharsets;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.nio.file.Paths;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
34+
35+
public class DataNodeSchemaMessagesZhFormatTest {
36+
37+
private static final String ZH_MESSAGES_RELATIVE_PATH =
38+
"src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java";
39+
40+
@Test
41+
public void testZhSlf4jTemplatesPreserveLoggerArgumentOrder() throws IOException {
42+
Assert.assertEquals(
43+
"从 mlog.bin 反序列化 MTree 耗时 12 ms,对应路径 root.sg",
44+
formatSlf4j(readZhMessage("SPEND_TIME_DESERIALIZE_MTREE"), 12, "root.sg"));
45+
Assert.assertEquals(
46+
"跳过 128 失败,schemaRegion 目录为 C:/schema",
47+
formatSlf4j(readZhMessage("FAILED_TO_SKIP_MLOG"), 128, "C:/schema"));
48+
Assert.assertEquals(
49+
"恢复 root.sg.d.s 的 tagIndex 失败,schemaRegion 为 SchemaRegionId{1}。",
50+
formatSlf4j(
51+
readZhMessage("FAILED_TO_RECOVER_TAG_INDEX"), "root.sg.d.s", "SchemaRegionId{1}"));
52+
Assert.assertEquals(
53+
"MTree 刷写耗时 321ms,SchemaRegion 为 SchemaRegionId{1}",
54+
formatSlf4j(readZhMessage("MTREE_FLUSH_COST"), 321, "SchemaRegionId{1}"));
55+
}
56+
57+
@Test
58+
public void testZhStringFormatTemplatePreservesArgumentTypesAndOrder() throws IOException {
59+
Assert.assertEquals(
60+
"SchemaRegion [7] 在 StorageGroup [root.sg] 中恢复失败。",
61+
String.format(readZhMessage("SCHEMA_REGION_FAILED_TO_RECOVER"), 7, "root.sg"));
62+
}
63+
64+
private static String formatSlf4j(String template, Object... arguments) {
65+
return MessageFormatter.arrayFormat(template, arguments).getMessage();
66+
}
67+
68+
private static String readZhMessage(String constantName) throws IOException {
69+
Path basePath = resolveZhMessagesPath();
70+
Assert.assertTrue("Missing zh messages file: " + basePath, Files.exists(basePath));
71+
72+
String content = new String(Files.readAllBytes(basePath), StandardCharsets.UTF_8);
73+
Matcher matcher =
74+
Pattern.compile(
75+
"public static final String\\s+"
76+
+ Pattern.quote(constantName)
77+
+ "\\s*=\\s*\"([^\"]*)\";",
78+
Pattern.DOTALL)
79+
.matcher(content);
80+
Assert.assertTrue("Missing zh message constant: " + constantName, matcher.find());
81+
return matcher.group(1);
82+
}
83+
84+
private static Path resolveZhMessagesPath() throws IOException {
85+
try {
86+
Path testClassesDir =
87+
Paths.get(
88+
DataNodeSchemaMessagesZhFormatTest.class
89+
.getProtectionDomain()
90+
.getCodeSource()
91+
.getLocation()
92+
.toURI());
93+
Path moduleBaseDir = testClassesDir.getParent().getParent();
94+
return moduleBaseDir.resolve(ZH_MESSAGES_RELATIVE_PATH);
95+
} catch (URISyntaxException e) {
96+
throw new IOException("Failed to resolve zh messages path", e);
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)