Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

SCB-227 stop sub tx from running when global tx failed #114

Merged
merged 6 commits into from
Jan 16, 2018

Conversation

eric-lee-ltk
Copy link
Contributor

@eric-lee-ltk eric-lee-ltk commented Jan 12, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling dfb53f2 on eric-lee-ltk:SCB-227 into ** on apache:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling b95ae53 on eric-lee-ltk:SCB-227 into ** on apache:master**.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 95.416% when pulling cd867f9 on eric-lee-ltk:SCB-227 into 9dd6a63 on apache:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 94.901% when pulling e9128a1 on eric-lee-ltk:SCB-227 into 5b2b59a on apache:master.

@@ -100,4 +106,8 @@ private boolean isGlobalTxAborted(TxEvent event) {
private boolean isTxEndedEvent(TxEvent event) {
return TxEndedEvent.name().equals(event.type());
}

private boolean isInvalidTxStarted(TxEvent event) {
Copy link
Member

Choose a reason for hiding this comment

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

probably inlining this method is more readable

if (!ok) {
LOG.info("Skipped transaction {} due to abort.", context.globalTxId());
context.setLocalTxId(localTxId);
return null;
Copy link
Member

Choose a reason for hiding this comment

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

not a good idea to return null, since user doesn't expect it

@@ -33,6 +33,7 @@ message GrpcServiceConfig {
}

message GrpcAck {
bool valid = 1;
Copy link
Member

Choose a reason for hiding this comment

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

valid doesn't seem to be a proper name, because the transaction is indeed valid. probably just aborted?

blockingEventService.onTxEvent(convertEvent(event));
public boolean send(TxEvent event) {
GrpcAck grpcAck = blockingEventService.onTxEvent(convertEvent(event));
return grpcAck.getValid();
Copy link
Member

Choose a reason for hiding this comment

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

better to return a proper AlphaResponse class instead of boolean

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 95.306% when pulling 3891afc on eric-lee-ltk:SCB-227 into 5b2b59a on apache:master.

if (response.aborted()) {
String abortedLocalTxId = context.localTxId();
context.setLocalTxId(localTxId);
throw new IllegalStateException("Abort local sub transaction " + abortedLocalTxId +
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this throw transaction exception?

@@ -123,14 +124,15 @@ public void close() {
}

@Override
public void send(TxEvent event) {
public AlphaResponse send(TxEvent event) {
AlphaResponse response = new AlphaResponse(false);
Copy link
Member

Choose a reason for hiding this comment

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

what behavior is expected from omega, if this response returns?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 95.329% when pulling 0bc5598 on eric-lee-ltk:SCB-227 into 7bfb6a9 on apache:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 95.28% when pulling 0550e93 on eric-lee-ltk:SCB-227 into 7bfb6a9 on apache:master.

if (response.aborted()) {
String abortedLocalTxId = context.localTxId();
context.setLocalTxId(localTxId);
throw new OmegaTxAbortedException("Abort local sub transaction " + abortedLocalTxId +
Copy link
Member

Choose a reason for hiding this comment

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

better to throw TransactionException defined in spring, because user is not going to catch OmegaTxAbortedException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using the spring's TransactionException will introduce spring dependency in our omega transaction module, is it all right to do so?

@@ -124,14 +125,15 @@ public void close() {
}

@Override
public void send(TxEvent event) {
public AlphaResponse send(TxEvent event) {
AlphaResponse response = null;
Copy link
Member

Choose a reason for hiding this comment

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

have to think about when this response will be returned, and the consequence of returning this response under such a scenario. apparently it's only possible when this thread is interrupted and throwing an exception is a better idea in such case.

} catch (OmegaTxAbortedException e) {
assertThat(e.getMessage().contains("Abort local sub transaction"), is(true));
} catch (Throwable throwable) {
expectFailing(OmegaTxAbortedException.class);
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 not necessary, since test will fail on uncaught exception

} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return new AlphaResponse(true);
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@@ -85,7 +87,12 @@ public void onTxEvent(GrpcTxEvent message, StreamObserver<GrpcAck> responseObser
message.getPayloads().toByteArray()
));

responseObserver.onNext(ACK);
if (ok) {
Copy link
Member

Choose a reason for hiding this comment

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

this can be simplified into one line

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 95.367% when pulling 264c32d on eric-lee-ltk:SCB-227 into d6e9c48 on apache:master.

Signed-off-by: Eric Lee <dagang.li@huawei.com>
Signed-off-by: Eric Lee <dagang.li@huawei.com>
Signed-off-by: Eric Lee <dagang.li@huawei.com>
Signed-off-by: Eric Lee <dagang.li@huawei.com>
Signed-off-by: Eric Lee <dagang.li@huawei.com>
@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 95.186% when pulling 1d23495 on eric-lee-ltk:SCB-227 into 5f1dce3 on apache:master.

}
});
thread.start();
thread.interrupt();
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 join here to wait for thread exit

if (response.aborted()) {
String abortedLocalTxId = context.localTxId();
context.setLocalTxId(localTxId);
throw new InvalidTransactionException("Abort local sub transaction " + abortedLocalTxId +
Copy link
Member

Choose a reason for hiding this comment

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

local transaction is sub transaction, "Aborted sub transaction... because global transaction ..."

Thread.currentThread().interrupt();
}
}));
throw new OmegaException("Failed to send event " + event + " due to interruption");
Copy link
Member

Choose a reason for hiding this comment

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

preferably to move this line to catch clause and pass interrupted exception to its constructor

Signed-off-by: Eric Lee <dagang.li@huawei.com>
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 94.891% when pulling 366edd4 on eric-lee-ltk:SCB-227 into 5f1dce3 on apache:master.

@seanyinx seanyinx merged commit 9643ad8 into apache:master Jan 16, 2018
@eric-lee-ltk eric-lee-ltk deleted the SCB-227 branch January 16, 2018 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants