Repository: asterixdb Updated Branches: refs/heads/master 206381e6d -> 689fb185c
Exceptions Cleanup for Replication/FaultTolerance Strategies Change-Id: I8f28b8db42bf7c8537ff2da22cbd2a97e243f32f Reviewed-on: https://asterix-gerrit.ics.uci.edu/1529 Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Yingyi Bu <buyin...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/689fb185 Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/689fb185 Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/689fb185 Branch: refs/heads/master Commit: 689fb185c63a9aeea78d03f82b1a3d85dafd45dc Parents: 206381e Author: Murtadha Hubail <mhub...@uci.edu> Authored: Tue Feb 28 19:10:17 2017 +0300 Committer: Yingyi Bu <buyin...@gmail.com> Committed: Tue Feb 28 14:53:57 2017 -0800 ---------------------------------------------------------------------- .../asterix/app/nc/NCAppRuntimeContext.java | 2 +- .../apache/asterix/app/nc/RecoveryManager.java | 10 ++++++---- .../app/nc/task/MetadataBootstrapTask.java | 2 +- .../replication/AutoFaultToleranceStrategy.java | 6 ++++-- .../MetadataNodeFaultToleranceStrategy.java | 12 ++++++++---- .../app/replication/NoFaultToleranceStrategy.java | 8 ++++++-- .../bootstrap/NCApplicationEntryPoint.java | 8 ++++---- .../apache/asterix/util/FaultToleranceUtil.java | 4 +++- .../apache/asterix/test/common/TestExecutor.java | 4 ++-- .../asterix/common/config/ClusterProperties.java | 3 ++- .../common/config/ReplicationProperties.java | 3 ++- .../asterix/common/exceptions/ErrorCode.java | 7 +++++-- .../ChainedDeclusteringReplicationStrategy.java | 11 ++++++++--- .../common/replication/IReplicationStrategy.java | 3 ++- .../MetadataOnlyReplicationStrategy.java | 12 ++++++++---- .../replication/ReplicationStrategyFactory.java | 12 ++++++++---- .../common/transactions/IRecoveryManager.java | 18 ++++++++++++------ .../src/main/resources/asx_errormsg/en.properties | 4 ++++ .../installer/test/MetadataReplicationIT.java | 5 ++++- 19 files changed, 90 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java index b4b7a95..625f18f 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java @@ -191,7 +191,7 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { IRecoveryManager recoveryMgr = txnSubsystem.getRecoveryManager(); SystemState systemState = recoveryMgr.getSystemState(); - if (initialRun || systemState == SystemState.NEW_UNIVERSE) { + if (initialRun || systemState == SystemState.PERMANENT_DATA_LOSS) { //delete any storage data before the resource factory is initialized localResourceRepository.deleteStorageData(true); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java index 2efb139..4ee1122 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/RecoveryManager.java @@ -121,10 +121,10 @@ public class RecoveryManager implements IRecoveryManager, ILifeCycleComponent { Checkpoint checkpointObject = checkpointManager.getLatest(); if (checkpointObject == null) { //The checkpoint file doesn't exist => Failure happened during NC initialization. - //Retry to initialize the NC by setting the state to NEW_UNIVERSE - state = SystemState.NEW_UNIVERSE; + //Retry to initialize the NC by setting the state to PERMANENT_DATA_LOSS + state = SystemState.PERMANENT_DATA_LOSS; if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info("The checkpoint file doesn't exist: systemState = NEW_UNIVERSE"); + LOGGER.info("The checkpoint file doesn't exist: systemState = PERMANENT_DATA_LOSS"); } return state; } @@ -182,7 +182,9 @@ public class RecoveryManager implements IRecoveryManager, ILifeCycleComponent { @Override public void startLocalRecovery(Set<Integer> partitions) throws IOException, ACIDException { state = SystemState.RECOVERING; - LOGGER.log(Level.INFO, "starting recovery ..."); + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.info("starting recovery ..."); + } long readableSmallestLSN = logMgr.getReadableSmallestLSN(); Checkpoint checkpointObject = checkpointManager.getLatest(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/task/MetadataBootstrapTask.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/task/MetadataBootstrapTask.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/task/MetadataBootstrapTask.java index b6d85d9..ab19573 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/task/MetadataBootstrapTask.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/task/MetadataBootstrapTask.java @@ -36,7 +36,7 @@ public class MetadataBootstrapTask implements INCLifecycleTask { IAppRuntimeContext appContext = (IAppRuntimeContext) ncs.getApplicationContext().getApplicationObject(); try { SystemState state = appContext.getTransactionSubsystem().getRecoveryManager().getSystemState(); - appContext.initializeMetadata(state == SystemState.NEW_UNIVERSE); + appContext.initializeMetadata(state == SystemState.PERMANENT_DATA_LOSS); } catch (Exception e) { throw ExceptionUtils.convertToHyracksDataException(e); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java index 084563f..5104610 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java @@ -55,7 +55,9 @@ import org.apache.asterix.common.api.INCLifecycleTask; import org.apache.asterix.common.cluster.ClusterPartition; import org.apache.asterix.common.cluster.IClusterStateManager; import org.apache.asterix.common.config.ReplicationProperties; +import org.apache.asterix.common.exceptions.ErrorCode; import org.apache.asterix.common.exceptions.ExceptionUtils; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.common.messaging.api.ICCMessageBroker; import org.apache.asterix.common.replication.IFaultToleranceStrategy; import org.apache.asterix.common.replication.INCLifecycleMessage; @@ -448,7 +450,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { process((CompleteFailbackResponseMessage) message); break; default: - throw new HyracksDataException("Unsupported message type: " + message.getType().name()); + throw new RuntimeDataException(ErrorCode.UNSUPPORTED_MESSAGE_TYPE, message.getType().name()); } } @@ -485,7 +487,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { final String nodeId = msg.getNodeId(); final SystemState state = msg.getState(); List<INCLifecycleTask> tasks; - if (state == SystemState.INITIAL_RUN || state == SystemState.HEALTHY) { + if (state == SystemState.BOOTSTRAPPING || state == SystemState.HEALTHY) { tasks = buildStartupSequence(nodeId); } else { // failed node returned. Need to start failback process http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/MetadataNodeFaultToleranceStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/MetadataNodeFaultToleranceStrategy.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/MetadataNodeFaultToleranceStrategy.java index e6638e8..5a7036a 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/MetadataNodeFaultToleranceStrategy.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/MetadataNodeFaultToleranceStrategy.java @@ -46,7 +46,9 @@ import org.apache.asterix.app.replication.message.StartupTaskResponseMessage; import org.apache.asterix.common.api.INCLifecycleTask; import org.apache.asterix.common.cluster.ClusterPartition; import org.apache.asterix.common.cluster.IClusterStateManager; +import org.apache.asterix.common.exceptions.ErrorCode; import org.apache.asterix.common.exceptions.ExceptionUtils; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.common.messaging.api.ICCMessageBroker; import org.apache.asterix.common.replication.IFaultToleranceStrategy; import org.apache.asterix.common.replication.INCLifecycleMessage; @@ -129,7 +131,7 @@ public class MetadataNodeFaultToleranceStrategy implements IFaultToleranceStrate process((ReplayPartitionLogsResponseMessage) message); break; default: - throw new HyracksDataException("Unsupported message type: " + message.getType().name()); + throw new RuntimeDataException(ErrorCode.UNSUPPORTED_MESSAGE_TYPE, message.getType().name()); } } @@ -141,7 +143,9 @@ public class MetadataNodeFaultToleranceStrategy implements IFaultToleranceStrate private synchronized void process(ReplayPartitionLogsResponseMessage msg) { hotStandbyMetadataReplica.add(msg.getNodeId()); - LOGGER.log(Level.INFO, "Hot Standby Metadata Replicas: " + hotStandbyMetadataReplica); + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.info("Hot Standby Metadata Replicas: " + hotStandbyMetadataReplica); + } } private synchronized void process(StartupTaskRequestMessage msg) throws HyracksDataException { @@ -202,7 +206,7 @@ public class MetadataNodeFaultToleranceStrategy implements IFaultToleranceStrate private List<INCLifecycleTask> buildParticipantStartupSequence(String nodeId, SystemState state) { final List<INCLifecycleTask> tasks = new ArrayList<>(); switch (state) { - case NEW_UNIVERSE: + case PERMANENT_DATA_LOSS: // If the metadata node (or replica) failed and lost its data // => Metadata Remote Recovery from standby replica tasks.add(getMetadataPartitionRecoveryPlan()); @@ -215,7 +219,7 @@ public class MetadataNodeFaultToleranceStrategy implements IFaultToleranceStrate .stream().map(ClusterPartition::getPartitionId).collect(Collectors.toSet())); tasks.add(rt); break; - case INITIAL_RUN: + case BOOTSTRAPPING: case HEALTHY: case RECOVERING: break; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NoFaultToleranceStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NoFaultToleranceStrategy.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NoFaultToleranceStrategy.java index 0ee4f6a..51defaa 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NoFaultToleranceStrategy.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NoFaultToleranceStrategy.java @@ -40,7 +40,9 @@ import org.apache.asterix.app.replication.message.StartupTaskResponseMessage; import org.apache.asterix.common.api.INCLifecycleTask; import org.apache.asterix.common.cluster.ClusterPartition; import org.apache.asterix.common.cluster.IClusterStateManager; +import org.apache.asterix.common.exceptions.ErrorCode; import org.apache.asterix.common.exceptions.ExceptionUtils; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.common.messaging.api.ICCMessageBroker; import org.apache.asterix.common.replication.IFaultToleranceStrategy; import org.apache.asterix.common.replication.INCLifecycleMessage; @@ -81,7 +83,7 @@ public class NoFaultToleranceStrategy implements IFaultToleranceStrategy { process((NCLifecycleTaskReportMessage) message); break; default: - throw new HyracksDataException("Unsupported message type: " + message.getType().name()); + throw new RuntimeDataException(ErrorCode.UNSUPPORTED_MESSAGE_TYPE, message.getType().name()); } } @@ -118,7 +120,9 @@ public class NoFaultToleranceStrategy implements IFaultToleranceStrategy { } clusterManager.refreshState(); } else { - LOGGER.log(Level.SEVERE, msg.getNodeId() + " failed to complete startup. ", msg.getException()); + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.log(Level.SEVERE, msg.getNodeId() + " failed to complete startup. ", msg.getException()); + } } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java index ce57648..7f649bc 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java @@ -117,9 +117,9 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { IRecoveryManager recoveryMgr = runtimeContext.getTransactionSubsystem().getRecoveryManager(); systemState = recoveryMgr.getSystemState(); - if (systemState == SystemState.NEW_UNIVERSE) { + if (systemState == SystemState.PERMANENT_DATA_LOSS) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info("System state: " + SystemState.NEW_UNIVERSE); + LOGGER.info("System state: " + SystemState.PERMANENT_DATA_LOSS); LOGGER.info("Node ID: " + nodeId); LOGGER.info("Stores: " + PrintUtil.toString(metadataProperties.getStores())); LOGGER.info("Root Metadata Store: " + metadataProperties.getStores().get(nodeId)[0]); @@ -160,8 +160,8 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { @Override public void notifyStartupComplete() throws Exception { // Since we don't pass initial run flag in AsterixHyracksIntegrationUtil, we use the virtualNC flag - if (systemState == SystemState.NEW_UNIVERSE && (initialRun || virtualNC)) { - systemState = SystemState.INITIAL_RUN; + if (systemState == SystemState.PERMANENT_DATA_LOSS && (initialRun || virtualNC)) { + systemState = SystemState.BOOTSTRAPPING; } // Request startup tasks from CC StartupTaskRequestMessage.send((NodeControllerService) ncApplicationContext.getControllerService(), http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java index 0a9a215..0ab4e54 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java @@ -59,7 +59,9 @@ public class FaultToleranceUtil { try { messageBroker.sendApplicationMessageToNC(msg, replica); } catch (Exception e) { - LOGGER.log(Level.WARNING, "Failed sending an application message to an NC", e); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.log(Level.WARNING, "Failed sending an application message to an NC", e); + } } } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java index f5d97ba..ae40827 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java @@ -59,6 +59,7 @@ import org.apache.asterix.testframework.context.TestCaseContext.OutputFormat; import org.apache.asterix.testframework.context.TestFileContext; import org.apache.asterix.testframework.xml.TestCase.CompilationUnit; import org.apache.asterix.testframework.xml.TestGroup; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.lang3.StringUtils; @@ -1119,8 +1120,7 @@ public class TestExecutor { String config = actual.toString(); ObjectMapper om = new ObjectMapper(); String logDir = om.readTree(config).findPath("transaction.log.dirs").get(nodeId).asText(); - ProcessBuilder pb = new ProcessBuilder("rm", "-rf", logDir); - pb.start().waitFor(); + FileUtils.deleteQuietly(new File(logDir)); } public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb, http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ClusterProperties.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ClusterProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ClusterProperties.java index 980ad24..1ba9471 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ClusterProperties.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ClusterProperties.java @@ -32,6 +32,7 @@ import org.apache.asterix.event.schema.cluster.Cluster; import org.apache.asterix.event.schema.cluster.Node; import org.apache.asterix.event.schema.cluster.Replica; import org.apache.commons.lang3.StringUtils; +import org.apache.hyracks.api.exceptions.HyracksDataException; public class ClusterProperties { @@ -83,7 +84,7 @@ public class ClusterProperties { return -1; } - public IReplicationStrategy getReplicationStrategy() { + public IReplicationStrategy getReplicationStrategy() throws HyracksDataException { return ReplicationStrategyFactory.create(cluster); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ReplicationProperties.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ReplicationProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ReplicationProperties.java index cf2ce4f..116609e 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ReplicationProperties.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/ReplicationProperties.java @@ -25,6 +25,7 @@ import org.apache.asterix.common.replication.IReplicationStrategy; import org.apache.asterix.common.replication.Replica; import org.apache.asterix.event.schema.cluster.Cluster; import org.apache.asterix.event.schema.cluster.Node; +import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.util.StorageUtil; import org.apache.hyracks.util.StorageUtil.StorageUnit; @@ -54,7 +55,7 @@ public class ReplicationProperties extends AbstractProperties { private final Cluster cluster; private final IReplicationStrategy repStrategy; - public ReplicationProperties(PropertiesAccessor accessor) { + public ReplicationProperties(PropertiesAccessor accessor) throws HyracksDataException { super(accessor); this.cluster = ClusterProperties.INSTANCE.getCluster(); this.repStrategy = ClusterProperties.INSTANCE.getReplicationStrategy(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java index 6dbafd1..70e0ae9 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java @@ -18,10 +18,10 @@ */ package org.apache.asterix.common.exceptions; -import java.io.File; import java.io.InputStream; import java.util.Map; +import org.apache.asterix.event.schema.cluster.FaultTolerance; import org.apache.hyracks.api.util.ErrorMessageUtil; // Error code: @@ -37,6 +37,9 @@ public class ErrorCode { // Extension errors public static final int EXTENSION_ID_CONFLICT = 4001; public static final int EXTENSION_COMPONENT_CONFLICT = 4002; + public static final int UNSUPPORTED_MESSAGE_TYPE = 4003; + public static final int INVALID_CONFIGURATION = 4004; + public static final int UNSUPPORTED_REPLICATION_STRATEGY = 4005; // Runtime errors public static final int CASTING_FIELD = 1; @@ -53,7 +56,7 @@ public class ErrorCode { public static final int COERCION = 12; public static final int DUPLICATE_FIELD_NAME = 13; public static final int PROPERTY_NOT_SET = 14; - + public static final int INSTANTIATION_ERROR = 100; // Compilation errors public static final int PARSE_ERROR = 1001; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ChainedDeclusteringReplicationStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ChainedDeclusteringReplicationStrategy.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ChainedDeclusteringReplicationStrategy.java index ad326b2..dc69383 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ChainedDeclusteringReplicationStrategy.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ChainedDeclusteringReplicationStrategy.java @@ -25,7 +25,10 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.asterix.common.config.ClusterProperties; +import org.apache.asterix.common.exceptions.ErrorCode; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.event.schema.cluster.Cluster; +import org.apache.hyracks.api.exceptions.HyracksDataException; public class ChainedDeclusteringReplicationStrategy implements IReplicationStrategy { @@ -45,7 +48,9 @@ public class ChainedDeclusteringReplicationStrategy implements IReplicationStrat int nodeIndex = ClusterProperties.INSTANCE.getNodeIndex(nodeId); if (nodeIndex == -1) { - LOGGER.log(Level.WARNING, "Could not find node " + nodeId + " in cluster configurations"); + if (LOGGER.isLoggable(Level.WARNING)) { + LOGGER.warning("Could not find node " + nodeId + " in cluster configurations"); + } return Collections.emptySet(); } @@ -74,9 +79,9 @@ public class ChainedDeclusteringReplicationStrategy implements IReplicationStrat } @Override - public ChainedDeclusteringReplicationStrategy from(Cluster cluster) { + public ChainedDeclusteringReplicationStrategy from(Cluster cluster) throws HyracksDataException { if (cluster.getHighAvailability().getDataReplication().getReplicationFactor() == null) { - throw new IllegalStateException("Replication factor must be specified."); + throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "Replication factor must be specified."); } ChainedDeclusteringReplicationStrategy cd = new ChainedDeclusteringReplicationStrategy(); cd.replicationFactor = cluster.getHighAvailability().getDataReplication().getReplicationFactor().intValue(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IReplicationStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IReplicationStrategy.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IReplicationStrategy.java index f65f6ac..b3f1701 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IReplicationStrategy.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/IReplicationStrategy.java @@ -21,6 +21,7 @@ package org.apache.asterix.common.replication; import java.util.Set; import org.apache.asterix.event.schema.cluster.Cluster; +import org.apache.hyracks.api.exceptions.HyracksDataException; public interface IReplicationStrategy { @@ -54,5 +55,5 @@ public interface IReplicationStrategy { * @param cluster * @return A replication strategy based on the passed configurations. */ - IReplicationStrategy from(Cluster cluster); + IReplicationStrategy from(Cluster cluster) throws HyracksDataException; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/MetadataOnlyReplicationStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/MetadataOnlyReplicationStrategy.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/MetadataOnlyReplicationStrategy.java index 711f06d..bd4b32f 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/MetadataOnlyReplicationStrategy.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/MetadataOnlyReplicationStrategy.java @@ -24,9 +24,12 @@ import java.util.HashSet; import java.util.Set; import org.apache.asterix.common.config.ClusterProperties; +import org.apache.asterix.common.exceptions.ErrorCode; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.common.metadata.MetadataIndexImmutableProperties; import org.apache.asterix.event.schema.cluster.Cluster; import org.apache.asterix.event.schema.cluster.Node; +import org.apache.hyracks.api.exceptions.HyracksDataException; public class MetadataOnlyReplicationStrategy implements IReplicationStrategy { @@ -57,9 +60,9 @@ public class MetadataOnlyReplicationStrategy implements IReplicationStrategy { } @Override - public MetadataOnlyReplicationStrategy from(Cluster cluster) { + public MetadataOnlyReplicationStrategy from(Cluster cluster) throws HyracksDataException { if (cluster.getMetadataNode() == null) { - throw new IllegalStateException("Metadata node must be specified."); + throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "Metadata node must be specified."); } Node metadataNode = ClusterProperties.INSTANCE.getNodeById(cluster.getMetadataNode()); @@ -70,14 +73,15 @@ public class MetadataOnlyReplicationStrategy implements IReplicationStrategy { if (cluster.getHighAvailability().getFaultTolerance().getReplica() == null || cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId() == null || cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId().isEmpty()) { - throw new IllegalStateException("One or more replicas must be specified for metadata node."); + throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, + "One or more replicas must be specified for metadata node."); } final Set<Replica> replicas = new HashSet<>(); for (String nodeId : cluster.getHighAvailability().getFaultTolerance().getReplica().getNodeId()) { Node node = ClusterProperties.INSTANCE.getNodeById(nodeId); if (node == null) { - throw new IllegalStateException("Invalid replica specified: " + nodeId); + throw new RuntimeDataException(ErrorCode.INVALID_CONFIGURATION, "Invalid replica specified: " + nodeId); } replicas.add(new Replica(node)); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ReplicationStrategyFactory.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ReplicationStrategyFactory.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ReplicationStrategyFactory.java index b61b38a..703ddcc 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ReplicationStrategyFactory.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/replication/ReplicationStrategyFactory.java @@ -21,7 +21,10 @@ package org.apache.asterix.common.replication; import java.util.HashMap; import java.util.Map; +import org.apache.asterix.common.exceptions.ErrorCode; +import org.apache.asterix.common.exceptions.RuntimeDataException; import org.apache.asterix.event.schema.cluster.Cluster; +import org.apache.hyracks.api.exceptions.HyracksDataException; public class ReplicationStrategyFactory { @@ -38,7 +41,7 @@ public class ReplicationStrategyFactory { throw new AssertionError(); } - public static IReplicationStrategy create(Cluster cluster) { + public static IReplicationStrategy create(Cluster cluster) throws HyracksDataException { boolean highAvailabilityEnabled = cluster.getHighAvailability() != null && cluster.getHighAvailability().getEnabled() != null && Boolean.valueOf(cluster.getHighAvailability().getEnabled()); @@ -49,14 +52,15 @@ public class ReplicationStrategyFactory { } String strategyName = cluster.getHighAvailability().getDataReplication().getStrategy().toLowerCase(); if (!BUILT_IN_REPLICATION_STRATEGY.containsKey(strategyName)) { - throw new IllegalArgumentException(String.format("Unsupported Replication Strategy. Available types: %s", - BUILT_IN_REPLICATION_STRATEGY.keySet().toString())); + throw new RuntimeDataException(ErrorCode.UNSUPPORTED_REPLICATION_STRATEGY, + String.format("%s. Available strategies: %s", strategyName, + BUILT_IN_REPLICATION_STRATEGY.keySet().toString())); } Class<? extends IReplicationStrategy> clazz = BUILT_IN_REPLICATION_STRATEGY.get(strategyName); try { return clazz.newInstance().from(cluster); } catch (InstantiationException | IllegalAccessException e) { - throw new IllegalStateException(e); + throw new RuntimeDataException(ErrorCode.INSTANTIATION_ERROR, e, clazz.getName()); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/IRecoveryManager.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/IRecoveryManager.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/IRecoveryManager.java index 3e85276..84e1019 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/IRecoveryManager.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/IRecoveryManager.java @@ -34,11 +34,11 @@ import org.apache.hyracks.api.exceptions.HyracksDataException; public interface IRecoveryManager { public enum SystemState { - INITIAL_RUN, - NEW_UNIVERSE, - RECOVERING, - HEALTHY, - CORRUPTED + BOOTSTRAPPING, // The first time the NC is bootstrapped. + PERMANENT_DATA_LOSS, // No checkpoint files found on NC and it is not BOOTSTRAPPING (data loss). + RECOVERING, // Recovery process is on-going. + HEALTHY, // All txn logs effects are on disk (no need to perform recovery). + CORRUPTED // Some txn logs need to be replayed (need to perform recover). } public class ResourceType { @@ -99,7 +99,6 @@ public interface IRecoveryManager { * * @param partitions * @param lowWaterMarkLSN - * @param failedNode * @throws IOException * @throws ACIDException */ @@ -122,5 +121,12 @@ public interface IRecoveryManager { */ public void deleteRecoveryTemporaryFiles(); + /** + * Performs the local recovery process on {@code partitions} + * + * @param partitions + * @throws IOException + * @throws ACIDException + */ void startLocalRecovery(Set<Integer> partitions) throws IOException, ACIDException; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties index 14bd0c7..2bdb2a3 100644 --- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties +++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties @@ -27,6 +27,9 @@ # For the extension lifecycle 4001 = Two Extensions share the same Id: %1$s 4002 = Extension Conflict between %1$s and %2$s both extensions extend %3$s +4003 = Unsupported message type: %1$s +4004 = Invalid configuration: %1$s +4005 = Unsupported replication strategy %1$s # Type errors 2,1002 = Type mismatch: function %1$s expects its %2$s input parameter to be type %3$s, but the actual input type is %4$s @@ -45,6 +48,7 @@ 11 = Index out of bound in %1$s: %2$s 12 = Invalid implicit scalar to collection coercion in %1$s 14 = Property %1$s not set +100 = Unable to instantiate class %1$s # Compile-time check errors 1007 = Invalid expression: function %1$s expects its %2$s input parameter to be a %3$s expression, but the actual expression is %4$s http://git-wip-us.apache.org/repos/asf/asterixdb/blob/689fb185/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/MetadataReplicationIT.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/MetadataReplicationIT.java b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/MetadataReplicationIT.java index 2db6114..7a0a797 100644 --- a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/MetadataReplicationIT.java +++ b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/MetadataReplicationIT.java @@ -19,6 +19,7 @@ package org.apache.asterix.installer.test; import java.io.File; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Map; @@ -41,7 +42,9 @@ import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class MetadataReplicationIT { - private static final String PATH_BASE = "src/test/resources/integrationts/metadata_only_replication/"; + private static final String PATH_BASE = + Paths.get("src", "test", "resources", "integrationts", "metadata_only_replication").toString() + + File.separator; private static final String PATH_ACTUAL = "target" + File.separator + "ittest" + File.separator; private static final Logger LOGGER = Logger.getLogger(MetadataReplicationIT.class.getName()); private static String reportPath = new File(