Merge branch 'stable-2.11'

* stable-2.11:
  Set version to 2.11.2 in dev-plugins.txt
  Release notes for Gerrit 2.11.2
  Bind OnlineReindexer.Factory in LuceneIndexModule
  Add ssh command to activate the latest index
  Add ssh command to restart online indexer
  PluginAPI: Don't convert to String in RestApi.get() method

Change-Id: I907e665b20568fce8563bf9e22a7a0ffc96fc847
This commit is contained in:
David Pursehouse
2015-07-14 11:33:11 +09:00
16 changed files with 507 additions and 22 deletions

View File

@@ -48,6 +48,7 @@ public class LuceneIndexModule extends LifecycleModule {
@Override
protected void configure() {
factory(LuceneChangeIndex.Factory.class);
factory(OnlineReindexer.Factory.class);
install(new IndexModule(threads));
if (singleVersion == null && base == null) {
install(new MultiVersionModule());
@@ -65,7 +66,6 @@ public class LuceneIndexModule extends LifecycleModule {
private static class MultiVersionModule extends LifecycleModule {
@Override
public void configure() {
factory(OnlineReindexer.Factory.class);
listener().to(LuceneVersionManager.class);
}
}

View File

@@ -46,7 +46,7 @@ import java.util.List;
import java.util.TreeMap;
@Singleton
class LuceneVersionManager implements LifecycleListener {
public class LuceneVersionManager implements LifecycleListener {
private static final Logger log = LoggerFactory
.getLogger(LuceneVersionManager.class);
@@ -95,6 +95,7 @@ class LuceneVersionManager implements LifecycleListener {
private final IndexCollection indexes;
private final OnlineReindexer.Factory reindexerFactory;
private final boolean onlineUpgrade;
private OnlineReindexer reindexer;
@Inject
LuceneVersionManager(
@@ -165,7 +166,53 @@ class LuceneVersionManager implements LifecycleListener {
int latest = write.get(0).version;
if (onlineUpgrade && latest != search.version) {
reindexerFactory.create(latest).start();
reindexer = reindexerFactory.create(latest);
reindexer.start();
}
}
/**
* Start the online reindexer if the current index is not already the latest.
*
* @return true if started, otherwise false.
* @throws ReindexerAlreadyRunningException
*/
public synchronized boolean startReindexer()
throws ReindexerAlreadyRunningException {
validateReindexerNotRunning();
if (!isCurrentIndexVersionLatest()) {
reindexer.start();
return true;
}
return false;
}
/**
* Activate the latest index if the current index is not already the latest.
*
* @return true if index was activate, otherwise false.
* @throws ReindexerAlreadyRunningException
*/
public synchronized boolean activateLatestIndex()
throws ReindexerAlreadyRunningException {
validateReindexerNotRunning();
if (!isCurrentIndexVersionLatest()) {
reindexer.activateIndex();
return true;
}
return false;
}
private boolean isCurrentIndexVersionLatest() {
return reindexer == null
|| reindexer.getVersion() == indexes.getSearchIndex().getSchema()
.getVersion();
}
private void validateReindexerNotRunning()
throws ReindexerAlreadyRunningException {
if (reindexer != null && reindexer.isRunning()) {
throw new ReindexerAlreadyRunningException();
}
}

View File

@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class OnlineReindexer {
private static final Logger log = LoggerFactory
@@ -42,6 +43,8 @@ public class OnlineReindexer {
private final SiteIndexer batchIndexer;
private final ProjectCache projectCache;
private final int version;
private ChangeIndex index;
private final AtomicBoolean running = new AtomicBoolean();
@Inject
OnlineReindexer(
@@ -56,15 +59,29 @@ public class OnlineReindexer {
}
public void start() {
Thread t = new Thread() {
@Override
public void run() {
reindex();
}
};
t.setName(String.format("Reindex v%d-v%d",
version(indexes.getSearchIndex()), version));
t.start();
if (running.compareAndSet(false, true)) {
Thread t = new Thread() {
@Override
public void run() {
try {
reindex();
} finally {
running.set(false);
}
}
};
t.setName(String.format("Reindex v%d-v%d",
version(indexes.getSearchIndex()), version));
t.start();
}
}
public boolean isRunning() {
return running.get();
}
public int getVersion() {
return version;
}
private static int version(ChangeIndex i) {
@@ -72,7 +89,7 @@ public class OnlineReindexer {
}
private void reindex() {
ChangeIndex index = checkNotNull(indexes.getWriteIndex(version),
index = checkNotNull(indexes.getWriteIndex(version),
"not an active write schema version: %s", version);
log.info("Starting online reindex from schema version {} to {}",
version(indexes.getSearchIndex()), version(index));
@@ -84,9 +101,13 @@ public class OnlineReindexer {
version(index), result.doneCount(), result.failedCount());
return;
}
log.info("Reindex to version {} complete", version(index));
activateIndex();
}
void activateIndex() {
indexes.setSearchIndex(index);
log.info("Reindex complete, using schema version {}", version(index));
log.info("Using schema version {}", version(index));
try {
index.markReady(true);
} catch (IOException e) {

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.lucene;
public class ReindexerAlreadyRunningException extends Exception {
private static final long serialVersionUID = 1L;
public ReindexerAlreadyRunningException() {
super("Reindexer is already running.");
}
}