Search in sources :

Example 86 with HazelcastException

use of com.hazelcast.core.HazelcastException in project orientdb by orientechnologies.

the class ODistributedStorage method commit.

@Override
public List<ORecordOperation> commit(final OTransaction iTx, final Runnable callback) {
    resetLastValidBackup();
    if (OScenarioThreadLocal.INSTANCE.isRunModeDistributed()) {
        // ALREADY DISTRIBUTED
        try {
            return wrapped.commit(iTx, callback);
        } catch (ORecordDuplicatedException e) {
            // CHECK THE RECORD HAS THE SAME KEY IS STILL UNDER DISTRIBUTED TX
            final ODistributedDatabase dDatabase = dManager.getMessageService().getDatabase(getName());
            if (dDatabase.getRecordIfLocked(e.getRid()) != null) {
                throw new OPossibleDuplicatedRecordException(e);
            }
            throw e;
        }
    }
    final ODistributedConfiguration dbCfg = distributedConfiguration;
    final String localNodeName = dManager.getLocalNodeName();
    checkNodeIsMaster(localNodeName, dbCfg, "Transaction Commit");
    checkClusterRebalanceIsNotRunning();
    try {
        if (!dbCfg.isReplicationActive(null, localNodeName)) {
            // DON'T REPLICATE
            OScenarioThreadLocal.executeAsDistributed(new Callable() {

                @Override
                public Object call() throws Exception {
                    return wrapped.commit(iTx, callback);
                }
            });
        } else {
            // EXECUTE DISTRIBUTED TX
            int maxAutoRetry = OGlobalConfiguration.DISTRIBUTED_CONCURRENT_TX_MAX_AUTORETRY.getValueAsInteger();
            if (maxAutoRetry <= 0)
                maxAutoRetry = 1;
            int autoRetryDelay = OGlobalConfiguration.DISTRIBUTED_CONCURRENT_TX_AUTORETRY_DELAY.getValueAsInteger();
            if (autoRetryDelay <= 0)
                autoRetryDelay = 1;
            Throwable lastException = null;
            for (int retry = 1; retry <= maxAutoRetry; ++retry) {
                try {
                    return txManager.commit((ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get(), iTx, callback, eventListener);
                } catch (Throwable e) {
                    lastException = e;
                    if (retry >= maxAutoRetry) {
                        // REACHED MAX RETRIES
                        ODistributedServerLog.debug(this, localNodeName, null, ODistributedServerLog.DIRECTION.NONE, "Distributed transaction retries exceed maximum auto-retries (%d)", maxAutoRetry);
                        break;
                    }
                    // SKIP RETRY IN CASE OF OConcurrentModificationException BECAUSE IT NEEDS A RETRY AT APPLICATION LEVEL
                    if (!(e instanceof OConcurrentModificationException) && (e instanceof ONeedRetryException || e instanceof ORecordNotFoundException)) {
                        // RETRY
                        final long wait = autoRetryDelay / 2 + new Random().nextInt(autoRetryDelay);
                        ODistributedServerLog.debug(this, localNodeName, null, ODistributedServerLog.DIRECTION.NONE, "Distributed transaction cannot be completed, wait %dms and retry again (%d/%d)", wait, retry, maxAutoRetry);
                        Thread.sleep(wait);
                        Orient.instance().getProfiler().updateCounter("db." + getName() + ".distributedTxRetries", "Number of retries executed in distributed transaction", +1, "db.*.distributedTxRetries");
                    } else
                        // SKIP RETRY LOOP
                        break;
                }
            }
            if (lastException instanceof RuntimeException)
                throw (RuntimeException) lastException;
            else
                throw OException.wrapException(new ODistributedException("Error on executing distributed transaction"), lastException);
        }
    } catch (OValidationException e) {
        throw e;
    } catch (HazelcastInstanceNotActiveException e) {
        throw new OOfflineNodeException("Hazelcast instance is not available");
    } catch (HazelcastException e) {
        throw new OOfflineNodeException("Hazelcast instance is not available");
    } catch (Exception e) {
        handleDistributedException("Cannot route TX operation against distributed node", e);
    }
    return null;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OCallable(com.orientechnologies.common.util.OCallable) Callable(java.util.concurrent.Callable) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) HazelcastException(com.hazelcast.core.HazelcastException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException)

Example 87 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class JsonValueFunctionIntegrationTest method initMultiTypeObject.

private void initMultiTypeObject() {
    final MultiTypeObject value = new MultiTypeObject();
    final String serializedValue;
    try {
        serializedValue = SERIALIZER.writeValueAsString(value);
    } catch (JsonProcessingException e) {
        throw new HazelcastException(e);
    }
    final IMap<Long, HazelcastJsonValue> test = instance().getMap("test");
    test.put(1L, new HazelcastJsonValue(serializedValue));
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 88 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class JsonSchemaHelper method findValueWithPattern.

/**
 * Extract the JsonValue that is stored in attributePath in input.
 * This method validates expectedPattern using attributePath while
 * extraction. If expectedPattern points to invalid or wrong attributes
 * at any point, this method returns {@code null}
 *
 * NOTE: this method cannot handle patterns with "any" in it.
 *
 * @param input             a byte array containing the target object
 * @param schemaNode        valid schema description to the target
 *                          object. The behavior is undefined if
 *                          description does not match the actual
 *                          object
 * @param expectedPattern   this cannot contain "any"
 * @param attributePath     this cannot contain "any"
 * @return                  JsonValue extracted or null
 */
@SuppressWarnings("checkstyle:npathcomplexity")
public static JsonValue findValueWithPattern(NavigableJsonInputAdapter input, JsonSchemaNode schemaNode, JsonPattern expectedPattern, JsonPathCursor attributePath) throws IOException {
    for (int i = 0; i < expectedPattern.depth(); i++) {
        if (attributePath.getNext() == null) {
            return null;
        }
        if (schemaNode.isTerminal()) {
            return null;
        }
        int expectedOrderIndex = expectedPattern.get(i);
        JsonSchemaStructNode structDescription = (JsonSchemaStructNode) schemaNode;
        if (structDescription.getChildCount() <= expectedOrderIndex) {
            return null;
        }
        JsonSchemaNameValue nameValue = structDescription.getChild(expectedOrderIndex);
        if (structMatches(input, nameValue, expectedOrderIndex, attributePath)) {
            schemaNode = nameValue.getValue();
        } else {
            return null;
        }
    }
    if (attributePath.getNext() == null) {
        if (schemaNode.isTerminal()) {
            // Otherwise, let the exceptions propagate
            try {
                JsonReducedValueParser valueParser = new JsonReducedValueParser();
                int valuePos = ((JsonSchemaTerminalNode) schemaNode).getValueStartLocation();
                return input.parseValue(valueParser, valuePos);
            } catch (ParseException parseException) {
                throw new HazelcastException(parseException);
            }
        } else {
            return NonTerminalJsonValue.INSTANCE;
        }
    }
    return null;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) JsonReducedValueParser(com.hazelcast.internal.json.JsonReducedValueParser) ParseException(com.hazelcast.internal.json.ParseException)

Example 89 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class OperationRunnerImpl method setOperationResponseHandler.

private void setOperationResponseHandler(Operation op) {
    OperationResponseHandler handler = outboundResponseHandler;
    if (op.getCallId() == 0) {
        if (op.returnsResponse()) {
            throw new HazelcastException("Operation " + op + " wants to return a response, but doesn't have a call ID");
        }
        handler = createEmptyResponseHandler();
    }
    op.setOperationResponseHandler(handler);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) OperationResponseHandler(com.hazelcast.spi.impl.operationservice.OperationResponseHandler)

Example 90 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class PreJoinCacheConfigTest method serializationSucceeds_whenValueTypeNotResolvable.

@Test
public void serializationSucceeds_whenValueTypeNotResolvable() {
    PreJoinCacheConfig preJoinCacheConfig = new PreJoinCacheConfig(newDefaultCacheConfig("test"));
    preJoinCacheConfig.setKeyClassName("java.lang.String");
    preJoinCacheConfig.setValueClassName("some.inexistent.Class");
    Data data = serializationService.toData(preJoinCacheConfig);
    PreJoinCacheConfig deserialized = serializationService.toObject(data);
    assertEquals(deserialized, preJoinCacheConfig);
    try {
        Class klass = deserialized.asCacheConfig().getValueType();
        fail("Getting the value type on deserialized CacheConfig should fail because the value type cannot be resolved");
    } catch (HazelcastException e) {
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            fail("Unexpected exception: " + e.getCause());
        }
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) CacheConfigTest(com.hazelcast.config.CacheConfigTest) Test(org.junit.Test)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)123 IOException (java.io.IOException)43 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)14 TransactionException (com.hazelcast.transaction.TransactionException)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 File (java.io.File)13 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 Data (com.hazelcast.internal.serialization.Data)7 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)6 Future (java.util.concurrent.Future)6 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)5 OException (com.orientechnologies.common.exception.OException)5 OIOException (com.orientechnologies.common.io.OIOException)5 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)5 EOFException (java.io.EOFException)5 ArrayList (java.util.ArrayList)5