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);
}
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations