From fcf7e6b8acd4353867778824bd776db9ba0a2e97 Mon Sep 17 00:00:00 2001 From: Andrew Sail Date: Thu, 17 Dec 2020 22:12:48 -0500 Subject: [PATCH] eliminate dup code --- .../elasticsearch/MetadataBackendKV.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/metadata/elasticsearch/src/main/java/com/spotify/heroic/metadata/elasticsearch/MetadataBackendKV.java b/metadata/elasticsearch/src/main/java/com/spotify/heroic/metadata/elasticsearch/MetadataBackendKV.java index 1ba8938f3..a9e494e6d 100644 --- a/metadata/elasticsearch/src/main/java/com/spotify/heroic/metadata/elasticsearch/MetadataBackendKV.java +++ b/metadata/elasticsearch/src/main/java/com/spotify/heroic/metadata/elasticsearch/MetadataBackendKV.java @@ -236,27 +236,21 @@ public AsyncFuture write( try (Scope ignored = tracer.withSpan(span)) { span.putAttribute("index", AttributeValue.stringAttributeValue(index)); - if (indexResourceIdentifiers) { - if (!writeCache.acquire(Pair.of(index, series.getHashCode()), - reporter::reportWriteDroppedByCacheHit)) { - span.setStatus( - Status - .ALREADY_EXISTS - .withDescription("Write dropped by cache hit")); - span.end(); - continue; - } - } else { - if (!writeCache.acquire(Pair.of(index, series.getHashCodeTagOnly()), - reporter::reportWriteDroppedByCacheHit)) { - span.setStatus( - Status - .ALREADY_EXISTS - .withDescription("Write dropped by cache hit")); - span.end(); - continue; - } + HashCode hc = + indexResourceIdentifiers ? + series.getHashCode() : + series.getHashCodeTagOnly(); + + if (!writeCache.acquire(Pair.of(index, hc), + reporter::reportWriteDroppedByCacheHit)) { + span.setStatus( + Status + .ALREADY_EXISTS + .withDescription("Write dropped by cache hit")); + span.end(); + continue; } + indexSpans.add(span); final XContentBuilder source = XContentFactory.jsonBuilder();