Search in sources :

Example 1 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 typeId Type id.
     * @param meta Metadata.
     */
private void writeMetadata0(BinaryRawWriterEx writer, int typeId, BinaryType meta) {
    if (meta == null)
        writer.writeBoolean(false);
    else {
        writer.writeBoolean(true);
        BinaryMetadata meta0 = ((BinaryTypeImpl) meta).metadata();
        Map<String, BinaryFieldMetadata> fields = meta0.fieldsMap();
        writer.writeInt(typeId);
        writer.writeString(meta.typeName());
        writer.writeString(meta.affinityKeyFieldName());
        writer.writeInt(fields.size());
        for (Map.Entry<String, BinaryFieldMetadata> e : fields.entrySet()) {
            writer.writeString(e.getKey());
            writer.writeInt(e.getValue().typeId());
            writer.writeInt(e.getValue().fieldId());
        }
        if (meta.isEnum()) {
            writer.writeBoolean(true);
            Map<String, Integer> enumMap = meta0.enumMap();
            writer.writeInt(enumMap.size());
            for (Map.Entry<String, Integer> e : enumMap.entrySet()) {
                writer.writeString(e.getKey());
                writer.writeInt(e.getValue());
            }
        } else
            writer.writeBoolean(false);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with BinaryTypeImpl

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

the class PlatformContextImpl method writeSchema.

/** {@inheritDoc} */
@Override
public void writeSchema(BinaryRawWriterEx writer, int typeId, int schemaId) {
    BinarySchemaRegistry schemaReg = cacheObjProc.binaryContext().schemaRegistry(typeId);
    BinarySchema schema = schemaReg.schema(schemaId);
    if (schema == null) {
        BinaryTypeImpl meta = (BinaryTypeImpl) cacheObjProc.metadata(typeId);
        if (meta != null) {
            for (BinarySchema typeSchema : meta.metadata().schemas()) {
                if (schemaId == typeSchema.schemaId()) {
                    schema = typeSchema;
                    break;
                }
            }
        }
        if (schema != null)
            schemaReg.addSchema(schemaId, schema);
    }
    int[] fieldIds = schema == null ? null : schema.fieldIds();
    writer.writeIntArray(fieldIds);
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinarySchema(org.apache.ignite.internal.binary.BinarySchema) BinarySchemaRegistry(org.apache.ignite.internal.binary.BinarySchemaRegistry)

Example 3 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) throws BinaryObjectException {
    assert newMeta != null;
    assert newMeta instanceof BinaryTypeImpl;
    BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
    try {
        BinaryMetadataHolder metaHolder = metadataLocCache.get(typeId);
        BinaryMetadata oldMeta = metaHolder != null ? metaHolder.metadata() : null;
        BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
        // metadata requested to be added is exactly the same as already presented in the cache
        if (mergedMeta == oldMeta)
            return;
        MetadataUpdateResult res = transport.requestMetadataUpdate(mergedMeta).get();
        assert res != null;
        if (res.rejected())
            throw res.error();
    } catch (IgniteCheckedException e) {
        throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 4 with BinaryTypeImpl

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

the class BinaryMetadataMoveLegacyFolderTest method createBinaryType.

/**
 * Get byte representation of simple binary type with one field
 *
 * @param typeName  Type name.
 * @param fieldName Field name.
 */
private byte[] createBinaryType(String typeName, String fieldName) throws Exception {
    IgniteConfiguration configuration = getConfiguration();
    IgniteEx grid = startGrid(configuration);
    IgniteBinary binary = grid.binary();
    BinaryObjectBuilder builder = binary.builder("TestBinaryType");
    builder.setField(fieldName, 1);
    builder.build();
    BinaryMetadata metadata = ((BinaryTypeImpl) binary.type(typeName)).metadata();
    byte[] marshalled = U.marshal(grid.context(), metadata);
    stopAllGrids();
    cleanPersistenceDir();
    return marshalled;
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 5 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(boolean activeOnStart) throws IgniteCheckedException {
    if (marsh instanceof BinaryMarshaller) {
        if (ctx.clientNode())
            ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED);
        transport = new BinaryMetadataTransport(metadataLocCache, 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.putIfAbsent(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);
            }
        }
    }
}
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)

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