Skip to content

Commit c253960

Browse files
authored
Merge pull request #419 from YangSen-qn/multi-region
server config retry interval to [2min, 5min]
2 parents 6c461c6 + 3ffeb02 commit c253960

File tree

13 files changed

+69
-12
lines changed

13 files changed

+69
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#Changelog
2+
## 8.5.1 (2022-11-24)
3+
- 支持 multi 区域
4+
- 优化 Server 配置获取逻辑
5+
26
## 8.5.0 (2022-10-25)
37
- 优化分片上传 ctx 超时检测
48
- QNDnsDelegate 代理函数名调整 lookup: 调整为 query:【不兼容变更】

Qiniu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Qiniu'
3-
s.version = '8.5.0'
3+
s.version = '8.5.1'
44
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/objc-sdk'
66
s.social_media_url = 'http://weibo.com/qiniutek'

QiniuSDK/Collect/QNReportItem.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ - (void)setReportValue:(id _Nullable)value forKey:(NSString * _Nullable)key{
3737
if (!value || !key || ![key isKindOfClass:[NSString class]]) {
3838
return;
3939
}
40+
if ([value isKindOfClass:[NSString class]] && [(NSString *)value length] > 1024) {
41+
value = [(NSString *)value substringToIndex:1024];
42+
}
4043
[self.keyValues setValue:value forKey:key];
4144
}
4245

QiniuSDK/Common/QNAutoZone.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13+
@class QNFixedZone;
1314
@interface QNAutoZone : QNZone
1415

1516
+ (instancetype)zoneWithUcHosts:(NSArray *)ucHosts;
1617

1718
+ (void)clearCache;
1819

20+
/**
21+
* 当 查询失败时,会使用 zones 进行上传,默认不配置。
22+
*/
23+
- (void)setDefaultZones:(NSArray <QNFixedZone *> *)zones;
24+
1925
@end
2026

2127
NS_ASSUME_NONNULL_END

QiniuSDK/Common/QNAutoZone.m

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ @implementation QNUCQuerySingleFlightValue
9797
@interface QNAutoZone()
9898

9999
@property(nonatomic, strong)NSArray *ucHosts;
100+
@property(nonatomic, strong)QNFixedZone *defaultZone;
100101
@property(nonatomic, strong)NSMutableArray <QNRequestTransaction *> *transactions;
101102

102103
@end
@@ -128,6 +129,10 @@ - (instancetype)init{
128129
return self;
129130
}
130131

132+
- (void)setDefaultZones:(NSArray <QNFixedZone *> *)zones {
133+
self.defaultZone = [QNFixedZone combineZones:zones];
134+
}
135+
131136
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token
132137
actionType:(QNActionType)actionType {
133138

@@ -196,9 +201,17 @@ - (void)preQuery:(QNUpToken *)token actionType:(QNActionType)actionType on:(QNPr
196201
if (responseInfo.isConnectionBroken) {
197202
ret(kQNNetworkError, responseInfo, metrics);
198203
} else {
199-
QNZonesInfo *zonesInfo = [[QNFixedZone localsZoneInfo] getZonesInfoWithToken:token];
200-
if ([zonesInfo isValid]) {
201-
[[QNAutoZoneCache share] cache:zonesInfo forKey:cacheKey];
204+
QNZonesInfo *info = nil;
205+
if (self.defaultZone) {
206+
QNZonesInfo * infoP = [self.defaultZone getZonesInfoWithToken:token actionType:actionType];
207+
if (infoP && [infoP isValid]) {
208+
[infoP toTemporary];
209+
info = infoP;
210+
}
211+
}
212+
213+
if (info) {
214+
[[QNAutoZoneCache share] cache:info forKey:cacheKey];
202215
ret(0, responseInfo, metrics);
203216
} else {
204217
ret(-1, responseInfo, metrics);
@@ -213,7 +226,7 @@ - (QNRequestTransaction *)createUploadRequestTransaction:(QNUpToken *)token{
213226
if (self.ucHosts && self.ucHosts.count > 0) {
214227
hosts = [self.ucHosts copy];
215228
} else {
216-
hosts = @[kQNPreQueryHost02, kQNPreQueryHost00, kQNPreQueryHost01];
229+
hosts = kQNPreQueryHosts;
217230
}
218231
QNRequestTransaction *transaction = [[QNRequestTransaction alloc] initWithHosts:hosts
219232
regionId:QNZoneInfoEmptyRegionId

QiniuSDK/Common/QNConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
#define kQNPreQueryHost00 @"uc.qbox.me"
1313
#define kQNPreQueryHost01 @"api.qiniu.com"
1414
#define kQNPreQueryHost02 @"kodo-config.qiniuapi.com"
15+
#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost02, kQNPreQueryHost01]
16+
1517
#define kQNUpLogHost @"uplog.qbox.me"

QiniuSDK/Common/QNFixedZone.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ NS_ASSUME_NONNULL_BEGIN
8383
*/
8484
+ (QNFixedZone *)localsZoneInfo;
8585

86+
/**
87+
* 合并区域
88+
*/
89+
+ (QNFixedZone *)combineZones:(NSArray<QNFixedZone *> *)zones;
90+
8691
@end
8792

8893
NS_ASSUME_NONNULL_END

QiniuSDK/Common/QNFixedZone.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ + (QNFixedZone *)localsZoneInfo{
103103
[QNFixedZone zoneNa0],
104104
[QNFixedZone zoneApNorthEast1],
105105
[QNFixedZone zoneAs0]];
106+
QNFixedZone *zone = [self combineZones:zones];
107+
if (zone) {
108+
[zone.zonesInfo toTemporary];
109+
}
110+
return zone;
111+
}
112+
113+
+ (QNFixedZone *)combineZones:(NSArray<QNFixedZone *> *)zones {
114+
if (zones == nil || zones.count == 0) {
115+
return nil;
116+
}
106117

107118
NSMutableArray <QNZoneInfo *> *zoneInfoArray = [NSMutableArray array];
108119
for (QNFixedZone *zone in zones) {

QiniuSDK/Common/QNZoneInfo.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,18 @@ - (void)toTemporary {
191191
}
192192

193193
- (BOOL)isValid {
194-
return [self.zonesInfo count] > 0 && [self.zonesInfo.firstObject isValid];
194+
if ([self.zonesInfo count] == 0) {
195+
return false;
196+
}
197+
198+
BOOL valid = true;
199+
for (QNZoneInfo *info in self.zonesInfo) {
200+
if (![info isValid]) {
201+
valid = false;
202+
break;
203+
}
204+
}
205+
return valid;
195206
}
196207

197208
- (id)copyWithZone:(NSZone *)zone {

QiniuSDK/Storage/ServerConfig/QNServerConfigMonitor.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ + (void)startMonitor {
8383
return;
8484
}
8585

86-
QNTransaction *transaction = [QNTransaction timeTransaction:kQNServerConfigTransactionKey after:0 interval:10 action:^{
86+
int interval = 120 + arc4random()%240;
87+
QNTransaction *transaction = [QNTransaction timeTransaction:kQNServerConfigTransactionKey after:0 interval:interval action:^{
8788
[[QNServerConfigMonitor share] monitor];
8889
}];
8990
[kQNTransactionManager addTransaction:transaction];

0 commit comments

Comments
 (0)