RapperCL opened a new issue, #5197:
URL: https://github.com/apache/rocketmq/issues/5197
# code location: MQFaultStrategy.LatencyFaultTolerance.FaultItem
At present, when a suitable broker is not found, when sorting
FaultItems, there is only a strategy with currentLatency first and startTime
second. I think we should also provide an alternative strategy: startTime
first, currentLatency second strategy。
startTime priority is also very reasonable.
for example:
`abstract class FaultItem implements Comparable<FaultItem> {
private final String name;
// 延迟
protected volatile long currentLatency;
// 开始可用的时间
protected volatile long startTimestamp;
public FaultItem(final String name) {
this.name = name;
}
@Override
public abstract int compareTo(final FaultItem other);
public boolean isAvailable() {
return (System.currentTimeMillis() - startTimestamp) >= 0;
}
@Override
public int hashCode() {
int result = getName() != null ? getName().hashCode() : 0;
result = 31 * result + (int) (getCurrentLatency() ^
(getCurrentLatency() >>> 32));
result = 31 * result + (int) (getStartTimestamp() ^
(getStartTimestamp() >>> 32));
return result;
}
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (!(o instanceof FaultItem))
return false;
final FaultItem faultItem = (FaultItem) o;
if (getCurrentLatency() != faultItem.getCurrentLatency())
return false;
if (getStartTimestamp() != faultItem.getStartTimestamp())
return false;
return getName() != null ? getName().equals(faultItem.getName())
: faultItem.getName() == null;
}
@Override
public String toString() {
return "FaultItem{" +
"name='" + name + '\'' +
", currentLatency=" + currentLatency +
", startTimestamp=" + startTimestamp +
'}';
}
public String getName() {
return name;
}
public long getCurrentLatency() {
return currentLatency;
}
public void setCurrentLatency(final long currentLatency) {
this.currentLatency = currentLatency;
}
public long getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(final long startTimestamp) {
this.startTimestamp = startTimestamp;
}
}
final class LatencyFaultItem extends FaultItem {
public LatencyFaultItem(String name) {
super(name);
}
@Override
public int compareTo(FaultItem other) {
if (this.isAvailable() != other.isAvailable()) {
if (this.isAvailable())
return -1;
if (other.isAvailable())
return 1;
}
if (this.currentLatency < other.currentLatency)
return -1;
else if (this.currentLatency > other.currentLatency) {
return 1;
}
if (this.startTimestamp < other.startTimestamp)
return -1;
else if (this.startTimestamp > other.startTimestamp) {
return 1;
}
return 0;
}
}
final class StartTimeFaultItem extends FaultItem {
public StartTimeFaultItem(String name) {
super(name);
}
@Override
public int compareTo(FaultItem other) {
if (this.isAvailable() != other.isAvailable()) {
if (this.isAvailable())
return -1;
if (other.isAvailable())
return 1;
}
if (this.startTimestamp < other.startTimestamp)
return -1;
else if (this.startTimestamp > other.startTimestamp) {
return 1;
}
if (this.currentLatency < other.currentLatency)
return -1;
else if (this.currentLatency > other.currentLatency) {
return 1;
}
return 0;
}
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]