Skip to content

Commit 1d16f15

Browse files
author
yangsen
committed
revert multi region code
1 parent 123e947 commit 1d16f15

13 files changed

+60
-182
lines changed

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

Lines changed: 0 additions & 45 deletions
This file was deleted.

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

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AutoRegion extends Region {
1717
private String ucServer;
1818

1919
/**
20-
* 空间机房,域名信息缓存,此缓存绑定了 actionType、token、bucket,且仅 AutoRegion 对象内部有效。
20+
* 空间机房,域名信息缓存,此缓存绑定了 token、bucket,且仅 AutoRegion 对象内部有效。
2121
*/
2222
private Map<String, Region> regions;
2323

@@ -60,45 +60,12 @@ private UCRet queryRegionInfoFromServerIfNeeded(RegionIndex index) throws QiniuE
6060
return ret;
6161
}
6262

63-
static Region regionGroup(UCRet ret, int actionType) {
63+
static Region regionGroup(UCRet ret) {
6464
if (ret == null || ret.hosts == null || ret.hosts.length == 0) {
6565
return null;
6666
}
6767

6868
RegionGroup group = new RegionGroup();
69-
70-
String[] apis = ApiType.apisWithActionType(actionType);
71-
if (apis != null && apis.length > 0 && ret.universal != null &&
72-
ret.universal.support_apis != null &&
73-
ret.universal.support_apis.length > 0) {
74-
75-
boolean support = true;
76-
for (String api : apis) {
77-
78-
// 需要支持的 api 是否存在,任何一个不存在则不支持。
79-
boolean contain = false;
80-
for (String supportApi : ret.universal.support_apis) {
81-
if (api.equals(supportApi)) {
82-
contain = true;
83-
break;
84-
}
85-
}
86-
87-
if (!contain) {
88-
support = false;
89-
break;
90-
}
91-
}
92-
93-
if (support) {
94-
if (ret.universal.region == null || ret.universal.region.length() == 0) {
95-
ret.universal.region = "universal";
96-
}
97-
Region region = ret.universal.createRegion();
98-
group.addRegion(region);
99-
}
100-
}
101-
10269
for (HostRet host : ret.hosts) {
10370
Region region = host.createRegion();
10471
group.addRegion(region);
@@ -110,22 +77,21 @@ static Region regionGroup(UCRet ret, int actionType) {
11077
/**
11178
* 首先从缓存读取Region信息,如果没有则发送请求从接口查询
11279
*
113-
* @param accessKey 账号 accessKey
114-
* @param bucket 空间名
115-
* @param actionType action 类型
80+
* @param accessKey 账号 accessKey
81+
* @param bucket 空间名
11682
* @return 机房域名信息
11783
*/
118-
private Region queryRegionInfo(String accessKey, String bucket, int actionType) throws QiniuException {
84+
private Region queryRegionInfo(String accessKey, String bucket) throws QiniuException {
11985
RegionIndex index = new RegionIndex(accessKey, bucket);
120-
String cacheKey = index.accessKey + "::" + index.bucket + "::" + ApiType.actionTypeString(actionType);
86+
String cacheKey = index.accessKey + "::" + index.bucket;
12187
Region region = regions.get(cacheKey);
12288

12389
Exception ex = null;
12490
if (region == null || !region.isValid()) {
12591
for (int i = 0; i < 2; i++) {
12692
try {
12793
UCRet ret = queryRegionInfoFromServerIfNeeded(index);
128-
region = AutoRegion.regionGroup(ret, actionType);
94+
region = AutoRegion.regionGroup(ret);
12995
if (region != null) {
13096
regions.put(cacheKey, region);
13197
break;
@@ -152,27 +118,27 @@ private Region queryRegionInfo(String accessKey, String bucket, int actionType)
152118
* @param regionReqInfo 封装了 accessKey 和 bucket 的对象
153119
* @return 机房域名信息
154120
*/
155-
private Region queryRegionInfo(RegionReqInfo regionReqInfo, int actionType) throws QiniuException {
156-
return queryRegionInfo(regionReqInfo.getAccessKey(), regionReqInfo.getBucket(), actionType);
121+
private Region queryRegionInfo(RegionReqInfo regionReqInfo) throws QiniuException {
122+
return queryRegionInfo(regionReqInfo.getAccessKey(), regionReqInfo.getBucket());
157123
}
158124

159125
@Override
160-
boolean switchRegion(RegionReqInfo regionReqInfo, int actionType) {
161-
Region currentRegion = getCurrentRegion(regionReqInfo, actionType);
126+
boolean switchRegion(RegionReqInfo regionReqInfo) {
127+
Region currentRegion = getCurrentRegion(regionReqInfo);
162128
if (currentRegion == null) {
163129
return false;
164130
} else {
165-
return currentRegion.switchRegion(regionReqInfo, actionType);
131+
return currentRegion.switchRegion(regionReqInfo);
166132
}
167133
}
168134

169135
@Override
170-
String getRegion(RegionReqInfo regionReqInfo, int actionType) {
171-
Region currentRegion = getCurrentRegion(regionReqInfo, actionType);
136+
String getRegion(RegionReqInfo regionReqInfo) {
137+
Region currentRegion = getCurrentRegion(regionReqInfo);
172138
if (currentRegion == null) {
173139
return "";
174140
} else {
175-
return currentRegion.getRegion(regionReqInfo, actionType);
141+
return currentRegion.getRegion(regionReqInfo);
176142
}
177143
}
178144

@@ -182,10 +148,10 @@ boolean isValid() {
182148
}
183149

184150
@Override
185-
Region getCurrentRegion(RegionReqInfo regionReqInfo, int actionType) {
151+
Region getCurrentRegion(RegionReqInfo regionReqInfo) {
186152
try {
187-
Region region = queryRegionInfo(regionReqInfo, actionType);
188-
return region.getCurrentRegion(regionReqInfo, actionType);
153+
Region region = queryRegionInfo(regionReqInfo);
154+
return region.getCurrentRegion(regionReqInfo);
189155
} catch (QiniuException e) {
190156
return null;
191157
}
@@ -195,24 +161,24 @@ Region getCurrentRegion(RegionReqInfo regionReqInfo, int actionType) {
195161
* 获取源站直传域名
196162
*/
197163
@Override
198-
List<String> getSrcUpHost(RegionReqInfo regionReqInfo, int actionType) throws QiniuException {
164+
List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
199165
if (regionReqInfo == null) {
200166
return null;
201167
}
202-
Region region = queryRegionInfo(regionReqInfo, actionType);
203-
return region.getSrcUpHost(regionReqInfo, actionType);
168+
Region region = queryRegionInfo(regionReqInfo);
169+
return region.getSrcUpHost(regionReqInfo);
204170
}
205171

206172
/**
207173
* 获取加速上传域名
208174
*/
209175
@Override
210-
List<String> getAccUpHost(RegionReqInfo regionReqInfo, int actionType) throws QiniuException {
176+
List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
211177
if (regionReqInfo == null) {
212178
return null;
213179
}
214-
Region region = queryRegionInfo(regionReqInfo, actionType);
215-
return region.getAccUpHost(regionReqInfo, actionType);
180+
Region region = queryRegionInfo(regionReqInfo);
181+
return region.getAccUpHost(regionReqInfo);
216182
}
217183

218184
/**
@@ -223,7 +189,7 @@ String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
223189
if (regionReqInfo == null) {
224190
return "";
225191
}
226-
Region region = queryRegionInfo(regionReqInfo, ApiType.ActionTypeNone);
192+
Region region = queryRegionInfo(regionReqInfo);
227193
return region.getIovipHost(regionReqInfo);
228194
}
229195

@@ -235,7 +201,7 @@ String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
235201
if (regionReqInfo == null) {
236202
return "";
237203
}
238-
Region region = queryRegionInfo(regionReqInfo, ApiType.ActionTypeNone);
204+
Region region = queryRegionInfo(regionReqInfo);
239205
return region.getRsHost(regionReqInfo);
240206
}
241207

@@ -247,7 +213,7 @@ String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
247213
if (regionReqInfo == null) {
248214
return "";
249215
}
250-
Region region = queryRegionInfo(regionReqInfo, ApiType.ActionTypeNone);
216+
Region region = queryRegionInfo(regionReqInfo);
251217
return region.getRsfHost(regionReqInfo);
252218
}
253219

@@ -259,7 +225,7 @@ String getApiHost(RegionReqInfo regionReqInfo) throws QiniuException {
259225
if (regionReqInfo == null) {
260226
return "";
261227
}
262-
Region region = queryRegionInfo(regionReqInfo, ApiType.ActionTypeNone);
228+
Region region = queryRegionInfo(regionReqInfo);
263229
return region.getApiHost(regionReqInfo);
264230
}
265231

@@ -320,7 +286,7 @@ private void setupDeadline() {
320286
if (ret != null) {
321287
ttl = ret.ttl;
322288
}
323-
deadline = System.currentTimeMillis()/1000 + ttl;
289+
deadline = System.currentTimeMillis() / 1000 + ttl;
324290
}
325291
}
326292

@@ -377,7 +343,7 @@ Region createRegion() {
377343
regionId = "";
378344
}
379345

380-
return new Region(timestamp, regionId, srcUpHosts, accUpHosts, iovipHost, rsHost, rsfHost, apiHost, ucHost);
346+
return new Region(timestamp, regionId, srcUpHosts, accUpHosts, iovipHost, rsHost, rsfHost, apiHost, ucHost);
381347
}
382348
}
383349

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private Response uploadWithRegionRetry() throws QiniuException {
5656
}
5757

5858
// 切换 region
59-
if (config.region == null || !this.config.region.switchRegion(new UploadToken(upToken), actionType())) {
59+
if (config.region == null || !this.config.region.switchRegion(new UploadToken(upToken))) {
6060
break;
6161
}
6262
}
@@ -73,6 +73,4 @@ private Response uploadWithRegionRetry() throws QiniuException {
7373
abstract boolean couldReloadSource();
7474

7575
abstract boolean reloadSource();
76-
77-
abstract int actionType();
7876
}

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,31 @@ class ConfigHelper {
1414
makeSureRegion();
1515
}
1616

17-
@Deprecated
1817
public String upHost(String upToken) throws QiniuException {
19-
return upHost(upToken, ApiType.ActionTypeNone);
20-
}
21-
22-
public String upHost(String upToken, int actionType) throws QiniuException {
2318
try {
24-
return upHost(upToken, actionType, null, false, false);
19+
return upHost(upToken, null, false, false);
2520
} catch (QiniuException e) {
2621
if (e.response == null || e.response.needRetry()) {
2722
try {
2823
Thread.sleep(500);
2924
} catch (Exception e1) {
3025
// do nothing
3126
}
32-
return upHost(upToken, actionType, null, false, true);
27+
return upHost(upToken, null, false, true);
3328
}
3429
throw e;
3530
}
3631
}
3732

3833
@Deprecated
3934
public String tryChangeUpHost(String upToken, String lastUsedHost) throws QiniuException {
40-
return tryChangeUpHost(upToken, ApiType.ActionTypeNone, lastUsedHost);
41-
}
42-
43-
public String tryChangeUpHost(String upToken, int actionType, String lastUsedHost) throws QiniuException {
44-
return upHost(upToken, actionType, lastUsedHost, true, false);
35+
return upHost(upToken, lastUsedHost, true, false);
4536
}
4637

47-
private String upHost(String upToken, int actionType, String lastUsedHost, boolean changeHost, boolean mustReturnUpHost)
38+
private String upHost(String upToken, String lastUsedHost, boolean changeHost, boolean mustReturnUpHost)
4839
throws QiniuException {
4940
return getScheme()
50-
+ getHelper().upHost(config.region, actionType, upToken, toDomain(lastUsedHost), changeHost, mustReturnUpHost);
41+
+ getHelper().upHost(config.region, upToken, toDomain(lastUsedHost), changeHost, mustReturnUpHost);
5142
}
5243

5344
public String ioHost(String ak, String bucket) throws QiniuException {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Response uploadFlows() throws QiniuException {
7878
return Retry.retryRequestAction(retryConfig, new Retry.RequestRetryAction() {
7979
@Override
8080
public String getRequestHost() throws QiniuException {
81-
return configHelper.upHost(upToken, actionType());
81+
return configHelper.upHost(upToken);
8282
}
8383

8484
@Override
@@ -133,7 +133,7 @@ private void asyncRetryUploadBetweenRegion(final UpCompletionHandler handler) {
133133
public void complete(String key, Response r) {
134134
if (!Retry.shouldUploadAgain(r, null)
135135
|| !couldReloadSource() || !reloadSource()
136-
|| config.region == null || !config.region.switchRegion(finalToken, actionType())) {
136+
|| config.region == null || !config.region.switchRegion(finalToken)) {
137137
handler.complete(key, r);
138138
} else {
139139
asyncRetryUploadBetweenRegion(handler);
@@ -207,11 +207,6 @@ boolean reloadSource() {
207207
return true;
208208
}
209209

210-
@Override
211-
int actionType() {
212-
return ApiType.ActionTypeUploadByForm;
213-
}
214-
215210
private void changeHost(String upToken, String host) {
216211
try {
217212
configHelper.tryChangeUpHost(upToken, host);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,23 @@ public static Region autoRegion(String ucServer) {
290290
return new Builder().autoRegion(ucServer);
291291
}
292292

293-
boolean switchRegion(RegionReqInfo regionReqInfo, int apiType) {
293+
boolean switchRegion(RegionReqInfo regionReqInfo) {
294294
return false;
295295
}
296296

297-
String getRegion(RegionReqInfo regionReqInfo, int actionType) {
297+
String getRegion(RegionReqInfo regionReqInfo) {
298298
return this.region;
299299
}
300300

301-
Region getCurrentRegion(RegionReqInfo regionReqInfo, int actionType) {
301+
Region getCurrentRegion(RegionReqInfo regionReqInfo) {
302302
return this;
303303
}
304304

305-
List<String> getSrcUpHost(RegionReqInfo regionReqInfo, int actionType) throws QiniuException {
305+
List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
306306
return this.srcUpHosts;
307307
}
308308

309-
List<String> getAccUpHost(RegionReqInfo regionReqInfo, int actionType) throws QiniuException {
309+
List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
310310
return this.accUpHosts;
311311
}
312312

0 commit comments

Comments
 (0)