Skip to content

Commit 1fd37ed

Browse files
authored
Merge pull request #569 from YangSen-qn/multi-region
uc_query add gloable cache
2 parents 0d6b795 + 250bd07 commit 1fd37ed

File tree

9 files changed

+196
-153
lines changed

9 files changed

+196
-153
lines changed

src/main/java/com/qiniu/storage/AutoRegion.java

Lines changed: 159 additions & 125 deletions
Large diffs are not rendered by default.

src/main/java/com/qiniu/storage/Configuration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ public Configuration(Zone zone) {
144144

145145
public Configuration clone() {
146146
try {
147-
return (Configuration) super.clone();
147+
Configuration configuration = (Configuration) super.clone();
148+
if (region != null) {
149+
configuration.region = (Region)region.clone();
150+
}
151+
return configuration;
148152
} catch (CloneNotSupportedException e) {
149153
e.printStackTrace();
150154
}

src/main/java/com/qiniu/storage/FormUploader.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ public final class FormUploader extends BaseUploader {
2020
private final byte[] data;
2121
private final String mime;
2222
private final boolean checkCrc;
23-
private final Configuration config;
24-
private final ConfigHelper configHelper;
2523
private StringMap params;
2624
private String filename;
27-
private Client client;
2825

2926
/**
3027
* 构建一个表单上传字节数组的对象
@@ -64,14 +61,11 @@ private FormUploader(Client client, String upToken, String key, byte[] data, Fil
6461
String mime, boolean checkCrc, Configuration configuration) {
6562
super(client, upToken, key, configuration);
6663

67-
this.client = client;
6864
this.file = file;
6965
this.data = data;
7066
this.params = params;
7167
this.mime = mime;
7268
this.checkCrc = checkCrc;
73-
this.configHelper = new ConfigHelper(configuration);
74-
this.config = configuration;
7569
}
7670

7771
@Override

src/main/java/com/qiniu/storage/RegionGroup.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ synchronized boolean switchRegion(RegionReqInfo regionReqInfo) {
4141
}
4242
}
4343

44+
@Override
4445
String getRegion(RegionReqInfo regionReqInfo) {
4546
if (currentRegion == null) {
4647
return "";
@@ -49,6 +50,7 @@ String getRegion(RegionReqInfo regionReqInfo) {
4950
}
5051
}
5152

53+
@Override
5254
List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
5355
if (currentRegion == null) {
5456
return null;
@@ -57,6 +59,7 @@ List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
5759
}
5860
}
5961

62+
@Override
6063
List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
6164
if (currentRegion == null) {
6265
return null;
@@ -65,6 +68,7 @@ List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
6568
}
6669
}
6770

71+
@Override
6872
String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
6973
if (currentRegion == null) {
7074
return null;
@@ -73,6 +77,7 @@ String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
7377
}
7478
}
7579

80+
@Override
7681
String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
7782
if (currentRegion == null) {
7883
return null;
@@ -81,6 +86,7 @@ String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
8186
}
8287
}
8388

89+
@Override
8490
String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
8591
if (currentRegion == null) {
8692
return null;
@@ -89,6 +95,7 @@ String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
8995
}
9096
}
9197

98+
@Override
9299
String getApiHost(RegionReqInfo regionReqInfo) throws QiniuException {
93100
if (currentRegion == null) {
94101
return null;
@@ -97,6 +104,7 @@ String getApiHost(RegionReqInfo regionReqInfo) throws QiniuException {
97104
}
98105
}
99106

107+
@Override
100108
Region getCurrentRegion(RegionReqInfo regionReqInfo) {
101109
if (currentRegion == null) {
102110
return null;
@@ -109,11 +117,18 @@ Region getCurrentRegion(RegionReqInfo regionReqInfo) {
109117

110118
@Override
111119
boolean isValid() {
112-
if (currentRegion == null) {
120+
if (regionList.size() == 0) {
113121
return false;
114122
}
115-
// 只判断当前的
116-
return currentRegion.isValid();
123+
124+
boolean valid = true;
125+
for (Region region : regionList) {
126+
if (region == null || !region.isValid()) {
127+
valid = false;
128+
break;
129+
}
130+
}
131+
return valid;
117132
}
118133

119134
private void updateCurrentRegion() {

src/main/java/com/qiniu/storage/ResumeUploadPerformer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ boolean isAllBlocksUploaded() {
3838
return uploadSource.isAllBlocksUploaded();
3939
}
4040

41-
4241
abstract boolean shouldUploadInit();
4342

4443
abstract Response uploadInit() throws QiniuException;

src/main/java/com/qiniu/storage/ResumeUploadSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ abstract class ResumeUploadSource {
2828

2929
ResumeUploadSource(Configuration config, String recordKey) {
3030
this.config = config;
31+
this.resumableUploadAPIVersion = config.resumableUploadAPIVersion;
3132
this.blockSize = getBlockSize(config);
3233
this.recordKey = recordKey;
33-
this.resumableUploadAPIVersion = config.resumableUploadAPIVersion;
3434
}
3535

3636
// 所有块数据是否 正在上传 或者 已上传,为 true 则说明没有需要上传的数据块

src/main/java/com/qiniu/storage/Retry.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,24 @@ static boolean shouldUploadAgain(Response response, QiniuException exception) {
2525
}
2626

2727
static Boolean requestShouldRetry(Response response, QiniuException exception) {
28-
if (response != null && response.needRetry()) {
29-
return true;
28+
if (response != null) {
29+
return response.needRetry();
3030
}
3131

3232
if (exception == null || exception.isUnrecoverable()) {
3333
return false;
3434
}
3535

36-
if (exception.response != null && exception.response.needRetry()) {
37-
// 异常需可恢复
38-
return true;
36+
if (exception.response != null) {
37+
return exception.response.needRetry();
3938
}
4039

41-
return false;
40+
return true;
4241
}
4342

4443
static Boolean requestShouldSwitchHost(Response response, QiniuException exception) {
45-
if (response != null && response.needSwitchServer()) {
46-
return true;
44+
if (response != null) {
45+
return response.needSwitchServer();
4746
}
4847

4948
if (exception == null) {
@@ -54,12 +53,11 @@ static Boolean requestShouldSwitchHost(Response response, QiniuException excepti
5453
return false;
5554
}
5655

57-
if (exception.response == null || exception.response.needSwitchServer()) {
58-
// 异常需可恢复
59-
return true;
56+
if (exception.response != null) {
57+
return exception.response.needSwitchServer();
6058
}
6159

62-
return false;
60+
return true;
6361
}
6462

6563
static Response retryRequestAction(RequestRetryConfig config, RequestRetryAction action) throws QiniuException {

src/main/java/com/qiniu/storage/UpHostHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ protected boolean removeEldestEntry(Map.Entry<String, RegionUpHost> eldest) {
2323
}
2424

2525

26-
String upHost(Region region, String upToken, String lastUsedHost, boolean changeHost, boolean mustReturnUpHost)
27-
throws QiniuException {
26+
String upHost(Region region, String upToken, String lastUsedHost, boolean changeHost, boolean mustReturnUpHost) throws QiniuException {
2827
RegionReqInfo regionReqInfo = new RegionReqInfo(upToken);
2928

3029
// auto region may failed here.

src/test/java/test/com/qiniu/storage/FormUploadTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public void hello(UploadManager up, String bucket) {
7979
try {
8080
r = up.put("hello".getBytes(), expectKey, token, params, null, false);
8181
} catch (QiniuException e) {
82-
fail();
82+
fail(e.toString());
8383
}
8484
StringMap map = null;
8585
try {
8686
map = r.jsonToMap();
8787
} catch (QiniuException e) {
88-
fail();
88+
fail(e.toString());
8989
}
9090
assertEquals(200, r.statusCode);
9191
assert map != null;

0 commit comments

Comments
 (0)