Skip to content

Commit b92a02b

Browse files
IGNITE-26330 Add logs for local snapshot creation steps (#12456)
1 parent 41f0eeb commit b92a02b

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ private IgniteInternalFuture<SnapshotOperationResponse> initLocalSnapshotStartSt
779779
if (!CU.baselineNode(cctx.localNode(), cctx.kernalContext().state().clusterState()))
780780
return new GridFinishedFuture<>();
781781

782+
if (log.isInfoEnabled())
783+
log.info("Starting local snapshot operation [req=" + req + ']');
784+
782785
Set<UUID> leftNodes = new HashSet<>(req.nodes());
783786
leftNodes.removeAll(F.viewReadOnly(cctx.discovery().serverNodes(AffinityTopologyVersion.NONE), node2id()));
784787

@@ -1279,8 +1282,14 @@ else if (!F.isEmpty(req.warnings())) {
12791282
enableIncrementalSnapshotsCreation(grpIds);
12801283
}
12811284
}
1285+
1286+
if (log.isInfoEnabled())
1287+
log.info("Finishing local snapshot operation [req=" + req + ']');
12821288
}
12831289
catch (Exception e) {
1290+
log.error("Finishing local snapshot operation failed " +
1291+
"[req=" + req + ", err=" + e + ']');
1292+
12841293
throw F.wrap(e);
12851294
}
12861295

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
import org.apache.ignite.metric.MetricRegistry;
8585
import org.apache.ignite.spi.metric.LongMetric;
8686
import org.apache.ignite.testframework.GridTestUtils;
87+
import org.apache.ignite.testframework.ListeningTestLogger;
88+
import org.apache.ignite.testframework.LogListener;
8789
import org.apache.ignite.transactions.Transaction;
8890
import org.jetbrains.annotations.Nullable;
8991
import org.junit.Before;
@@ -1311,6 +1313,116 @@ public void testClientHandlesSnapshotFailOnStartStage() throws Exception {
13111313
assertSnapshotCacheKeys(cln.cache(dfltCacheCfg.getName()));
13121314
}
13131315

1316+
/**
1317+
* Test snapshot operation logging for incremental snapshots.
1318+
*/
1319+
@Test
1320+
public void testIncrementalSnapshotOperationLogging() throws Exception {
1321+
assumeFalse("https://issues.apache.org/jira/browse/IGNITE-17819", encryption);
1322+
1323+
int gridsCnt = 2;
1324+
ListeningTestLogger[] listeningLogs = new ListeningTestLogger[gridsCnt];
1325+
IgniteEx ignite = null;
1326+
1327+
for (int i = 0; i < gridsCnt; ++i) {
1328+
listeningLogs[i] = new ListeningTestLogger(log);
1329+
1330+
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(i))
1331+
.setGridLogger(listeningLogs[i]);
1332+
1333+
if (ignite == null)
1334+
ignite = startGrid(cfg);
1335+
else
1336+
startGrid(cfg);
1337+
}
1338+
ignite.cluster().state(ACTIVE);
1339+
1340+
LogListener[] fullStartListeners = new LogListener[gridsCnt];
1341+
LogListener[] fullEndListeners = new LogListener[gridsCnt];
1342+
1343+
for (int i = 0; i < gridsCnt; ++i) {
1344+
fullStartListeners[i] = LogListener.matches("Starting local snapshot operation")
1345+
.andMatches("incremental=false")
1346+
.build();
1347+
1348+
fullEndListeners[i] = LogListener.matches("Finishing local snapshot operation")
1349+
.andMatches("err=null")
1350+
.andMatches("incremental=false")
1351+
.build();
1352+
1353+
listeningLogs[i].registerListener(fullStartListeners[i]);
1354+
listeningLogs[i].registerListener(fullEndListeners[i]);
1355+
}
1356+
1357+
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(getTestTimeout());
1358+
1359+
for (int i = 0; i < gridsCnt; i++) {
1360+
assertTrue("Full snapshot start log not found on node " + i,
1361+
fullStartListeners[i].check());
1362+
assertTrue("Full snapshot end log not found on node " + i,
1363+
fullEndListeners[i].check());
1364+
}
1365+
1366+
LogListener[] incStartListeners = new LogListener[gridsCnt];
1367+
LogListener[] incEndListeners = new LogListener[gridsCnt];
1368+
1369+
for (int i = 0; i < gridsCnt; i++) {
1370+
incStartListeners[i] = LogListener.matches("Starting local snapshot operation")
1371+
.andMatches("incremental=true")
1372+
.andMatches("incIdx=1")
1373+
.build();
1374+
1375+
incEndListeners[i] = LogListener.matches("Finishing local snapshot operation")
1376+
.andMatches("err=null")
1377+
.andMatches("incremental=true")
1378+
.andMatches("incIdx=1")
1379+
.build();
1380+
1381+
listeningLogs[i].registerListener(incStartListeners[i]);
1382+
listeningLogs[i].registerListener(incEndListeners[i]);
1383+
}
1384+
1385+
ignite.snapshot().createIncrementalSnapshot(SNAPSHOT_NAME).get(getTestTimeout());
1386+
1387+
for (int i = 0; i < gridsCnt; i++) {
1388+
assertTrue("Incremental snapshot start log not found on node " + i,
1389+
incStartListeners[i].check());
1390+
assertTrue("Incremental snapshot end log not found on node " + i,
1391+
incEndListeners[i].check());
1392+
}
1393+
1394+
LogListener[] failureListeners = new LogListener[gridsCnt];
1395+
1396+
for (int i = 0; i < gridsCnt; i++) {
1397+
failureListeners[i] = LogListener.matches("Finishing local snapshot operation")
1398+
.andMatches("Snapshot process failure for testing")
1399+
.build();
1400+
1401+
listeningLogs[i].registerListener(failureListeners[i]);
1402+
}
1403+
1404+
snp(ignite).localSnapshotSenderFactory(sft -> {
1405+
throw new IgniteException("Snapshot process failure for testing");
1406+
});
1407+
1408+
try {
1409+
IgniteFuture<Void> fut = ignite.snapshot().createSnapshot("testSnp2");
1410+
1411+
fut.get();
1412+
fail("Should have failed");
1413+
}
1414+
catch (Exception e) {
1415+
// No-op.
1416+
}
1417+
1418+
stopAllGrids();
1419+
1420+
for (int i = 0; i < gridsCnt; i++) {
1421+
assertTrue("Failure snapshot log not found on node " + i,
1422+
failureListeners[i].check());
1423+
}
1424+
}
1425+
13141426
/**
13151427
* @param ignite Ignite instance.
13161428
* @param started Latch will be released when delta partition processing starts.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,10 @@ public void testFullSnapshotCreationLog() throws Exception {
617617
LogListener matchFinish = LogListener.matches("Cluster-wide snapshot operation finished successfully: ").times(entriesCnt).build();
618618
listenLog.registerListener(matchFinish);
619619

620-
LogListener matchFullParams = LogListener.matches("incremental=false, incIdx=-1").times(2).build();
620+
LogListener matchFullParams = LogListener.matches("incremental=false, incIdx=-1").times(4).build();
621621
listenLog.registerListener(matchFullParams);
622622

623-
LogListener matchIncParams = LogListener.matches("incremental=true").times(2 * (entriesCnt - 1)).build();
623+
LogListener matchIncParams = LogListener.matches("incremental=true").times(4 * (entriesCnt - 1)).build();
624624
listenLog.registerListener(matchIncParams);
625625

626626
LogListener noMatchParams = LogListener.matches("incremental=true, incIdx=-1").build();

0 commit comments

Comments
 (0)