Search in sources :

Example 11 with MetaStorage

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage in project ignite by apache.

the class DistributedMetaStoragePersistentTest method testNamesCollision.

/**
 * @throws Exception If failed.
 */
@Test
public void testNamesCollision() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteCacheDatabaseSharedManager dbSharedMgr = ignite.context().cache().context().database();
    MetaStorage locMetastorage = dbSharedMgr.metaStorage();
    DistributedMetaStorage distributedMetastorage = ignite.context().distributedMetastorage();
    dbSharedMgr.checkpointReadLock();
    try {
        locMetastorage.write("key", "localValue");
    } finally {
        dbSharedMgr.checkpointReadUnlock();
    }
    distributedMetastorage.write("key", "globalValue");
    dbSharedMgr.checkpointReadLock();
    try {
        assertEquals("localValue", locMetastorage.read("key"));
    } finally {
        dbSharedMgr.checkpointReadUnlock();
    }
    assertEquals("globalValue", distributedMetastorage.read("key"));
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Test(org.junit.Test)

Example 12 with MetaStorage

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage in project ignite by apache.

the class ClusterReadOnlyModeSelfTest method testMetaStorageAvailableForUpdatesOnReadOnlyCluster.

/**
 */
@Test
public void testMetaStorageAvailableForUpdatesOnReadOnlyCluster() throws Exception {
    IgniteEx node = startGrid(0);
    node.cluster().state(ACTIVE);
    IgniteCacheDatabaseSharedManager db = node.context().cache().context().database();
    MetaStorage metaStorage = db.metaStorage();
    db.checkpointReadLock();
    try {
        metaStorage.write("key", "val");
    } finally {
        db.checkpointReadUnlock();
    }
    node.cluster().state(ACTIVE_READ_ONLY);
    db.checkpointReadLock();
    try {
        assertEquals("val", metaStorage.read("key"));
        metaStorage.write("key", "new_val");
        assertEquals("new_val", metaStorage.read("key"));
        metaStorage.remove("key");
        assertNull(metaStorage.read("key"));
    } finally {
        db.checkpointReadUnlock();
    }
}
Also used : MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with MetaStorage

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage in project ignite by apache.

the class MasterKeyChangeTest method testRecoveryFromWalWithCacheOperations.

/**
 * @throws Exception If failed.
 */
@Test
public void testRecoveryFromWalWithCacheOperations() throws Exception {
    // 1. Start two nodes.
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    IgniteEx grid0 = grids.get1();
    grid0.cluster().active(true);
    CacheConfiguration<Long, String> ccfg = new CacheConfiguration<Long, String>(cacheName()).setWriteSynchronizationMode(FULL_SYNC).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setEncryptionEnabled(true);
    // 2. Create cache.
    IgniteCache<Long, String> cache1 = grids.get2().createCache(ccfg);
    assertEquals(DEFAULT_MASTER_KEY_NAME, grid0.encryption().getMasterKeyName());
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) grid0.context().cache().context().database();
    // 3. Prevent checkpoints to recovery from WAL.
    dbMgr.enableCheckpoints(false).get();
    AtomicLong cnt = new AtomicLong();
    AtomicBoolean stop = new AtomicBoolean();
    // 4. Run cache operations.
    IgniteInternalFuture loadFut = runAsync(() -> {
        while (!stop.get()) {
            try (Transaction tx = grids.get2().transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
                cache1.put(cnt.get(), String.valueOf(cnt.get()));
                tx.commit();
                cnt.incrementAndGet();
            }
        }
    });
    // Put some data before master key change.
    waitForCondition(() -> cnt.get() >= 20, 10_000);
    // 5. Change master key.
    grid0.encryption().changeMasterKey(MASTER_KEY_NAME_2).get();
    MetaStorage metaStorage = grid0.context().cache().context().database().metaStorage();
    DynamicCacheDescriptor desc = grid0.context().cache().cacheDescriptor(cacheName());
    Serializable oldKey = metaStorage.read(ENCRYPTION_KEYS_PREFIX + desc.groupId());
    assertNotNull(oldKey);
    dbMgr.checkpointReadLock();
    // 6. Simulate group key write error to MetaStore for one node to check recovery from WAL.
    metaStorage.write(ENCRYPTION_KEYS_PREFIX + desc.groupId(), new byte[0]);
    dbMgr.checkpointReadUnlock();
    // Put some data after master key change.
    long oldCnt = cnt.get();
    waitForCondition(() -> cnt.get() >= oldCnt + 20, 10_000);
    stop.set(true);
    loadFut.get();
    // 7. Restart node.
    stopGrid(GRID_0, true);
    IgniteEx grid = startGrid(GRID_0);
    grid(GRID_1).resetLostPartitions(Collections.singleton(ENCRYPTED_CACHE));
    // 8. Check that restarted node recoveries keys from WAL. Check data.
    assertEquals(MASTER_KEY_NAME_2, grid(GRID_0).encryption().getMasterKeyName());
    assertEquals(MASTER_KEY_NAME_2, grid(GRID_1).encryption().getMasterKeyName());
    IgniteCache<Long, String> cache0 = grid.cache(cacheName());
    for (long i = 0; i < cnt.get(); i++) {
        assertEquals(String.valueOf(i), cache0.get(i));
        assertEquals(String.valueOf(i), cache1.get(i));
    }
}
Also used : Serializable(java.io.Serializable) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.apache.ignite.transactions.Transaction) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 14 with MetaStorage

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage in project ignite by apache.

