Search in sources :

Example 1 with EnvironmentFailureException

use of com.sleepycat.je.EnvironmentFailureException in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacade method tryToRestartEnvironment.

private void tryToRestartEnvironment(final DatabaseException dbe) {
    if (_state.compareAndSet(State.OPEN, State.RESTARTING) || _state.compareAndSet(State.OPENING, State.RESTARTING)) {
        if (dbe != null && LOGGER.isDebugEnabled()) {
            LOGGER.debug("Environment restarting due to exception {}", dbe.getMessage(), dbe);
        }
        // Tell the virtualhostnode that we are no longer attached to the group.  It will close the virtualhost,
        // closing the connections, housekeeping etc meaning all transactions are finished before we
        // restart the environment.
        _stateChangeExecutor.submit(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                StateChangeListener listener = _stateChangeListener.get();
                if (listener != null && _state.get() == State.RESTARTING) {
                    try {
                        StateChangeEvent detached = new StateChangeEvent(ReplicatedEnvironment.State.DETACHED, NameIdPair.NULL);
                        listener.stateChange(detached);
                    } catch (Throwable t) {
                        handleUncaughtExceptionInExecutorService(t);
                    }
                }
                return null;
            }
        }).addListener(new Runnable() {

            @Override
            public void run() {
                int attemptNumber = 1;
                boolean restarted = false;
                Exception lastException = null;
                while (_state.get() == State.RESTARTING && attemptNumber <= _environmentRestartRetryLimit) {
                    try {
                        restartEnvironment();
                        restarted = true;
                        break;
                    } catch (EnvironmentFailureException e) {
                        LOGGER.warn("Failure whilst trying to restart environment (attempt number " + "{} of {})", attemptNumber, _environmentRestartRetryLimit, e);
                        lastException = e;
                    } catch (Exception e) {
                        LOGGER.error("Fatal failure whilst trying to restart environment", e);
                        lastException = e;
                        break;
                    }
                    attemptNumber++;
                }
                if (!restarted) {
                    LOGGER.error("Failed to restart environment.");
                    if (lastException != null) {
                        handleUncaughtExceptionInExecutorService(lastException);
                    }
                }
            }
        }, _environmentJobExecutor);
    } else if (_state.get() == State.RESTARTING) {
        LOGGER.debug("Environment restart already in progress, ignoring restart request.");
    } else {
        LOGGER.debug("Ignoring restart because the environment because state is {}", _state.get());
    }
}
Also used : EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) StateChangeListener(com.sleepycat.je.rep.StateChangeListener) StateChangeEvent(com.sleepycat.je.rep.StateChangeEvent) Callable(java.util.concurrent.Callable) UnknownMasterException(com.sleepycat.je.rep.UnknownMasterException) DatabaseException(com.sleepycat.je.DatabaseException) ReplicaConsistencyException(com.sleepycat.je.rep.ReplicaConsistencyException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) RestartRequiredException(com.sleepycat.je.rep.RestartRequiredException) SocketTimeoutException(java.net.SocketTimeoutException) InsufficientLogException(com.sleepycat.je.rep.InsufficientLogException) ServiceConnectFailedException(com.sleepycat.je.rep.utilint.ServiceDispatcher.ServiceConnectFailedException) ExternalServiceException(org.apache.qpid.server.util.ExternalServiceException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MasterStateException(com.sleepycat.je.rep.MasterStateException) TimeoutException(java.util.concurrent.TimeoutException) LogWriteException(com.sleepycat.je.LogWriteException) RollbackException(com.sleepycat.je.rep.RollbackException) InsufficientReplicasException(com.sleepycat.je.rep.InsufficientReplicasException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) StoreException(org.apache.qpid.server.store.StoreException) ReplicaWriteException(com.sleepycat.je.rep.ReplicaWriteException) ExternalServiceTimeoutException(org.apache.qpid.server.util.ExternalServiceTimeoutException) InsufficientAcksException(com.sleepycat.je.rep.InsufficientAcksException) EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) MemberNotFoundException(com.sleepycat.je.rep.MemberNotFoundException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Example 2 with EnvironmentFailureException

use of com.sleepycat.je.EnvironmentFailureException in project dcache by dCache.

the class CacheRepositoryEntryImpl method setFileAttributes.

private Void setFileAttributes(FileAttributes attributes) throws CacheException {
    try {
        String id = _pnfsId.toString();
        // invalidate cached value
        _storageInfoCache.clear();
        // TODO to check the case when STORAGEINFO size=0
        if (attributes.isDefined(FileAttribute.STORAGEINFO)) {
            _repository.getStorageInfoMap().put(id, StorageInfos.extractFrom(attributes));
        } else {
            _repository.getStorageInfoMap().remove(id);
        }
        // TODO check should there be separate methods
        if (attributes.isDefined(FileAttribute.ACCESS_TIME) && attributes.isDefined(FileAttribute.CREATION_TIME)) {
            AccessTimeInfo accessTimeInfo = new AccessTimeInfo();
            accessTimeInfo.setLastAccessTime(attributes.getAccessTime());
            accessTimeInfo.setCreationTime(attributes.getCreationTime());
            _repository.getAccessTimeInfo().put(id, accessTimeInfo);
        } else {
            _repository.getAccessTimeInfo().remove(id);
        }
    } catch (EnvironmentFailureException e) {
        if (!_repository.isValid()) {
            throw new DiskErrorCacheException("Meta data update failed and a pool restart is required: " + e.getMessage(), e);
        }
        throw new CacheException("Meta data update failed: " + e.getMessage(), e);
    } catch (OperationFailureException e) {
        throw new CacheException("Meta data update failed: " + e.getMessage(), e);
    }
    return null;
}
Also used : DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) OperationFailureException(com.sleepycat.je.OperationFailureException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException)

