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/08/17 17:32:55 UTC

[lucene-solr] 01/01: SOLR-14749: Initial draft.

This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-14749
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 1bac7831bd9c8743216712126384d686c541718b
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Mon Aug 17 19:32:18 2020 +0200

    SOLR-14749: Initial draft.
---
 .../org/apache/solr/cloud/events/ClusterEvent.java | 40 ++++++++++++++++++++++
 .../solr/cloud/events/ClusterEventListener.java    | 29 ++++++++++++++++
 .../solr/cloud/events/ClusterEventProducer.java    | 35 +++++++++++++++++++
 .../apache/solr/cloud/events/ClusterSingleton.java | 14 ++++++++
 .../apache/solr/cloud/events/NodeDownEvent.java    | 24 +++++++++++++
 .../org/apache/solr/cloud/events/NodeUpEvent.java  | 24 +++++++++++++
 .../apache/solr/cloud/events/ScheduledEvent.java   | 25 ++++++++++++++
 7 files changed, 191 insertions(+)

diff --git a/solr/core/src/java/org/apache/solr/cloud/events/ClusterEvent.java b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEvent.java
new file mode 100644
index 0000000..a3b0eff
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEvent.java
@@ -0,0 +1,40 @@
+/*
+ * 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.cloud.events;
+
+import java.time.Instant;
+
+/**
+ *
+ */
+public interface ClusterEvent {
+
+  enum EventType {
+    NODE_DOWN,
+    NODE_UP,
+    REPLICA_DOWN,
+    SCHEDULED,
+    // 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/cloud/events/ClusterEventListener.java b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEventListener.java
new file mode 100644
index 0000000..5d5c6b2
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEventListener.java
@@ -0,0 +1,29 @@
+/*
+ * 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.cloud.events;
+
+/**
+ * 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 {
+
+  void onEvent(ClusterEvent event);
+
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/events/ClusterEventProducer.java b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEventProducer.java
new file mode 100644
index 0000000..e7fa633
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/ClusterEventProducer.java
@@ -0,0 +1,35 @@
+/*
+ * 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.cloud.events;
+
+import java.util.Collection;
+
+/**
+ * Component that produces {@link ClusterEvent} instances.
+ */
+public interface ClusterEventProducer {
+
+  void registerListener(ClusterEventListener listener);
+
+  void unregisterListener(ClusterEventListener listener);
+
+  Collection<ClusterEventListener> getEventListeners();
+
+  default void fireEvent(ClusterEvent event) {
+    getEventListeners().forEach(listener -> listener.onEvent(event));
+  }
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/events/ClusterSingleton.java b/solr/core/src/java/org/apache/solr/cloud/events/ClusterSingleton.java
new file mode 100644
index 0000000..f665143
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/ClusterSingleton.java
@@ -0,0 +1,14 @@
+package org.apache.solr.cloud.events;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Intended for {@link org.apache.solr.core.CoreContainer} plugins that should be
+ * enabled only one instance per cluster.
+ * <p>Implementation detail: currently these plugins are instantiated on the
+ * Overseer leader, and closed when the current node loses its leadership.</p>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ClusterSingleton {
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/events/NodeDownEvent.java b/solr/core/src/java/org/apache/solr/cloud/events/NodeDownEvent.java
new file mode 100644
index 0000000..ae545da
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/NodeDownEvent.java
@@ -0,0 +1,24 @@
+/*
+ * 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.cloud.events;
+
+/**
+ *
+ */
+public interface NodeDownEvent extends ClusterEvent {
+  String getNodeName();
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/events/NodeUpEvent.java b/solr/core/src/java/org/apache/solr/cloud/events/NodeUpEvent.java
new file mode 100644
index 0000000..4e5e445
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/NodeUpEvent.java
@@ -0,0 +1,24 @@
+/*
+ * 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.cloud.events;
+
+/**
+ *
+ */
+public interface NodeUpEvent extends ClusterEvent {
+  String getNodeName();
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/events/ScheduledEvent.java b/solr/core/src/java/org/apache/solr/cloud/events/ScheduledEvent.java
new file mode 100644
index 0000000..46df81a
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/events/ScheduledEvent.java
@@ -0,0 +1,25 @@
+/*
+ * 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.cloud.events;
+
+/**
+ *
+ */
+public interface ScheduledEvent extends ClusterEvent {
+  String getScheduleName();
+  Object getScheduleParam(String key);
+}