Merge "AbstractLuceneIndex: Pass in index name"

This commit is contained in:
Edwin Kempin
2016-04-27 07:37:00 +00:00
committed by Gerrit Code Review
3 changed files with 14 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.lucene;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ListenableFuture;
@@ -94,12 +95,14 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
Schema<V> schema,
SitePaths sitePaths,
Directory dir,
final String name,
String name,
String subIndex,
GerritIndexWriterConfig writerConfig,
SearcherFactory searcherFactory) throws IOException {
this.schema = schema;
this.sitePaths = sitePaths;
this.dir = dir;
final String index = Joiner.on('_').skipNulls().join(name, subIndex);
IndexWriter delegateWriter;
long commitPeriod = writerConfig.getCommitWithinMs();
@@ -114,7 +117,7 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
delegateWriter = autoCommitWriter;
new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder()
.setNameFormat("Commit-%d " + name)
.setNameFormat("Commit-%d " + index)
.setDaemon(true)
.build())
.scheduleAtFixedRate(new Runnable() {
@@ -126,13 +129,13 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
autoCommitWriter.commit();
}
} catch (IOException e) {
log.error("Error committing " + name + " Lucene index", e);
log.error("Error committing " + index + " Lucene index", e);
} catch (OutOfMemoryError e) {
log.error("Error committing " + name + " Lucene index", e);
log.error("Error committing " + index + " Lucene index", e);
try {
autoCommitWriter.close();
} catch (IOException e2) {
log.error("SEVERE: Error closing " + name
log.error("SEVERE: Error closing " + index
+ " Lucene index after OOM; index may be corrupted.", e);
}
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.lucene;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.gerrit.lucene.LuceneChangeIndex.ID_SORT_FIELD;
import static com.google.gerrit.lucene.LuceneChangeIndex.UPDATED_SORT_FIELD;
import static com.google.gerrit.server.index.change.ChangeSchemaDefinitions.NAME;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.config.SitePaths;
@@ -57,10 +58,11 @@ public class ChangeSubIndex extends AbstractLuceneIndex<Change.Id, ChangeData>
Schema<ChangeData> schema,
SitePaths sitePaths,
Directory dir,
String name,
String subIndex,
GerritIndexWriterConfig writerConfig,
SearcherFactory searcherFactory) throws IOException {
super(schema, sitePaths, dir, name, writerConfig, searcherFactory);
super(schema, sitePaths, dir, NAME, subIndex, writerConfig,
searcherFactory);
}
@Override

View File

@@ -70,10 +70,11 @@ public class ChangeSchemaDefinitions extends SchemaDefinitions<ChangeData> {
static final Schema<ChangeData> V29 =
schema(V28, ChangeField.HASHTAG_CASE_AWARE);
public static final String NAME = "changes";
public static final ChangeSchemaDefinitions INSTANCE =
new ChangeSchemaDefinitions();
private ChangeSchemaDefinitions() {
super("changes", ChangeData.class);
super(NAME, ChangeData.class);
}
}