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