Search in sources :

Example 66 with CacheDataRow

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

the class IgniteSnapshotManagerSelfTest method testSnapshotIteratorLargeRows.

/**
 * @throws Exception If fails.
 */
@Test
public void testSnapshotIteratorLargeRows() throws Exception {
    int keys = 2;
    CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<Integer, Value>(DEFAULT_CACHE_NAME)).setAffinity(new RendezvousAffinityFunction(false, 1));
    IgniteEx ignite = startGridsWithoutCache(2);
    assertEquals(DFLT_PAGE_SIZE, ignite.configuration().getDataStorageConfiguration().getPageSize());
    for (int i = 0; i < keys; i++) ignite.getOrCreateCache(ccfg).put(i, new Value(new byte[SIZE_FOR_FIT_3_PAGES]));
    forceCheckpoint();
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    int rows = 0;
    try (GridCloseableIterator<CacheDataRow> iter = snp(ignite).partitionRowIterator(ignite.context(), SNAPSHOT_NAME, ignite.context().pdsFolderResolver().resolveFolders().folderName(), dfltCacheCfg.getName(), 0)) {
        CacheObjectContext coctx = ignite.cachex(dfltCacheCfg.getName()).context().cacheObjectContext();
        while (iter.hasNext()) {
            CacheDataRow row = iter.next();
            assertEquals(SIZE_FOR_FIT_3_PAGES, ((Value) row.value().value(coctx, false)).arr().length);
            assertTrue((Integer) row.key().value(coctx, false, null) < 2);
            rows++;
        }
    }
    assertEquals("Invalid number of rows: " + rows, keys, rows);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteEx(org.apache.ignite.internal.IgniteEx) GridTestUtils.setFieldValue(org.apache.ignite.testframework.GridTestUtils.setFieldValue) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 67 with CacheDataRow

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

the class SchemaIndexCachePartitionWorker method processPartition.

/**
 * Process partition.
 *
 * @throws IgniteCheckedException If failed.
 */
private void processPartition() throws IgniteCheckedException {
    if (stop())
        return;
    checkCancelled();
    boolean reserved = false;
    GridDhtPartitionState partState = locPart.state();
    if (partState != EVICTED)
        reserved = (partState == OWNING || partState == MOVING || partState == LOST) && locPart.reserve();
    if (!reserved)
        return;
    try {
        GridCursor<? extends CacheDataRow> cursor = locPart.dataStore().cursor(cctx.cacheId(), null, null, KEY_ONLY);
        boolean locked = false;
        try {
            int cntr = 0;
            while (!stop() && cursor.next()) {
                KeyCacheObject key = cursor.get().key();
                if (!locked) {
                    cctx.shared().database().checkpointReadLock();
                    locked = true;
                }
                processKey(key);
                if (++cntr % batchSize == 0) {
                    cctx.shared().database().checkpointReadUnlock();
                    locked = false;
                }
                cctx.cache().metrics0().addIndexRebuildKeyProcessed(1);
                if (locPart.state() == RENTING)
                    break;
            }
            wrappedClo.addNumberProcessedKeys(cntr);
        } finally {
            if (locked)
                cctx.shared().database().checkpointReadUnlock();
        }
    } finally {
        locPart.release();
        if (partsCnt.getAndUpdate(v -> v > 0 ? v - 1 : 0) > 0)
            cctx.group().metrics().decrementIndexBuildCountPartitionsLeft();
    }
}
Also used : IgniteSystemProperties.getBoolean(org.apache.ignite.IgniteSystemProperties.getBoolean) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) S(org.apache.ignite.internal.util.typedef.internal.S) MOVING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.MOVING) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) EVICTED(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.EVICTED) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING(org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING) QueryTypeDescriptorImpl(org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Nullable(org.jetbrains.annotations.Nullable) KEY_ONLY(org.apache.ignite.internal.processors.cache.persistence.CacheDataRowAdapter.RowData.KEY_ONLY) LOST(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.LOST) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Objects.nonNull(java.util.Objects.nonNull) IGNITE_INDEX_REBUILD_BATCH_SIZE(org.apache.ignite.IgniteSystemProperties.IGNITE_INDEX_REBUILD_BATCH_SIZE) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) RENTING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.RENTING) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 68 with CacheDataRow

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

the class CacheFreeListSelfTest method checkInsertDeleteSingleThreaded.

/**
 * @param pageSize Page size.
 * @param batched Batch mode flag.
 * @throws Exception if failed.
 */