the class IgniteWalRecoveryTest method testMetastorage.

/**
 * @throws Exception If fail.
 */
@Test
public void testMetastorage() throws Exception {
    int cnt = 5000;
    IgniteEx ignite0 = (IgniteEx) startGrid("node1");
    IgniteEx ignite1 = (IgniteEx) startGrid("node2");
    ignite1.cluster().active(true);
    GridCacheSharedContext<Object, Object> sharedCtx0 = ignite0.context().cache().context();
    GridCacheSharedContext<Object, Object> sharedCtx1 = ignite1.context().cache().context();
    MetaStorage storage0 = sharedCtx0.database().metaStorage();
    MetaStorage storage1 = sharedCtx1.database().metaStorage();
    assert storage0 != null;
    for (int i = 0; i < cnt; i++) {
        sharedCtx0.database().checkpointReadLock();
        try {
            storage0.writeRaw(String.valueOf(i), new byte[] { (byte) (i % 256), 2, 3 });
        } finally {
            sharedCtx0.database().checkpointReadUnlock();
        }
        byte[] b1 = new byte[i + 3];
        b1[0] = 1;
        b1[1] = 2;
        b1[2] = 3;
        sharedCtx1.database().checkpointReadLock();
        try {
            storage1.writeRaw(String.valueOf(i), b1);
        } finally {
            sharedCtx1.database().checkpointReadUnlock();
        }
    }
    for (int i = 0; i < cnt; i++) {
        byte[] d1 = storage0.readRaw(String.valueOf(i));
        assertEquals(3, d1.length);
        assertEquals((byte) (i % 256), d1[0]);
        assertEquals(2, d1[1]);
        assertEquals(3, d1[2]);
        byte[] d2 = storage1.readRaw(String.valueOf(i));
        assertEquals(i + 3, d2.length);
        assertEquals(1, d2[0]);
        assertEquals(2, d2[1]);
        assertEquals(3, d2[2]);
    }
}
Also used : ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 15 with MetaStorage

use of org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage in project ignite by apache.

the class IgniteWalRecoveryTest method testMetastorageWalRestore.

/**
 * @throws Exception If fail.
 */
@Test
public void testMetastorageWalRestore() throws Exception {
    int cnt = 2000;
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    GridCacheSharedContext<Object, Object> sharedCtx0 = ignite0.context().cache().context();
    MetaStorage storage = sharedCtx0.database().metaStorage();
    assert storage != null;
    for (int i = 0; i < cnt; i++) {
        sharedCtx0.database().checkpointReadLock();
        try {
            storage.writeRaw(String.valueOf(i), new byte[] { 1, 2, 3 });
        } finally {
            sharedCtx0.database().checkpointReadUnlock();
        }
    }
    for (int i = 0; i < cnt; i++) {
        byte[] value = storage.readRaw(String.valueOf(i));
        assert value != null;
        assert value.length == 3;
    }
    stopGrid(0);
    ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    sharedCtx0 = ignite0.context().cache().context();
    storage = sharedCtx0.database().metaStorage();
    assert storage != null;
    for (int i = 0; i < cnt; i++) {
        byte[] value = storage.readRaw(String.valueOf(i));
        assert value != null;
    }
}
Also used : ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Aggregations

MetaStorage (org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage)15 IgniteEx (org.apache.ignite.internal.IgniteEx)9 Test (org.junit.Test)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 ReadableDistributedMetaStorage (org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage)5 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)3 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 StorageException (org.apache.ignite.internal.pagemem.wal.StorageException)2 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)2 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)2 StoredCacheData (org.apache.ignite.internal.processors.cache.StoredCacheData)2 FileWALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.FileWALPointer)2 File (java.io.File)1 FileFilter (java.io.FileFilter)1 RandomAccessFile (java.io.RandomAccessFile)1