-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
feature: add single server rate limit #6756
base: 2.x
Are you sure you want to change the base?
Changes from 18 commits
e67bbe3
850a8d1
33e574c
f5c2945
512bcb8
6a6abc5
3c11c5e
3a8a385
4f1731f
e62bc8f
60346cd
85e9101
da1f952
c01b24f
8c5b916
973ec5c
900fe59
aa37e27
da4261e
5567c3f
4bae944
dda9f88
7555517
5b7ab52
8f8bca3
4a16e83
a795ab7
15c3bc5
ce28681
cf30cb8
037d8b2
24bb0b1
8d258fa
1a1ddb8
c1a587e
05d6cd5
11f31de
139a688
83632a0
0282825
d2a4787
313da85
901a660
475411b
a669fc9
0c4e5ee
dad819c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,8 +16,6 @@ | |||||||||
*/ | ||||||||||
package io.seata.tm.api; | ||||||||||
|
||||||||||
import java.util.concurrent.TimeUnit; | ||||||||||
|
||||||||||
import io.netty.util.HashedWheelTimer; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it |
||||||||||
import io.netty.util.Timeout; | ||||||||||
import io.netty.util.TimerTask; | ||||||||||
|
@@ -28,6 +26,8 @@ | |||||||||
import org.slf4j.Logger; | ||||||||||
import org.slf4j.LoggerFactory; | ||||||||||
|
||||||||||
import java.util.concurrent.TimeUnit; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
/** | ||||||||||
* The type Default failure handler. | ||||||||||
*/ | ||||||||||
|
@@ -77,6 +77,11 @@ public void onRollbacking(GlobalTransaction tx, Throwable originalException) { | |||||||||
SCHEDULE_INTERVAL_SECONDS, TimeUnit.SECONDS); | ||||||||||
} | ||||||||||
|
||||||||||
@Override | ||||||||||
public void onBeginRateLimitedFailure(org.apache.seata.tm.api.GlobalTransaction globalTransaction, Throwable cause) { | ||||||||||
LOGGER.warn("Failed to begin transaction due to RateLimit. ", cause); | ||||||||||
} | ||||||||||
|
||||||||||
protected class CheckTimerTask implements TimerTask { | ||||||||||
|
||||||||||
private final GlobalTransaction tx; | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.seata.core.event; | ||
|
||
public class RateLimitEvent implements Event { | ||
|
||
/** | ||
* The Trace id. | ||
*/ | ||
private String traceId; | ||
|
||
/** | ||
* The Limit type (like GlobalBeginFailed). | ||
*/ | ||
private String limitType; | ||
|
||
/** | ||
* The Application id. | ||
*/ | ||
private String applicationId; | ||
|
||
/** | ||
* The Client id. | ||
*/ | ||
private String clientId; | ||
|
||
/** | ||
* The Server ip address and port. | ||
*/ | ||
private String serverIpAddressAndPort; | ||
|
||
public String getTraceId() { | ||
return traceId; | ||
} | ||
|
||
public void setTraceId(String traceId) { | ||
this.traceId = traceId; | ||
} | ||
|
||
public String getLimitType() { | ||
return limitType; | ||
} | ||
|
||
public void setLimitType(String limitType) { | ||
this.limitType = limitType; | ||
} | ||
|
||
public String getApplicationId() { | ||
return applicationId; | ||
} | ||
|
||
public void setApplicationId(String applicationId) { | ||
this.applicationId = applicationId; | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
} | ||
|
||
public String getServerIpAddressAndPort() { | ||
return serverIpAddressAndPort; | ||
} | ||
|
||
public void setServerIpAddressAndPort(String serverIpAddressAndPort) { | ||
this.serverIpAddressAndPort = serverIpAddressAndPort; | ||
} | ||
|
||
public RateLimitEvent(String traceId, String limitType, String applicationId, String clientId, String serverIpAddressAndPort) { | ||
this.traceId = traceId; | ||
this.limitType = limitType; | ||
this.applicationId = applicationId; | ||
this.clientId = clientId; | ||
this.serverIpAddressAndPort = serverIpAddressAndPort; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RateLimitEvent{" + | ||
"traceId='" + traceId + '\'' + | ||
", limitType='" + limitType + '\'' + | ||
", applicationId='" + applicationId + '\'' + | ||
", clientId='" + clientId + '\'' + | ||
", serverIpAddressAndPort='" + serverIpAddressAndPort + '\'' + | ||
'}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,13 +16,6 @@ | |||||||||||||||||||
*/ | ||||||||||||||||||||
package org.apache.seata.integration.tx.api.interceptor.handler; | ||||||||||||||||||||
|
||||||||||||||||||||
import java.lang.reflect.Method; | ||||||||||||||||||||
import java.util.LinkedHashSet; | ||||||||||||||||||||
import java.util.Set; | ||||||||||||||||||||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||||||||||||||||||||
import java.util.concurrent.TimeUnit; | ||||||||||||||||||||
import java.util.concurrent.atomic.AtomicBoolean; | ||||||||||||||||||||
|
||||||||||||||||||||
import com.google.common.eventbus.Subscribe; | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it |
||||||||||||||||||||
import org.apache.seata.common.exception.ShouldNeverHappenException; | ||||||||||||||||||||
import org.apache.seata.common.thread.NamedThreadFactory; | ||||||||||||||||||||
|
@@ -59,6 +52,13 @@ | |||||||||||||||||||
import org.slf4j.Logger; | ||||||||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||||||||
|
||||||||||||||||||||
import java.lang.reflect.Method; | ||||||||||||||||||||
import java.util.LinkedHashSet; | ||||||||||||||||||||
import java.util.Set; | ||||||||||||||||||||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||||||||||||||||||||
import java.util.concurrent.TimeUnit; | ||||||||||||||||||||
import java.util.concurrent.atomic.AtomicBoolean; | ||||||||||||||||||||
|
||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it |
||||||||||||||||||||
import static org.apache.seata.common.DefaultValues.DEFAULT_DISABLE_GLOBAL_TRANSACTION; | ||||||||||||||||||||
import static org.apache.seata.common.DefaultValues.DEFAULT_GLOBAL_TRANSACTION_TIMEOUT; | ||||||||||||||||||||
import static org.apache.seata.common.DefaultValues.DEFAULT_TM_DEGRADE_CHECK; | ||||||||||||||||||||
|
@@ -248,6 +248,10 @@ public TransactionInfo getTransactionInfo() { | |||||||||||||||||||
succeed = false; | ||||||||||||||||||||
failureHandler.onBeginFailure(globalTransaction, cause); | ||||||||||||||||||||
throw cause; | ||||||||||||||||||||
case BeginFailedRateLimited: | ||||||||||||||||||||
succeed = false; | ||||||||||||||||||||
failureHandler.onBeginRateLimitedFailure(globalTransaction, cause); | ||||||||||||||||||||
throw cause; | ||||||||||||||||||||
case CommitFailure: | ||||||||||||||||||||
succeed = false; | ||||||||||||||||||||
failureHandler.onCommitFailure(globalTransaction, cause); | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ public interface IdConstants { | |
|
||
String SEATA_EXCEPTION = "seata.exception"; | ||
|
||
String SEATA_RATE_LIMIT = "seata.rate.limit"; | ||
|
||
String APP_ID_KEY = "applicationId"; | ||
|
||
String GROUP_KEY = "group"; | ||
|
@@ -79,4 +81,9 @@ public interface IdConstants { | |
|
||
String STATUS_VALUE_AFTER_ROLLBACKED_KEY = "AfterRollbacked"; | ||
|
||
String LIMIT_TYPE_KEY = "limitType"; | ||
|
||
String CLIENT_ID_KEY = "clientId"; | ||
|
||
String SERVER_IP_ADDRESS_AND_PORT_KEY = "serverIpAddressAndPort"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't 'hostAndPort' more concise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bucketTokenNumPerSecond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it