Skip to content

Commit

Permalink
OAK-11025 Silence more warnings for ordered properties (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmueller authored Aug 16, 2024
1 parent 36e5dcc commit 1a675de
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 42 deletions.
1 change: 1 addition & 0 deletions oak-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
org.apache.jackrabbit.oak.commons.concurrent,
org.apache.jackrabbit.oak.commons.io,
org.apache.jackrabbit.oak.commons.json,
org.apache.jackrabbit.oak.commons.log,
org.apache.jackrabbit.oak.commons.sort,
org.apache.jackrabbit.oak.commons.properties
</Export-Package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.oak.plugins.document.util;
package org.apache.jackrabbit.oak.commons.log;

import java.time.Duration;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <em>For Oak internal use only. Do not use outside Oak components.</em>
*/
@Internal(since = "1.0.0")
@Version("1.0.0")
package org.apache.jackrabbit.oak.commons.log;

import org.osgi.annotation.versioning.Version;
import org.apache.jackrabbit.oak.commons.annotations.Internal;

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.oak.plugins.document.util;
package org.apache.jackrabbit.oak.commons.log;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -29,6 +30,7 @@
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.log.LogSilencer;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.FacetsConfigProvider;
import org.apache.jackrabbit.oak.plugins.index.search.Aggregate;
import org.apache.jackrabbit.oak.plugins.index.search.FieldNames;
Expand Down Expand Up @@ -60,14 +62,14 @@ public class LuceneDocumentMaker extends FulltextDocumentMaker<Document> {

private static final String DYNAMIC_BOOST_SPLIT_REGEX = "[:/]";

// warn once every 10 seconds at most
private static final long DUPLICATE_WARNING_INTERVAL_MS = 10 * 1000;

private final FacetsConfigProvider facetsConfigProvider;
private final IndexAugmentorFactory augmentorFactory;

// when did we warn (static, as we construct new objects quite often)
private static long lastDuplicateWarning;
private static final LogSilencer LOG_SILENCER = new LogSilencer(Duration.ofSeconds(10).toMillis(), 10);
private static final String LOG_KEY_DUPLICATE = "Duplicate value";
private static final String LOG_KEY_NOT_A_DATE_STRING = "Not a date string";
private static final String LOG_KEY_UNABLE_TO_PARSE = "Unable to parse the provided date field";
private static final String LOG_KEY_FOR_INPUT_STRING = "For input string";

public LuceneDocumentMaker(IndexDefinition definition,
IndexDefinition.IndexingRule indexingRule,
Expand Down Expand Up @@ -299,19 +301,43 @@ protected boolean indexTypeOrderedFields(Document doc, String pname, int tag, Pr
doc.add(f);
fieldAdded = true;
} else {
long now = System.currentTimeMillis();
if (now > lastDuplicateWarning + DUPLICATE_WARNING_INTERVAL_MS) {
if (!LOG_SILENCER.silence(LOG_KEY_DUPLICATE)) {
log.warn("Duplicate value for ordered field {}; ignoring. Possibly duplicate index definition.", f.name());
lastDuplicateWarning = now;
}
}
}
} catch (Exception e) {
log.warn(
"[{}] Ignoring ordered property. Could not convert property {} of type {} to type {} for path {}",
getIndexName(), pname,
Type.fromTag(property.getType().tag(), false),
Type.fromTag(tag, false), path, e);
String message = e.getMessage();
String key = null;
// This is a known warning, one of:
// - IllegalArgumentException: Not a date string
// - RuntimeException: Unable to parse the provided date field
// - NumberFormatException: For input string
// For these we do not log a stack trace, and we only log once every 10 seconds
// (the location of the code can be found if needed, as it's in Oak)
if (message.startsWith("Not a date string")) {
key = LOG_KEY_NOT_A_DATE_STRING;
} else if (message.startsWith("Unable to parse the provided date field")) {
key = LOG_KEY_UNABLE_TO_PARSE;
} else if (message.startsWith("For input string")) {
key = LOG_KEY_FOR_INPUT_STRING;
}
if (key != null) {
if (!LOG_SILENCER.silence(key)) {
// log without stack trace (as it is known)
log.warn(
"[{}] Ignoring ordered property. Could not convert property {} of type {} to type {} for path {}, message {}",
getIndexName(), pname,
Type.fromTag(property.getType().tag(), false),
Type.fromTag(tag, false), path, e.getMessage());
}
} else {
log.warn(
"[{}] Ignoring ordered property. Could not convert property {} of type {} to type {} for path {}",
getIndexName(), pname,
Type.fromTag(property.getType().tag(), false),
Type.fromTag(tag, false), path, e);
}
}
return fieldAdded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
*/
package org.apache.jackrabbit.oak.plugins.document;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;
import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.guava.common.collect.ImmutableList.copyOf;
import static org.apache.jackrabbit.guava.common.collect.Iterables.filter;
import static org.apache.jackrabbit.guava.common.collect.Iterables.mergeSorted;
import static org.apache.jackrabbit.guava.common.collect.Iterables.transform;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator.REVERSE;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.abortingIterable;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision;
import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key;
import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -39,42 +53,26 @@

import org.apache.jackrabbit.guava.common.collect.AbstractIterator;
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.collect.Ordering;
import org.apache.jackrabbit.guava.common.collect.Queues;
import org.apache.jackrabbit.guava.common.collect.Sets;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
import org.apache.jackrabbit.oak.commons.json.JsopReader;
import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
import org.apache.jackrabbit.oak.commons.json.JsopWriter;
import org.apache.jackrabbit.oak.commons.log.LogSilencer;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.util.LogSilencer;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.collect.Sets;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.guava.common.collect.ImmutableList.copyOf;
import static org.apache.jackrabbit.guava.common.collect.Iterables.filter;
import static org.apache.jackrabbit.guava.common.collect.Iterables.mergeSorted;
import static org.apache.jackrabbit.guava.common.collect.Iterables.transform;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator.REVERSE;
import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key;
import static org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.abortingIterable;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision;

/**
* A document storing data about a node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@
*/
package org.apache.jackrabbit.oak.plugins.document;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.INTERMEDIATE;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.NONE;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;

import org.apache.jackrabbit.guava.common.collect.Lists;

import org.apache.jackrabbit.oak.commons.log.LogSilencer;
import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
import org.apache.jackrabbit.oak.plugins.document.util.LogSilencer;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.INTERMEDIATE;
import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.NONE;

/**
* Implements a split document cleanup.
*/
Expand Down

0 comments on commit 1a675de

Please sign in to comment.