Example 3 with EnvironmentFailureException

use of com.sleepycat.je.EnvironmentFailureException in project dcache by dCache.

the class BerkeleyDBMetaDataRepository method index.

@Override
public Set<PnfsId> index(IndexOption... options) throws CacheException {
    try {
        List<IndexOption> indexOptions = asList(options);
        if (indexOptions.contains(IndexOption.META_ONLY)) {
            return views.collectKeys(Collectors.mapping(PnfsId::new, Collectors.toSet()));
        }
        Stopwatch watch = Stopwatch.createStarted();
        Set<PnfsId> files = _fileStore.index();
        LOGGER.info("Indexed {} entries in {} in {}.", files.size(), _fileStore, watch);
        if (indexOptions.contains(IndexOption.ALLOW_REPAIR)) {
            watch.reset().start();
            Set<String> records = views.collectKeys(Collectors.toSet());
            LOGGER.info("Indexed {} entries in {} in {}.", records.size(), dir, watch);
            for (String id : records) {
                if (!files.contains(new PnfsId(id))) {
                    LOGGER.warn("Removing redundant meta data for {}.", id);
                    views.getStorageInfoMap().remove(id);
                    views.getStateMap().remove(id);
                    views.getAccessTimeInfo().remove(id);
                }
            }
        }
        return files;
    } catch (EnvironmentFailureException e) {
        if (!isValid()) {
            throw new DiskErrorCacheException("Meta data lookup failed and a pool restart is required: " + e.getMessage(), e);
        }
        throw new CacheException("Meta data lookup failed: " + e.getMessage(), e);
    } catch (OperationFailureException e) {
        throw new CacheException("Meta data lookup failed: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new DiskErrorCacheException("Meta data lookup failed and a pool restart is required: " + messageOrClassName(e), e);
    }
}
Also used : DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) PnfsId(diskCacheV111.util.PnfsId) Stopwatch(com.google.common.base.Stopwatch) OperationFailureException(com.sleepycat.je.OperationFailureException) IOException(java.io.IOException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException)

