Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[WFTC-38] Add a XAResourceRegistry to record in a file all in doubt r… #40

Merged
merged 1 commit into from
Mar 9, 2018

Conversation

fl4via
Copy link
Contributor

@fl4via fl4via commented Feb 28, 2018

…esources, and make recovery available using org.jboss.tm.XAResourceRecoveryRegistry

@@ -116,6 +116,31 @@ public int compareTo(final SimpleXid o) {
return res;
}

public String toHexString() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is used to name the file. Since the file name is not used for anything, we could alternatively use SimpleXid.toString() to name that file and remove this toHexString small refactoring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is OK.

@@ -82,6 +96,26 @@
@Message(value = "Failure on running doRecover during initialization")
void doRecoverFailureOnIntialization(@Cause Throwable e);

@LogMessage(level = Logger.Level.TRACE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added those methods as trace, let me know if you prefer DEBUG.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRACE is the correct choice here.

@@ -728,13 +747,36 @@ public Builder setTransactionSynchronizationRegistry(final TransactionSynchroniz
return this;
}

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I also need to add getter methods for these two properties in Builder?

/**
* {@inheritDoc}
*/
@Override
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review: is SystemException the best option here? I could go with IOException as well, but that would force XAOutflowedResources to treat that exception or to declare an extra exception, I assumed that from the pov of the XAOutflowedResources caller it made more sense SystemException

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that SystemException is correct. We want Transaction.enlistResource to fail with an exception when an exceptional state occurs.

* @throws XAException if there is a problem deleting the registry file
*/
@Override
protected void removeResource(XAResource resource) throws XAException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify correctness of XAException, hopefully I got it right

assert fileChannel != null;
try {
assert fileChannel.isOpen();
fileChannel.write(ByteBuffer.wrap(uri.toString().getBytes()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to double-check that this is OK in a multithreaded setting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No delimiter is added so it will be difficult to separate URIs on read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're relying on the default JDK character set encoding here; we should use StandardCharsets.UTF_8 instead.

*
* @author Flavia Rainone
*/
final class JBossXAResourceRegistry extends XAResourceRegistry {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about FileSystemXAResourceRegistry, and then it can be public?

/**
* The xa recovery path, i.e., the path containing {@link #RECOVERY_DIR}. See {@link #setRelativeToPath}.
*/
private static Path xaRecoveryPath = FileSystems.getDefault().getPath(RECOVERY_DIR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state definitely should not be static.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we really want is one instance per provider rather than one instance per transaction. The individual transaction files could be tracked via a ConcurrentMap<SimpleXid, Entry> where Entry tracks the individual file state and information. The per-provider instance would contain the global config (base recovery path). The set of open file paths can be derived from the values of the map.

The XID would have to be given as an argument to the registry methods to make this work.

recoverInDoubtRegistries(provider);
} catch (IOException e) {
// ignore with a logged message
Log.log.unexpectedExceptionOnXAResourceRecovery(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably throw an exception, like an IllegalStateException perhaps which wraps the IOException

* @return a newly-created resource representing a previously lost XA resource.
*/
protected XAResource reloadInDoubtResource(URI uri, String nodeName) {
return new SubordinateXAResource(uri, nodeName, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should set the flags argument to FL_COMMITTED | FL_CONFIRMED.

throw exception;
}
if (resourceRegistry != null)
resourceRegistry.removeResource(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we determine that it was safe to remove entries after prepare? Does the TM log the resource at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does, according to the discussion we had last year with Tom. Anyway, I'll double check with him.

Copy link
Member

@dmlloyd dmlloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending discussion.

throw Log.log.deleteXAResourceRecoveryFileFailed(XAException.XAER_RMERR, filePath, resource, e);
}
Log.log.xaResourceRecoveryFileDeleted(filePath);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remember to discuss whether it's safe or optimal to leave entries for resources which are no longer in doubt.

… files all in doubt resources, and make recovery available using org.jboss.tm.XAResourceRecoveryRegistry
@fl4via
Copy link
Contributor Author

fl4via commented Mar 9, 2018

@dmlloyd the PR is updated

@dmlloyd dmlloyd merged commit 476840c into wildfly:master Mar 9, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants