Search in sources :

Example 56 with HazelcastException

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

the class ODistributedAbstractPlugin method onOpen.

/**
   * Auto register myself as hook.
   */
@Override
public void onOpen(final ODatabaseInternal iDatabase) {
    if (!isRelatedToLocalServer(iDatabase))
        return;
    if (status != NODE_STATUS.ONLINE && status != NODE_STATUS.STARTING)
        return;
    final ODatabaseDocumentInternal currDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    try {
        final String dbName = iDatabase.getName();
        final ODistributedConfiguration cfg = getDatabaseConfiguration(dbName);
        if (cfg == null)
            return;
        ODistributedDatabaseImpl distribDatabase = getMessageService().getDatabase(dbName);
        if (distribDatabase == null) {
            // CHECK TO PUBLISH IT TO THE CLUSTER
            distribDatabase = messageService.registerDatabase(dbName, cfg);
            distribDatabase.resume();
            distribDatabase.setOnline();
        }
        if (!(iDatabase.getStorage() instanceof ODistributedStorage) || ((ODistributedStorage) iDatabase.getStorage()).getDistributedManager().isOffline()) {
            final ODistributedStorage storage = getStorage(dbName);
            // INIT IT
            storage.wrap((OAbstractPaginatedStorage) iDatabase.getStorage().getUnderlying());
            iDatabase.replaceStorage(storage);
            if (isNodeOnline(nodeName, dbName))
                installDbClustersLocalStrategy(iDatabase);
        }
    } catch (HazelcastException e) {
        throw new OOfflineNodeException("Hazelcast instance is not available");
    } catch (HazelcastInstanceNotActiveException e) {
        throw new OOfflineNodeException("Hazelcast instance is not available");
    } finally {
        // RESTORE ORIGINAL DATABASE INSTANCE IN TL
        ODatabaseRecordThreadLocal.INSTANCE.set(currDb);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastException(com.hazelcast.core.HazelcastException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException)

Example 57 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);
            }
        }
    }
    final ODistributedConfiguration dbCfg = distributedConfiguration;
    final String localNodeName = dManager.getLocalNodeName();
    checkLocalNodeIsAvailable();
    checkNodeIsMaster(localNodeName, dbCfg);
    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
            return txManager.commit((ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get(), iTx, callback, eventListener);
    } 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) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) 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)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)57 IOException (java.io.IOException)18 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)11 TransactionException (com.hazelcast.transaction.TransactionException)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 File (java.io.File)8 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 OCallable (com.orientechnologies.common.util.OCallable)6 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 Collator (com.hazelcast.mapreduce.Collator)4 CombinerFactory (com.hazelcast.mapreduce.CombinerFactory)4 Mapper (com.hazelcast.mapreduce.Mapper)4