Example 4 with EnvironmentFailureException

use of com.sleepycat.je.EnvironmentFailureException in project dcache by dCache.

the class BerkeleyDBMetaDataRepository method remove.

@Override
public void remove(PnfsId id) throws CacheException {
    try {
        _fileStore.remove(id);
    } catch (IOException e) {
        throw new DiskErrorCacheException("Failed to delete " + id + ": " + messageOrClassName(e), e);
    }
    try {
        views.getStorageInfoMap().remove(id.toString());
        views.getStateMap().remove(id.toString());
        views.getAccessTimeInfo().remove(id.toString());
    } catch (EnvironmentFailureException e) {
        if (!isValid()) {
            throw new DiskErrorCacheException("Meta data update failed and a pool restart is required: " + e.getMessage(), e);
        }
        throw new CacheException("Meta data update failed: " + e.getMessage(), e);
    } catch (OperationFailureException e) {
        throw new CacheException("Meta data update failed: " + e.getMessage(), e);
    }
}
Also used : DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException) CacheException(diskCacheV111.util.CacheException) EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) IOException(java.io.IOException) OperationFailureException(com.sleepycat.je.OperationFailureException) DiskErrorCacheException(diskCacheV111.util.DiskErrorCacheException)

Example 5 with EnvironmentFailureException

use of com.sleepycat.je.EnvironmentFailureException in project incubator-inlong by apache.

the class BdbMetaConfigMapperImpl method getMasterGroupStatus.

@Override
public MasterGroupStatus getMasterGroupStatus(boolean isFromHeartbeat) {
    // #lizard forgives
    if (repEnv == null) {
        return null;
    }
    ReplicationGroup replicationGroup = null;
    try {
        replicationGroup = repEnv.getGroup();
    } catch (DatabaseException e) {
        if (e instanceof EnvironmentFailureException) {
            if (isFromHeartbeat) {
                logger.error("[BDB Error] Check found EnvironmentFailureException", e);
                try {
                    stop();
                    start();
                    replicationGroup = repEnv.getGroup();
                } catch (Throwable e1) {
                    logger.error("[BDB Error] close and reopen storeManager error", e1);
                }
            } else {
                logger.error("[BDB Error] Get EnvironmentFailureException error while non heartBeat request", e);
            }
        } else {
            logger.error("[BDB Error] Get replication group info error", e);
        }
    } catch (Throwable ee) {
        logger.error("[BDB Error] Get replication group throw error", ee);
    }
    if (replicationGroup == null) {
        logger.error("[BDB Error] ReplicationGroup is null...please check the status of the group!");
        return null;
    }
    int activeNodes = 0;
    boolean isMasterActive = false;
    Set<String> tmp = new HashSet<>();
    for (ReplicationNode node : replicationGroup.getNodes()) {
        MasterNodeInfo masterNodeInfo = new MasterNodeInfo(replicationGroup.getName(), node.getName(), node.getHostName(), node.getPort());
        try {
            NodeState nodeState = replicationGroupAdmin.getNodeState(node, 2000);
            if (nodeState != null) {
                if (nodeState.getNodeState().isActive()) {
                    activeNodes++;
                    if (nodeState.getNodeName().equals(masterNodeName)) {
                        isMasterActive = true;
                        masterNodeInfo.setNodeStatus(1);
                    }
                }
                if (nodeState.getNodeState().isReplica()) {
                    tmp.add(nodeState.getNodeName());
                    replicas4Transfer = tmp;
                    masterNodeInfo.setNodeStatus(0);
                }
            }
        } catch (IOException e) {
            connectNodeFailCount++;
            masterNodeInfo.setNodeStatus(-1);
            metaSamplePrint.printExceptionCaught(e, node.getHostName(), node.getName());
            continue;
        } catch (ServiceDispatcher.ServiceConnectFailedException e) {
            masterNodeInfo.setNodeStatus(-2);
            metaSamplePrint.printExceptionCaught(e, node.getHostName(), node.getName());
            continue;
        } catch (Throwable ee) {
            masterNodeInfo.setNodeStatus(-3);
            metaSamplePrint.printExceptionCaught(ee, node.getHostName(), node.getName());
            continue;
        }
    }
    MasterGroupStatus masterGroupStatus = new MasterGroupStatus(isMasterActive);
    int groupSize = replicationGroup.getElectableNodes().size();
    int majoritySize = groupSize / 2 + 1;
    if ((activeNodes >= majoritySize) && isMasterActive) {
        masterGroupStatus.setMasterGroupStatus(true, true, true);
        connectNodeFailCount = 0;
        if (isPrimaryNodeActive()) {
            repEnv.setRepMutableConfig(repEnv.getRepMutableConfig().setDesignatedPrimary(false));
        }
    }
    if (groupSize == 2 && connectNodeFailCount >= 3) {
        masterGroupStatus.setMasterGroupStatus(true, false, true);
        if (connectNodeFailCount > 1000) {
            connectNodeFailCount = 3;
        }
        if (!isPrimaryNodeActive()) {
            logger.error("[BDB Error] DesignatedPrimary happened...please check if the other member is down");
            repEnv.setRepMutableConfig(repEnv.getRepMutableConfig().setDesignatedPrimary(true));
        }
    }
    return masterGroupStatus;
}
Also used : NodeState(com.sleepycat.je.rep.NodeState) EnvironmentFailureException(com.sleepycat.je.EnvironmentFailureException) IOException(java.io.IOException) ReplicationGroup(com.sleepycat.je.rep.ReplicationGroup) ReplicationNode(com.sleepycat.je.rep.ReplicationNode) MetaConfigSamplePrint(org.apache.inlong.tubemq.server.master.utils.MetaConfigSamplePrint) MasterNodeInfo(org.apache.inlong.tubemq.server.master.bdbstore.MasterNodeInfo) MasterGroupStatus(org.apache.inlong.tubemq.server.master.bdbstore.MasterGroupStatus) ServiceDispatcher(com.sleepycat.je.rep.utilint.ServiceDispatcher) DatabaseException(com.sleepycat.je.DatabaseException) HashSet(java.util.HashSet)

