Search in sources :

Example 6 with BinaryTypeImpl

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

the class PlatformContextImpl method writeMetadata0.

/**
 * Write binary metadata.
 *
 * @param writer Writer.
 * @param meta Metadata.
 */
private void writeMetadata0(BinaryRawWriterEx writer, BinaryType meta) {
    if (meta == null)
        writer.writeBoolean(false);
    else {
        writer.writeBoolean(true);
        BinaryMetadata meta0 = ((BinaryTypeImpl) meta).metadata();
        PlatformUtils.writeBinaryMetadata(writer, meta0, false);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 7 with BinaryTypeImpl

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

the class PlatformContextImpl method writeMetadata0.

/**
 * Write binary metadata.
 *
 * @param writer Writer.
 * @param meta Metadata.
 */
private void writeMetadata0(BinaryRawWriterEx writer, BinaryType meta, boolean includeSchemas) {
    if (meta == null)
        writer.writeBoolean(false);
    else {
        writer.writeBoolean(true);
        BinaryMetadata meta0 = ((BinaryTypeImpl) meta).metadata();
        PlatformUtils.writeBinaryMetadata(writer, meta0, includeSchemas);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 8 with BinaryTypeImpl

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

the class CacheObjectBinaryProcessorImpl method addMetaLocally.

/**
 * {@inheritDoc}
 */
@Override
public void addMetaLocally(int typeId, BinaryType newMeta) throws BinaryObjectException {
    assert newMeta != null;
    assert newMeta instanceof BinaryTypeImpl;
    BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
    BinaryMetadataHolder metaHolder = metadataLocCache.get(typeId);
    BinaryMetadata oldMeta = metaHolder != null ? metaHolder.metadata() : null;
    try {
        BinaryMetadata mergedMeta = mergeMetadata(oldMeta, newMeta0);
        if (!ctx.clientNode())
            metadataFileStore.mergeAndWriteMetadata(mergedMeta);
        metadataLocCache.put(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
    } catch (BinaryObjectException e) {
        throw new BinaryObjectException("New binary metadata is incompatible with binary metadata" + " persisted locally." + " Consider cleaning up persisted metadata from <workDir>/db/binary_meta directory.", e);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 9 with BinaryTypeImpl

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

the class CacheObjectBinaryProcessorImpl method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    if (marsh instanceof BinaryMarshaller) {
        if (!ctx.clientNode()) {
            metadataFileStore = new BinaryMetadataFileStore(metadataLocCache, ctx, log, CU.isPersistenceEnabled(ctx.config()) && binaryMetadataFileStoreDir == null ? resolveBinaryWorkDir(ctx.config().getWorkDirectory(), ctx.pdsFolderResolver().resolveFolders().folderName()) : binaryMetadataFileStoreDir);
            metadataFileStore.start();
        }
        BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {

            @Override
            public void addMeta(int typeId, BinaryType newMeta, boolean failIfUnregistered) 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 = 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), failIfUnregistered);
            }

            @Override
            public void addMetaLocally(int typeId, BinaryType meta, boolean failIfUnregistered) throws BinaryObjectException {
                CacheObjectBinaryProcessorImpl.this.addMetaLocally(typeId, meta);
            }

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

            @Override
            public Collection<BinaryType> metadata() throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata();
            }
        };
        BinaryMarshaller bMarsh0 = (BinaryMarshaller) marsh;
        binaryCtx = useTestBinaryCtx ? new TestBinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class)) : new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
        transport = new BinaryMetadataTransport(metadataLocCache, metadataFileStore, binaryCtx, ctx, log);
        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) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) 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) IncompleteCacheObject(org.apache.ignite.internal.processors.cache.IncompleteCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 10 with BinaryTypeImpl

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

the class CacheObjectBinaryProcessorImpl method addMeta.

/**
 * {@inheritDoc}
 */
@Override
public void addMeta(final int typeId, final BinaryType newMeta, boolean failIfUnregistered) throws BinaryObjectException {
    assert newMeta != null;
    assert newMeta instanceof BinaryTypeImpl;
    BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
    if (failIfUnregistered) {
        failIfUnregistered(typeId, newMeta0);
        return;
    }
    try {
        GridFutureAdapter<MetadataUpdateResult> fut = transport.requestMetadataUpdate(newMeta0);
        if (fut == null) {
            if (log.isDebugEnabled()) {
                log.debug("Metadata update was skipped [typeId=" + typeId + ", typeName=" + newMeta.typeName() + ']');
            }
            return;
        }
        long t0 = System.nanoTime();
        MetadataUpdateResult res = fut.get();
        if (log.isDebugEnabled()) {
            IgniteInternalTx tx = ctx.cache().context().tm().tx();
            log.debug("Completed metadata update [typeId=" + typeId + ", typeName=" + newMeta.typeName() + ", waitTime=" + MILLISECONDS.convert(System.nanoTime() - t0, NANOSECONDS) + "ms" + ", fut=" + fut + ", tx=" + CU.txString(tx) + ']');
        }
        assert res != null;
        if (res.rejected())
            throw res.error();
        else if (!ctx.clientNode())
            metadataFileStore.waitForWriteCompletion(typeId, res.typeVersion());
    } catch (IgniteCheckedException e) {
        IgniteCheckedException ex = e;
        if (ctx.isStopping()) {
            ex = new NodeStoppingException("Node is stopping.");
            ex.addSuppressed(e);
        }
        throw new BinaryObjectException("Failed to update metadata for type: " + newMeta.typeName(), ex);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)11 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)9 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryType (org.apache.ignite.binary.BinaryType)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 BinaryMetadataHandler (org.apache.ignite.internal.binary.BinaryMetadataHandler)2 BinarySchema (org.apache.ignite.internal.binary.BinarySchema)2 BinarySchemaRegistry (org.apache.ignite.internal.binary.BinarySchemaRegistry)2 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1