protected void checkInsertDeleteSingleThreaded(int pageSize, boolean batched) throws Exception {
    FreeList<CacheDataRow> list = createFreeList(pageSize);
    Random rnd = new Random();
    Map<Long, CacheDataRow> stored = new HashMap<>();
    for (int i = 0; i < 100; i++) {
        int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
        int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
        TestDataRow row = new TestDataRow(keySize, valSize);
        list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
        assertTrue(row.link() != 0L);
        CacheDataRow old = stored.put(row.link(), row);
        assertNull(old);
    }
    boolean grow = true;
    List<CacheDataRow> rows = new ArrayList<>(BATCH_SIZE);
    for (int i = 0; i < 1_000_000; i++) {
        if (grow) {
            if (stored.size() > 20_000) {
                grow = false;
                info("Shrink... [" + stored.size() + ']');
            }
        } else {
            if (stored.size() < 1_000) {
                grow = true;
                info("Grow... [" + stored.size() + ']');
            }
        }
        boolean insert = rnd.nextInt(100) < 70 == grow;
        if (insert) {
            int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
            int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
            TestDataRow row = new TestDataRow(keySize, valSize);
            if (batched) {
                rows.add(row);
                if (rows.size() == BATCH_SIZE) {
                    list.insertDataRows(rows, IoStatisticsHolderNoOp.INSTANCE);
                    for (CacheDataRow row0 : rows) {
                        assertTrue(row0.link() != 0L);
                        CacheDataRow old = stored.put(row0.link(), row0);
                        assertNull(old);
                    }
                    rows.clear();
                }
                continue;
            }
            list.insertDataRow(row, IoStatisticsHolderNoOp.INSTANCE);
            assertTrue(row.link() != 0L);
            CacheDataRow old = stored.put(row.link(), row);
            assertNull(old);
        } else {
            Iterator<CacheDataRow> it = stored.values().iterator();
            if (it.hasNext()) {
                CacheDataRow row = it.next();
                CacheDataRow rmvd = stored.remove(row.link());
                assertTrue(rmvd == row);
                list.removeDataRowByLink(row.link(), IoStatisticsHolderNoOp.INSTANCE);
            }
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 69 with CacheDataRow

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

the class VisorFindAndDeleteGarbageInPersistenceClosure method processPartition.

/**
 * @param grpCtx Group context.
 * @param part Local partition.
 */
private Map<Integer, Map<Integer, Long>> processPartition(CacheGroupContext grpCtx, GridDhtLocalPartition part) {
    if (!part.reserve())
        return Collections.emptyMap();
    Map<Integer, Map<Integer, Long>> stoppedCachesForGrpId = new HashMap<>();
    try {
        if (part.state() != GridDhtPartitionState.OWNING)
            return Collections.emptyMap();
        GridIterator<CacheDataRow> it = grpCtx.offheap().partitionIterator(part.id());
        while (it.hasNextX()) {
            CacheDataRow row = it.nextX();
            if (row.cacheId() == 0)
                break;
            int cacheId = row.cacheId();
            GridCacheContext cacheCtx = grpCtx.shared().cacheContext(row.cacheId());
            if (cacheCtx == null)
                stoppedCachesForGrpId.computeIfAbsent(grpCtx.groupId(), (x) -> new HashMap<>()).compute(cacheId, (x, y) -> y == null ? 1 : y + 1);
        }
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to process partition [grpId=" + grpCtx.groupId() + ", partId=" + part.id() + "]", e);
        return Collections.emptyMap();
    } finally {
        part.release();
    }
    processedPartitions.incrementAndGet();
    printProgressIfNeeded();
    return stoppedCachesForGrpId;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) LoggerResource(org.apache.ignite.resources.LoggerResource) ExecutorService(java.util.concurrent.ExecutorService) F(org.apache.ignite.internal.util.typedef.F) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) T2(org.apache.ignite.internal.util.typedef.T2) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Collections(java.util.Collections) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 70 with CacheDataRow

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

the class WalRecoveryTxLogicalRecordsTest method rows.

/**
 * @param ignite Ignite.
 * @param part Partition.
 * @param from From counter.
 * @param to To counter.
 */
private List<CacheDataRow> rows(Ignite ignite, int part, long from, long to) throws IgniteCheckedException {
    CacheGroupContext grp = ((IgniteEx) ignite).context().cache().cacheGroup(CU.cacheId(CACHE_NAME));
    IgniteCacheOffheapManager offh = grp.offheap();
    AffinityTopologyVersion topVer = grp.affinity().lastVersion();
    IgniteDhtDemandedPartitionsMap map = new IgniteDhtDemandedPartitionsMap();
    map.addHistorical(part, from, to, PARTS);
    List<CacheDataRow> rows = new ArrayList<>();
    WALPointer ptr = reserveWalPointerForIterator(grp.shared());
    try (IgniteRebalanceIterator it = offh.rebalanceIterator(map, topVer)) {
        assertNotNull(it);
        while (it.hasNextX()) rows.add(it.next());
    } finally {
        releaseWalPointerForIterator(grp.shared(), ptr);
    }
    return rows;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteDhtDemandedPartitionsMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) IgniteRebalanceIterator(org.apache.ignite.internal.processors.cache.IgniteRebalanceIterator) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Aggregations

CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)78 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)35 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)20 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)16 ArrayList (java.util.ArrayList)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 IgniteException (org.apache.ignite.IgniteException)14 Nullable (org.jetbrains.annotations.Nullable)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)11 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)11 HashMap (java.util.HashMap)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)10 HashSet (java.util.HashSet)9 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)9 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)8 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)8 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)7