Search in sources :

Example 1 with StandaloneGridKernalContext

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext in project ignite by apache.

the class CdcMain method runX.

/**
 * Runs Change Data Capture application with possible exception.
 */
public void runX() throws Exception {
    ackAsciiLogo();
    if (!CU.isPersistenceEnabled(igniteCfg)) {
        log.error(ERR_MSG);
        throw new IllegalArgumentException(ERR_MSG);
    }
    try (CdcFileLockHolder lock = lockPds()) {
        String consIdDir = cdcDir.getName(cdcDir.getNameCount() - 1).toString();
        Files.createDirectories(cdcDir.resolve(STATE_DIR));
        binaryMeta = CacheObjectBinaryProcessorImpl.binaryWorkDir(igniteCfg.getWorkDirectory(), consIdDir);
        marshaller = MarshallerContextImpl.mappingFileStoreWorkDir(igniteCfg.getWorkDirectory());
        if (log.isInfoEnabled()) {
            log.info("Change Data Capture [dir=" + cdcDir + ']');
            log.info("Ignite node Binary meta [dir=" + binaryMeta + ']');
            log.info("Ignite node Marshaller [dir=" + marshaller + ']');
        }
        StandaloneGridKernalContext kctx = startStandaloneKernal();
        initMetrics();
        try {
            kctx.resource().injectGeneric(consumer.consumer());
            state = createState(cdcDir.resolve(STATE_DIR));
            initState = state.load();
            if (initState != null) {
                committedSegmentIdx.value(initState.index());
                committedSegmentOffset.value(initState.fileOffset());
                if (log.isInfoEnabled())
                    log.info("Initial state loaded [state=" + initState + ']');
            }
            consumer.start(mreg, kctx.metric().registry(metricName("cdc", "consumer")));
            try {
                consumeWalSegmentsUntilStopped();
            } finally {
                consumer.stop();
                if (log.isInfoEnabled())
                    log.info("Ignite Change Data Capture Application stopped.");
            }
        } finally {
            for (GridComponent comp : kctx) comp.stop(false);
        }
    }
}
Also used : GridComponent(org.apache.ignite.internal.GridComponent) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext)

Example 2 with StandaloneGridKernalContext

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext in project ignite by apache.

the class IgniteWalIteratorSwitchSegmentTest method checkInvariantSwitchSegmentSize.

/**
 * @param serVer WAL serializer version.
 * @throws Exception If some thing failed.
 */
private void checkInvariantSwitchSegmentSize(int serVer) throws Exception {
    GridKernalContext kctx = new StandaloneGridKernalContext(log, null, null) {

        @Override
        public IgniteCacheObjectProcessor cacheObjects() {
            return new CacheObjectBinaryProcessorImpl(this);
        }
    };
    RecordSerializer serializer = new RecordSerializerFactoryImpl(new GridCacheSharedContext<>(kctx, null, null, null, null, null, null, new IgniteCacheDatabaseSharedManager() {

        @Override
        public int pageSize() {
            return DataStorageConfiguration.DFLT_PAGE_SIZE;
        }
    }, null, null, null, null, null, null, null, null, null, null, null, null, null)).createSerializer(serVer);
    SwitchSegmentRecord switchSegmentRecord = new SwitchSegmentRecord();
    int recordSize = serializer.size(switchSegmentRecord);
    Assert.assertEquals(1, recordSize);
}
Also used : SwitchSegmentRecord(org.apache.ignite.internal.pagemem.wal.record.SwitchSegmentRecord) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) GridKernalContext(org.apache.ignite.internal.GridKernalContext) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) RecordSerializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 3 with StandaloneGridKernalContext

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext in project ignite by apache.

the class CdcMain method startStandaloneKernal.

/**
 * @return Kernal instance.
 * @throws IgniteCheckedException If failed.
 */
private StandaloneGridKernalContext startStandaloneKernal() throws IgniteCheckedException {
    StandaloneGridKernalContext kctx = new StandaloneGridKernalContext(log, binaryMeta, marshaller) {

        @Override
        protected IgniteConfiguration prepareIgniteConfiguration() {
            IgniteConfiguration cfg = super.prepareIgniteConfiguration();
            cfg.setIgniteInstanceName(cdcInstanceName(igniteCfg.getIgniteInstanceName()));
            if (!F.isEmpty(cdcCfg.getMetricExporterSpi()))
                cfg.setMetricExporterSpi(cdcCfg.getMetricExporterSpi());
            initializeDefaultMBeanServer(cfg);
            return cfg;
        }
    };
    kctx.resource().setSpringContext(ctx);
    for (GridComponent comp : kctx) comp.start();
    mreg = kctx.metric().registry("cdc");
    return kctx;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridComponent(org.apache.ignite.internal.GridComponent) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext)

