Skip to content

Commit f47b67c

Browse files
authored
IGNITE-24157 Added LastArchivedSegment metric (#11794)
1 parent 3f0c010 commit f47b67c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docs/_docs/monitoring-metrics/new-metrics.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ Register name: `io.datastorage`
431431
|CheckpointTotalTime| long | Total duration of checkpoint
432432
|CheckpointWalRecordFsyncHistogram| histogram | Histogram of the WAL fsync after logging ChTotalNodeseckpointRecord on begin of checkpoint duration in milliseconds.
433433
|CheckpointWriteEntryHistogram| histogram | Histogram of entry buffer writing to file duration in milliseconds.
434+
|LastArchivedSegment | long | Last archived segment index.
434435
|LastCheckpointBeforeLockDuration| long | Duration of the checkpoint action before taken write lock in milliseconds.
435436
|LastCheckpointCopiedOnWritePagesNumber| long | Number of pages copied to a temporary checkpoint buffer during the last checkpoint.
436437
|LastCheckpointDataPagesNumber| long | Total number of data pages written during the last checkpoint.

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/DataStorageMetricsImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ public DataStorageMetricsImpl(
275275
this::walTotalSize,
276276
"Total size in bytes for storage wal files.");
277277

278+
mreg.register("LastArchivedSegment",
279+
this::lastArchivedSegment,
280+
"Last archived segment index.");
281+
278282
long[] cpBounds = new long[] {100, 500, 1000, 5000, 30000};
279283

280284
cpBeforeLockHistogram = mreg.histogram("CheckpointBeforeLockHistogram", cpBounds,
@@ -362,6 +366,16 @@ private int walArchiveSegments() {
362366
return walMgr == null ? 0 : walMgr.walArchiveSegments();
363367
}
364368

369+
/** @return Last archived segment index. */
370+
private long lastArchivedSegment() {
371+
if (!metricsEnabled)
372+
return -1;
373+
374+
IgniteWriteAheadLogManager walMgr = this.wal;
375+
376+
return walMgr == null ? -1 : walMgr.lastArchivedSegment();
377+
}
378+
365379
/**
366380
* @return The average WAL fsync duration in microseconds over the last time interval.
367381
*/

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgniteDataStorageMetricsSelfTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public class IgniteDataStorageMetricsSelfTest extends GridCommonAbstractTest {
125125
.setMaxSize(maxRegionSize)
126126
.setPersistenceEnabled(true)
127127
.setMetricsEnabled(true)
128-
.setName(PERSISTENCE_REGION_1))
128+
.setName(PERSISTENCE_REGION_1)
129+
.setCdcEnabled(true))
129130
.setDataRegionConfigurations(
130131
new DataRegionConfiguration()
131132
.setMaxSize(maxRegionSize)
@@ -538,6 +539,17 @@ private void checkWalArchiveAndTotalSize(IgniteEx igniteEx, boolean hasWalArchiv
538539
totalSize += walMgr.totalSize(walFiles(router.getWalArchiveDir()));
539540

540541
assertEquals(totalSize, dsMetricRegistry(igniteEx).<LongGauge>findMetric("WalTotalSize").value());
542+
543+
long lastArchivedSegIdx = dsMetricRegistry(igniteEx).<LongGauge>findMetric("LastArchivedSegment").value();
544+
545+
if (router.hasArchive()) {
546+
long cdcWalArchiveSegments = walFiles(walMgr.walCdcDirectory()).length;
547+
548+
// Count of segments = LastArchivedSegmentIndex + 1
549+
assertEquals(cdcWalArchiveSegments, lastArchivedSegIdx + 1);
550+
}
551+
else
552+
assertEquals(-1, lastArchivedSegIdx);
541553
}
542554

543555
/**

0 commit comments

Comments
 (0)