You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/03/01 08:10:01 UTC

[GitHub] [lucene] mogui commented on a change in pull request #679: Monitor Improvements LUCENE-10422

mogui commented on a change in pull request #679:
URL: https://github.com/apache/lucene/pull/679#discussion_r816533407



##########
File path: lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.lucene.monitor;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.SearcherManager;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.IOUtils;
+
+class ReadonlyQueryIndex extends QueryIndex {
+
+  public ReadonlyQueryIndex(MonitorConfiguration configuration) throws IOException {
+    if (configuration.getDirectoryProvider() == null) {
+      throw new IllegalStateException(
+          "You must specify a Directory when configuring a Monitor as read-only.");
+    }
+    Directory directory = configuration.getDirectoryProvider().get();
+    this.queries = new HashMap<>();
+    this.manager = new SearcherManager(directory, new TermsHashBuilder(termFilters));
+    this.decomposer = configuration.getQueryDecomposer();
+    this.serializer = configuration.getQuerySerializer();
+    this.populateQueryCache(serializer, decomposer);
+  }
+
+  @Override
+  public void commit(List<MonitorQuery> updates) throws IOException {
+    throw new IllegalStateException("Monitor is readOnly cannot commit");
+  }
+
+  @Override
+  long search(final Query query, QueryCollector matcher) throws IOException {
+    QueryBuilder builder = termFilter -> query;
+    return search(builder, matcher);
+  }
+
+  @Override
+  public long search(QueryBuilder queryBuilder, QueryCollector matcher) throws IOException {
+    IndexSearcher searcher = null;
+    try {
+      searcher = manager.acquire();
+      return searchInMemory(queryBuilder, matcher, searcher, this.queries);
+    } finally {
+      if (searcher != null) {
+        manager.release(searcher);
+      }
+    }
+  }
+
+  @Override
+  public void purgeCache() throws IOException {
+    this.populateQueryCache(serializer, decomposer);
+    lastPurged = System.nanoTime();
+  }
+
+  @Override
+  void purgeCache(CachePopulator populator) throws IOException {
+    manager.maybeRefresh();

Review comment:
       @romseygeek I just realized that main branch from which I started the fork requires java 17, is there a way to make a build that targets Java 11 or do I have to remake the pull request on topo of 9_0_0 branch ?




-- 
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: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org