Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/chubaostream/joyqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
iamazy committed Sep 25, 2020
2 parents 73e1c4f + 2db5fea commit afedf81
Show file tree
Hide file tree
Showing 91 changed files with 192 additions and 112 deletions.
2 changes: 1 addition & 1 deletion docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>joyqueue</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>joyqueue-docker</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion docker/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-docker</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>docker-server</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion docker/web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-docker</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>docker-web</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-all-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-core-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ protected Nodes getTopicNodes(TopicMetadata topicMetadata, List<BrokerNode> brok
Nodes cacheNodes = topicMetadata.getAttachment(NODES_CACHE_KEY);
if (cacheNodes == null) {
cacheNodes = new Nodes();
cacheNodes.setAttachment(topicMetadata.getTopic());
Nodes oldNodes = topicMetadata.putIfAbsentAttachment(NODES_CACHE_KEY, cacheNodes);
if (oldNodes != null) {
cacheNodes = oldNodes;
}
}

List<Node> cacheNodeList = Lists.newArrayListWithCapacity(brokerNodes.size());
List<Node> nodeList = Lists.newArrayListWithCapacity(brokerNodes.size());
for (BrokerNode brokerNode : brokerNodes) {
Node node = brokerNode.getAttachment(NODE_CACHE_KEY);
if (node == null) {
Expand All @@ -74,12 +75,13 @@ protected Nodes getTopicNodes(TopicMetadata topicMetadata, List<BrokerNode> brok
node = oldNode;
}
}
cacheNodeList.add(node);
nodeList.add(node);
}

Nodes nodes = new Nodes();
nodes.setMetric(cacheNodes.getMetric());
nodes.setNodes(cacheNodeList);
nodes.setNodes(nodeList);
nodes.setAttachment(cacheNodes.getAttachment());
return nodes;
}

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
10 changes: 6 additions & 4 deletions joyqueue-client/joyqueue-client-loadbalance-adaptive/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -17,6 +15,10 @@
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.joyqueue.client.loadbalance.adaptive;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.joyqueue.client.loadbalance.adaptive.config.AdaptiveLoadBalanceConfig;
import org.joyqueue.client.loadbalance.adaptive.node.Node;
import org.joyqueue.client.loadbalance.adaptive.node.Nodes;
import org.joyqueue.client.loadbalance.adaptive.node.WeightNode;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
* AdaptiveLoadBalance
Expand All @@ -21,9 +25,14 @@ public class AdaptiveLoadBalance {
private WeightLoadBalance weightLoadBalance = new WeightLoadBalance();
private RandomLoadBalance randomLoadBalance = new RandomLoadBalance();

private Cache<String, Node> selectCache;

public AdaptiveLoadBalance(AdaptiveLoadBalanceConfig config) {
this.config = config;
this.scoreJudges = getScoreJudges(config);
this.selectCache = CacheBuilder.newBuilder()
.expireAfterWrite(config.getComputeInterval(), TimeUnit.MILLISECONDS)
.build();
}

protected List<ScoreJudge> getScoreJudges(AdaptiveLoadBalanceConfig config) {
Expand All @@ -48,6 +57,17 @@ protected boolean isStartup(Nodes nodes) {
}

protected Node adaptiveSelect(Nodes nodes) {
String cacheKey = nodes.toString();
try {
return selectCache.get(cacheKey, () -> {
return doAdaptiveSelect(nodes);
});
} catch (ExecutionException e) {
return doAdaptiveSelect(nodes);
}
}

public Node doAdaptiveSelect(Nodes nodes) {
List<WeightNode> weightNodes = new ArrayList<>(nodes.getNodes().size());
for (Node node : nodes.getNodes()) {
double score = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class AdaptiveLoadBalanceConfig {

private int ssthreshhold = 10;
private String[] judges;
private int computeInterval = 1000 * 1;

public int getSsthreshhold() {
return ssthreshhold;
Expand All @@ -25,4 +26,12 @@ public String[] getJudges() {
public void setJudges(String[] judges) {
this.judges = judges;
}

public int getComputeInterval() {
return computeInterval;
}

public void setComputeInterval(int computeInterval) {
this.computeInterval = computeInterval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Node {
private Metric metric = new Metric();
private String url;
private boolean nearby;
private Object attachment;

public Node() {
}
Expand Down Expand Up @@ -38,4 +39,21 @@ public void setNearby(boolean nearby) {
public boolean isNearby() {
return nearby;
}

public Object getAttachment() {
return attachment;
}

public void setAttachment(Object attachment) {
this.attachment = attachment;
}

@Override
public String toString() {
return "Node{" +
"url='" + url + '\'' +
", nearby=" + nearby +
", attachment=" + attachment +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Nodes {

private Metric metric = new Metric();
private List<Node> nodes;
private Object attachment;

public Nodes() {
}
Expand All @@ -34,4 +35,20 @@ public void setNodes(List<Node> nodes) {
public List<Node> getNodes() {
return nodes;
}

public Object getAttachment() {
return attachment;
}

public void setAttachment(Object attachment) {
this.attachment = attachment;
}

@Override
public String toString() {
return "Nodes{" +
"nodes=" + nodes +
", attachment=" + attachment +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client-samples</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client-samples</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client-samples</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client-samples</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/joyqueue-client-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-client</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-datasource</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-datasource</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-common/joyqueue-datasource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-common</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion joyqueue-common/joyqueue-hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-common</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions joyqueue-common/joyqueue-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<parent>
<artifactId>joyqueue-common</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>joyqueue-model</artifactId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
<name>JoyQueue-Model</name>
<description>Domain models</description>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public boolean equals(Object o) {
return true;
}

return super.equals(((TopicConfig) o).getName());
return super.equals(o);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion joyqueue-common/joyqueue-network/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>joyqueue-common</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion joyqueue-common/joyqueue-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>joyqueue-common</artifactId>
<groupId>org.joyqueue</groupId>
<version>4.2.7.RC3</version>
<version>4.2.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit afedf81

Please sign in to comment.