Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
magibney commented on code in PR #1899:
URL: https://github.com/apache/solr/pull/1899#discussion_r2161511800
##
solr/core/src/java/org/apache/solr/search/OrdMapRegenerator.java:
##
@@ -0,0 +1,255 @@
+/*
+ * 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.
+ */
+package org.apache.solr.search;
+
+import static org.apache.solr.common.params.CommonParams.NAME;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.OrdinalMap;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.lucene.util.packed.PackedInts;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.index.SlowCompositeReaderWrapper;
+import org.apache.solr.search.SolrCache.MetaEntry;
+import org.apache.solr.util.IOFunction;
+
+/** Cache regenerator that builds OrdinalMap instances against the new
searcher. */
+public class OrdMapRegenerator>
+extends MetaCacheRegenerator {
+
+ private static final int DEFAULT_REGEN_KEEPALIVE_MINUTES = 2;
+ private static final long DEFAULT_REGEN_KEEPALIVE_NANOS =
+ TimeUnit.MINUTES.toNanos(DEFAULT_REGEN_KEEPALIVE_MINUTES);
+ private static final OrdMapRegenerator DEFAULT_INSTANCE =
+ new OrdMapRegenerator<>(DEFAULT_REGEN_KEEPALIVE_NANOS);
+
+ private final long regenKeepAliveNanos;
+
+ public OrdMapRegenerator() {
+this(DEFAULT_REGEN_KEEPALIVE_NANOS);
+// default ctor in case someone specifies this class via standard
`"regen"=[className]` syntax
+ }
+
+ private OrdMapRegenerator(long regenKeepAliveNanos) {
+super(getWrapFunction());
+this.regenKeepAliveNanos = regenKeepAliveNanos;
+ }
+
+ @SuppressWarnings({"unchecked", "UnnecessaryLambda"})
+ private static Function getWrapFunction() {
+return (v) -> (M) new OrdinalMapValue(v, 0);
+ }
+
+ public static class OrdinalMapValue implements MetaEntry {
+private static final long BASE_RAM_BYTES_USED =
+RamUsageEstimator.shallowSizeOfInstance(OrdinalMapValue.class);
+private final OrdinalMap ordinalMap;
+private long accessTimestampNanos;
+
+private OrdinalMapValue(OrdinalMap ordinalMap, long accessTimestampNanos) {
+ this.ordinalMap = ordinalMap;
+ this.accessTimestampNanos = accessTimestampNanos;
+}
+
+@Override
+public OrdinalMap get() {
+ accessTimestampNanos = System.nanoTime();
+ return ordinalMap;
+}
+
+@Override
+public long ramBytesUsed() {
+ return BASE_RAM_BYTES_USED + ordinalMap.ramBytesUsed();
+}
+
+@Override
+public OrdinalMapValue metaClone(OrdinalMap val) {
+ return new OrdinalMapValue(val, accessTimestampNanos);
+}
+ }
+
+ /**
+ * Configures and supplies a default `ordMapCache` {@link CacheConfig} of
unlimited maximum size
+ * and modest initial size, with no autowarming.
+ */
+ public static CacheConfig getDefaultCacheConfig() {
+// for back-compat, default to an effectively unlimited-sized cache with
no regeneration
+Map args = new HashMap<>();
+args.put(NAME, "ordMapCache");
+args.put("size", Integer.toString(Integer.MAX_VALUE)); // effectively
unlimited
+args.put("initialSize", "10");
+return new CacheConfig(CaffeineCache.class, args, null);
+ }
+
+ /**
+ * If no regenerator is explicitly configured for the specified {@link
CacheConfig}, and if
+ * autowarming is on, this method configures a regenerator. `regenKeepAlive`
is respected if
+ * explicitly set, implicitly defaulting to 2x the autocommit interval
defined by the specified
+ * {@link SolrConfig} (or default of {@value
#DEFAULT_REGEN_KEEPALIVE_MINUTES} minutes if no
+ * autocommit interval can be determined).
+ */
+ public static void configureRegenerator(SolrConfig solrConfig, CacheConfig
config)
Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
magibney commented on code in PR #1899:
URL: https://github.com/apache/solr/pull/1899#discussion_r2161511800
##
solr/core/src/java/org/apache/solr/search/OrdMapRegenerator.java:
##
@@ -0,0 +1,255 @@
+/*
+ * 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.
+ */
+package org.apache.solr.search;
+
+import static org.apache.solr.common.params.CommonParams.NAME;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.OrdinalMap;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.lucene.util.packed.PackedInts;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.index.SlowCompositeReaderWrapper;
+import org.apache.solr.search.SolrCache.MetaEntry;
+import org.apache.solr.util.IOFunction;
+
+/** Cache regenerator that builds OrdinalMap instances against the new
searcher. */
+public class OrdMapRegenerator>
+extends MetaCacheRegenerator {
+
+ private static final int DEFAULT_REGEN_KEEPALIVE_MINUTES = 2;
+ private static final long DEFAULT_REGEN_KEEPALIVE_NANOS =
+ TimeUnit.MINUTES.toNanos(DEFAULT_REGEN_KEEPALIVE_MINUTES);
+ private static final OrdMapRegenerator DEFAULT_INSTANCE =
+ new OrdMapRegenerator<>(DEFAULT_REGEN_KEEPALIVE_NANOS);
+
+ private final long regenKeepAliveNanos;
+
+ public OrdMapRegenerator() {
+this(DEFAULT_REGEN_KEEPALIVE_NANOS);
+// default ctor in case someone specifies this class via standard
`"regen"=[className]` syntax
+ }
+
+ private OrdMapRegenerator(long regenKeepAliveNanos) {
+super(getWrapFunction());
+this.regenKeepAliveNanos = regenKeepAliveNanos;
+ }
+
+ @SuppressWarnings({"unchecked", "UnnecessaryLambda"})
+ private static Function getWrapFunction() {
+return (v) -> (M) new OrdinalMapValue(v, 0);
+ }
+
+ public static class OrdinalMapValue implements MetaEntry {
+private static final long BASE_RAM_BYTES_USED =
+RamUsageEstimator.shallowSizeOfInstance(OrdinalMapValue.class);
+private final OrdinalMap ordinalMap;
+private long accessTimestampNanos;
+
+private OrdinalMapValue(OrdinalMap ordinalMap, long accessTimestampNanos) {
+ this.ordinalMap = ordinalMap;
+ this.accessTimestampNanos = accessTimestampNanos;
+}
+
+@Override
+public OrdinalMap get() {
+ accessTimestampNanos = System.nanoTime();
+ return ordinalMap;
+}
+
+@Override
+public long ramBytesUsed() {
+ return BASE_RAM_BYTES_USED + ordinalMap.ramBytesUsed();
+}
+
+@Override
+public OrdinalMapValue metaClone(OrdinalMap val) {
+ return new OrdinalMapValue(val, accessTimestampNanos);
+}
+ }
+
+ /**
+ * Configures and supplies a default `ordMapCache` {@link CacheConfig} of
unlimited maximum size
+ * and modest initial size, with no autowarming.
+ */
+ public static CacheConfig getDefaultCacheConfig() {
+// for back-compat, default to an effectively unlimited-sized cache with
no regeneration
+Map args = new HashMap<>();
+args.put(NAME, "ordMapCache");
+args.put("size", Integer.toString(Integer.MAX_VALUE)); // effectively
unlimited
+args.put("initialSize", "10");
+return new CacheConfig(CaffeineCache.class, args, null);
+ }
+
+ /**
+ * If no regenerator is explicitly configured for the specified {@link
CacheConfig}, and if
+ * autowarming is on, this method configures a regenerator. `regenKeepAlive`
is respected if
+ * explicitly set, implicitly defaulting to 2x the autocommit interval
defined by the specified
+ * {@link SolrConfig} (or default of {@value
#DEFAULT_REGEN_KEEPALIVE_MINUTES} minutes if no
+ * autocommit interval can be determined).
+ */
+ public static void configureRegenerator(SolrConfig solrConfig, CacheConfig
config)
Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
github-actions[bot] closed pull request #1899: SOLR-16966: Add a first-class cache for OrdinalMaps URL: https://github.com/apache/solr/pull/1899 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
github-actions[bot] commented on PR #1899: URL: https://github.com/apache/solr/pull/1899#issuecomment-2646664483 This PR is now closed due to 60 days of inactivity after being marked as stale. Re-opening this PR is still possible, in which case it will be marked as active again. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
github-actions[bot] commented on PR #1899: URL: https://github.com/apache/solr/pull/1899#issuecomment-2533260332 This PR has had no activity for 60 days and is now labeled as stale. Any new activity will remove the stale label. To attract more reviewers, please tag people who might be familiar with the code area and/or notify the [email protected] mailing list. To exempt this PR from being marked as stale, make it a draft PR or add the label "exempt-stale". If left unattended, this PR will be closed after another 60 days of inactivity. Thank you for your contribution! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] SOLR-16966: Add a first-class cache for OrdinalMaps [solr]
github-actions[bot] commented on PR #1899: URL: https://github.com/apache/solr/pull/1899#issuecomment-1912846980 This PR had no visible activity in the past 60 days, labeling it as stale. Any new activity will remove the stale label. To attract more reviewers, please tag someone or notify the [email protected] mailing list. Thank you for your contribution! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
