Skip to content
Permalink
Browse files

Reindex tickets on server start if no index exists

Check if tickets need to be reindexed when the server starts. This is the
case if no ticket index exists. In that case the ticket index is built.

This is done during the start of the `ITicketService`.

For this the interface of `ITicketService` needed to change. The `start`
method was defined abstract and the specific ticket services had to
implement it. None does any real starting stuff in it.
The `start` method is now final. It calls a new abstract method `onStart`
which the specific ticket services need to implement. In the existing
implementations I just changed `start` to `onStart`.
  • Loading branch information
fzs committed Mar 5, 2017
1 parent 197ddd2 commit 63dbdfda13daa78a26f1c2e77b0a4bfd5a35df8d
@@ -110,9 +110,8 @@ public BranchTicketService(
}

@Override
public BranchTicketService start() {
public void onStart() {
log.info("{} started", getClass().getSimpleName());
return this;
}

@Override
@@ -80,9 +80,8 @@ public FileTicketService(
}

@Override
public FileTicketService start() {
public void onStart() {
log.info("{} started", getClass().getSimpleName());
return this;
}

@Override
@@ -181,7 +181,24 @@ public ITicketService(
* @since 1.4.0
*/
@Override
public abstract ITicketService start();
public final ITicketService start() {
onStart();
if (shouldReindex()) {
log.info("Re-indexing all tickets...");
// long startTime = System.currentTimeMillis();
reindex();
// float duration = (System.currentTimeMillis() - startTime) / 1000f;
// log.info("Built Lucene index over all tickets in {} secs", duration);
}
return this;
}

/**
* Start the specific ticket service implementation.
*
* @since 1.9.0
*/
public abstract void onStart();

/**
* Stop the service.
@@ -196,6 +213,12 @@ public final ITicketService stop() {
return this;
}

/**
* Closes any open resources used by this service.
* @since 1.4.0
*/
protected abstract void close();

/**
* Creates a ticket notifier. The ticket notifier is not thread-safe!
* @since 1.4.0
@@ -273,12 +296,6 @@ public boolean hasTickets(RepositoryModel repository) {
return indexer.hasTickets(repository);
}

/**
* Closes any open resources used by this service.
* @since 1.4.0
*/
protected abstract void close();

/**
* Reset all caches in the service.
* @since 1.4.0
@@ -1343,6 +1360,18 @@ public final TicketModel deletePatchset(TicketModel ticket, Patchset patchset, S
return indexer.queryFor(query, page, pageSize, sortBy, descending);
}


/**
* Checks tickets should get re-indexed.
*
* @return true if tickets should get re-indexed, false otherwise.
*/
private boolean shouldReindex()
{
return indexer.shouldReindex();
}


/**
* Destroys an existing index and reindexes all tickets.
* This operation may be expensive and time-consuming.
@@ -61,9 +61,8 @@ public boolean isReady() {
}

@Override
public NullTicketService start() {
public void onStart() {
log.info("{} started", getClass().getSimpleName());
return this;
}

@Override
@@ -83,12 +83,11 @@ public RedisTicketService(
}

@Override
public RedisTicketService start() {
public void onStart() {
log.info("{} started", getClass().getSimpleName());
if (!isReady()) {
log.warn("{} is not ready!", getClass().getSimpleName());
}
return this;
}

@Override
@@ -226,6 +226,18 @@ public boolean deleteAll(RepositoryModel repository) {
return false;
}

/**
* Checks if a tickets index exists, that is compatible with Lucene.INDEX_VERSION
* and the Lucene codec version.
*
* @return true if no tickets index is found, false otherwise.
*
* @since 1.9.0
*/
boolean shouldReindex() {
return ! this.indexStore.hasIndex();
}

/**
* Bulk Add/Update tickets in the Lucene index
*
@@ -665,4 +677,4 @@ private int unpackInt(Document doc, Lucene lucene) {
int i = Integer.parseInt(val);
return i;
}
}
}
@@ -92,7 +92,7 @@ public boolean hasIndex()
{
return indexFolder.exists() &&
indexFolder.isDirectory() &&
(indexFolder.list().length > 1);
(indexFolder.list().length > 1); // Must have more than 'write.lock'
}

}
@@ -59,7 +59,7 @@ protected ITicketService getService(boolean deleteAll) throws Exception {
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();

BranchTicketService service = new BranchTicketService(
BranchTicketService service = (BranchTicketService) new BranchTicketService(
runtimeManager,
pluginManager,
notificationManager,
@@ -58,7 +58,7 @@ protected ITicketService getService(boolean deleteAll) throws Exception {
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();

FileTicketService service = new FileTicketService(
FileTicketService service = (FileTicketService) new FileTicketService(
runtimeManager,
pluginManager,
notificationManager,
@@ -66,7 +66,7 @@ protected ITicketService getService(boolean deleteAll) throws Exception {
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();

RedisTicketService service = new RedisTicketService(
RedisTicketService service = (RedisTicketService) new RedisTicketService(
runtimeManager,
pluginManager,
notificationManager,
@@ -83,7 +83,7 @@ protected ITicketService getService(boolean deleteAll) throws Exception {
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();

BranchTicketService service = new BranchTicketService(
BranchTicketService service = (BranchTicketService) new BranchTicketService(
runtimeManager,
pluginManager,
notificationManager,

0 comments on commit 63dbdfd

Please sign in to comment.
You can’t perform that action at this time.