Example 4 with StandaloneGridKernalContext

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext in project ignite by apache.

the class MaintenanceRegistrySimpleTest method initContext.

/**
 */
private GridKernalContext initContext(boolean persistenceEnabled) throws IgniteCheckedException {
    String dfltWorkDir = U.defaultWorkDirectory();
    GridKernalContext kctx = new StandaloneGridKernalContext(log, null, null) {

        @Override
        protected IgniteConfiguration prepareIgniteConfiguration() {
            IgniteConfiguration cfg = super.prepareIgniteConfiguration();
            cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistenceEnabled)));
            return cfg;
        }

        @Override
        public PdsFoldersResolver pdsFolderResolver() {
            return new PdsFoldersResolver() {

                @Override
                public PdsFolderSettings resolveFolders() {
                    return new PdsFolderSettings(new File(dfltWorkDir), U.maskForFileName(""));
                }
            };
        }
    };
    return kctx;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridKernalContext(org.apache.ignite.internal.GridKernalContext) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) PdsFoldersResolver(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) File(java.io.File) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext)

Example 5 with StandaloneGridKernalContext

use of org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext in project ignite by apache.

the class IgniteWalIteratorSwitchSegmentTest method initiate.

/**
 * Initiate WAL manager.
 *
 * @param serVer WAL serializer version.
 * @param workDir Work directory path.
 * @return Tuple of WAL manager and WAL record serializer.
 * @throws IgniteCheckedException If some think failed.
 */
private T2<IgniteWriteAheadLogManager, RecordSerializer> initiate(int serVer, String workDir) throws IgniteCheckedException {
    GridKernalContext kctx = new StandaloneGridKernalContext(log, null, null) {

        @Override
        protected IgniteConfiguration prepareIgniteConfiguration() {
            IgniteConfiguration cfg = super.prepareIgniteConfiguration();
            cfg.setDataStorageConfiguration(new DataStorageConfiguration().setWalSegmentSize(SEGMENT_SIZE).setWalRecordIteratorBufferSize(SEGMENT_SIZE / 2).setWalMode(WALMode.FSYNC).setWalPath(workDir + WORK_SUB_DIR).setWalArchivePath(workDir + ARCHIVE_SUB_DIR).setFileIOFactory(new RandomAccessFileIOFactory()));
            cfg.setEventStorageSpi(new NoopEventStorageSpi());
            return cfg;
        }

        @Override
        public GridInternalSubscriptionProcessor internalSubscriptionProcessor() {
            return new GridInternalSubscriptionProcessor(this);
        }

        @Override
        public GridEventStorageManager event() {
            return new GridEventStorageManager(this);
        }
    };
    IgniteWriteAheadLogManager walMgr = new FileWriteAheadLogManager(kctx);
    GridTestUtils.setFieldValue(walMgr, "serializerVer", serVer);
    GridCacheSharedContext<?, ?> ctx = new GridCacheSharedContext<>(kctx, null, null, null, null, walMgr, new WalStateManager(kctx), new GridCacheDatabaseSharedManager(kctx), null, null, null, null, null, new GridCacheIoManager(), null, null, null, null, null, null, null);
    walMgr.start(ctx);
    walMgr.onActivate(kctx);
    walMgr.resumeLogging(null);
    RecordSerializer recordSerializer = new RecordSerializerFactoryImpl(ctx).createSerializer(walMgr.serializerVersion());
    return new T2<>(walMgr, recordSerializer);
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RecordSerializerFactoryImpl(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl) WalStateManager(org.apache.ignite.internal.processors.cache.WalStateManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) GridCacheIoManager(org.apache.ignite.internal.processors.cache.GridCacheIoManager) RecordSerializer(org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer) T2(org.apache.ignite.internal.util.typedef.T2) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)

Aggregations

StandaloneGridKernalContext (org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 GridKernalContext (org.apache.ignite.internal.GridKernalContext)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 GridComponent (org.apache.ignite.internal.GridComponent)2 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)2 RecordSerializer (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializer)2 RecordSerializerFactoryImpl (org.apache.ignite.internal.processors.cache.persistence.wal.serializer.RecordSerializerFactoryImpl)2 File (java.io.File)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 GridEventStorageManager (org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager)1 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)1 SwitchSegmentRecord (org.apache.ignite.internal.pagemem.wal.record.SwitchSegmentRecord)1 GridCacheIoManager (org.apache.ignite.internal.processors.cache.GridCacheIoManager)1 WalStateManager (org.apache.ignite.internal.processors.cache.WalStateManager)1 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 RandomAccessFileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)1 PdsFolderSettings (org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings)1