-
Notifications
You must be signed in to change notification settings - Fork 77
Finishing clusterd #1165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Finishing clusterd #1165
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6e7d150
wip
akbashev 2e5522d
Merge branch 'main' into clusterd-poc
akbashev 325aff6
Cleaned up a bit
akbashev 77b75b2
fixed comments
akbashev da14a91
Merge branch 'main' into clusterd-poc
akbashev d734d2c
swift format
akbashev 80aa3bd
Merge branch 'main' into clusterd-poc
akbashev 21bb91a
Name fix
akbashev 2f67fb0
Merge branch 'main' into clusterd-poc
akbashev 0af3c5a
Filename fix
akbashev f60958d
Header fix
akbashev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,47 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift Distributed Actors open source project | ||
| // | ||
| // Copyright (c) 2020-2024 Apple Inc. and the Swift Distributed Actors project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift Distributed Actors project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ArgumentParser | ||
| import DistributedCluster | ||
| import Logging | ||
|
|
||
| @main | ||
| struct ClusterDBoot: AsyncParsableCommand { | ||
| @Option(name: .shortAndLong, help: "The port to bind the cluster daemon on.") | ||
| var port: Int = ClusterDaemon.defaultEndpoint.port | ||
|
|
||
| @Option(help: "The host address to bid the cluster daemon on.") | ||
| var host: String = ClusterDaemon.defaultEndpoint.host | ||
|
|
||
| func run() async throws { | ||
| let daemon = await ClusterSystem.startClusterDaemon(configuredWith: self.configure) | ||
|
|
||
| #if DEBUG | ||
| daemon.system.log.warning("RUNNING ClusterD DEBUG binary, operation is likely to be negatively affected. Please build/run the ClusterD process using '-c release' configuration!") | ||
| #endif | ||
|
|
||
| try daemon.system.park() | ||
| } | ||
|
|
||
| func configure(_ settings: inout ClusterSystemSettings) { | ||
| // other nodes will be discovering us, not the opposite | ||
| settings.discovery = .init(static: []) | ||
|
|
||
| settings.endpoint = Cluster.Endpoint( | ||
| systemName: "clusterd", | ||
| host: self.host, | ||
| port: self.port | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,88 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift Distributed Actors open source project | ||
| // | ||
| // Copyright (c) 2018-2022 Apple Inc. and the Swift Distributed Actors project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift Distributed Actors project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Atomics | ||
| import Backtrace | ||
| import CDistributedActorsMailbox | ||
| import Dispatch | ||
| import Distributed | ||
| import DistributedActorsConcurrencyHelpers | ||
| import Foundation // for UUID | ||
| import Logging | ||
| import NIO | ||
|
|
||
| extension ClusterSystem { | ||
| public static func startClusterDaemon(configuredWith configureSettings: (inout ClusterSystemSettings) -> Void = { _ in () }) async -> ClusterDaemon { | ||
| let system = await ClusterSystem("clusterd") { settings in | ||
| settings.endpoint = ClusterDaemon.defaultEndpoint | ||
| configureSettings(&settings) | ||
| } | ||
|
|
||
| return ClusterDaemon(system: system) | ||
| } | ||
| } | ||
|
|
||
| public struct ClusterDaemon { | ||
| public let system: ClusterSystem | ||
| public var settings: ClusterSystemSettings { | ||
| self.system.settings | ||
| } | ||
|
|
||
| public init(system: ClusterSystem) { | ||
| self.system = system | ||
| } | ||
| } | ||
|
|
||
| extension ClusterDaemon { | ||
| /// Suspends until the ``ClusterSystem`` is terminated by a call to ``shutdown()``. | ||
| public var terminated: Void { | ||
| get async throws { | ||
| try await self.system.terminated | ||
| } | ||
| } | ||
|
|
||
| /// Returns `true` if the system was already successfully terminated (i.e. awaiting ``terminated`` would resume immediately). | ||
| public var isTerminated: Bool { | ||
| self.system.isTerminated | ||
| } | ||
|
|
||
| /// Forcefully stops this actor system and all actors that live within it. | ||
| /// This is an asynchronous operation and will be executed on a separate thread. | ||
| /// | ||
| /// You can use `shutdown().wait()` to synchronously await on the system's termination, | ||
| /// or provide a callback to be executed after the system has completed it's shutdown. | ||
| /// | ||
| /// - Returns: A `Shutdown` value that can be waited upon until the system has completed the shutdown. | ||
| @discardableResult | ||
| public func shutdown() throws -> ClusterSystem.Shutdown { | ||
| try self.system.shutdown() | ||
| } | ||
| } | ||
|
|
||
| extension ClusterDaemon { | ||
| /// The default endpoint | ||
| public static let defaultEndpoint = Cluster.Endpoint(host: "127.0.0.1", port: 3137) | ||
| } | ||
|
|
||
| internal distributed actor ClusterDaemonServant { | ||
| typealias ActorSystem = ClusterSystem | ||
|
|
||
| @ActorID.Metadata(\.wellKnown) | ||
| public var wellKnownName: String | ||
|
|
||
| init(system: ClusterSystem) async { | ||
| self.actorSystem = system | ||
| self.wellKnownName = "$cluster-daemon-servant" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to put subscribe and initialize closures here, as otherwise it's quite confusing to have optional values in settings itself.