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;
}
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));
}
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;
}
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);
}
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());
}
}
}
Aggregations