X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.indexing%2Fsrc%2Forg%2Fsimantics%2Fdb%2Findexing%2FMemoryIndexing.java;fp=bundles%2Forg.simantics.db.indexing%2Fsrc%2Forg%2Fsimantics%2Fdb%2Findexing%2FMemoryIndexing.java;h=7f86d2bc1635fe762d40c4321632448ab916ff87;hb=da749c56c5caad4252cd27276bf19b08f4dcb778;hp=cee5eb26bfb616799c522baca31cf186b2a46a17;hpb=dca20c7c10ae30a7ea50a22e15a043dc8d71af1b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/MemoryIndexing.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/MemoryIndexing.java index cee5eb26b..7f86d2bc1 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/MemoryIndexing.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/MemoryIndexing.java @@ -2,12 +2,10 @@ package org.simantics.db.indexing; import java.io.IOException; import java.nio.file.Path; -import java.util.Collection; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Semaphore; -import java.util.stream.Stream; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexWriter; @@ -17,13 +15,13 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Version; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.common.SimanticsInternal; import org.simantics.db.common.request.Adapt; -import org.simantics.db.indexing.IndexedRelationsSearcherBase.State; import org.simantics.db.layer0.adapter.GenericRelation; +import org.simantics.db.layer0.genericrelation.IndexedRelations; import org.slf4j.LoggerFactory; /** @@ -52,6 +50,13 @@ public class MemoryIndexing { return DatabaseIndexing.getIndexLocation(session, relation, input); } + List getAllSearchers() { + List r = new ArrayList<>(); + r.addAll(searchers.values()); + r.addAll(immutableSearchers.values()); + return r; + } + public IndexedRelationsSearcher get(RequestProcessor processor, Resource relation, Resource input) { Path location = getIndexDirectory(relation, input); String key = location.toAbsolutePath().toString(); @@ -109,35 +114,15 @@ public class MemoryIndexing { directories.remove(path); } + /** + * @param progress + * @throws Exception + * @deprecated Use {@link IndexUtils#flushIndexCaches(IProgressMonitor, Session)} instead + */ + @Deprecated public void flush(IProgressMonitor progress) throws Exception { - long startTime = System.currentTimeMillis(); - SubMonitor monitor = SubMonitor.convert(progress); - Collection searcherEntries = searchers.values(); - Collection immutableSearcherEntries = immutableSearchers.values(); - int count = searcherEntries.size() + immutableSearcherEntries.size(); - Semaphore sema = new Semaphore(0); - Stream.concat(searcherEntries.stream(), immutableSearcherEntries.stream()).parallel().forEach(base -> { - try { - if (base.isIndexAvailable()) { - if (base instanceof IndexedRelationsSearcher) { - IndexedRelationsMemorySearcher searcher = ((IndexedRelationsSearcher) base).cache; - try { - List os = searcher.allDocs(monitor, session); - ((IndexedRelationsSearcher) base).applyChanges(monitor, session, searcher.r, os); - } catch (Exception e) { - LOGGER.error("Could not flush", e); - } - } - } - monitor.worked(1); - base.changeState(monitor, session, State.READY); - } finally { - sema.release(); - } - }); - sema.acquire(count); - long totalTime = System.currentTimeMillis() - startTime; - LOGGER.info("index flush " + totalTime); + Session s = SimanticsInternal.getSession(); + s.getService(IndexedRelations.class).flush(progress, s); } - + }