use of org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId in project ignite by apache.
the class IgniteSnapshotManagerSelfTest method testSnapshotCreateLocalCopyPartitionFail.
/**
* @throws Exception If fails.
*/
@Test
public void testSnapshotCreateLocalCopyPartitionFail() throws Exception {
String err_msg = "Test. Fail to copy partition: ";
IgniteEx ig = startGridWithCache(dfltCacheCfg, CACHE_KEYS_RANGE);
Map<Integer, Set<Integer>> parts = new HashMap<>();
parts.put(CU.cacheId(DEFAULT_CACHE_NAME), new HashSet<>(Collections.singletonList(0)));
IgniteSnapshotManager mgr0 = snp(ig);
IgniteInternalFuture<?> fut = startLocalSnapshotTask(ig.context().cache().context(), SNAPSHOT_NAME, parts, encryption, new DelegateSnapshotSender(log, mgr0.snapshotExecutorService(), mgr0.localSnapshotSenderFactory().apply(SNAPSHOT_NAME)) {
@Override
public void sendPart0(File part, String cacheDirName, GroupPartitionId pair, Long length) {
if (pair.getPartitionId() == 0)
throw new IgniteException(err_msg + pair);
delegate.sendPart0(part, cacheDirName, pair, length);
}
});
assertThrowsAnyCause(log, fut::get, IgniteException.class, err_msg);
}
use of org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId in project ignite by apache.
the class IgniteSnapshotManagerSelfTest method testSnapshotLocalPartitionMultiCpWithLoad.
/**
* Test that all partitions are copied successfully even after multiple checkpoints occur during
* the long copy of cache partition files.
*
* Data consistency checked through a test node started right from snapshot directory and all values
* read successes.
*
* @throws Exception If fails.
*/
@Test
public void testSnapshotLocalPartitionMultiCpWithLoad() throws Exception {
int valMultiplier = 2;
CountDownLatch slowCopy = new CountDownLatch(1);
// Start grid node with data before each test.
IgniteEx ig = startGridsWithCache(1, CACHE_KEYS_RANGE, key -> new Account(key, key), new CacheConfiguration<>(DEFAULT_CACHE_NAME));
GridCacheSharedContext<?, ?> cctx = ig.context().cache().context();
AtomicInteger cntr = new AtomicInteger();
CountDownLatch ldrLatch = new CountDownLatch(1);
IgniteSnapshotManager mgr = snp(ig);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) cctx.database();
IgniteInternalFuture<?> loadFut = GridTestUtils.runMultiThreadedAsync(() -> {
try {
U.await(ldrLatch);
while (!Thread.currentThread().isInterrupted()) ig.cache(DEFAULT_CACHE_NAME).put(cntr.incrementAndGet(), new Account(cntr.incrementAndGet(), cntr.incrementAndGet()));
} catch (IgniteInterruptedCheckedException e) {
log.warning("Loader has been interrupted", e);
}
}, 5, "cache-loader-");
// Register task but not schedule it on the checkpoint.
SnapshotFutureTask snpFutTask = (SnapshotFutureTask) mgr.registerSnapshotTask(SNAPSHOT_NAME, cctx.localNodeId(), F.asMap(CU.cacheId(DEFAULT_CACHE_NAME), null), encryption, new DelegateSnapshotSender(log, mgr.snapshotExecutorService(), mgr.localSnapshotSenderFactory().apply(SNAPSHOT_NAME)) {
@Override
public void sendPart0(File part, String cacheDirName, GroupPartitionId pair, Long length) {
try {
U.await(slowCopy);
delegate.sendPart0(part, cacheDirName, pair, length);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
});
db.addCheckpointListener(new CheckpointListener() {
/**
* {@inheritDoc}
*/
@Override
public void beforeCheckpointBegin(Context ctx) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void onMarkCheckpointBegin(Context ctx) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void onCheckpointBegin(Context ctx) {
Map<Integer, Set<Integer>> processed = GridTestUtils.getFieldValue(snpFutTask, SnapshotFutureTask.class, "processed");
if (!processed.isEmpty())
ldrLatch.countDown();
}
});
try {
snpFutTask.start();
// Change data before snapshot creation which must be included into it with correct value multiplier.
for (int i = 0; i < CACHE_KEYS_RANGE; i++) ig.cache(DEFAULT_CACHE_NAME).put(i, new Account(i, valMultiplier * i));
// Snapshot is still in the INIT state. beforeCheckpoint has been skipped
// due to checkpoint already running and we need to schedule the next one
// right after current will be completed.
cctx.database().forceCheckpoint(String.format(CP_SNAPSHOT_REASON, SNAPSHOT_NAME));
snpFutTask.started().get();
db.forceCheckpoint("snapshot is ready to be created").futureFor(CheckpointState.MARKER_STORED_TO_DISK).get();
// Change data after snapshot.
for (int i = 0; i < CACHE_KEYS_RANGE; i++) ig.cache(DEFAULT_CACHE_NAME).put(i, new Account(i, 3 * i));
// Snapshot on the next checkpoint must copy page to delta file before write it to a partition.
forceCheckpoint(ig);
slowCopy.countDown();
snpFutTask.get();
} finally {
loadFut.cancel();
}
// Now can stop the node and check created snapshots.
stopGrid(0);
cleanPersistenceDir(ig.name());
// Start Ignite instance from snapshot directory.
IgniteEx ig2 = startGridsFromSnapshot(1, SNAPSHOT_NAME);
for (int i = 0; i < CACHE_KEYS_RANGE; i++) {
assertEquals("snapshot data consistency violation [key=" + i + ']', i * valMultiplier, ((Account) ig2.cache(DEFAULT_CACHE_NAME).get(i)).balance);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId in project ignite by apache.
the class IgniteSnapshotRestoreFromRemoteTest method assertPartitionsDuplicates.
/**
*/
private static void assertPartitionsDuplicates(List<Object> msgs) {
List<GroupPartitionId> all = new ArrayList<>();
for (Object o : msgs) {
SnapshotFilesRequestMessage msg0 = (SnapshotFilesRequestMessage) o;
Map<Integer, Set<Integer>> parts = msg0.parts();
for (Map.Entry<Integer, Set<Integer>> e : parts.entrySet()) {
for (Integer partId : e.getValue()) all.add(new GroupPartitionId(e.getKey(), partId));
}
}
assertEquals(all.size(), new HashSet<>(all).size());
}
use of org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId in project ignite by apache.
the class IgniteSnapshotRemoteRequestTest method testRemoteRequestedInitiatorNodeLeft.
/**
* @throws Exception If fails.
*/
@Test
public void testRemoteRequestedInitiatorNodeLeft() throws Exception {
IgniteEx ignite = startGridsWithCache(2, CACHE_KEYS_RANGE, valueBuilder(), dfltCacheCfg);
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
awaitPartitionMapExchange();
IgniteSnapshotManager mgr1 = snp(grid(1));
UUID rmtNodeId = grid(1).localNode().id();
UUID locNodeId = grid(0).localNode().id();
Map<Integer, Set<Integer>> parts = owningParts(ignite, CU.cacheId(DEFAULT_CACHE_NAME), rmtNodeId);
CountDownLatch sndLatch = new CountDownLatch(1);
mgr1.remoteSnapshotSenderFactory(new BiFunction<String, UUID, SnapshotSender>() {
@Override
public SnapshotSender apply(String s, UUID uuid) {
return new DelegateSnapshotSender(log, mgr1.snapshotExecutorService(), mgr1.remoteSnapshotSenderFactory(s, uuid)) {
@Override
public void sendPart0(File part, String cacheDirName, GroupPartitionId pair, Long length) {
if (partId(part.getName()) > 0) {
try {
sndLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new IgniteException(e);
}
}
super.sendPart0(part, cacheDirName, pair, length);
}
};
}
});
snp(ignite).requestRemoteSnapshotFiles(grid(1).localNode().id(), SNAPSHOT_NAME, parts, () -> false, (part, t) -> {
});
IgniteInternalFuture<?>[] futs = new IgniteInternalFuture[1];
assertTrue(waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
IgniteInternalFuture<?> snpFut = snp(grid(1)).lastScheduledSnapshotResponseRemoteTask(locNodeId);
if (snpFut == null)
return false;
else {
futs[0] = snpFut;
return true;
}
}
}, 5_000L));
stopGrid(0);
sndLatch.countDown();
GridTestUtils.assertThrowsAnyCause(log, () -> futs[0].get(TIMEOUT), ClusterTopologyCheckedException.class, null);
}
Aggregations