Skip to content

Commit

Permalink
IGNITE-20309 Snapshot creation must fail if check throws (#10913)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Aug 30, 2023
1 parent de1b67e commit b6f49f8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public SnapshotPartitionsQuickVerifyHandler(GridCacheSharedContext<?, ?> cctx) {
String name,
Collection<SnapshotHandlerResult<Map<PartitionKeyV2, PartitionHashRecordV2>>> results
) throws IgniteCheckedException {
for (SnapshotHandlerResult<Map<PartitionKeyV2, PartitionHashRecordV2>> result : results) {
if (result.error() != null)
throw new IgniteCheckedException(result.error());
}

if (results.stream().anyMatch(r -> r.data() == null))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,18 @@ public SnapshotPartitionsVerifyHandler(GridCacheSharedContext<?, ?> cctx) {

SnapshotMetadata meta = opCtx.metadata();

Set<Integer> grps = F.isEmpty(opCtx.groups()) ? new HashSet<>(meta.partitions().keySet()) :
opCtx.groups().stream().map(CU::cacheId).collect(Collectors.toSet());
Set<Integer> grps = F.isEmpty(opCtx.groups())
? new HashSet<>(meta.partitions().keySet())
: opCtx.groups().stream().map(CU::cacheId).collect(Collectors.toSet());

if (type() == SnapshotHandlerType.CREATE) {
grps = grps.stream().filter(grp -> grp == MetaStorage.METASTORAGE_CACHE_ID ||
CU.affinityNode(
cctx.localNode(),
cctx.kernalContext().cache().cacheGroupDescriptor(grp).config().getNodeFilter()
)
).collect(Collectors.toSet());
}

Set<File> partFiles = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.function.Function;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
Expand All @@ -48,6 +49,7 @@
import org.junit.Test;

import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_METAFILE_EXT;
import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause;

/**
* Snapshot custom handlers test.
Expand Down Expand Up @@ -405,4 +407,32 @@ public void testHandlerSnapshotLocation() throws Exception {
U.delete(snpDir);
}
}

/**
* Test ensures that snapshot fails if some files are absent during the check.
* @see SnapshotPartitionsQuickVerifyHandler
*/
@Test
public void testHandlerExceptionFailSnapshot() throws Exception {
handlers.add(new SnapshotHandler<Void>() {
@Override public SnapshotHandlerType type() {
return SnapshotHandlerType.CREATE;
}

@Override public Void invoke(SnapshotHandlerContext ctx) {
// Someone removes snapshot files during creation.
// In this case snapshot must fail.
U.delete(ctx.snapshotDirectory());

return null;
}
});

IgniteEx ignite = startGridsWithCache(1, CACHE_KEYS_RANGE, valueBuilder(), dfltCacheCfg);

assertThrowsWithCause(
() -> snp(ignite).createSnapshot("must_fail", null, false, onlyPrimary).get(getTestTimeout()),
IgniteException.class
);
}
}

0 comments on commit b6f49f8

Please sign in to comment.