Search in sources :

Example 56 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class GridCacheProcessor method startCache.

/**
 * @param cache Cache to start.
 * @param schema Cache schema.
 * @throws IgniteCheckedException If failed to start cache.
 */
@SuppressWarnings({ "TypeMayBeWeakened", "unchecked" })
private void startCache(GridCacheAdapter<?, ?> cache, QuerySchema schema) throws IgniteCheckedException {
    GridCacheContext<?, ?> cacheCtx = cache.context();
    CacheConfiguration cfg = cacheCtx.config();
    // Intentionally compare Boolean references using '!=' below to check if the flag has been explicitly set.
    if (cfg.isStoreKeepBinary() && cfg.isStoreKeepBinary() != CacheConfiguration.DFLT_STORE_KEEP_BINARY && !(ctx.config().getMarshaller() instanceof BinaryMarshaller))
        U.warn(log, "CacheConfiguration.isStoreKeepBinary() configuration property will be ignored because " + "BinaryMarshaller is not used");
    // Start managers.
    for (GridCacheManager mgr : F.view(cacheCtx.managers(), F.notContains(dhtExcludes(cacheCtx)))) mgr.start(cacheCtx);
    cacheCtx.initConflictResolver();
    if (cfg.getCacheMode() != LOCAL && GridCacheUtils.isNearEnabled(cfg)) {
        GridCacheContext<?, ?> dhtCtx = cacheCtx.near().dht().context();
        // Start DHT managers.
        for (GridCacheManager mgr : dhtManagers(dhtCtx)) mgr.start(dhtCtx);
        dhtCtx.initConflictResolver();
        // Start DHT cache.
        dhtCtx.cache().start();
        if (log.isDebugEnabled())
            log.debug("Started DHT cache: " + dhtCtx.cache().name());
    }
    ctx.continuous().onCacheStart(cacheCtx);
    cacheCtx.cache().start();
    ctx.query().onCacheStart(cacheCtx, schema);
    cacheCtx.onStarted();
    String memPlcName = cfg.getDataRegionName();
    if (memPlcName == null && ctx.config().getDataStorageConfiguration() != null)
        memPlcName = ctx.config().getDataStorageConfiguration().getDefaultDataRegionConfiguration().getName();
    if (log.isInfoEnabled()) {
        log.info("Started cache [name=" + cfg.getName() + ", id=" + cacheCtx.cacheId() + (cfg.getGroupName() != null ? ", group=" + cfg.getGroupName() : "") + ", memoryPolicyName=" + memPlcName + ", mode=" + cfg.getCacheMode() + ", atomicity=" + cfg.getAtomicityMode() + ", backups=" + cfg.getBackups() + ']');
    }
}
Also used : GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 57 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    if (marsh instanceof BinaryMarshaller) {
        if (ctx.clientNode())
            ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED);
        if (!ctx.clientNode())
            metadataFileStore = new BinaryMetadataFileStore(metadataLocCache, ctx, log, binaryMetadataFileStoreDir);
        transport = new BinaryMetadataTransport(metadataLocCache, metadataFileStore, ctx, log);
        BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {

            @Override
            public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
                assert newMeta != null;
                assert newMeta instanceof BinaryTypeImpl;
                if (!discoveryStarted) {
                    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
                    BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;
                    BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, ((BinaryTypeImpl) newMeta).metadata());
                    if (oldMeta != mergedMeta)
                        metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
                    return;
                }
                BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
                CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(binaryCtx));
            }

            @Override
            public BinaryType metadata(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
            }

            @Override
            public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
            }

            @Override
            public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
            }
        };
        BinaryMarshaller bMarsh0 = (BinaryMarshaller) marsh;
        binaryCtx = new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
        IgniteUtils.invoke(BinaryMarshaller.class, bMarsh0, "setBinaryContext", binaryCtx, ctx.config());
        binaryMarsh = new GridBinaryMarshaller(binaryCtx);
        binaries = new IgniteBinaryImpl(ctx, this);
        if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
            BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();
            if (bCfg != null) {
                Map<String, Object> map = new HashMap<>();
                map.put("globIdMapper", bCfg.getIdMapper() != null ? bCfg.getIdMapper().getClass().getName() : null);
                map.put("globSerializer", bCfg.getSerializer() != null ? bCfg.getSerializer().getClass() : null);
                map.put("compactFooter", bCfg.isCompactFooter());
                if (bCfg.getTypeConfigurations() != null) {
                    Map<Object, Object> typeCfgsMap = new HashMap<>();
                    for (BinaryTypeConfiguration c : bCfg.getTypeConfigurations()) {
                        typeCfgsMap.put(c.getTypeName() != null, Arrays.asList(c.getIdMapper() != null ? c.getIdMapper().getClass() : null, c.getSerializer() != null ? c.getSerializer().getClass() : null, c.isEnum()));
                        if (c.isEnum())
                            BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
                    }
                    map.put("typeCfgs", typeCfgsMap);
                }
                ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
            }
        }
        if (!ctx.clientNode())
            metadataFileStore.restoreMetadata();
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryType(org.apache.ignite.binary.BinaryType) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BinaryMetadataHandler(org.apache.ignite.internal.binary.BinaryMetadataHandler) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 58 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method contextForCache.

