Search in sources :

Example 61 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException 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 62 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException 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)

Example 63 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException 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)

Example 64 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class ClientMetadataRequestFuture method requestMetadata.

/**
 */
void requestMetadata() {
    boolean noSrvsInCluster;
    synchronized (this) {
        while (!aliveSrvNodes.isEmpty()) {
            ClusterNode srvNode = aliveSrvNodes.poll();
            try {
                if (log.isDebugEnabled())
                    log.debug("Requesting metadata for typeId " + typeId + " from node " + srvNode.id());
                ioMgr.sendToGridTopic(srvNode, GridTopic.TOPIC_METADATA_REQ, new MetadataRequestMessage(typeId), GridIoPolicy.SYSTEM_POOL);
                if (discoMgr.node(srvNode.id()) == null)
                    continue;
                pendingNode = srvNode;
                break;
            } catch (IgniteCheckedException ignored) {
                U.warn(log, "Failed to request marshaller mapping from remote node (proceeding with the next one): " + srvNode);
            }
        }
        noSrvsInCluster = pendingNode == null;
    }
    if (noSrvsInCluster)
        onDone(MetadataUpdateResult.createFailureResult(new BinaryObjectException("All server nodes have left grid, cannot request metadata [typeId: " + typeId + "]")));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 65 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.

the class BinaryConfigurationConsistencySelfTest method customConfig.

/**
 * @return Custom BinaryConfiguration.
 * @param compactFooter Compact footer.
 */
private BinaryConfiguration customConfig(boolean compactFooter) {
    BinaryConfiguration c = new BinaryConfiguration();
    c.setIdMapper(new BinaryBasicIdMapper(true));
    c.setSerializer(new BinarySerializer() {

        @Override
        public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
        // No-op.
        }

        @Override
        public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
        // No-op.
        }
    });
    c.setCompactFooter(compactFooter);
    BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
    btc.setIdMapper(BinaryContext.defaultIdMapper());
    btc.setEnum(false);
    btc.setSerializer(new BinarySerializer() {

        @Override
        public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
        // No-op.
        }

        @Override
        public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
        // No-op.
        }
    });
    c.setTypeConfigurations(Arrays.asList(btc));
    return c;
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryWriter(org.apache.ignite.binary.BinaryWriter) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryReader(org.apache.ignite.binary.BinaryReader) BinarySerializer(org.apache.ignite.binary.BinarySerializer) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)68 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 BinaryObject (org.apache.ignite.binary.BinaryObject)12 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)9 IOException (java.io.IOException)7 BinaryType (org.apache.ignite.binary.BinaryType)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 IgniteException (org.apache.ignite.IgniteException)5 BigInteger (java.math.BigInteger)3 Time (java.sql.Time)3 Timestamp (java.sql.Timestamp)3 BinaryEnumObjectImpl (org.apache.ignite.internal.binary.BinaryEnumObjectImpl)3 BinaryTypeImpl (org.apache.ignite.internal.binary.BinaryTypeImpl)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2