You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/09/04 09:08:28 UTC
[lucene-solr] 02/02: SOLR-14749: Keep only scheduler-related bits
here.
This is an automated email from the ASF dual-hosted git repository.
ab pushed a commit to branch jira/solr-14749-scheduler
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 8c4b460cda3df1d39366cacb8c838272ee4a1c56
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Fri Sep 4 11:07:47 2020 +0200
SOLR-14749: Keep only scheduler-related bits here.
---
.../apache/solr/cluster/events/ClusterEvent.java | 39 -----
.../solr/cluster/events/ClusterEventListener.java | 41 -----
.../solr/cluster/events/ClusterEventProducer.java | 67 --------
.../apache/solr/cluster/events/NodeDownEvent.java | 30 ----
.../apache/solr/cluster/events/NodeUpEvent.java | 30 ----
.../solr/cluster/events/ReplicaDownEvent.java | 37 -----
.../events/impl/AutoAddReplicasEventListener.java | 102 ------------
.../events/impl/ClusterEventProducerImpl.java | 180 ---------------------
.../apache/solr/cluster/scheduler/Schedulable.java | 7 +-
9 files changed, 6 insertions(+), 527 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEvent.java b/solr/core/src/java/org/apache/solr/cluster/events/ClusterEvent.java
deleted file mode 100644
index ee8d955..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEvent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-import java.time.Instant;
-
-/**
- *
- */
-public interface ClusterEvent {
-
- enum EventType {
- NODE_DOWN,
- NODE_UP,
- REPLICA_DOWN,
- // other types? eg. Overseer leader change, shard leader change,
- // node overload (eg. CPU / MEM circuit breakers tripped)?
- }
-
- /** Get event type. */
- EventType getType();
-
- /** Get event timestamp. */
- Instant getTimestamp();
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventListener.java b/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventListener.java
deleted file mode 100644
index adf2e2b..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-import java.util.Set;
-
-/**
- * Components that want to be notified of cluster-wide events should use this.
- *
- * XXX should this work only for ClusterSingleton-s? some types of events may be
- * XXX difficult (or pointless) to propagate to every node.
- */
-public interface ClusterEventListener {
-
- /**
- * The types of events that this listener can process.
- */
- Set<ClusterEvent.EventType> getEventTypes();
-
- /**
- * Handle the event. Implementations should be non-blocking - if any long
- * processing is needed it should be performed asynchronously.
- * @param event cluster event
- */
- void onEvent(ClusterEvent event);
-
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventProducer.java b/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventProducer.java
deleted file mode 100644
index a46703d..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/ClusterEventProducer.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Component that produces {@link ClusterEvent} instances.
- */
-public interface ClusterEventProducer {
-
- /**
- * Returns a modifiable map of event types and listeners to process events
- * of a given type.
- */
- Map<ClusterEvent.EventType, Set<ClusterEventListener>> getEventListeners();
-
- /**
- * Register an event listener. This listener will be notified about event
- * of the types that it declares in {@link ClusterEventListener#getEventTypes()}
- * @param listener non-null listener. If the same instance of the listener is
- * already registered it will be ignored.
- */
- default void registerListener(ClusterEventListener listener) throws Exception {
- listener.getEventTypes().forEach(type -> {
- Set<ClusterEventListener> perType = getEventListeners().computeIfAbsent(type, t -> ConcurrentHashMap.newKeySet());
- perType.add(listener);
- });
- }
-
- /**
- * Unregister an event listener.
- * @param listener non-null listener.
- */
- default void unregisterListener(ClusterEventListener listener) {
- listener.getEventTypes().forEach(type ->
- getEventListeners().getOrDefault(type, Collections.emptySet()).remove(listener)
- );
- }
-
- /**
- * Fire an event. This method will call registered listeners that subscribed to the
- * type of event being passed.
- * @param event cluster event
- */
- default void fireEvent(ClusterEvent event) {
- getEventListeners().getOrDefault(event.getType(), Collections.emptySet())
- .forEach(listener -> listener.onEvent(event));
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/NodeDownEvent.java b/solr/core/src/java/org/apache/solr/cluster/events/NodeDownEvent.java
deleted file mode 100644
index 47e6d84..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/NodeDownEvent.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-/**
- *
- */
-public interface NodeDownEvent extends ClusterEvent {
-
- @Override
- default EventType getType() {
- return EventType.NODE_DOWN;
- }
-
- String getNodeName();
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/NodeUpEvent.java b/solr/core/src/java/org/apache/solr/cluster/events/NodeUpEvent.java
deleted file mode 100644
index 594473d..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/NodeUpEvent.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-/**
- *
- */
-public interface NodeUpEvent extends ClusterEvent {
-
- @Override
- default EventType getType() {
- return EventType.NODE_UP;
- }
-
- String getNodeName();
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/ReplicaDownEvent.java b/solr/core/src/java/org/apache/solr/cluster/events/ReplicaDownEvent.java
deleted file mode 100644
index bce20b4..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/ReplicaDownEvent.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events;
-
-/**
- *
- */
-public interface ReplicaDownEvent extends ClusterEvent {
-
- @Override
- default EventType getType() {
- return EventType.REPLICA_DOWN;
- }
-
- String getNodeName();
-
- String getCollectionName();
-
- String getShardName();
-
- // so called coreNodeName
- String getReplicaName();
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/impl/AutoAddReplicasEventListener.java b/solr/core/src/java/org/apache/solr/cluster/events/impl/AutoAddReplicasEventListener.java
deleted file mode 100644
index a10b846..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/impl/AutoAddReplicasEventListener.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events.impl;
-
-import java.lang.invoke.MethodHandles;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.solr.client.solrj.io.SolrClientCache;
-import org.apache.solr.cluster.events.ClusterEvent;
-import org.apache.solr.cluster.events.ClusterEventListener;
-import org.apache.solr.cloud.ClusterSingleton;
-import org.apache.solr.core.CoreContainer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-public class AutoAddReplicasEventListener implements ClusterSingleton, ClusterEventListener {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private static final Set<ClusterEvent.EventType> EVENT_TYPES = new HashSet<>(
- Arrays.asList(
- ClusterEvent.EventType.NODE_DOWN,
- ClusterEvent.EventType.REPLICA_DOWN
- ));
-
- private final CoreContainer cc;
- private final SolrClientCache solrClientCache;
-
- private boolean running = false;
-
- public AutoAddReplicasEventListener(CoreContainer cc) {
- this.cc = cc;
- this.solrClientCache = cc.getSolrClientCache();
- }
-
- @Override
- public Set<ClusterEvent.EventType> getEventTypes() {
- return EVENT_TYPES;
- }
-
- @Override
- public void onEvent(ClusterEvent event) {
- if (!isRunning()) {
- // ignore the event
- return;
- }
- switch (event.getType()) {
- case NODE_DOWN:
- handleNodeDown(event);
- break;
- case NODE_UP:
- // ignore?
- break;
- case REPLICA_DOWN:
- handleReplicaDown(event);
- break;
- default:
- log.warn("Unsupported event {}, ignoring...", event);
- }
- }
-
- private void handleNodeDown(ClusterEvent event) {
- // send MOVEREPLICA admin requests for all replicas from that node
- }
-
- private void handleReplicaDown(ClusterEvent event) {
- // send ADDREPLICA admin request
- }
-
- @Override
- public void start() throws Exception {
- running = true;
- }
-
- @Override
- public boolean isRunning() {
- return running;
- }
-
- @Override
- public void stop() {
- running = false;
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/impl/ClusterEventProducerImpl.java b/solr/core/src/java/org/apache/solr/cluster/events/impl/ClusterEventProducerImpl.java
deleted file mode 100644
index 9fc218c..0000000
--- a/solr/core/src/java/org/apache/solr/cluster/events/impl/ClusterEventProducerImpl.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.solr.cluster.events.impl;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.cluster.events.ClusterEvent;
-import org.apache.solr.cluster.events.ClusterEventListener;
-import org.apache.solr.cluster.events.ClusterEventProducer;
-import org.apache.solr.cloud.ClusterSingleton;
-import org.apache.solr.cluster.events.NodeDownEvent;
-import org.apache.solr.cluster.events.NodeUpEvent;
-import org.apache.solr.common.cloud.LiveNodesListener;
-import org.apache.solr.core.CoreContainer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of {@link ClusterEventProducer}.
- * <h3>Implementation notes</h3>
- * <p>For each cluster event relevant listeners are always invoked sequentially
- * (not in parallel) and in arbitrary order. This means that if any listener blocks the
- * processing other listeners may be invoked much later or not at all.</p>
- */
-public class ClusterEventProducerImpl implements ClusterEventProducer, ClusterSingleton, Closeable {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private final Map<ClusterEvent.EventType, Set<ClusterEventListener>> listeners = new HashMap<>();
- private final CoreContainer cc;
- private LiveNodesListener liveNodesListener;
- private ZkController zkController;
- private boolean running;
-
- private final Set<ClusterEvent.EventType> supportedEvents =
- new HashSet<>() {{
- add(ClusterEvent.EventType.NODE_DOWN);
- add(ClusterEvent.EventType.NODE_UP);
- }};
-
- private volatile boolean isClosed = false;
-
- public ClusterEventProducerImpl(CoreContainer coreContainer) {
- this.cc = coreContainer;
- this.zkController = this.cc.getZkController();
- }
-
- // ClusterSingleton lifecycle methods
- @Override
- public void start() {
- if (zkController == null) {
- liveNodesListener = null;
- return;
- }
-
- // clean up any previous instances
- doStop();
-
- // register liveNodesListener
- liveNodesListener = (oldNodes, newNodes) -> {
- // already closed but still registered
- if (isClosed) {
- // remove the listener
- return true;
- }
- // spurious event, ignore but keep listening
- if (oldNodes.equals(newNodes)) {
- return false;
- }
- oldNodes.forEach(oldNode -> {
- if (!newNodes.contains(oldNode)) {
- fireEvent(new NodeDownEvent() {
- final Instant timestamp = Instant.now();
- @Override
- public Instant getTimestamp() {
- return timestamp;
- }
-
- @Override
- public String getNodeName() {
- return oldNode;
- }
- });
- }
- });
- newNodes.forEach(newNode -> {
- if (!oldNodes.contains(newNode)) {
- fireEvent(new NodeUpEvent() {
- final Instant timestamp = Instant.now();
- @Override
- public Instant getTimestamp() {
- return timestamp;
- }
- @Override
- public String getNodeName() {
- return newNode;
- }
- });
- }
- });
- return false;
- };
-
- // XXX register collection state listener?
- // XXX not sure how to efficiently monitor for REPLICA_DOWN events
- }
-
- @Override
- public boolean isRunning() {
- return running;
- }
-
- @Override
- public void stop() {
- doStop();
- running = false;
- }
-
- private void doStop() {
- if (liveNodesListener != null) {
- zkController.zkStateReader.removeLiveNodesListener(liveNodesListener);
- }
- liveNodesListener = null;
- }
-
- private void ensureRunning() {
- if (isClosed || !running) {
- throw new RuntimeException("ClusterEventProducerImpl is not running.");
- }
- }
-
- @Override
- public void registerListener(ClusterEventListener listener) throws Exception {
- ensureRunning();
- try {
- listener.getEventTypes().forEach(type -> {
- if (!supportedEvents.contains(type)) {
- throw new RuntimeException("event type " + type + " not supported yet");
- }
- });
- } catch (Throwable e) {
- throw new Exception(e);
- }
- ClusterEventProducer.super.registerListener(listener);
- }
-
- @Override
- public void close() throws IOException {
- stop();
- isClosed = true;
- listeners.clear();
- }
-
- @Override
- public Map<ClusterEvent.EventType, Set<ClusterEventListener>> getEventListeners() {
- ensureRunning();
- return listeners;
- }
-}
diff --git a/solr/core/src/java/org/apache/solr/cluster/scheduler/Schedulable.java b/solr/core/src/java/org/apache/solr/cluster/scheduler/Schedulable.java
index f907245..2f47fa4 100644
--- a/solr/core/src/java/org/apache/solr/cluster/scheduler/Schedulable.java
+++ b/solr/core/src/java/org/apache/solr/cluster/scheduler/Schedulable.java
@@ -17,11 +17,16 @@
package org.apache.solr.cluster.scheduler;
/**
- *
+ * Component to be scheduled and executed according to the schedule.
*/
public interface Schedulable {
Schedule getSchedule();
+ /**
+ * Execute the component.
+ * <p>NOTE: this should be a lightweight method that executes quickly, to avoid blocking the
+ * execution of other schedules. If it requires more work it should do this in a separate thread.</p>
+ */
void run();
}