use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project ignite by apache.
the class CheckpointFreeListTest method testFreeListUnderLoadMultipleCheckpoints.
/**
* Test checks that free-list works and pages cache flushes correctly under the high concurrent load.
*/
@Test
public void testFreeListUnderLoadMultipleCheckpoints() throws Throwable {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
int minValSize = 64;
int maxValSize = 128;
int valsCnt = maxValSize - minValSize;
int keysCnt = 1_000;
byte[][] vals = new byte[valsCnt][];
for (int i = 0; i < valsCnt; i++) vals[i] = new byte[minValSize + i];
IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAffinity(// Maximize contention per partition.
new RendezvousAffinityFunction().setPartitions(2)).setAtomicityMode(CacheAtomicityMode.ATOMIC));
AtomicBoolean done = new AtomicBoolean();
AtomicReference<Throwable> error = new AtomicReference<>();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) ignite.context().cache().context().database();
AtomicLong pageListCacheLimitHolder = db.pageListCacheLimitHolder(ignite.context().cache().cache(DEFAULT_CACHE_NAME).context().dataRegion());
long initPageListCacheLimit = pageListCacheLimitHolder.get();
// Add listener after cache is started, so this listener will be triggered after listener for cache.
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
// Need to wait for condition here, since checkpointer can store free-list metadata asynchronously.
if (!waitForCondition(() -> initPageListCacheLimit == pageListCacheLimitHolder.get(), 1_000L)) {
IgniteCheckedException e = new IgniteCheckedException("Page list cache limit doesn't restored " + "correctly [init=" + initPageListCacheLimit + ", cur=" + pageListCacheLimitHolder.get() + ']');
error.set(e);
throw e;
}
}
@Override
public void onCheckpointBegin(Context ctx) {
// No-op.
}
@Override
public void beforeCheckpointBegin(Context ctx) {
// No-op.
}
});
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
Random rnd = new Random();
try {
while (!done.get()) {
int key = rnd.nextInt(keysCnt);
byte[] val = vals[rnd.nextInt(valsCnt)];
// Put with changed value size - worst case for free list, since row will be removed first and
// then inserted again.
cache.put(key, val);
}
} catch (Throwable t) {
error.set(t);
}
}, 20, "cache-put");
for (int i = 0; i < SF.applyLB(10, 2); i++) {
if (error.get() != null)
break;
forceCheckpoint(ignite);
doSleep(1_000L);
}
done.set(true);
fut.get();
stopAllGrids();
if (error.get() != null)
throw error.get();
}
use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project ignite by apache.
the class ResumeCreateIndexTest method awaitBeforeCheckpointBeginAsync.
/**
* Waiting for a {@link CheckpointListener#beforeCheckpointBegin} asynchronously
* for a checkpoint for a specific reason.
*
* @param n Node.
* @param reason Checkpoint reason.
* @return Future for waiting for the {@link CheckpointListener#beforeCheckpointBegin}.
*/
private IgniteInternalFuture<Void> awaitBeforeCheckpointBeginAsync(IgniteEx n, String reason) {
GridFutureAdapter<Void> fut = new GridFutureAdapter<>();
dbMgr(n).addCheckpointListener(new CheckpointListener() {
/**
* {@inheritDoc}
*/
@Override
public void onMarkCheckpointBegin(Context ctx) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void onCheckpointBegin(Context ctx) {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void beforeCheckpointBegin(Context ctx) {
if (reason.equals(ctx.progress().reason()))
fut.onDone();
}
});
return fut;
}
use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project ignite by apache.
the class IgnitePersistentStoreSchemaLoadTest method checkpointLatch.
/**
* @param node Node whose checkpoint to wait for.
* @return Latch released when checkpoint happens.
*/
private CountDownLatch checkpointLatch(IgniteEx node) {
final CountDownLatch cnt = new CountDownLatch(1);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) node.context().cache().context().database();
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) {
cnt.countDown();
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
@Override
public void onCheckpointBegin(Context ctx) {
/* No-op. */
}
});
return cnt;
}
use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project gridgain by gridgain.
the class IgnitePersistentStoreSchemaLoadTest method checkpointLatch.
/**
* @param node Node whose checkpoint to wait for.
* @return Latch released when checkpoint happens.
*/
private CountDownLatch checkpointLatch(IgniteEx node) {
final CountDownLatch cnt = new CountDownLatch(1);
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) node.context().cache().context().database();
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) {
cnt.countDown();
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
@Override
public void onCheckpointBegin(Context ctx) {
/* No-op. */
}
});
return cnt;
}
use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project gridgain by gridgain.
the class MetaStorage method init.
/**
*/
public void init(GridCacheDatabaseSharedManager db) throws IgniteCheckedException {
dataRegion.metrics().clear();
initInternal(db);
if (!PRESERVE_LEGACY_METASTORAGE_PARTITION_ID) {
if (partId == OLD_METASTORE_PARTITION)
db.temporaryMetaStorage(copyDataToTmpStorage());
else if (db.temporaryMetaStorage() != null) {
restoreDataFromTmpStorage(db.temporaryMetaStorage());
db.temporaryMetaStorage(null);
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) {
}
@Override
public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
assert cctx.pageStore() != null;
int partTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION);
cctx.pageStore().truncate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION, partTag);
int idxTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
PageStore store = ((FilePageStoreManager) cctx.pageStore()).getStore(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
store.truncate(idxTag);
db.removeCheckpointListener(this);
}
@Override
public void beforeCheckpointBegin(Context ctx) {
}
}, dataRegion);
}
}
}
Aggregations