Skip to content
Snippets Groups Projects
Commit c8ecb6cf authored by srosse's avatar srosse
Browse files

no-jira: calculate last full index time from file at start of the instance

parent f6b1d011
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@
$r.translate("fullindexer.label.running.indexer") : $searchstatus.fullIndexerStatus.NumberRunningFolderIndexer<br />
$r.translate("fullindexer.label.available.indexer") : $searchstatus.fullIndexerStatus.NumberAvailableFolderIndexer<br />
<br />
$r.translate("fullindexer.label.finished") : $searchstatus.fullIndexerStatus.lastFullIndexTime<br />
$r.translate("fullindexer.label.finished") : #if($searchstatus.fullIndexerStatus.lastFullIndexTime > 1) $searchstatus.fullIndexerStatus.lastFullIndexDateString #else - #end<br />
$r.translate("fullindexer.label.time") : $searchstatus.fullIndexerStatus.indexingTime ms<br />
$r.translate("fullindexer.label.size") : $searchstatus.fullIndexerStatus.IndexSize
</fieldset>
......
......@@ -131,7 +131,7 @@ public class IndexerWebService {
stats.setDocumentQueueSize(fStatus.getDocumentQueueSize());
stats.setRunningFolderIndexerCount(fStatus.getNumberRunningFolderIndexer());
stats.setAvailableFolderIndexerCount(fStatus.getNumberAvailableFolderIndexer());
stats.setLastFullIndexTime(fStatus.getLastFullIndexTime());
stats.setLastFullIndexTime(fStatus.getLastFullIndexDateString());
stats.setStatus(status.getStatus());
} else {
stats.setStatus("disabled");
......
......@@ -75,14 +75,22 @@ public class FullIndexerStatus {
/**
* @return Returns the lastFullIndexTime.
*/
public String getLastFullIndexTime() {
if (lastFullIndexTime != 0) {
public String getLastFullIndexDateString() {
if (lastFullIndexTime > 0) {
return new Date(lastFullIndexTime).toString();
} else {
// not finished yet
return "-";
}
}
public long getLastFullIndexTime() {
return lastFullIndexTime;
}
public void setLastFullIndexTime(long time) {
lastFullIndexTime = time;
}
/**
* @return Returns the status.
......@@ -116,7 +124,7 @@ public class FullIndexerStatus {
* reset full-index document-counter and all document-counters.
*/
public void indexingStarted() {
this.fullIndexStartedAt = System.currentTimeMillis();
fullIndexStartedAt = System.currentTimeMillis();
setStatus(STATUS_RUNNING);
setDocumentCount(0);//Reset FullIndex-DocumentCounter
resetAllDocumentCounters();
......@@ -138,8 +146,8 @@ public class FullIndexerStatus {
* Indexing finished. Set end time, calculate duration and set status to 'finished'.
*/
public void indexingFinished() {
this.lastFullIndexTime = System.currentTimeMillis();
indexingTime = this.lastFullIndexTime - this.fullIndexStartedAt;
lastFullIndexTime = System.currentTimeMillis();
indexingTime = lastFullIndexTime - fullIndexStartedAt;
setStatus(STATUS_FINISHED);
}
......
......@@ -27,10 +27,17 @@ package org.olat.search.service.indexer;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.LucenePackage;
import org.apache.lucene.analysis.Analyzer;
......@@ -65,6 +72,7 @@ public class OlatFullIndexer {
private static final int MAX_SIZE_QUEUE = 500;
private int numberIndexWriter = 5;
private String indexPath;
private String tempIndexPath;
/**
......@@ -116,17 +124,45 @@ public class OlatFullIndexer {
this.index = index;
this.mainIndexer = mainIndexer;
this.coordinatorManager = coordinatorManager;
indexPath = searchModuleConfig.getFullIndexPath();
tempIndexPath = searchModuleConfig.getFullTempIndexPath();
indexInterval = searchModuleConfig.getIndexInterval();
numberIndexWriter = searchModuleConfig.getNumberIndexWriter();
documentsPerInterval = searchModuleConfig.getDocumentsPerInterval();
ramBufferSizeMB = searchModuleConfig.getRAMBufferSizeMB();
fullIndexerStatus = new FullIndexerStatus(numberIndexWriter);
fullIndexerStatus = new FullIndexerStatus(numberIndexWriter);
stopIndexing = true;
documentQueue = new Vector<Document>();
initStatus();
resetDocumentCounters();
}
private void initStatus() {
File indexDir = new File(indexPath);
if (indexDir.exists()) {
final AtomicLong last = new AtomicLong(1);
try {
Files.walkFileTree(indexDir.toPath(), new SimpleFileVisitor<Path>(){
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if(attrs.isRegularFile()) {
FileTime time = attrs.lastModifiedTime();
long timeInMillis = time.toMillis();
if(timeInMillis > 0 && last.longValue() < timeInMillis) {
last.set(timeInMillis);
}
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("", e);
}
fullIndexerStatus.setLastFullIndexTime(last.get());
} else {
fullIndexerStatus.setLastFullIndexTime(1);
}
}
/**
* Start full indexer thread.
*/
......@@ -267,7 +303,7 @@ public class OlatFullIndexer {
*/
public void run() {
try {
//TODO: Workround : does not start immediately
//TODO: Workround : does not start immediately
Thread.sleep(10000);
log.info("full indexing starts... Lucene-version:" + LucenePackage.get().getImplementationVersion());
......@@ -286,7 +322,7 @@ public class OlatFullIndexer {
log.info("full indexing summary: started: "+status.getFullIndexStartedAt());
log.info("full indexing summary: counter: "+status.getDocumentCount());
log.info("full indexing summary: index.per.minute: "+status.getIndexPerMinute());
log.info("full indexing summary: finished: "+status.getLastFullIndexTime());
log.info("full indexing summary: finished: "+status.getLastFullIndexDateString());
log.info("full indexing summary: time: "+status.getIndexingTime()+" ms");
log.info("full indexing summary: size: "+status.getIndexSize());
......@@ -446,7 +482,7 @@ public class OlatFullIndexer {
}
private void resetDocumentCounters() {
documentCounters = new Hashtable<String,Integer>();
fileTypeCounters = new Hashtable<String,Integer>();
documentCounters = new Hashtable<String,Integer>();
fileTypeCounters = new Hashtable<String,Integer>();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment