Skip to content

Commit 18022bf

Browse files
xinlian12annie-mac
andauthored
CodeCleanBasedOnFewGithubIssues (Azure#30099)
* clean code based on few open github issues Co-authored-by: annie-mac <[email protected]>
1 parent 567eba8 commit 18022bf

16 files changed

+57
-79
lines changed

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/PathsHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ public static boolean tryParsePathSegments(String resourceUrl, PathInfo pathInfo
400400
// modify.
401401
if (!StringUtils.isEmpty(clientVersion)
402402
&& pathInfo.resourcePath.equalsIgnoreCase(Paths.MEDIA_PATH_SEGMENT)) {
403-
String attachmentId = null;
404-
byte storeIndex = 0;
403+
// String attachmentId = null;
404+
// byte storeIndex = 0;
405405
// MEDIA Id parsing code will come here , supported MediaIdHelper file missing in java sdk(Sync and Async both)
406406
//Below code from .net
407407
// if (!MediaIdHelper.TryParseMediaId(resourceIdOrFullName, out attachmentId, out storeIndex))

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/QueryMetrics.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,6 @@
2020
* This metric represents a moving average for a set of queries whose metrics have been aggregated together.
2121
*/
2222
public final class QueryMetrics {
23-
public final static QueryMetrics ZERO = new QueryMetrics(
24-
new ArrayList<>(), /* */
25-
0, /* retrievedDocumentCount */
26-
0, /* retrievedDocumentSize */
27-
0, /* outputDocumentCount */
28-
0, /* outputDocumentSize */
29-
0, /* indexHitCount */
30-
Duration.ZERO,
31-
QueryPreparationTimes.ZERO,
32-
Duration.ZERO,
33-
Duration.ZERO,
34-
Duration.ZERO,
35-
RuntimeExecutionTimes.ZERO,
36-
Duration.ZERO,
37-
ClientSideMetrics.ZERO,
38-
IndexUtilizationInfo.ZERO);
39-
4023
private final long retrievedDocumentCount;
4124
private final long retrievedDocumentSize;
4225
private final long outputDocumentCount;
@@ -269,7 +252,6 @@ public static QueryMetrics createFromCollection(Collection<QueryMetrics> queryMe
269252
}
270253

271254
public static QueryMetrics createFromDelimitedString(String delimitedString) {
272-
HashMap<String, Double> metrics = QueryMetricsUtils.parseDelimitedString(delimitedString);
273255
return QueryMetrics.createFromDelimitedStringAndClientSideMetrics(delimitedString,
274256
new ClientSideMetrics(0, 0, new ArrayList<FetchExecutionRange>(),
275257
new ArrayList<ImmutablePair<String, SchedulingTimeSpan>>()), "", "");

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ResourceId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static Pair<Boolean, ResourceId> tryParse(String id) {
172172
byte[] temp = new byte[4];
173173
ResourceId.blockCopy(buffer, 4, temp, 0, 4);
174174

175-
boolean isCollection = (temp[0] & (128)) > 0;
175+
boolean isCollection = (temp[0] & (128)) != 0;
176176

177177
if (isCollection) {
178178
rid.documentCollection = ByteBuffer.wrap(temp).getInt();

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ResourceTokenAuthorizationHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,9 @@ public static String getAuthorizationTokenUsingResourceTokens(
168168
&& (RequestVerb.GET == requestVerb
169169
|| RequestVerb.HEAD == requestVerb)) {
170170
for (Map.Entry<String, List<PartitionKeyAndResourceTokenPair>> entry : resourceTokensMap.entrySet()) {
171-
ResourceId tokenRid;
172171
final String key = entry.getKey();
173172
Pair<Boolean, ResourceId> pair = ResourceId.tryParse(key);
174173
if (pair.getLeft()) {
175-
ResourceId test1= pair.getRight().getDocumentCollectionId();
176-
boolean test = test1.equals(resourceId);
177174
if (!PathsHelper.isNameBased(key) && pair.getLeft()
178175
&& pair.getRight().getDocumentCollectionId().equals(resourceId)) {
179176
List<PartitionKeyAndResourceTokenPair> resourceTokens = entry.getValue();

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4078,7 +4078,7 @@ public Flux<DatabaseAccount> getDatabaseAccountFromEndpoint(URI endpoint) {
40784078
private RxStoreModel getStoreProxy(RxDocumentServiceRequest request) {
40794079
// If a request is configured to always use GATEWAY mode(in some cases when targeting .NET Core)
40804080
// we return the GATEWAY store model
4081-
if (request.UseGatewayMode) {
4081+
if (request.useGatewayMode) {
40824082
return this.gatewayProxy;
40834083
}
40844084

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentServiceRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class RxDocumentServiceRequest implements Cloneable {
6767
// some of these fields are missing from the main java sdk service request
6868
// so it means most likely the corresponding features are also missing from the main sdk
6969
// we need to wire this up.
70-
public boolean UseGatewayMode;
70+
public boolean useGatewayMode;
7171

7272
private volatile boolean isDisposed = false;
7373
public volatile String entityId;
@@ -1027,7 +1027,7 @@ public RxDocumentServiceRequest clone() {
10271027
rxDocumentServiceRequest.setPartitionKeyRangeIdentity(this.getPartitionKeyRangeIdentity());
10281028
rxDocumentServiceRequest.forceCollectionRoutingMapRefresh = this.forceCollectionRoutingMapRefresh;
10291029
rxDocumentServiceRequest.forcePartitionKeyRangeRefresh = this.forcePartitionKeyRangeRefresh;
1030-
rxDocumentServiceRequest.UseGatewayMode = this.UseGatewayMode;
1030+
rxDocumentServiceRequest.useGatewayMode = this.useGatewayMode;
10311031
rxDocumentServiceRequest.requestContext = this.requestContext;
10321032
return rxDocumentServiceRequest;
10331033
}

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxPartitionKeyRangeCache.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,17 @@ public Mono<Utils.ValueHolder<PartitionKeyRange>> tryGetRangeByPartitionKeyRange
157157
return routingMapObs.map(routingMapValueHolder -> new Utils.ValueHolder<>(routingMapValueHolder.v.getRangeByPartitionKeyRangeId(partitionKeyRangeId)))
158158
.onErrorResume(err -> {
159159
CosmosException dce = Utils.as(err, CosmosException.class);
160-
logger.debug("tryGetRangeByPartitionKeyRangeId on collectionRid {} and partitionKeyRangeId {} encountered failure",
161-
collectionRid, partitionKeyRangeId, err);
160+
logger.debug(
161+
"tryGetRangeByPartitionKeyRangeId on collectionRid {} and partitionKeyRangeId {} encountered failure",
162+
collectionRid,
163+
partitionKeyRangeId,
164+
err);
162165

163-
if (dce != null && Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.NOTFOUND)) {
166+
if (dce != null && Exceptions.isNotFound(dce)) {
164167
return Mono.just(new Utils.ValueHolder<>(null));
165168
}
166169

167-
return Mono.error(dce);
170+
return dce != null ? Mono.error(dce) : Mono.error(err);
168171
});
169172
}
170173

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/changefeed/ServiceItemLease.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public class ServiceItemLease implements Lease {
3838

3939
private String id;
4040
private String _etag;
41-
private String LeaseToken;
42-
private String Owner;
43-
private String ContinuationToken;
41+
private String leaseToken;
42+
private String owner;
43+
private String continuationToken;
4444

4545
private Map<String, String> properties;
4646
private String timestamp; // ExplicitTimestamp
@@ -57,9 +57,9 @@ public ServiceItemLease(ServiceItemLease other)
5757
{
5858
this.id = other.id;
5959
this._etag = other._etag;
60-
this.LeaseToken = other.LeaseToken;
61-
this.Owner = other.Owner;
62-
this.ContinuationToken = other.ContinuationToken;
60+
this.leaseToken = other.leaseToken;
61+
this.owner = other.owner;
62+
this.continuationToken = other.continuationToken;
6363
this.properties = other.properties;
6464
this.timestamp = other.timestamp;
6565
this._ts = other._ts;
@@ -85,27 +85,27 @@ public ServiceItemLease withETag(String etag) {
8585
}
8686

8787
public String getLeaseToken() {
88-
return this.LeaseToken;
88+
return this.leaseToken;
8989
}
9090

9191
public ServiceItemLease withLeaseToken(String leaseToken) {
92-
this.LeaseToken = leaseToken;
92+
this.leaseToken = leaseToken;
9393
return this;
9494
}
9595

9696
@Override
9797
public String getOwner() {
98-
return this.Owner;
98+
return this.owner;
9999
}
100100

101101
public ServiceItemLease withOwner(String owner) {
102-
this.Owner = owner;
102+
this.owner = owner;
103103
return this;
104104
}
105105

106106
@Override
107107
public String getContinuationToken() {
108-
return this.ContinuationToken;
108+
return this.continuationToken;
109109
}
110110

111111
public ChangeFeedState getContinuationState(
@@ -119,7 +119,7 @@ public ChangeFeedState getContinuationState(
119119
containerRid,
120120
feedRange,
121121
ChangeFeedMode.INCREMENTAL,
122-
ChangeFeedStartFromInternal.createFromETagAndFeedRange(this.ContinuationToken, feedRange),
122+
ChangeFeedStartFromInternal.createFromETagAndFeedRange(this.continuationToken, feedRange),
123123
null);
124124
}
125125

@@ -129,7 +129,7 @@ public void setContinuationToken(String continuationToken) {
129129
}
130130

131131
public ServiceItemLease withContinuationToken(String continuationToken) {
132-
this.ContinuationToken = continuationToken;
132+
this.continuationToken = continuationToken;
133133
return this;
134134
}
135135

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/AddressResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ private static class RefreshState {
343343
volatile boolean collectionRoutingMapCacheIsUptoDate;
344344
volatile DocumentCollection collection;
345345
volatile CollectionRoutingMap routingMap;
346-
volatile ResolutionResult resolutionResult;
347346
}
348347

349348
private Mono<RefreshState> getOrRefreshRoutingMap(RxDocumentServiceRequest request, boolean forceRefreshPartitionAddresses) {

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/ConsistencyReader.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,7 @@ public Mono<StoreResponse> readAsync(RxDocumentServiceRequest entity,
212212
return this.readPrimaryAsync(entity, useSessionToken.v);
213213

214214
case Strong:
215-
entity.requestContext.performLocalRefreshOnGoneException = true;
216-
return this.quorumReader.readStrongAsync(this.diagnosticsClientContext, entity, readQuorumValue, desiredReadMode);
217-
218215
case BoundedStaleness:
219-
entity.requestContext.performLocalRefreshOnGoneException = true;
220-
221216
// for bounded staleness, we are defaulting to read strong for local region reads.
222217
// this can be done since we are always running with majority quorum w = 3 (or 2 during quorum downshift).
223218
// This means that the primary will always be part of the write quorum, and
@@ -228,6 +223,8 @@ public Mono<StoreResponse> readAsync(RxDocumentServiceRequest entity,
228223
// we always contact two secondary replicas and exclude primary.
229224
// However, this model significantly reduces availability and available throughput for serving reads for bounded staleness during reconfiguration.
230225
// Therefore, to ensure monotonic read guarantee from any replica set we will just use regular quorum read(R=2) since our write quorum is always majority(W=3)
226+
227+
entity.requestContext.performLocalRefreshOnGoneException = true;
231228
return this.quorumReader.readStrongAsync(this.diagnosticsClientContext, entity, readQuorumValue, desiredReadMode);
232229

233230
case Any:

0 commit comments

Comments
 (0)