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