Aggregations

EnvironmentFailureException (com.sleepycat.je.EnvironmentFailureException)10 CacheException (diskCacheV111.util.CacheException)6 IOException (java.io.IOException)6 OperationFailureException (com.sleepycat.je.OperationFailureException)5 DiskErrorCacheException (diskCacheV111.util.DiskErrorCacheException)5 DatabaseException (com.sleepycat.je.DatabaseException)3 ReplicationNode (com.sleepycat.je.rep.ReplicationNode)3 HashSet (java.util.HashSet)3 MasterStateException (com.sleepycat.je.rep.MasterStateException)2 MemberNotFoundException (com.sleepycat.je.rep.MemberNotFoundException)2 NodeState (com.sleepycat.je.rep.NodeState)2 ReplicationGroup (com.sleepycat.je.rep.ReplicationGroup)2 UnknownMasterException (com.sleepycat.je.rep.UnknownMasterException)2 ServiceDispatcher (com.sleepycat.je.rep.utilint.ServiceDispatcher)2 MasterGroupStatus (org.apache.inlong.tubemq.server.master.bdbstore.MasterGroupStatus)2 MasterNodeInfo (org.apache.inlong.tubemq.server.master.bdbstore.MasterNodeInfo)2 MetaConfigSamplePrint (org.apache.inlong.tubemq.server.master.utils.MetaConfigSamplePrint)2 Stopwatch (com.google.common.base.Stopwatch)1 LogWriteException (com.sleepycat.je.LogWriteException)1 InsufficientAcksException (com.sleepycat.je.rep.InsufficientAcksException)1