Skip to content

Commit

Permalink
WFLY-10009 Update to introduce a maximum timeout attribute in the tra…
Browse files Browse the repository at this point in the history
…nsaction subsystem
  • Loading branch information
zhfeng authored and jamezp committed Jul 30, 2018
1 parent 366851c commit 3614d35
Show file tree
Hide file tree
Showing 19 changed files with 561 additions and 63 deletions.
Expand Up @@ -250,4 +250,7 @@ public interface TransactionLogger extends BasicLogger {
@Message(id = 38, value = "Unexpected error on suspending transaction for work %s")
RuntimeException cannotSuspendInflowTransactionUnexpectedError(Work txn, @Cause Exception e);

@LogMessage(level = WARN)
@Message(id = 39, value = "The transaction timeout has been set to %s while the value is 0")
void timeoutValueIsSetToMaximum(int maximum_timeout);
}
Expand Up @@ -40,6 +40,7 @@ enum Attribute {
ENABLE_STATISTICS("enable-statistics"),
ENABLE_TSM_STATUS("enable-tsm-status"),
DEFAULT_TIMEOUT("default-timeout"),
MAXIMUM_TIMEOUT("maximum-timeout"),
RECOVERY_LISTENER("recovery-listener"),
RELATIVE_TO("relative-to"),
STATISTICS_ENABLED("statistics-enabled"),
Expand Down
Expand Up @@ -32,6 +32,7 @@ interface CommonAttributes {
String CORE_ENVIRONMENT = "core-environment";
String COORDINATOR_ENVIRONMENT = "coordinator-environment";
String DEFAULT_TIMEOUT = "default-timeout";
String MAXIMUM_TIMEOUT = "maximum-timeout";
String ENABLE_STATISTICS = "enable-statistics";
/** transaction status manager (TSM) service, needed for out of process recovery, should be provided or not */
String ENABLE_TSM_STATUS = "enable-tsm-status";
Expand Down
Expand Up @@ -43,12 +43,13 @@ enum Namespace {
TRANSACTIONS_2_0("urn:jboss:domain:transactions:2.0"),
TRANSACTIONS_3_0("urn:jboss:domain:transactions:3.0"),
TRANSACTIONS_4_0("urn:jboss:domain:transactions:4.0"),
TRANSACTIONS_4_1("urn:jboss:domain:transactions:4.1"),
;

/**
* The current namespace version.
*/
public static final Namespace CURRENT = TRANSACTIONS_4_0;
public static final Namespace CURRENT = TRANSACTIONS_4_1;

private final String name;

Expand Down
Expand Up @@ -59,7 +59,7 @@ public class TransactionExtension implements Extension {

private static final String RESOURCE_NAME = TransactionExtension.class.getPackage().getName() + ".LocalDescriptions";

static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(4, 0, 0);
static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(4, 1, 0);


private static final ServiceName MBEAN_SERVER_SERVICE_NAME = ServiceName.JBOSS.append("mbean", "server");
Expand Down Expand Up @@ -133,5 +133,6 @@ public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.TRANSACTIONS_2_0.getUriString(), TransactionSubsystem20Parser::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.TRANSACTIONS_3_0.getUriString(), TransactionSubsystem30Parser::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.TRANSACTIONS_4_0.getUriString(), TransactionSubsystem40Parser::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.TRANSACTIONS_4_1.getUriString(), TransactionSubsystem41Parser::new);
}
}
Expand Up @@ -23,7 +23,7 @@
package org.jboss.as.txn.subsystem;

/**
* The {@link org.jboss.staxmapper.XMLElementReader} that handles the version 3.1 of Transaction subsystem xml.
* The {@link org.jboss.staxmapper.XMLElementReader} that handles the version 4.0 of Transaction subsystem xml.
*/
class TransactionSubsystem40Parser extends TransactionSubsystem30Parser {

Expand All @@ -32,4 +32,8 @@ class TransactionSubsystem40Parser extends TransactionSubsystem30Parser {
this.relativeToHasDefaultValue = false;
}

TransactionSubsystem40Parser(Namespace namespace) {
super(namespace);
this.relativeToHasDefaultValue = false;
}
}
@@ -0,0 +1,77 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
*/
package org.jboss.as.txn.subsystem;

import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLExtendedStreamReader;

import javax.xml.stream.XMLStreamException;

import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;

/**
* The {@link org.jboss.staxmapper.XMLElementReader} that handles the version 4.1 of Transaction subsystem xml.
*/
class TransactionSubsystem41Parser extends TransactionSubsystem40Parser {

TransactionSubsystem41Parser() {
super(Namespace.TRANSACTIONS_4_1);
}

TransactionSubsystem41Parser(Namespace namespace) {
super(namespace);
}

protected void parseCoordinatorEnvironmentElement(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException {

final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case STATISTICS_ENABLED:
TransactionSubsystemRootResourceDefinition.STATISTICS_ENABLED.parseAndSetParameter(value, operation, reader);
break;
case ENABLE_STATISTICS:
TransactionSubsystemRootResourceDefinition.ENABLE_STATISTICS.parseAndSetParameter(value, operation, reader);
break;
case ENABLE_TSM_STATUS:
TransactionSubsystemRootResourceDefinition.ENABLE_TSM_STATUS.parseAndSetParameter(value, operation, reader);
break;
case DEFAULT_TIMEOUT:
TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.parseAndSetParameter(value, operation, reader);
break;
case MAXIMUM_TIMEOUT:
TransactionSubsystemRootResourceDefinition.MAXIMUM_TIMEOUT.parseAndSetParameter(value, operation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
// Handle elements
requireNoContent(reader);
}
}
Expand Up @@ -169,6 +169,7 @@ private void populateModelWithCoordinatorEnvConfig(ModelNode operation, ModelNod
TransactionSubsystemRootResourceDefinition.ENABLE_STATISTICS.validateAndSet(operation, coordEnvModel);
TransactionSubsystemRootResourceDefinition.ENABLE_TSM_STATUS.validateAndSet(operation, coordEnvModel);
TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.validateAndSet(operation, coordEnvModel);
TransactionSubsystemRootResourceDefinition.MAXIMUM_TIMEOUT.validateAndSet(operation, coordEnvModel);

ModelNode mceVal = coordEnvModel.get(TransactionSubsystemRootResourceDefinition.ENABLE_STATISTICS.getName());
if (mceVal.isDefined()) {
Expand Down Expand Up @@ -508,8 +509,15 @@ private void performCoordinatorEnvBoottime(OperationContext context, ModelNode c
final boolean coordinatorEnableStatistics = TransactionSubsystemRootResourceDefinition.STATISTICS_ENABLED.resolveModelAttribute(context, coordEnvModel).asBoolean();
final boolean transactionStatusManagerEnable = TransactionSubsystemRootResourceDefinition.ENABLE_TSM_STATUS.resolveModelAttribute(context, coordEnvModel).asBoolean();
final int coordinatorDefaultTimeout = TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.resolveModelAttribute(context, coordEnvModel).asInt();
final int maximumTimeout = TransactionSubsystemRootResourceDefinition.MAXIMUM_TIMEOUT.resolveModelAttribute(context, coordEnvModel).asInt();

ContextTransactionManager.setGlobalDefaultTransactionTimeout(coordinatorDefaultTimeout);
// WFLY-9955 Allow the timeout set to "0" while translating into the maximum timeout
if (coordinatorDefaultTimeout == 0) {
ContextTransactionManager.setGlobalDefaultTransactionTimeout(maximumTimeout);
TransactionLogger.ROOT_LOGGER.timeoutValueIsSetToMaximum(maximumTimeout);
} else {
ContextTransactionManager.setGlobalDefaultTransactionTimeout(coordinatorDefaultTimeout);
}
final ArjunaTransactionManagerService transactionManagerService = new ArjunaTransactionManagerService(coordinatorEnableStatistics, coordinatorDefaultTimeout, transactionStatusManagerEnable, jts);
final ServiceBuilder<com.arjuna.ats.jbossatx.jta.TransactionManagerService> transactionManagerServiceServiceBuilder = context.getServiceTarget().addService(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, transactionManagerService);
// add dependency on JTA environment bean service
Expand Down
Expand Up @@ -155,6 +155,12 @@ public class TransactionSubsystemRootResourceDefinition extends SimpleResourceDe
.setXmlName(Attribute.DEFAULT_TIMEOUT.getLocalName())
.setAllowExpression(true).build();

public static final SimpleAttributeDefinition MAXIMUM_TIMEOUT = new SimpleAttributeDefinitionBuilder(CommonAttributes.MAXIMUM_TIMEOUT, ModelType.INT, true)
.setValidator(new IntRangeValidator(300))
.setMeasurementUnit(MeasurementUnit.SECONDS)
.setDefaultValue(new ModelNode().set(31536000))
.setFlags(AttributeAccess.Flag.RESTART_NONE)
.setAllowExpression(true).build();
//object store
public static final SimpleAttributeDefinition OBJECT_STORE_RELATIVE_TO = new SimpleAttributeDefinitionBuilder(CommonAttributes.OBJECT_STORE_RELATIVE_TO, ModelType.STRING, true)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
Expand Down Expand Up @@ -259,7 +265,7 @@ public class TransactionSubsystemRootResourceDefinition extends SimpleResourceDe
// all attributes
static final AttributeDefinition[] attributes = new AttributeDefinition[] {
BINDING, STATUS_BINDING, RECOVERY_LISTENER, NODE_IDENTIFIER, PROCESS_ID_UUID, PROCESS_ID_SOCKET_BINDING,
PROCESS_ID_SOCKET_MAX_PORTS, STATISTICS_ENABLED, ENABLE_TSM_STATUS, DEFAULT_TIMEOUT,
PROCESS_ID_SOCKET_MAX_PORTS, STATISTICS_ENABLED, ENABLE_TSM_STATUS, DEFAULT_TIMEOUT, MAXIMUM_TIMEOUT,
OBJECT_STORE_RELATIVE_TO, OBJECT_STORE_PATH, JTS, USE_JOURNAL_STORE, USE_JDBC_STORE, JDBC_STORE_DATASOURCE,
JDBC_ACTION_STORE_DROP_TABLE, JDBC_ACTION_STORE_TABLE_PREFIX, JDBC_COMMUNICATION_STORE_DROP_TABLE,
JDBC_COMMUNICATION_STORE_TABLE_PREFIX, JDBC_STATE_STORE_DROP_TABLE, JDBC_STATE_STORE_TABLE_PREFIX,
Expand All @@ -281,6 +287,7 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati

attributesWithoutMutuals.remove(STATISTICS_ENABLED);
attributesWithoutMutuals.remove(DEFAULT_TIMEOUT);
attributesWithoutMutuals.remove(MAXIMUM_TIMEOUT);
attributesWithoutMutuals.remove(JDBC_STORE_DATASOURCE); // Remove these as it also needs special write handler

attributesWithoutMutuals.remove(PROCESS_ID_UUID);
Expand All @@ -300,6 +307,7 @@ public void registerAttributes(ManagementResourceRegistration resourceRegistrati

//Register default-timeout attribute
resourceRegistration.registerReadWriteAttribute(DEFAULT_TIMEOUT, null, new DefaultTimeoutHandler(DEFAULT_TIMEOUT));
resourceRegistration.registerReadWriteAttribute(MAXIMUM_TIMEOUT, null, new MaximumTimeoutHandler(MAXIMUM_TIMEOUT));

// Register jdbc-store-datasource attribute
resourceRegistration.registerReadWriteAttribute(JDBC_STORE_DATASOURCE, null, new JdbcStoreDatasourceWriteHandler(JDBC_STORE_DATASOURCE));
Expand Down Expand Up @@ -489,14 +497,20 @@ public DefaultTimeoutHandler(final AttributeDefinition... definitions) {
super(definitions);
}


@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode resolvedValue,
final ModelNode currentValue, final HandbackHolder<Void> handbackHolder)
throws OperationFailedException {
TxControl.setDefaultTimeout(resolvedValue.asInt());
ContextTransactionManager.setGlobalDefaultTransactionTimeout(resolvedValue.asInt());
int timeout = resolvedValue.asInt();

TxControl.setDefaultTimeout(timeout);
if (timeout == 0) {
ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
timeout = MAXIMUM_TIMEOUT.resolveModelAttribute(context, model).asInt();
TransactionLogger.ROOT_LOGGER.timeoutValueIsSetToMaximum(timeout);
}
ContextTransactionManager.setGlobalDefaultTransactionTimeout(timeout);
return false;
}

Expand All @@ -510,6 +524,30 @@ protected void revertUpdateToRuntime(final OperationContext context, final Model
}
}

private static class MaximumTimeoutHandler extends AbstractWriteAttributeHandler<Void> {
public MaximumTimeoutHandler(final AttributeDefinition... definitions) {
super(definitions);
}

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation,
final String attributeName, final ModelNode resolvedValue,
final ModelNode currentValue, final HandbackHolder<Void> handbackHolder)
throws OperationFailedException {
int maximum_timeout = resolvedValue.asInt();
if (TxControl.getDefaultTimeout() == 0) {
TransactionLogger.ROOT_LOGGER.timeoutValueIsSetToMaximum(maximum_timeout);
ContextTransactionManager.setGlobalDefaultTransactionTimeout(maximum_timeout);
}
return false;
}

@Override
protected void revertUpdateToRuntime(OperationContext operationContext, ModelNode modelNode, String s, ModelNode modelNode1, ModelNode modelNode2, Void aVoid) throws OperationFailedException {

}
}

private static class StatisticsEnabledHandler extends AbstractWriteAttributeHandler<Void> {

private volatile CoordinatorEnvironmentBean coordinatorEnvironmentBean;
Expand Down
Expand Up @@ -76,13 +76,15 @@ public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingCon
}
if (TransactionSubsystemRootResourceDefinition.STATISTICS_ENABLED.isMarshallable(node)
|| TransactionSubsystemRootResourceDefinition.ENABLE_TSM_STATUS.isMarshallable(node)
|| TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.isMarshallable(node)) {
|| TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.isMarshallable(node)
|| TransactionSubsystemRootResourceDefinition.MAXIMUM_TIMEOUT.isMarshallable(node)) {

writer.writeStartElement(Element.COORDINATOR_ENVIRONMENT.getLocalName());

TransactionSubsystemRootResourceDefinition.STATISTICS_ENABLED.marshallAsAttribute(node, writer);
TransactionSubsystemRootResourceDefinition.ENABLE_TSM_STATUS.marshallAsAttribute(node, writer);
TransactionSubsystemRootResourceDefinition.DEFAULT_TIMEOUT.marshallAsAttribute(node, writer);
TransactionSubsystemRootResourceDefinition.MAXIMUM_TIMEOUT.marshallAsAttribute(node, writer);

writer.writeEndElement();
}
Expand Down

0 comments on commit 3614d35

Please sign in to comment.