Skip to content

Commit 203e11e

Browse files
committed
#4217 Suppress expected shard write errors
1 parent 1c231ff commit 203e11e

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

stroom-cache/stroom-cache-impl/src/main/java/stroom/cache/impl/AbstractStroomCache.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import java.util.Optional;
2727
import java.util.Set;
2828
import java.util.concurrent.ConcurrentMap;
29+
import java.util.concurrent.atomic.AtomicInteger;
2930
import java.util.function.BiConsumer;
3031
import java.util.function.BiPredicate;
3132
import java.util.function.Function;
3233
import java.util.function.Supplier;
33-
import java.util.stream.Collectors;
3434

3535
abstract class AbstractStroomCache<K, V> implements StroomCache<K, V> {
3636

@@ -39,6 +39,7 @@ abstract class AbstractStroomCache<K, V> implements StroomCache<K, V> {
3939
private final String name;
4040
private final Supplier<CacheConfig> cacheConfigSupplier;
4141
private final BiConsumer<K, V> removalNotificationConsumer;
42+
private final AtomicInteger reachedSizeLimitCount = new AtomicInteger();
4243

4344
protected volatile CacheHolder<K, V> cacheHolder = null;
4445

@@ -73,6 +74,7 @@ public AbstractStroomCache(final String name,
7374
*/
7475
abstract Cache<K, V> createCacheFromBuilder(final Caffeine<K, V> cacheBuilder);
7576

77+
@SuppressWarnings({"unchecked", "rawtypes"})
7678
@Override
7779
public synchronized void rebuild() {
7880
LOGGER.trace(() -> buildMessage("rebuild"));
@@ -143,11 +145,10 @@ private RemovalListener<K, V> createRemovalListener() {
143145
cause + ")";
144146

145147
if (cause == RemovalCause.SIZE) {
146-
LOGGER.warn(() -> "Cache reached size limit '" + name + "'");
147-
LOGGER.debug(messageSupplier);
148-
} else {
149-
LOGGER.trace(messageSupplier);
148+
reachedSizeLimitCount.incrementAndGet();
149+
LOGGER.debug(() -> "Cache reached size limit '" + name + "'");
150150
}
151+
LOGGER.trace(messageSupplier);
151152
removalNotificationConsumer.accept(key, value);
152153
};
153154
}
@@ -246,7 +247,7 @@ public void invalidateEntries(final BiPredicate<K, V> entryPredicate) {
246247
LOGGER.trace(() -> buildMessage("invalidateEntries", entry.getKey()));
247248
return entry.getKey();
248249
})
249-
.collect(Collectors.toList());
250+
.toList();
250251

251252
// Doing the remove on the cacheAsMap means if rebuild was called we are still operating on
252253
// the old cache
@@ -304,6 +305,9 @@ public CacheInfo getCacheInfo() {
304305
// We don't make use of Weighers in the cache so the weight stats are meaningless
305306
map.remove("EvictionWeight");
306307

308+
// Let users know how many times we have evicted items for hitting the size limit.
309+
map.put("Reached Size Limit Count", Integer.toString(reachedSizeLimitCount.get()));
310+
307311
return new CacheInfo(name, basePropertyPath, map);
308312
}
309313

@@ -331,10 +335,10 @@ private void addEntries(final Map<String, String> map, String string) {
331335
if (kv.length == 2) {
332336
String key = kv[0].replaceAll("\\W", "");
333337
String value = kv[1].replaceAll("\\D", "");
334-
if (key.length() > 0) {
338+
if (!key.isEmpty()) {
335339
final char[] chars = key.toCharArray();
336340
chars[0] = Character.toUpperCase(chars[0]);
337-
key = new String(chars, 0, chars.length);
341+
key = new String(chars);
338342
}
339343

340344
map.put(key, value);

stroom-index/stroom-index-impl/src/main/java/stroom/index/impl/ActiveShardsCacheImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ private boolean addDocument(final IndexDocument document,
191191
LOGGER.trace(e::getMessage, e);
192192

193193
} catch (final RuntimeException e) {
194-
LOGGER.error(e::getMessage, e);
195194
if (throwException) {
195+
LOGGER.error(e::getMessage, e);
196196
throw e;
197+
} else {
198+
LOGGER.debug(e::getMessage, e);
197199
}
198200
}
199201
return false;
@@ -241,7 +243,7 @@ private List<IndexShard> getExistingShards(final IndexShardKey indexShardKey) {
241243
final List<IndexShard> indexShards = new ArrayList<>();
242244
final ResultPage<IndexShard> indexShardResultPage = indexShardService.find(criteria);
243245
for (final IndexShard indexShard : indexShardResultPage.getValues()) {
244-
// Look for non deleted, non full, non corrupt index shards.
246+
// Look for non deleted, non-full, non-corrupt index shards.
245247
if (IndexShardStatus.CLOSED.equals(indexShard.getStatus()) &&
246248
indexShard.getDocumentCount() < maxDocsPerShard) {
247249
indexShards.add(indexShard);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
* Issue **#4217** : Suppress expected shard write errors.
2+
3+
4+
```sh
5+
# ********************************************************************************
6+
# Issue title: Shard ERROR
7+
# Issue link: https://github.com/gchq/stroom/issues/4217
8+
# ********************************************************************************
9+
10+
# ONLY the top line will be included as a change entry in the CHANGELOG.
11+
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
12+
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
13+
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
14+
# 'Fixed nasty bug'.
15+
#
16+
# Examples of acceptable entries are:
17+
#
18+
#
19+
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
20+
#
21+
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
22+
#
23+
# * Fix bug with no associated GitHub issue.
24+
```

0 commit comments

Comments
 (0)