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



##########
File path: 
lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
+
+class ReadonlyQueryIndex implements QueryIndex {
+  private final SearcherManager manager;
+  private final QueryDecomposer decomposer;
+  private final MonitorQuerySerializer serializer;
+
+  final Map<IndexReader.CacheKey, WritableQueryIndex.QueryTermFilter> 
termFilters = new HashMap<>();
+
+  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.manager = new SearcherManager(directory, new 
TermsHashBuilder(termFilters));
+    this.decomposer = configuration.getQueryDecomposer();
+    this.serializer = configuration.getQuerySerializer();

Review comment:
       AIUI, this implementation doesn't have an in-memory query cache, and 
re-parses the queries every time we do a match.  I think having a lazy parser 
is definitely a valid use-case but I think we should decouple it from the 
notion of a read-only monitor.

##########
File path: lucene/monitor/src/java/org/apache/lucene/monitor/Monitor.java
##########
@@ -125,14 +108,21 @@ public Monitor(Analyzer analyzer, Presearcher 
presearcher, MonitorConfiguration
    * Monitor's queryindex
    *
    * @param listener listener to register
+   * @throws IllegalStateException when Monitor is readonly
    */
   public void addQueryIndexUpdateListener(MonitorUpdateListener listener) {
-    listeners.add(listener);

Review comment:
       I think we can just make `addListener()` a method on `QueryIndex` and 
delegate there? And then we don't need the `readOnly` member variable on 
`Monitor`

##########
File path: 
lucene/monitor/src/java/org/apache/lucene/monitor/ReadonlyQueryIndex.java
##########
@@ -0,0 +1,184 @@
+/*
+ * 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.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
+
+class ReadonlyQueryIndex implements QueryIndex {
+  private final SearcherManager manager;
+  private final QueryDecomposer decomposer;
+  private final MonitorQuerySerializer serializer;
+
+  final Map<IndexReader.CacheKey, WritableQueryIndex.QueryTermFilter> 
termFilters = new HashMap<>();
+
+  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.manager = new SearcherManager(directory, new 
TermsHashBuilder(termFilters));
+    this.decomposer = configuration.getQueryDecomposer();
+    this.serializer = configuration.getQuerySerializer();
+  }
+
+  @Override
+  public void commit(List<MonitorQuery> updates) throws IOException {
+    throw new IllegalStateException("Monitor is readOnly cannot commit");
+  }
+
+  @Override
+  public MonitorQuery getQuery(String queryId) throws IOException {
+    if (serializer == null) {
+      throw new IllegalStateException(
+          "Cannot get queries from an index with no MonitorQuerySerializer");
+    }
+    BytesRef[] bytesHolder = new BytesRef[1];
+    search(
+        new TermQuery(new Term(WritableQueryIndex.FIELDS.query_id, queryId)),

Review comment:
       Given that we're re-using a fair amount of stuff from 
WriteableQueryIndex here, it probably makes more sense to make QueryIndex an 
abstract class and move the shared code there.

##########
File path: 
lucene/monitor/src/java/org/apache/lucene/monitor/MonitorConfiguration.java
##########
@@ -47,16 +49,39 @@ private static IndexWriterConfig defaultIndexWriterConfig() 
{
     return iwc;
   }
 
+  public Boolean isReadOnly() {

Review comment:
       Can this be a plain `boolean`?




-- 
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-unsubscr...@lucene.apache.org

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



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

Reply via email to