Skip to content

Commit 5145c80

Browse files
authored
IGNITE-21656: Fix cache dump check fails on a cache with a node filter (#11276)
1 parent 2ccb962 commit 5145c80

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

modules/core/src/main/java/org/apache/ignite/dump/DumpReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public DumpReader(DumpReaderConfiguration cfg, IgniteLogger log) {
9797
: null;
9898

9999
for (SnapshotMetadata meta : dump.metadata()) {
100-
for (Integer grp : meta.cacheGroupIds()) {
100+
for (Integer grp : meta.partitions().keySet()) {
101101
if (cacheGrpIds == null || cacheGrpIds.contains(grp))
102102
grpToNodes.computeIfAbsent(grp, key -> new ArrayList<>()).add(meta.folderName());
103103
}

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

+15-19
Original file line numberDiff line numberDiff line change
@@ -1181,27 +1181,23 @@ private IgniteInternalFuture<SnapshotOperationResponse> initLocalFullSnapshot(
11811181
parts.put(grpId, null);
11821182
}
11831183

1184-
IgniteInternalFuture<?> task0;
1184+
IgniteInternalFuture<?> task0 = registerSnapshotTask(req.snapshotName(),
1185+
req.snapshotPath(),
1186+
req.operationalNodeId(),
1187+
req.requestId(),
1188+
parts,
1189+
withMetaStorage,
1190+
req.dump(),
1191+
req.compress(),
1192+
req.encrypt(),
1193+
locSndrFactory.apply(req.snapshotName(), req.snapshotPath())
1194+
);
11851195

1186-
if (parts.isEmpty() && !withMetaStorage)
1187-
task0 = new GridFinishedFuture<>(Collections.emptySet());
1188-
else {
1189-
task0 = registerSnapshotTask(req.snapshotName(),
1190-
req.snapshotPath(),
1191-
req.operationalNodeId(),
1192-
req.requestId(),
1193-
parts,
1194-
withMetaStorage,
1195-
req.dump(),
1196-
req.compress(),
1197-
req.encrypt(),
1198-
locSndrFactory.apply(req.snapshotName(), req.snapshotPath())
1199-
);
1196+
if (withMetaStorage) {
1197+
assert task0 instanceof SnapshotFutureTask;
12001198

1201-
if (withMetaStorage && task0 instanceof SnapshotFutureTask) {
1202-
((DistributedMetaStorageImpl)cctx.kernalContext().distributedMetastorage())
1203-
.suspend(((SnapshotFutureTask)task0).started());
1204-
}
1199+
((DistributedMetaStorageImpl)cctx.kernalContext().distributedMetastorage())
1200+
.suspend(((SnapshotFutureTask)task0).started());
12051201
}
12061202

12071203
return task0.chain(() -> {

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

+69
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@
2929
import java.util.concurrent.atomic.AtomicBoolean;
3030
import java.util.concurrent.atomic.AtomicInteger;
3131
import java.util.function.Consumer;
32+
import java.util.stream.Collectors;
3233
import java.util.stream.IntStream;
34+
import java.util.stream.Stream;
3335
import javax.cache.expiry.Duration;
3436
import javax.cache.expiry.ExpiryPolicy;
3537
import javax.cache.processor.MutableEntry;
3638
import org.apache.ignite.Ignite;
3739
import org.apache.ignite.IgniteCache;
3840
import org.apache.ignite.IgniteCheckedException;
41+
import org.apache.ignite.IgniteDataStreamer;
3942
import org.apache.ignite.IgniteException;
4043
import org.apache.ignite.cache.CacheEntryProcessor;
44+
import org.apache.ignite.cluster.ClusterState;
4145
import org.apache.ignite.configuration.CacheConfiguration;
4246
import org.apache.ignite.configuration.IgniteConfiguration;
4347
import org.apache.ignite.dump.DumpEntry;
@@ -52,8 +56,10 @@
5256
import org.apache.ignite.internal.util.typedef.internal.CU;
5357
import org.apache.ignite.internal.util.typedef.internal.U;
5458
import org.apache.ignite.platform.model.Key;
59+
import org.apache.ignite.platform.model.User;
5560
import org.apache.ignite.platform.model.Value;
5661
import org.apache.ignite.testframework.GridTestUtils;
62+
import org.apache.ignite.util.AttributeNodeFilter;
5763
import org.junit.Test;
5864

5965
import static java.lang.Boolean.FALSE;
@@ -63,6 +69,7 @@
6369
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.CreateDumpFutureTask.DUMP_FILE_EXT;
6470
import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
6571
import static org.junit.Assume.assumeFalse;
72+
import static org.junit.Assume.assumeTrue;
6673

6774
/** */
6875
public class IgniteCacheDumpSelfTest extends AbstractCacheDumpTest {
@@ -110,6 +117,68 @@ public class IgniteCacheDumpSelfTest extends AbstractCacheDumpTest {
110117
return cfg;
111118
}
112119

120+
/** */
121+
@Test
122+
public void testDumpWithNodeFilterCache() throws Exception {
123+
assumeTrue(nodes > 1);
124+
125+
CacheConfiguration<?, ?> ccfg0 = cacheConfiguration(getConfiguration(getTestIgniteInstanceName()), DEFAULT_CACHE_NAME)
126+
.setNodeFilter(new AttributeNodeFilter(DEFAULT_CACHE_NAME, null));
127+
128+
CacheConfiguration<?, ?> ccfg1 = cacheConfiguration(getConfiguration(getTestIgniteInstanceName()), CACHE_0)
129+
.setNodeFilter(ccfg0.getNodeFilter());
130+
131+
for (int i = 0; i <= nodes; ++i) {
132+
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(i));
133+
134+
if (i == 0)
135+
cfg.setUserAttributes(F.asMap(DEFAULT_CACHE_NAME, ""));
136+
137+
cfg.setCacheConfiguration(null);
138+
139+
cfg.setClientMode(i == nodes);
140+
141+
IgniteEx ig = startGrid(cfg);
142+
143+
cli = i == nodes ? ig : null;
144+
}
145+
146+
cli.cluster().state(ClusterState.ACTIVE);
147+
148+
cli.createCache(ccfg0);
149+
cli.createCache(ccfg1);
150+
151+
try (IgniteDataStreamer<Integer, Integer> ds0 = cli.dataStreamer(DEFAULT_CACHE_NAME);
152+
IgniteDataStreamer<Integer, User> ds1 = cli.dataStreamer(CACHE_0)) {
153+
IgniteCache<Integer, Integer> cache0 = cli.cache(DEFAULT_CACHE_NAME);
154+
IgniteCache<Integer, User> cache1 = cli.cache(CACHE_0);
155+
156+
for (int i = 0; i < KEYS_CNT; ++i) {
157+
if (useDataStreamer) {
158+
ds0.addData(i, i);
159+
ds1.addData(i, USER_FACTORY.apply(i));
160+
}
161+
else {
162+
cache0.put(i, i);
163+
cache1.put(i, USER_FACTORY.apply(i));
164+
}
165+
}
166+
}
167+
168+
createDump(cli, DMP_NAME, null);
169+
170+
checkDump(cli,
171+
DMP_NAME,
172+
new String[] {DEFAULT_CACHE_NAME, GRP},
173+
Stream.of(DEFAULT_CACHE_NAME, CACHE_0).collect(Collectors.toSet()),
174+
KEYS_CNT + (onlyPrimary ? 0 : KEYS_CNT * backups),
175+
KEYS_CNT + (onlyPrimary ? 0 : KEYS_CNT * backups),
176+
0,
177+
false,
178+
false
179+
);
180+
}
181+
113182
/** */
114183
@Test
115184
public void testCacheDump() throws Exception {

0 commit comments

Comments
 (0)