Skip to content

Support secondary cache#7

Merged
schernysh merged 6 commits intomasterfrom
support-secondary-cache
Oct 2, 2018
Merged

Support secondary cache#7
schernysh merged 6 commits intomasterfrom
support-secondary-cache

Conversation

@dhutsalo
Copy link
Copy Markdown
Contributor

added secondary cache replication functionality
incoming request copies exactly one time to each other cache server described in config file, without retries in case of failure

Comment thread pom.xml Outdated
<dependency>
<groupId>com.github.JensPiegsa</groupId>
<artifactId>wiremock-extension</artifactId>
<version>0.3.1</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version is better to be extracted to a property

val bodyMono = request.bodyToMono(RequestObject.class)
.doOnSuccess(requestObject ->
sendRequestToSecondaryPrebidCacheHosts(requestObject, request.queryParam(SECONDARY_CACHE_KEY)
.orElse(Strings.EMPTY)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please user StringUtils.EMPTY from apache-commons instead

val bodyMono = request.bodyToMono(RequestObject.class);

val bodyMono = request.bodyToMono(RequestObject.class)
.doOnSuccess(requestObject ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this might be not the right place to perform replication, because at this point UUIDs for cache entries are not generated yet

private int timeoutMs;
private long minExpiry;
private long maxExpiry;
private List<String> secondaryIps;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed configuration approach seems a little too restraining. For example cache servers might run on different ports - it's impossible to utilize such setup with current configuration.

The most simple and straightforward approach might work better - have a list of URLs where requests need to be propagated, i.e. List<String> secondaryUris (assuming these URIs point to the root context of cache application)

if(!secondaryCache.equals("yes")) {
config.getSecondaryIps().forEach(ip -> {
WebClient.create().post().uri(uriBuilder -> uriBuilder.scheme(config.getSecondaryCacheScheme())
.host(ip).port(config.getSecondaryCachePort()).path(CACHE_PATH)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's dangerous to hard-code "/cache" into the path as cache application might be exposed via reverse-proxy. It's better to move that part into configuration.

private void sendRequestToSecondaryPrebidCacheHosts(RequestObject requestObject, String secondaryCache) {
if(!secondaryCache.equals("yes")) {
config.getSecondaryIps().forEach(ip -> {
WebClient.create().post().uri(uriBuilder -> uriBuilder.scheme(config.getSecondaryCacheScheme())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since URIs don't change from call to call, maybe they can be cached?

XML("pbc.${prefix}.xml"),
ERROR_DB("pbc.${prefix}.err.db");
ERROR_DB("pbc.${prefix}.err.db"),
SECONDARY_CACHE_WRITE_ERROR("error.secondary.cache.write");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should follow convention for enum values and metric names: ERROR_SECONDARY_WRITE("pbc.err.secondaryWrite") or alike


import com.google.common.collect.ImmutableMap;
import org.apache.logging.log4j.util.Strings;
import org.luaj.vm2.ast.Str;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this import is not used.

private void sendRequestToSecondaryPrebidCacheHosts(RequestObject requestObject, String secondaryCache) {
if(!secondaryCache.equals("yes")) {
config.getSecondaryIps().forEach(ip -> {
WebClient.create().post().uri(uriBuilder -> uriBuilder.scheme(config.getSecondaryCacheScheme())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to create WebClient only once, not for every request?

TerentievEvgany
TerentievEvgany previously approved these changes Oct 2, 2018
@schernysh schernysh merged commit 7724dac into master Oct 2, 2018
@schernysh schernysh deleted the support-secondary-cache branch October 2, 2018 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants