Search in sources :

Example 1 with ODatabaseIsOldException

use of com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException in project orientdb by orientechnologies.

the class OAbstractSyncDatabaseTask method databaseIsOld.

private void databaseIsOld(ODistributedServerManager iManager, String databaseName, ODistributedDatabase dDatabase) {
    final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    final String msg = String.format("Skip deploying delta database '%s' because the requesting server has a most recent database (requester LastOperationOn=%s current LastOperationOn=%s)", databaseName, df.format(new Date(lastOperationTimestamp)), df.format(new Date(dDatabase.getSyncConfiguration().getLastOperationTimestamp())));
    ODistributedServerLog.error(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.NONE, msg);
    throw new ODatabaseIsOldException(msg);
}
Also used : ODatabaseIsOldException(com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with ODatabaseIsOldException

use of com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException in project orientdb by orientechnologies.

the class ODistributedAbstractPlugin method requestDatabaseDelta.

public boolean requestDatabaseDelta(final ODistributedDatabaseImpl distrDatabase, final String databaseName, final OModifiableDistributedConfiguration cfg) {
    // GET ALL THE OTHER SERVERS
    final Collection<String> nodes = cfg.getServers(null, nodeName);
    getAvailableNodes(nodes, databaseName);
    if (nodes.size() == 0)
        return false;
    ODistributedServerLog.warn(this, nodeName, nodes.toString(), DIRECTION.OUT, "requesting delta database sync for '%s' on local server...", databaseName);
    // CREATE A MAP OF NODE/LSN BY READING LAST LSN SAVED
    final Map<String, OLogSequenceNumber> selectedNodes = new HashMap<String, OLogSequenceNumber>(nodes.size());
    for (String node : nodes) {
        final OLogSequenceNumber lsn = distrDatabase.getSyncConfiguration().getLastLSN(node);
        if (lsn != null) {
            selectedNodes.put(node, lsn);
        } else
            ODistributedServerLog.info(this, nodeName, node, DIRECTION.OUT, "Last LSN not found for database '%s', skip delta database sync", databaseName);
    }
    if (selectedNodes.isEmpty()) {
        // FORCE FULL DATABASE SYNC
        ODistributedServerLog.error(this, nodeName, null, DIRECTION.NONE, "No LSN found for delta sync for database '%s'. Asking for full database sync...", databaseName);
        throw new ODistributedDatabaseDeltaSyncException("Requested database delta sync but no LSN was found");
    }
    for (Map.Entry<String, OLogSequenceNumber> entry : selectedNodes.entrySet()) {
        final String targetNode = entry.getKey();
        final OLogSequenceNumber lsn = entry.getValue();
        final OSyncDatabaseDeltaTask deployTask = new OSyncDatabaseDeltaTask(lsn, distrDatabase.getSyncConfiguration().getLastOperationTimestamp());
        final List<String> targetNodes = new ArrayList<String>(1);
        targetNodes.add(targetNode);
        ODistributedServerLog.info(this, nodeName, targetNode, DIRECTION.OUT, "Requesting database delta sync for '%s' LSN=%s...", databaseName, lsn);
        try {
            final Map<String, Object> results = (Map<String, Object>) sendRequest(databaseName, null, targetNodes, deployTask, getNextMessageIdCounter(), ODistributedRequest.EXECUTION_MODE.RESPONSE, null, null).getPayload();
            ODistributedServerLog.debug(this, nodeName, selectedNodes.toString(), DIRECTION.OUT, "Database delta sync returned: %s", results);
            final String dbPath = serverInstance.getDatabaseDirectory() + databaseName;
            // EXTRACT THE REAL RESULT
            for (Map.Entry<String, Object> r : results.entrySet()) {
                final Object value = r.getValue();
                if (value instanceof Boolean)
                    continue;
                else {
                    final String server = r.getKey();
                    if (value instanceof ODistributedDatabaseDeltaSyncException) {
                        final ODistributedDatabaseDeltaSyncException exc = (ODistributedDatabaseDeltaSyncException) value;
                        ODistributedServerLog.warn(this, nodeName, server, DIRECTION.IN, "Error on installing database delta for '%s' (err=%s)", databaseName, exc.getMessage());
                        ODistributedServerLog.warn(this, nodeName, server, DIRECTION.IN, "Requesting full database '%s' sync...", databaseName);
                        // RESTORE STATUS TO ONLINE
                        setDatabaseStatus(server, databaseName, DB_STATUS.ONLINE);
                        throw (ODistributedDatabaseDeltaSyncException) value;
                    } else if (value instanceof ODatabaseIsOldException) {
                        // MANAGE THIS EXCEPTION AT UPPER LEVEL
                        throw (ODatabaseIsOldException) value;
                    } else if (value instanceof Throwable) {
                        ODistributedServerLog.error(this, nodeName, server, DIRECTION.IN, "Error on installing database delta %s in %s (%s)", value, databaseName, dbPath, value);
                        setDatabaseStatus(nodeName, databaseName, DB_STATUS.NOT_AVAILABLE);
                        return false;
                    } else if (value instanceof ODistributedDatabaseChunk) {
                        // distrDatabase.filterBeforeThisMomentum(((ODistributedDatabaseChunk) value).getMomentum());
                        // DISABLED BECAYSE THE MOMENTUM IS NOT YET RELIABLE
                        // distrDatabase.setParsing(true);
                        final File uniqueClustersBackupDirectory = getClusterOwnedExclusivelyByCurrentNode(dbPath, databaseName);
                        installDatabaseFromNetwork(dbPath, databaseName, distrDatabase, server, (ODistributedDatabaseChunk) value, true, uniqueClustersBackupDirectory, cfg);
                        ODistributedServerLog.info(this, nodeName, targetNode, DIRECTION.IN, "Installed delta of database '%s'...", databaseName);
                        if (!cfg.isSharded())
                            // DB NOT SHARDED, THE 1ST BACKUP IS GOOD
                            break;
                    } else
                        throw new IllegalArgumentException("Type " + value + " not supported");
                }
            }
        } catch (ODatabaseIsOldException e) {
            // FORWARD IT
            throw (ODatabaseIsOldException) e;
        } catch (Exception e) {
            ODistributedServerLog.error(this, nodeName, targetNode, DIRECTION.OUT, "Error on asking delta backup of database '%s' (err=%s)", databaseName, e.getMessage());
            throw new ODistributedDatabaseDeltaSyncException(lsn, e.toString());
        }
    }
    distrDatabase.resume();
    return true;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ODatabaseIsOldException(com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) OException(com.orientechnologies.common.exception.OException) HazelcastException(com.hazelcast.core.HazelcastException) ODistributedDatabaseDeltaSyncException(com.orientechnologies.orient.server.distributed.task.ODistributedDatabaseDeltaSyncException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODatabaseIsOldException(com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) ODistributedDatabaseDeltaSyncException(com.orientechnologies.orient.server.distributed.task.ODistributedDatabaseDeltaSyncException) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OClusterPositionMap(com.orientechnologies.orient.core.storage.impl.local.paginated.OClusterPositionMap)

Example 3 with ODatabaseIsOldException

use of com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException in project orientdb by orientechnologies.

the class ODistributedAbstractPlugin method requestDatabaseFullSync.

protected boolean requestDatabaseFullSync(final ODistributedDatabaseImpl distrDatabase, final boolean backupDatabase, final String databaseName, final boolean iAskToAllNodes, final OModifiableDistributedConfiguration cfg) {
    // GET ALL THE OTHER SERVERS
    final Collection<String> nodes = cfg.getServers(null, nodeName);
    if (nodes.isEmpty()) {
        ODistributedServerLog.warn(this, nodeName, null, DIRECTION.NONE, "Cannot request full deploy of database '%s' because there are no nodes available with such database", databaseName);
        return false;
    }
    final List<String> selectedNodes = new ArrayList<String>();
    if (!iAskToAllNodes) {
        // VALID FOR FURTHER NODES
        for (String n : nodes) {
            if (isNodeStatusEqualsTo(n, databaseName, DB_STATUS.BACKUP)) {
                // SERVER ALREADY IN BACKUP: USE IT
                selectedNodes.add(n);
                break;
            }
        }
        if (selectedNodes.isEmpty()) {
            // GET THE FIRST ONE TO ASK FOR DATABASE. THIS FORCES TO HAVE ONE NODE TO DO BACKUP SAVING RESOURCES IN CASE BACKUP IS STILL
            // VALID FOR FURTHER NODES
            final Iterator<String> it = nodes.iterator();
            while (it.hasNext()) {
                final String f = it.next();
                if (isNodeStatusEqualsTo(f, databaseName, DB_STATUS.ONLINE, DB_STATUS.BACKUP)) {
                    selectedNodes.add(f);
                    break;
                }
            }
        }
    }
    if (selectedNodes.isEmpty())
        // NO NODE ONLINE, SEND THE MESSAGE TO EVERYONE
        selectedNodes.addAll(nodes);
    ODistributedServerLog.warn(this, nodeName, selectedNodes.toString(), DIRECTION.OUT, "Requesting deploy of database '%s' on local server...", databaseName);
    final OLogSequenceNumber lastLSN = distrDatabase.getSyncConfiguration().getLastLSN(getLocalNodeName());
    final OAbstractReplicatedTask deployTask = new OSyncDatabaseTask(lastLSN, distrDatabase.getSyncConfiguration().getLastOperationTimestamp());
    final Map<String, Object> results = (Map<String, Object>) sendRequest(databaseName, null, selectedNodes, deployTask, getNextMessageIdCounter(), ODistributedRequest.EXECUTION_MODE.RESPONSE, null, null).getPayload();
    ODistributedServerLog.debug(this, nodeName, selectedNodes.toString(), DIRECTION.OUT, "Deploy returned: %s", results);
    final String dbPath = serverInstance.getDatabaseDirectory() + databaseName;
    // EXTRACT THE REAL RESULT
    for (Map.Entry<String, Object> r : results.entrySet()) {
        final Object value = r.getValue();
        if (value instanceof Boolean)
            continue;
        else if (value instanceof ODatabaseIsOldException) {
            // MANAGE THIS EXCEPTION AT UPPER LEVEL
            throw (ODatabaseIsOldException) value;
        } else if (value instanceof Throwable) {
            ODistributedServerLog.error(this, nodeName, r.getKey(), DIRECTION.IN, "Error on installing database '%s' in %s", (Exception) value, databaseName, dbPath);
            setDatabaseStatus(nodeName, databaseName, DB_STATUS.NOT_AVAILABLE);
            if (value instanceof ODistributedException)
                throw (ODistributedException) value;
        } else if (value instanceof ODistributedDatabaseChunk) {
            // DISABLED BECAUSE MOMENTUM IS NOT RELIABLE YET
            // distrDatabase.filterBeforeThisMomentum(((ODistributedDatabaseChunk) value).getMomentum());
            final File uniqueClustersBackupDirectory = getClusterOwnedExclusivelyByCurrentNode(dbPath, databaseName);
            // CLOSE THE STORAGE FIRST
            final ODistributedStorage stg = storages.remove(databaseName);
            if (stg != null)
                stg.close(true, false);
            if (backupDatabase)
                backupCurrentDatabase(databaseName);
            installDatabaseFromNetwork(dbPath, databaseName, distrDatabase, r.getKey(), (ODistributedDatabaseChunk) value, false, uniqueClustersBackupDirectory, cfg);
            distrDatabase.resume();
            return true;
        } else
            throw new IllegalArgumentException("Type " + value + " not supported");
    }
    throw new ODistributedException("No response received from remote nodes for auto-deploy of database '" + databaseName + "'");
}
Also used : ODatabaseIsOldException(com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OClusterPositionMap(com.orientechnologies.orient.core.storage.impl.local.paginated.OClusterPositionMap) OAbstractReplicatedTask(com.orientechnologies.orient.server.distributed.task.OAbstractReplicatedTask)

Aggregations

ODatabaseIsOldException (com.orientechnologies.orient.server.distributed.task.ODatabaseIsOldException)3 OClusterPositionMap (com.orientechnologies.orient.core.storage.impl.local.paginated.OClusterPositionMap)2 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)1 OException (com.orientechnologies.common.exception.OException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OAbstractReplicatedTask (com.orientechnologies.orient.server.distributed.task.OAbstractReplicatedTask)1 ODistributedDatabaseDeltaSyncException (com.orientechnologies.orient.server.distributed.task.ODistributedDatabaseDeltaSyncException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1