Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cats): Remove unmodifiable collections from modifiable codepaths #2022

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.netflix.spinnaker.cats.cache.CacheData;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -30,7 +30,7 @@ public class DefaultCacheResult implements CacheResult {
private final Map<String, Collection<String>> evictions;

public DefaultCacheResult(Map<String, Collection<CacheData>> cacheResults) {
this(cacheResults, Collections.emptyMap());
this(cacheResults, new HashMap<>());
}
public DefaultCacheResult(Map<String, Collection<CacheData>> cacheResults, Map<String, Collection<String>> evictions) {
this.cacheResults = cacheResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ private Collection<CacheData> buildResponse(Collection<CacheData> source) {
private Collection<String> getExistingSourceIdentifiers(String type, String sourceAgentType) {
CacheData all = backingStore.get(type, ALL_ID);
if (all == null) {
return Collections.emptySet();
return new HashSet<>();
}
Collection<String> relationship = all.getRelationships().get(sourceAgentType);
if (relationship == null) {
return Collections.emptySet();
return new HashSet<>();
}
return relationship;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ protected void evictItems(String type, List<String> identifiers, Collection<Stri
.run(() -> redisClientDelegate.withPipeline(pipeline -> {
DynoJedisPipeline p = (DynoJedisPipeline) pipeline;

boolean pipelineHasOps = false;
for (List<String> idPartition : Lists.partition(identifiers, options.getMaxDelSize())) {
pipelineHasOps = true;
String[] ids = idPartition.toArray(new String[idPartition.size()]);
pipeline.srem(allOfTypeId(type), ids);
sremOperations.incrementAndGet();
Expand All @@ -228,14 +226,13 @@ protected void evictItems(String type, List<String> identifiers, Collection<Stri
}

for (String id : identifiers) {
pipelineHasOps = true;
pipeline.del(itemId(type, id));
delOperations.incrementAndGet();
pipeline.del(itemHashesId(type, id));
delOperations.incrementAndGet();
}

if (pipelineHasOps) {
if (!identifiers.isEmpty()) {
p.sync();
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -64,7 +63,7 @@ protected AbstractRedisCache(String prefix, RedisClientDelegate redisClientDeleg

@Override
public void merge(String type, CacheData item) {
mergeAll(type, Collections.singletonList(item));
mergeAll(type, Arrays.asList(item));
}

@Override
Expand All @@ -76,7 +75,7 @@ public void mergeAll(String type, Collection<CacheData> items) {

@Override
public void evict(String type, String id) {
evictAll(type, Collections.singletonList(id));
evictAll(type, Arrays.asList(id));
}

@Override
Expand All @@ -97,7 +96,7 @@ public CacheData get(String type, String id) {

@Override
public CacheData get(String type, String id, CacheFilter cacheFilter) {
Collection<CacheData> result = getAll(type, Collections.singletonList(id), cacheFilter);
Collection<CacheData> result = getAll(type, Arrays.asList(id), cacheFilter);
if (result.isEmpty()) {
return null;
}
Expand Down