mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
WIP run and setup
This commit is contained in:
parent
ef87e123ba
commit
5f758cbb0e
@ -85,5 +85,6 @@ converter-process ${SAMPLE_DIR}/plan.yaml
|
|||||||
loader-process ${SAMPLE_DIR}/plan.yaml
|
loader-process ${SAMPLE_DIR}/plan.yaml
|
||||||
|
|
||||||
mv vol/iw/index.dat vol/iw/0/page-index.dat
|
mv vol/iw/index.dat vol/iw/0/page-index.dat
|
||||||
|
rm -f vol/ir/0/*
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
@ -7,26 +7,34 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
|||||||
import nu.marginalia.index.index.SearchIndex;
|
import nu.marginalia.index.index.SearchIndex;
|
||||||
import nu.marginalia.index.svc.IndexOpsService;
|
import nu.marginalia.index.svc.IndexOpsService;
|
||||||
import nu.marginalia.index.svc.IndexQueryService;
|
import nu.marginalia.index.svc.IndexQueryService;
|
||||||
|
import nu.marginalia.index.svc.IndexSearchSetsService;
|
||||||
import nu.marginalia.model.gson.GsonFactory;
|
import nu.marginalia.model.gson.GsonFactory;
|
||||||
import nu.marginalia.service.server.Initialization;
|
import nu.marginalia.service.server.Initialization;
|
||||||
import nu.marginalia.service.server.MetricsServer;
|
import nu.marginalia.service.server.MetricsServer;
|
||||||
import nu.marginalia.service.server.Service;
|
import nu.marginalia.service.server.Service;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import spark.Request;
|
import spark.Request;
|
||||||
import spark.Response;
|
import spark.Response;
|
||||||
import spark.Spark;
|
import spark.Spark;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static spark.Spark.get;
|
import static spark.Spark.get;
|
||||||
|
|
||||||
public class IndexService extends Service {
|
public class IndexService extends Service {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Initialization init;
|
private final Initialization init;
|
||||||
private final IndexOpsService opsService;
|
private final IndexOpsService opsService;
|
||||||
private final SearchIndex searchIndex;
|
private final SearchIndex searchIndex;
|
||||||
|
|
||||||
|
private final IndexServicesFactory servicesFactory;
|
||||||
|
private final IndexSearchSetsService searchSetsService;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IndexService(@Named("service-host") String ip,
|
public IndexService(@Named("service-host") String ip,
|
||||||
@ -35,12 +43,15 @@ public class IndexService extends Service {
|
|||||||
MetricsServer metricsServer,
|
MetricsServer metricsServer,
|
||||||
IndexOpsService opsService,
|
IndexOpsService opsService,
|
||||||
IndexQueryService indexQueryService,
|
IndexQueryService indexQueryService,
|
||||||
SearchIndex searchIndex
|
SearchIndex searchIndex,
|
||||||
)
|
IndexServicesFactory servicesFactory,
|
||||||
|
IndexSearchSetsService searchSetsService)
|
||||||
{
|
{
|
||||||
super(ip, port, init, metricsServer);
|
super(ip, port, init, metricsServer);
|
||||||
this.opsService = opsService;
|
this.opsService = opsService;
|
||||||
this.searchIndex = searchIndex;
|
this.searchIndex = searchIndex;
|
||||||
|
this.servicesFactory = servicesFactory;
|
||||||
|
this.searchSetsService = searchSetsService;
|
||||||
|
|
||||||
final Gson gson = GsonFactory.get();
|
final Gson gson = GsonFactory.get();
|
||||||
|
|
||||||
@ -61,6 +72,7 @@ public class IndexService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
volatile boolean initialized = false;
|
volatile boolean initialized = false;
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
init.waitReady();
|
init.waitReady();
|
||||||
@ -68,6 +80,22 @@ public class IndexService extends Service {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!opsService.run(this::autoConvert)) {
|
||||||
|
logger.warn("Auto-convert could not be performed, ops lock busy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void autoConvert() {
|
||||||
|
if (!servicesFactory.isConvertedIndexMissing() || !servicesFactory.isPreconvertedIndexPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
searchSetsService.recalculateAll();
|
||||||
|
searchIndex.switchIndex();
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
logger.error("Auto convert failed", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class IndexServicesFactory {
|
public class IndexServicesFactory {
|
||||||
@ -42,6 +44,7 @@ public class IndexServicesFactory {
|
|||||||
int LIVE_PART = 0;
|
int LIVE_PART = 0;
|
||||||
|
|
||||||
int NEXT_PART = 1;
|
int NEXT_PART = 1;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IndexServicesFactory(
|
public IndexServicesFactory(
|
||||||
@Named("tmp-file-dir") Path tmpFileDir,
|
@Named("tmp-file-dir") Path tmpFileDir,
|
||||||
@ -72,6 +75,28 @@ public class IndexServicesFactory {
|
|||||||
return searchSetsBase;
|
return searchSetsBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPreconvertedIndexPresent() {
|
||||||
|
return Stream.of(
|
||||||
|
revIndexWords.get(NEXT_PART).toPath(),
|
||||||
|
revIndexDoc.get(NEXT_PART).toPath(),
|
||||||
|
revPrioIndexWords.get(NEXT_PART).toPath(),
|
||||||
|
revPrioIndexDoc.get(NEXT_PART).toPath(),
|
||||||
|
fwdIndexDocData.get(NEXT_PART).toPath(),
|
||||||
|
fwdIndexDocId.get(NEXT_PART).toPath()
|
||||||
|
).allMatch(Files::exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConvertedIndexMissing() {
|
||||||
|
return !Stream.of(
|
||||||
|
revIndexWords.get(LIVE_PART).toPath(),
|
||||||
|
revIndexDoc.get(LIVE_PART).toPath(),
|
||||||
|
revPrioIndexWords.get(LIVE_PART).toPath(),
|
||||||
|
revPrioIndexDoc.get(LIVE_PART).toPath(),
|
||||||
|
fwdIndexDocData.get(LIVE_PART).toPath(),
|
||||||
|
fwdIndexDocId.get(LIVE_PART).toPath()
|
||||||
|
).allMatch(Files::exists);
|
||||||
|
}
|
||||||
|
|
||||||
public void convertIndex(DomainRankings domainRankings) throws IOException {
|
public void convertIndex(DomainRankings domainRankings) throws IOException {
|
||||||
convertForwardIndex(domainRankings);
|
convertForwardIndex(domainRankings);
|
||||||
convertFullReverseIndex(domainRankings);
|
convertFullReverseIndex(domainRankings);
|
||||||
|
@ -31,7 +31,7 @@ public class SearchIndex {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final IndexServicesFactory servicesFactory;
|
private final IndexServicesFactory servicesFactory;
|
||||||
private IndexSearchSetsService searchSetsService;
|
private final IndexSearchSetsService searchSetsService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SearchIndex(@NotNull IndexServicesFactory servicesFactory, IndexSearchSetsService searchSetsService) {
|
public SearchIndex(@NotNull IndexServicesFactory servicesFactory, IndexSearchSetsService searchSetsService) {
|
||||||
|
@ -48,7 +48,7 @@ public class IndexOpsService {
|
|||||||
|
|
||||||
|
|
||||||
@CheckReturnValue
|
@CheckReturnValue
|
||||||
private <T> Optional<T> run(Callable<T> c) throws Exception {
|
public <T> Optional<T> run(Callable<T> c) throws Exception {
|
||||||
if (!opsLock.tryLock())
|
if (!opsLock.tryLock())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
try {
|
try {
|
||||||
@ -61,7 +61,7 @@ public class IndexOpsService {
|
|||||||
|
|
||||||
|
|
||||||
@CheckReturnValue
|
@CheckReturnValue
|
||||||
private boolean run(Runnable r) {
|
public boolean run(Runnable r) {
|
||||||
if (!opsLock.tryLock())
|
if (!opsLock.tryLock())
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user