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;
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;
/**
return DatabaseIndexing.getIndexLocation(session, relation, input);
}
+ List<IndexedRelationsSearcherBase> getAllSearchers() {
+ List<IndexedRelationsSearcherBase> 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();
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<IndexedRelationsSearcher> searcherEntries = searchers.values();
- Collection<IndexedRelationsSearcherBase> 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<Object[]> 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);
}
-
+
}