Search in sources :

Example 21 with BinaryMetadata

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

the class CacheObjectBinaryProcessorImpl method updateMetadata.

/**
 * {@inheritDoc}
 */
@Override
public void updateMetadata(int typeId, String typeName, @Nullable String affKeyFieldName, Map<String, BinaryFieldMetadata> fieldTypeIds, boolean isEnum, @Nullable Map<String, Integer> enumMap) throws BinaryObjectException {
    BinaryMetadata meta = new BinaryMetadata(typeId, typeName, fieldTypeIds, affKeyFieldName, null, isEnum, enumMap);
    binaryCtx.updateMetadata(typeId, meta, false);
}
Also used : BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 22 with BinaryMetadata

use of org.apache.ignite.internal.binary.BinaryMetadata 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 23 with BinaryMetadata

use of org.apache.ignite.internal.binary.BinaryMetadata 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 24 with BinaryMetadata

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

the class CacheObjectBinaryProcessorImpl method buildEnum.

/**
 * {@inheritDoc}
 */
@Override
public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException {
    A.notNullOrEmpty(typeName, "enum type name");
    A.notNullOrEmpty(name, "enum name");
    int typeId = binaryCtx.typeId(typeName);
    BinaryMetadata metadata = metadata0(typeId);
    if (metadata == null)
        throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']");
    Integer ordinal = metadata.getEnumOrdinalByName(name);
    typeName = binaryCtx.userTypeName(typeName);
    if (ordinal == null)
        throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']");
    return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal);
}
Also used : BinaryEnumObjectImpl(org.apache.ignite.internal.binary.BinaryEnumObjectImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 25 with BinaryMetadata

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

the class CacheObjectBinaryProcessorImpl method updateMetadata.

/**
 * {@inheritDoc}
 */
@Override
public void updateMetadata(File metadataDir, BooleanSupplier stopChecker) throws IgniteCheckedException {
    if (!metadataDir.exists())
        return;
    try {
        ConcurrentMap<Integer, BinaryMetadataHolder> metaCache = new ConcurrentHashMap<>();
        new BinaryMetadataFileStore(metaCache, ctx, log, metadataDir).restoreMetadata();
        Collection<BinaryMetadata> metadata = F.viewReadOnly(metaCache.values(), BinaryMetadataHolder::metadata);
        // Check the compatibility of the binary metadata.
        for (BinaryMetadata newMeta : metadata) {
            BinaryMetadata oldMeta = binaryMetadata(newMeta.typeId());
            if (oldMeta != null)
                BinaryUtils.mergeMetadata(oldMeta, newMeta, null);
        }
        // Update cluster metadata.
        for (BinaryMetadata newMeta : metadata) {
            if (stopChecker.getAsBoolean())
                return;
            if (Thread.interrupted())
                throw new IgniteInterruptedCheckedException("Thread has been interrupted.");
            addMeta(newMeta.typeId(), newMeta.wrap(binaryContext()), false);
        }
    } catch (BinaryObjectException e) {
        throw new IgniteCheckedException(e);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)32 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)11 HashMap (java.util.HashMap)9 BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 BinaryObject (org.apache.ignite.binary.BinaryObject)6 LinkedHashMap (java.util.LinkedHashMap)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 IgniteException (org.apache.ignite.IgniteException)3 BinaryFieldMetadata (org.apache.ignite.internal.binary.BinaryFieldMetadata)3 Array (java.lang.reflect.Array)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2