Create change-indexed extension point
Add a new extension point so that plugins can be notified when a change has been indexed or removed from the secondary index. This allows the new Sync-index plugin to keep the secondary index of two Gerrit instances in sync. Listening to existing change/patch events cause the plugin to miss other cases where index updating is done, e.g., deleted drafts or changes reindexed to update their mergeability status. Change-Id: I87de17de26e907d77b2fb5175b5c90c5dd0381e9
This commit is contained in:
committed by
Hugo Arès
parent
0cae3ee337
commit
5fbbdadd65
@@ -415,6 +415,10 @@ Publication of usage data
|
|||||||
+
|
+
|
||||||
Garbage collection ran on a project
|
Garbage collection ran on a project
|
||||||
|
|
||||||
|
* `com.google.gerrit.server.extensions.events.ChangeIndexedListener`:
|
||||||
|
+
|
||||||
|
Update of the secondary index
|
||||||
|
|
||||||
[[stream-events]]
|
[[stream-events]]
|
||||||
== Sending Events to the Events Stream
|
== Sending Events to the Events Stream
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ import com.google.gerrit.server.change.ChangeKindCacheImpl;
|
|||||||
import com.google.gerrit.server.change.MergeabilityCacheImpl;
|
import com.google.gerrit.server.change.MergeabilityCacheImpl;
|
||||||
import com.google.gerrit.server.events.EventFactory;
|
import com.google.gerrit.server.events.EventFactory;
|
||||||
import com.google.gerrit.server.events.EventsMetrics;
|
import com.google.gerrit.server.events.EventsMetrics;
|
||||||
|
import com.google.gerrit.server.extensions.events.ChangeIndexedListener;
|
||||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||||
import com.google.gerrit.server.git.BatchUpdate;
|
import com.google.gerrit.server.git.BatchUpdate;
|
||||||
import com.google.gerrit.server.git.EmailMerge;
|
import com.google.gerrit.server.git.EmailMerge;
|
||||||
@@ -272,6 +273,7 @@ public class GerritGlobalModule extends FactoryModule {
|
|||||||
DynamicSet.setOf(binder(), ReceivePackInitializer.class);
|
DynamicSet.setOf(binder(), ReceivePackInitializer.class);
|
||||||
DynamicSet.setOf(binder(), PostReceiveHook.class);
|
DynamicSet.setOf(binder(), PostReceiveHook.class);
|
||||||
DynamicSet.setOf(binder(), PreUploadHook.class);
|
DynamicSet.setOf(binder(), PreUploadHook.class);
|
||||||
|
DynamicSet.setOf(binder(), ChangeIndexedListener.class);
|
||||||
DynamicSet.setOf(binder(), NewProjectCreatedListener.class);
|
DynamicSet.setOf(binder(), NewProjectCreatedListener.class);
|
||||||
DynamicSet.setOf(binder(), ProjectDeletedListener.class);
|
DynamicSet.setOf(binder(), ProjectDeletedListener.class);
|
||||||
DynamicSet.setOf(binder(), GarbageCollectorListener.class);
|
DynamicSet.setOf(binder(), GarbageCollectorListener.class);
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// 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.server.extensions.events;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
||||||
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
|
|
||||||
|
/** Notified whenever a change is indexed or deleted from the index. */
|
||||||
|
@ExtensionPoint
|
||||||
|
public interface ChangeIndexedListener {
|
||||||
|
/** Invoked when a change is indexed. */
|
||||||
|
void onChangeIndexed(ChangeData change);
|
||||||
|
|
||||||
|
/** Invoked when a change is deleted from the index. */
|
||||||
|
void onChangeDeleted(Change.Id id);
|
||||||
|
}
|
||||||
@@ -20,10 +20,12 @@ import com.google.common.util.concurrent.CheckedFuture;
|
|||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
|
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.extensions.events.ChangeIndexedListener;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.util.RequestContext;
|
import com.google.gerrit.server.util.RequestContext;
|
||||||
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
import com.google.gerrit.server.util.ThreadLocalRequestContext;
|
||||||
@@ -94,11 +96,13 @@ public class ChangeIndexer {
|
|||||||
private final ChangeData.Factory changeDataFactory;
|
private final ChangeData.Factory changeDataFactory;
|
||||||
private final ThreadLocalRequestContext context;
|
private final ThreadLocalRequestContext context;
|
||||||
private final ListeningExecutorService executor;
|
private final ListeningExecutorService executor;
|
||||||
|
private final DynamicSet<ChangeIndexedListener> indexedListener;
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
ChangeIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
ChangeIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
||||||
ChangeData.Factory changeDataFactory,
|
ChangeData.Factory changeDataFactory,
|
||||||
ThreadLocalRequestContext context,
|
ThreadLocalRequestContext context,
|
||||||
|
DynamicSet<ChangeIndexedListener> indexedListener,
|
||||||
@Assisted ListeningExecutorService executor,
|
@Assisted ListeningExecutorService executor,
|
||||||
@Assisted ChangeIndex index) {
|
@Assisted ChangeIndex index) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
@@ -107,12 +111,14 @@ public class ChangeIndexer {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.indexes = null;
|
this.indexes = null;
|
||||||
|
this.indexedListener = indexedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
ChangeIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
ChangeIndexer(SchemaFactory<ReviewDb> schemaFactory,
|
||||||
ChangeData.Factory changeDataFactory,
|
ChangeData.Factory changeDataFactory,
|
||||||
ThreadLocalRequestContext context,
|
ThreadLocalRequestContext context,
|
||||||
|
DynamicSet<ChangeIndexedListener> indexedListener,
|
||||||
@Assisted ListeningExecutorService executor,
|
@Assisted ListeningExecutorService executor,
|
||||||
@Assisted IndexCollection indexes) {
|
@Assisted IndexCollection indexes) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
@@ -121,6 +127,7 @@ public class ChangeIndexer {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.index = null;
|
this.index = null;
|
||||||
this.indexes = indexes;
|
this.indexes = indexes;
|
||||||
|
this.indexedListener = indexedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,6 +167,19 @@ public class ChangeIndexer {
|
|||||||
for (ChangeIndex i : getWriteIndexes()) {
|
for (ChangeIndex i : getWriteIndexes()) {
|
||||||
i.replace(cd);
|
i.replace(cd);
|
||||||
}
|
}
|
||||||
|
fireChangeIndexedEvent(cd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireChangeIndexedEvent(ChangeData change) {
|
||||||
|
for (ChangeIndexedListener listener : indexedListener) {
|
||||||
|
listener.onChangeIndexed(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireChangeDeletedFromIndexEvent(Change.Id id) {
|
||||||
|
for (ChangeIndexedListener listener : indexedListener) {
|
||||||
|
listener.onChangeDeleted(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -280,6 +300,7 @@ public class ChangeIndexer {
|
|||||||
for (ChangeIndex i : getWriteIndexes()) {
|
for (ChangeIndex i : getWriteIndexes()) {
|
||||||
i.delete(id);
|
i.delete(id);
|
||||||
}
|
}
|
||||||
|
fireChangeDeletedFromIndexEvent(id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user