Skip to content

Commit

Permalink
Adding support for multiple destination ips
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumanth Pasupuleti [email protected] committed Jul 24, 2020
1 parent c6a0534 commit 78e3928
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface EVCacheInternal extends EVCache {

EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, String serverGroup) throws EVCacheException;

EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, String serverGroupName, String destinationIp) throws EVCacheException;
EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, String serverGroupName, List<String> destinationIps) throws EVCacheException;

KeyHashedState isKeyHashed(String appName, String serverGroup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value,
return addOrSet(replaceItem, key, value, timeToLive, policy, serverGroupName, null);
}

public EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, String serverGroupName, String destinationIp) throws EVCacheException {
public EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, String serverGroupName, List<String> destinationIps) throws EVCacheException {
List<String> serverGroups = new ArrayList<>();
serverGroups.add(serverGroupName);

return addOrSet(replaceItem, key, value, timeToLive, policy, serverGroups, destinationIp);
return addOrSet(replaceItem, key, value, timeToLive, policy, serverGroups, destinationIps);
}

private EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, List<String> serverGroups, String destinationIp) throws EVCacheException {
private EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value, int timeToLive, EVCacheLatch.Policy policy, List<String> serverGroups, List<String> destinationIps) throws EVCacheException {
Map<ServerGroup, List<EVCacheClient>> clientsByServerGroup = _pool.getAllInstancesByZone();

List<EVCacheClient> evCacheClients = clientsByServerGroup.entrySet().stream()
Expand All @@ -66,12 +66,12 @@ private EVCacheLatch addOrSet(boolean replaceItem, String key, CachedData value,
.flatMap(List::stream)
.collect(Collectors.toList());

if (null != destinationIp && !destinationIp.isEmpty()) {
if (null != destinationIps && !destinationIps.isEmpty()) {
// identify that evcache client whose primary node is the destination ip for the key being processed
evCacheClients = evCacheClients.stream().filter(client ->
((InetSocketAddress) client.getNodeLocator()
destinationIps.contains(((InetSocketAddress) client.getNodeLocator()
.getPrimary(getEVCacheKey(key).getDerivedKey(client.isDuetClient(), client.getHashingAlgorithm(), client.shouldEncodeHashKey(), client.getMaxHashingBytes()))
.getSocketAddress()).getAddress().getHostAddress().equals(destinationIp)
.getSocketAddress()).getAddress().getHostAddress())
).collect(Collectors.toList());
}

Expand Down

0 comments on commit 78e3928

Please sign in to comment.