/**
 * {@inheritDoc}
 */
@Override
public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException {
    assert cfg != null;
    boolean binaryEnabled = marsh instanceof BinaryMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) && !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName());
    CacheObjectContext ctx0 = super.contextForCache(cfg);
    CacheObjectContext res = new CacheObjectBinaryContext(ctx, cfg, ctx0.copyOnGet(), ctx0.storeValue(), binaryEnabled, ctx0.addDeploymentInfo());
    ctx.resource().injectGeneric(res.defaultAffMapper());
    return res;
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 59 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class PlatformCppConfigurationClosure method apply0.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("deprecation")
@Override
protected void apply0(IgniteConfiguration igniteCfg) {
    // 3. Validate and copy Interop configuration setting environment pointer along the way.
    PlatformConfiguration interopCfg = igniteCfg.getPlatformConfiguration();
    if (interopCfg != null && !(interopCfg instanceof PlatformCppConfiguration))
        throw new IgniteException("Illegal interop configuration (must be of type " + PlatformCppConfiguration.class.getName() + "): " + interopCfg.getClass().getName());
    PlatformCppConfiguration cppCfg = interopCfg != null ? (PlatformCppConfiguration) interopCfg : null;
    if (cppCfg == null)
        cppCfg = new PlatformCppConfiguration();
    PlatformMemoryManagerImpl memMgr = new PlatformMemoryManagerImpl(gate, 1024);
    PlatformCppConfigurationEx cppCfg0 = new PlatformCppConfigurationEx(cppCfg, gate, memMgr);
    igniteCfg.setPlatformConfiguration(cppCfg0);
    // Check marshaller
    Marshaller marsh = igniteCfg.getMarshaller();
    if (marsh == null) {
        igniteCfg.setMarshaller(new BinaryMarshaller());
        cppCfg0.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
    } else if (!(marsh instanceof BinaryMarshaller))
        throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite C++): " + marsh.getClass().getName());
    BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
    if (bCfg == null) {
        bCfg = new BinaryConfiguration();
        bCfg.setCompactFooter(false);
        bCfg.setNameMapper(new BinaryBasicNameMapper(true));
        bCfg.setIdMapper(new BinaryBasicIdMapper(true));
        igniteCfg.setBinaryConfiguration(bCfg);
        cppCfg0.warnings(Collections.singleton("Binary configuration is automatically initiated, " + "note that binary name mapper is set to " + bCfg.getNameMapper() + " and binary ID mapper is set to " + bCfg.getIdMapper() + " (other nodes must have the same binary name and ID mapper types)."));
    } else {
        BinaryNameMapper nameMapper = bCfg.getNameMapper();
        if (nameMapper == null) {
            bCfg.setNameMapper(new BinaryBasicNameMapper(true));
            cppCfg0.warnings(Collections.singleton("Binary name mapper is automatically set to " + bCfg.getNameMapper() + " (other nodes must have the same binary name mapper type)."));
        }
        BinaryIdMapper idMapper = bCfg.getIdMapper();
        if (idMapper == null) {
            bCfg.setIdMapper(new BinaryBasicIdMapper(true));
            cppCfg0.warnings(Collections.singleton("Binary ID mapper is automatically set to " + bCfg.getIdMapper() + " (other nodes must have the same binary ID mapper type)."));
        }
    }
    if (bCfg.isCompactFooter())
        throw new IgniteException("Unsupported " + BinaryMarshaller.class.getName() + " \"compactFooter\" flag: must be false when running Apache Ignite C++.");
    // Set Ignite home so that marshaller context works.
    String ggHome = igniteCfg.getIgniteHome();
    if (ggHome != null)
        U.setIgniteHome(ggHome);
}
Also used : PlatformConfiguration(org.apache.ignite.configuration.PlatformConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformCppConfiguration(org.apache.ignite.platform.cpp.PlatformCppConfiguration) IgniteException(org.apache.ignite.IgniteException) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryNameMapper(org.apache.ignite.binary.BinaryNameMapper) PlatformMemoryManagerImpl(org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl)

Example 60 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class PlatformDotNetConfigurationClosure method setBinaryConfiguration.

/**
 * Sets binary config.
 *
 * @param igniteCfg Ignite config.
 * @param dotNetCfg .NET config.
 */
private void setBinaryConfiguration(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx dotNetCfg) {
    // Check marshaller.
    Marshaller marsh = igniteCfg.getMarshaller();
    if (marsh == null) {
        igniteCfg.setMarshaller(new BinaryMarshaller());
        dotNetCfg.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
    } else if (!(marsh instanceof BinaryMarshaller))
        throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite.NET): " + marsh.getClass().getName());
    BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) IgniteException(org.apache.ignite.IgniteException)

Aggregations

BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)93 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)61 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)34 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)14 Ignite (org.apache.ignite.Ignite)9 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)9 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)8 ArrayList (java.util.ArrayList)7 BinaryObject (org.apache.ignite.binary.BinaryObject)7 Marshaller (org.apache.ignite.marshaller.Marshaller)7 IgniteException (org.apache.ignite.IgniteException)6 NullLogger (org.apache.ignite.logger.NullLogger)6 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)6 HashMap (java.util.HashMap)5 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)5 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)5 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)4