Skip to content

Commit

Permalink
Merge pull request #20 from apache/master
Browse files Browse the repository at this point in the history
Update the latest code
  • Loading branch information
CrazyHZM authored Dec 18, 2018
2 parents da21cdc + e4acdf7 commit 16f252e
Show file tree
Hide file tree
Showing 62 changed files with 827 additions and 357 deletions.
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
2. Asset transfer to ASF, includeing pom, license, DISCLAIMER and so on, #1491
3. Introduce of new dispatcher policy: EagerThreadpool, #1568
4. Separate monitor data with group and version, #1407
5. Spring Boot Enhancenment, #1611
6. Gaceful shutdown enhancement
5. Spring Boot Enhancement, #1611
6. Graceful shutdown enhancement
- Remove exporter destroy logic in AnnotationBean.
- Waiting for registry notification on consumer side by checking channel state.
7. Simplify consumer/provider side check in RpcContext, #1444.

Issues and Pull Requests, check [milestone-2.6.2](https://github.com/apache/incubator-dubbo/milestone/15).
Issues and Pull Requests, check [milestone-2.6.2](https://github.com/apache/incubator-dubbo/milestone/15).
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ Thanks for contributing!
### Code style

We provide a template file [dubbo_codestyle_for_idea.xml](https://github.com/apache/incubator-dubbo/tree/master/codestyle/dubbo_codestyle_for_idea.xml) for IntelliJ idea, you can import it to you IDE.
If you use Eclipse you can config manually by referencing the same file.
If you use Eclipse you can config manually by referencing the same file.

**NOTICE**

It is very important to set the dubbo_codestyle_for_idea.xml, otherwise you will fail to pass the Travis CI. Steps to set the code style are as below:

1. Enter `Editor > Code Style`
2. To manage a code style scheme, in the Code Style page, select the desired scheme from the drop-down list, and click ![manage profiles](codestyle/manage_profiles.png).
From the drop-down list, select `Import Scheme`, then select this option `IntelliJ IDEA code style XML` to import scheme
3. In the Scheme field, type the name of the new scheme and press ⏎ to save the changes.

25 changes: 0 additions & 25 deletions FAQ.md

This file was deleted.

2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Follow this checklist to help us incorporate your contribution quickly and easil
- [ ] Format the pull request title like `[Dubbo-XXX] Fix UnknownException when host config not exist #XXX`. Each commit in the pull request should have a meaningful subject line and body.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/apache/incubator-dubbo/tree/master/dubbo-test).
- [ ] Run `mvn clean install -DskipTests` & `mvn clean test-compile failsafe:integration-test` to make sure unit-test and integration-test pass.
- [ ] Run `mvn clean install -DskipTests=false` & `mvn clean test-compile failsafe:integration-test` to make sure unit-test and integration-test pass.
- [ ] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/incubator-dubbo/wiki/Software-donation-guide).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ The consumer will print out `Hello world` on the screen.

* [Your first Dubbo application](http://dubbo.apache.org/en-us/blog/dubbo-101.html) - A 101 tutorial to reveal more details, with the same code above.
* [Dubbo user manual](http://dubbo.apache.org/en-us/docs/user/preface/background.html) - How to use Dubbo and all its features.
* [Dubbo developer guide](http://dubbo.apache.org/en-us/docs/dev/build.html) - How to invovle in Dubbo development.
* [Dubbo developer guide](http://dubbo.apache.org/en-us/docs/dev/build.html) - How to involve in Dubbo development.
* [Dubbo admin manual](http://dubbo.apache.org/en-us/docs/admin/install/provider-demo.html) - How to admin and manage Dubbo services.

## Contact
Expand Down
Binary file added codestyle/manage_profiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@

/**
* AbstractLoadBalance
*
*/
public abstract class AbstractLoadBalance implements LoadBalance {

/**
* Calculate the weight according to the uptime proportion of warmup time
* the new weight will be within 1(inclusive) to weight(inclusive)
*
* @param uptime the uptime in milliseconds
* @param warmup the warmup time in milliseconds
* @param weight the weight of an invoker
* @return weight which takes warmup into account
*/
static int calculateWarmupWeight(int uptime, int warmup, int weight) {
int ww = (int) ((float) uptime / ((float) warmup / (float) weight));
return ww < 1 ? 1 : (ww > weight ? weight : ww);
Expand All @@ -48,6 +55,15 @@ public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invo

protected abstract <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation);


/**
* Get the weight of the invoker's invocation which takes warmup time into account
* if the uptime is within the warmup time, the weight will be reduce proportionally
*
* @param invoker the invoker
* @param invocation the invocation of this invoker
* @return weight
*/
protected int getWeight(Invoker<?> invoker, Invocation invocation) {
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
if (weight > 0) {
Expand All @@ -60,7 +76,7 @@ protected int getWeight(Invoker<?> invoker, Invocation invocation) {
}
}
}
return weight;
return weight >= 0 ? weight : 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,25 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
int leastCount = 0;
// The index of invokers having the same least active value (leastActive)
int[] leastIndexes = new int[length];
// the weight of every invokers
int[] weights = new int[length];
// The sum of the warmup weights of all the least active invokes
int totalWeight = 0;
// The weight of the first least active invoke
int firstWeight = 0;
// Every least active invoker has the same weight value?
boolean sameWeight = true;


// Filter out all the least active invokers
for (int i = 0; i < length; i++) {
Invoker<T> invoker = invokers.get(i);
// Get the active number of the invoke
int active = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()).getActive();
// Get the weight of the invoke configuration. The default value is 100.
int afterWarmup = getWeight(invoker, invocation);
// save for later use
weights[i] = afterWarmup;
// If it is the first invoker or the active number of the invoker is less than the current least active number
if (leastActive == -1 || active < leastActive) {
// Reset the active number of the current invoker to the least active number
Expand Down Expand Up @@ -95,12 +100,12 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
if (!sameWeight && totalWeight > 0) {
// If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on
// totalWeight.
int offsetWeight = ThreadLocalRandom.current().nextInt(totalWeight) + 1;
int offsetWeight = ThreadLocalRandom.current().nextInt(totalWeight);
// Return a invoker based on the random value.
for (int i = 0; i < leastCount; i++) {
int leastIndex = leastIndexes[i];
offsetWeight -= getWeight(invokers.get(leastIndex), invocation);
if (offsetWeight <= 0) {
offsetWeight -= weights[leastIndex];
if (offsetWeight < 0) {
return invokers.get(leastIndex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,30 @@

/**
* random load balance.
*
*/
public class RandomLoadBalance extends AbstractLoadBalance {

public static final String NAME = "random";

@Override
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
int length = invokers.size(); // Number of invokers
boolean sameWeight = true; // Every invoker has the same weight?
// Number of invokers
int length = invokers.size();
// Every invoker has the same weight?
boolean sameWeight = true;
// the weight of every invokers
int[] weights = new int[length];
// the first invoker's weight
int firstWeight = getWeight(invokers.get(0), invocation);
int totalWeight = firstWeight; // The sum of weights
weights[0] = firstWeight;
// The sum of weights
int totalWeight = firstWeight;
for (int i = 1; i < length; i++) {
int weight = getWeight(invokers.get(i), invocation);
totalWeight += weight; // Sum
// save for later use
weights[i] = weight;
// Sum
totalWeight += weight;
if (sameWeight && weight != firstWeight) {
sameWeight = false;
}
Expand All @@ -49,7 +58,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
int offset = ThreadLocalRandom.current().nextInt(totalWeight);
// Return a invoker based on the random value.
for (int i = 0; i < length; i++) {
offset -= getWeight(invokers.get(i), invocation);
offset -= weights[i];
if (offset < 0) {
return invokers.get(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
String identifyString = invoker.getUrl().toIdentityString();
WeightedRoundRobin weightedRoundRobin = map.get(identifyString);
int weight = getWeight(invoker, invocation);
if (weight < 0) {
weight = 0;
}

if (weightedRoundRobin == null) {
weightedRoundRobin = new WeightedRoundRobin();
weightedRoundRobin.setWeight(weight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.rpc.cluster.merger;

import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.cluster.Merger;

import java.lang.reflect.Array;
Expand All @@ -25,34 +26,48 @@ public class ArrayMerger implements Merger<Object[]> {
public static final ArrayMerger INSTANCE = new ArrayMerger();

@Override
public Object[] merge(Object[]... others) {
if (others.length == 0) {
return null;
public Object[] merge(Object[]... items) {
if (ArrayUtils.isEmpty(items)) {
return new Object[0];
}

int i = 0;
while (i < items.length && items[i] == null) {
i++;
}

if (i == items.length) {
return new Object[0];
}

Class<?> type = items[i].getClass().getComponentType();

int totalLen = 0;
for (int i = 0; i < others.length; i++) {
Object item = others[i];
if (item != null && item.getClass().isArray()) {
totalLen += Array.getLength(item);
} else {
throw new IllegalArgumentException((i + 1) + "th argument is not an array");
for (; i < items.length; i++) {
if (items[i] == null) {
continue;
}
Class<?> itemType = items[i].getClass().getComponentType();
if (itemType != type) {
throw new IllegalArgumentException("Arguments' types are different");
}
totalLen += items[i].length;
}

if (totalLen == 0) {
return null;
return new Object[0];
}

Class<?> type = others[0].getClass().getComponentType();

Object result = Array.newInstance(type, totalLen);

int index = 0;
for (Object array : others) {
for (int i = 0; i < Array.getLength(array); i++) {
Array.set(result, index++, Array.get(array, i));
for (Object[] array : items) {
if (array != null) {
for (int j = 0; j < array.length; j++) {
Array.set(result, index++, array[j]);
}
}
}
return (Object[]) result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@

package org.apache.dubbo.rpc.cluster.merger;

import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.cluster.Merger;

public class BooleanArrayMerger implements Merger<boolean[]> {

@Override
public boolean[] merge(boolean[]... items) {
if (ArrayUtils.isEmpty(items)) {
return new boolean[0];
}
int totalLen = 0;
for (boolean[] array : items) {
totalLen += array.length;
if (array != null) {
totalLen += array.length;
}
}
boolean[] result = new boolean[totalLen];
int index = 0;
for (boolean[] array : items) {
for (boolean item : array) {
result[index++] = item;
if (array != null) {
for (boolean item : array) {
result[index++] = item;
}
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@

package org.apache.dubbo.rpc.cluster.merger;

import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.cluster.Merger;

public class ByteArrayMerger implements Merger<byte[]> {

@Override
public byte[] merge(byte[]... items) {
if (ArrayUtils.isEmpty(items)) {
return new byte[0];
}
int total = 0;
for (byte[] array : items) {
total += array.length;
if (array != null) {
total += array.length;
}
}
byte[] result = new byte[total];
int index = 0;
for (byte[] array : items) {
for (byte item : array) {
result[index++] = item;
if (array != null) {
for (byte item : array) {
result[index++] = item;
}
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,29 @@

package org.apache.dubbo.rpc.cluster.merger;

import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.rpc.cluster.Merger;

public class CharArrayMerger implements Merger<char[]> {

@Override
public char[] merge(char[]... items) {
if (ArrayUtils.isEmpty(items)) {
return new char[0];
}
int total = 0;
for (char[] array : items) {
total += array.length;
if (array != null) {
total += array.length;
}
}
char[] result = new char[total];
int index = 0;
for (char[] array : items) {
for (char item : array) {
result[index++] = item;
if (array != null) {
for (char item : array) {
result[index++] = item;
}
}
}
return result;
Expand Down
Loading

0 comments on commit 16f252e

Please sign in to comment.