Skip to content

Commit c73c7c4

Browse files
authored
IGNITE-28408 Added Ignite version to the performance statistics error message (#12960)
1 parent a4c4ab6 commit c73c7c4

8 files changed

Lines changed: 67 additions & 13 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsReader.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import static java.nio.ByteOrder.nativeOrder;
5151
import static java.nio.file.Files.walkFileTree;
5252
import static java.nio.file.StandardOpenOption.READ;
53+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
54+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION;
5355
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
5456
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CHECKPOINT;
5557
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
@@ -83,6 +85,9 @@
8385
* @see FilePerformanceStatisticsWriter
8486
*/
8587
public class FilePerformanceStatisticsReader {
88+
/** Legacy format version without Ignite product version in header. */
89+
static final short LEGACY_FILE_FORMAT_VERSION_1 = 1;
90+
8691
/** Default file read buffer size. */
8792
private static final int DFLT_READ_BUFFER_SIZE = (int)(8 * U.MB);
8893

@@ -229,14 +234,24 @@ private boolean deserialize(ByteBuffer buf, UUID nodeId, boolean firstRecord) th
229234
throw new IgniteException("Unsupported file format");
230235

231236
if (opType == VERSION) {
232-
if (buf.remaining() < OperationType.versionRecordSize())
237+
if (buf.remaining() < Short.BYTES)
233238
return false;
234239

235240
short ver = buf.getShort();
241+
String ignVer = null;
242+
243+
if (ver > LEGACY_FILE_FORMAT_VERSION_1) {
244+
ForwardableString verStr = readString(buf);
245+
246+
if (verStr == null)
247+
return false;
248+
249+
ignVer = verStr.str;
250+
}
236251

237-
if (ver != FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION) {
238-
throw new IgniteException("Unsupported file format version [fileVer=" + ver + ", supportedVer=" +
239-
FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION + ']');
252+
if (ver != FILE_FORMAT_VERSION && ver != LEGACY_FILE_FORMAT_VERSION_1) {
253+
throw new IgniteException("Unsupported file format version [igniteVer=" + ignVer + ", fileVer=" + ver +
254+
"]. The reader version [readerIgniteVer=" + VER_STR + ", readerFileVer=" + FILE_FORMAT_VERSION + ']');
240255
}
241256

242257
return true;

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PERF_STAT_BUFFER_SIZE;
4747
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PERF_STAT_FILE_MAX_SIZE;
4848
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PERF_STAT_FLUSH_SIZE;
49+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
4950
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
5051
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CHECKPOINT;
5152
import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
@@ -96,7 +97,7 @@ public class FilePerformanceStatisticsWriter {
9697
* File format version. This version should be incremented each time when format of existing events are
9798
* changed (fields added/removed) to avoid unexpected non-informative errors on deserialization.
9899
*/
99-
public static final short FILE_FORMAT_VERSION = 1;
100+
public static final short FILE_FORMAT_VERSION = 2;
100101

101102
/** File writer thread name. */
102103
static final String WRITER_THREAD_NAME = "performance-statistics-writer";
@@ -155,7 +156,10 @@ public FilePerformanceStatisticsWriter(GridKernalContext ctx) throws IgniteCheck
155156

156157
fileWriter = new FileWriter(ctx, log);
157158

158-
doWrite(OperationType.VERSION, OperationType.versionRecordSize(), buf -> buf.putShort(FILE_FORMAT_VERSION));
159+
doWrite(OperationType.VERSION, OperationType.versionRecordSize(), buf -> {
160+
buf.putShort(FILE_FORMAT_VERSION);
161+
writeString(buf, VER_STR, false);
162+
});
159163
}
160164

161165
/** Starts collecting performance statistics. */

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Map;
2424
import org.jetbrains.annotations.Nullable;
2525

26+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
27+
2628
/**
2729
* Performance statistics operation type.
2830
*/
@@ -295,7 +297,7 @@ public static int checkpointRecordSize() {
295297

296298
/** @return Version record size. */
297299
public static int versionRecordSize() {
298-
return Short.BYTES;
300+
return Short.BYTES + 1 + Integer.BYTES + VER_STR.length();
299301
}
300302

301303
/** @return Pages write throttle record size. */

modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/SystemViewFileWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PERF_STAT_BUFFER_SIZE;
4141
import static org.apache.ignite.IgniteSystemProperties.IGNITE_PERF_STAT_FLUSH_SIZE;
42+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
4243
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.DFLT_BUFFER_SIZE;
4344
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.DFLT_FLUSH_SIZE;
4445
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION;
@@ -112,6 +113,7 @@ public SystemViewFileWriter(GridKernalContext ctx) throws IgniteCheckedException
112113
doWrite(buf -> {
113114
buf.put(OperationType.VERSION.id());
114115
buf.putShort(FILE_FORMAT_VERSION);
116+
writeString(buf, VER_STR, false);
115117
});
116118
}
117119

modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/ForwardReadQueryPropertyTest.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,58 @@
2020
import java.io.File;
2121
import java.nio.ByteBuffer;
2222
import java.nio.ByteOrder;
23+
import java.util.Collection;
2324
import java.util.HashMap;
25+
import java.util.List;
2426
import java.util.Map;
2527
import java.util.UUID;
2628
import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
2729
import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
2830
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
2931
import org.apache.ignite.internal.util.typedef.internal.U;
3032
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
import org.junit.runners.Parameterized;
3135

3236
import static java.util.Collections.singletonList;
3337
import static java.util.UUID.randomUUID;
38+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
39+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader.LEGACY_FILE_FORMAT_VERSION_1;
40+
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION;
3441
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
3542
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeString;
3643
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeUuid;
44+
import static org.junit.runners.Parameterized.Parameter;
45+
import static org.junit.runners.Parameterized.Parameters;
3746

3847
/**
3948
* Tests forward read mode for {@link OperationType#QUERY_PROPERTY} records.
4049
*/
50+
@RunWith(Parameterized.class)
4151
public class ForwardReadQueryPropertyTest extends AbstractPerformanceStatisticsTest {
4252
/** Read buffer size. */
4353
private static final int BUFFER_SIZE = 100;
4454

55+
/** File format version. */
56+
@Parameter
57+
public short fileFormatVer;
58+
59+
/** @return Test parameters. */
60+
@Parameters(name = "fileFormatVer={0}")
61+
public static Collection<?> parameters() {
62+
return List.of(FILE_FORMAT_VERSION, LEGACY_FILE_FORMAT_VERSION_1);
63+
}
64+
4565
/** @throws Exception If failed. */
4666
@Test
4767
public void testStringForwardRead() throws Exception {
4868
File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), PERF_STAT_DIR, false);
4969

50-
Map<String, String> expProps = createStatistics(dir);
70+
Map<String, String> expProps = createStatistics(dir, fileFormatVer);
5171
Map<String, String> actualProps = new HashMap<>();
5272

5373
new FilePerformanceStatisticsReader(BUFFER_SIZE, new TestHandler() {
54-
@Override public void queryProperty(UUID nodeId, GridCacheQueryType type, UUID qryNodeId, long id, String name,
55-
String val) {
74+
@Override public void queryProperty(UUID nodeId, GridCacheQueryType type, UUID qryNodeId, long id, String name, String val) {
5675
assertNotNull(name);
5776
assertNotNull(val);
5877

@@ -64,14 +83,20 @@ public void testStringForwardRead() throws Exception {
6483
}
6584

6685
/** Creates test performance statistics file. */
67-
private Map<String, String> createStatistics(File dir) throws Exception {
86+
private Map<String, String> createStatistics(File dir, short fileFormatVer) throws Exception {
6887
File file = new File(dir, "node-" + randomUUID() + ".prf");
6988

7089
try (FileIO fileIo = new RandomAccessFileIOFactory().create(file)) {
7190
ByteBuffer buf = ByteBuffer.allocate(1024).order(ByteOrder.nativeOrder());
7291

7392
buf.put(OperationType.VERSION.id());
74-
buf.putShort(FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION);
93+
94+
if (fileFormatVer == FILE_FORMAT_VERSION) {
95+
buf.putShort(fileFormatVer);
96+
writeString(buf, VER_STR, false);
97+
}
98+
else
99+
buf.putShort(fileFormatVer);
75100

76101
writeQueryProperty(buf, "property", true, "val", true);
77102
writeQueryProperty(buf, "property", false, "val", false);

modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/ForwardReadTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static com.google.common.collect.Lists.cartesianProduct;
4040
import static java.util.Collections.singletonList;
4141
import static java.util.UUID.randomUUID;
42+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
4243
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
4344
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeIgniteUuid;
4445
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeString;
@@ -93,6 +94,7 @@ private Map<String, Integer> createStatistics(File dir) throws Exception {
9394

9495
buf.put(OperationType.VERSION.id());
9596
buf.putShort(FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION);
97+
writeString(buf, VER_STR, false);
9698

9799
expTasks = writeData(buf);
98100

modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsPropertiesTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ public void testFileMaxSize() throws Exception {
113113
@Test
114114
@WithSystemProperty(key = IGNITE_PERF_STAT_FLUSH_SIZE, value = "" + TEST_FLUSH_SIZE)
115115
public void testFlushSize() throws Exception {
116-
long initLen = srv.context().cache().cacheDescriptors().values().stream().mapToInt(
116+
long initLen = 1 + OperationType.versionRecordSize();
117+
118+
initLen += srv.context().cache().cacheDescriptors().values().stream().mapToInt(
117119
desc -> 1 + cacheStartRecordSize(desc.cacheName().getBytes().length, false)).sum();
118120

119121
long opsCnt = (TEST_FLUSH_SIZE - initLen) / (/*typeOp*/1 + OperationType.cacheRecordSize());

modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSystemViewTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import static java.util.UUID.randomUUID;
4343
import static java.util.function.Function.identity;
44+
import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR;
4445
import static org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW;
4546
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
4647
import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeString;
@@ -197,6 +198,7 @@ private List<String> createStatistics(File dir) throws Exception {
197198

198199
buf.put(OperationType.VERSION.id());
199200
buf.putShort(FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION);
201+
writeString(buf, VER_STR, false);
200202

201203
writeSystemView(buf, "customView", "customWalker", null);
202204

0 commit comments

Comments
 (0)