-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support notification for host shutting down
We want to support custom notification mechanism for quicker drain signal recognition to minimize compute wastage. This mechanism is currently intended to be used for both the exchange client and supporting a faster graceful shutdown of worker.
- Loading branch information
1 parent
7edd2c2
commit 1fda136
Showing
13 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
presto-main/src/main/java/com/facebook/presto/server/NodeStatusNotificationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.facebook.presto.server; | ||
|
||
import com.facebook.presto.spi.nodestatus.NoOpNodeStatusNotificationProvider; | ||
import com.facebook.presto.spi.nodestatus.NodeStatusNotificationProvider; | ||
import com.facebook.presto.spi.nodestatus.NodeStatusNotificationProviderFactory; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static com.facebook.presto.util.PropertiesUtil.loadProperties; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public class NodeStatusNotificationManager | ||
{ | ||
private static final File NODE_STATUS_NOTIFICATION_CONFIG = new File("etc/node-status-notification.properties"); | ||
private NodeStatusNotificationProviderFactory notificationProviderFactory; | ||
private NodeStatusNotificationProvider notificationProvider = new NoOpNodeStatusNotificationProvider(); | ||
private boolean isNotificationProviderAdded; | ||
|
||
public void addNodeStatusNotificationProviderFactory(NodeStatusNotificationProviderFactory notificationProviderFactory) | ||
{ | ||
this.notificationProviderFactory = requireNonNull(notificationProviderFactory, "notificationProviderFactory is null"); | ||
} | ||
|
||
public void loadNodeStatusNotificationProvider() | ||
throws IOException | ||
{ | ||
if (this.notificationProviderFactory == null) { | ||
return; | ||
} | ||
checkState(!isNotificationProviderAdded, "NotificationProvider can only be set once"); | ||
this.notificationProvider = this.notificationProviderFactory.create(getConfig()); | ||
this.isNotificationProviderAdded = true; | ||
} | ||
|
||
private Map<String, String> getConfig() | ||
throws IOException | ||
{ | ||
if (NODE_STATUS_NOTIFICATION_CONFIG.exists()) { | ||
return loadProperties(NODE_STATUS_NOTIFICATION_CONFIG); | ||
} | ||
return ImmutableMap.of(); | ||
} | ||
|
||
public NodeStatusNotificationProvider getNotificationProvider() | ||
{ | ||
return this.notificationProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...o-spi/src/main/java/com/facebook/presto/spi/nodestatus/GracefulShutdownEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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.facebook.presto.spi.nodestatus; | ||
|
||
@FunctionalInterface | ||
public interface GracefulShutdownEventListener | ||
{ | ||
void onNodeShuttingDown(); | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/com/facebook/presto/spi/nodestatus/NoOpNodeStatusNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.facebook.presto.spi.nodestatus; | ||
|
||
public class NoOpNodeStatusNotificationProvider | ||
implements NodeStatusNotificationProvider | ||
{ | ||
@Override | ||
public void registerGracefulShutdownEventListener(GracefulShutdownEventListener listener) | ||
{ | ||
} | ||
|
||
@Override | ||
public void removeGracefulShutdownEventListener(GracefulShutdownEventListener listener) | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...-spi/src/main/java/com/facebook/presto/spi/nodestatus/NodeStatusNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.facebook.presto.spi.nodestatus; | ||
|
||
/** | ||
* The {@code NodeStatusNotificationProvider} interface provides a registry for node status listeners. | ||
* Implementations of this interface can listen to node status events and notify all registered listeners, | ||
* especially when a node goes down. | ||
* | ||
* <p>It is essential for implementations to ensure proper synchronization if the registry is accessed | ||
* by multiple threads.</p> | ||
*/ | ||
public interface NodeStatusNotificationProvider | ||
{ | ||
void registerGracefulShutdownEventListener(GracefulShutdownEventListener listener); | ||
|
||
void removeGracefulShutdownEventListener(GracefulShutdownEventListener listener); | ||
} |
23 changes: 23 additions & 0 deletions
23
...c/main/java/com/facebook/presto/spi/nodestatus/NodeStatusNotificationProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.facebook.presto.spi.nodestatus; | ||
|
||
import java.util.Map; | ||
|
||
public interface NodeStatusNotificationProviderFactory | ||
{ | ||
String getName(); | ||
|
||
NodeStatusNotificationProvider create(Map<String, String> config); | ||
} |