forked from apple/swift-distributed-actors
-
Notifications
You must be signed in to change notification settings - Fork 1
New system #9
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
Open
akbashev
wants to merge
3
commits into
main
Choose a base branch
from
new_system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New system #9
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift Distributed Actors open source project | ||
| // | ||
| // Copyright (c) 2018-2025 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 Foundation | ||
|
|
||
| // ==== ---------------------------------------------------------------------------------------------------------------- | ||
| extension ClusterSystem { | ||
| public struct ActorID: Hashable, Sendable { | ||
| /// The unique node on which the actor identified by this identity is located. | ||
| public let node: Cluster.Node | ||
| public let id: String | ||
|
|
||
| public init( | ||
| node: Cluster.Node, | ||
| id: String | ||
| ) { | ||
| self.node = node | ||
| self.id = id | ||
| traceLog_DeathWatch("Made ID: \(self)") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TODO: Needed for actorid now, refactor or remove when adding serialization | ||
| extension ClusterSystem.ActorID: Codable {} | ||
91 changes: 91 additions & 0 deletions
91
Sources/NewDistributedCluster/Cluster/Cluster+Endpoint.swift
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,91 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 Distributed | ||
| import Foundation | ||
|
|
||
| // ==== ---------------------------------------------------------------------------------------------------------------- | ||
| // MARK: Cluster.Endpoint | ||
|
|
||
| extension Cluster { | ||
| /// An `Endpoint` is a triplet of protocol, host and port that a node is bound to. | ||
| /// | ||
| /// Unlike `Cluster.Node`, it does not carry identity (`Cluster.Node.ID`) of a specific incarnation of an actor system node, | ||
| /// and represents an address of _any_ node that could live under this address. During the handshake process between two nodes, | ||
| /// the remote `Node` that the local side started out to connect with is "upgraded" to a `Cluster.Node`, as soon as we discover | ||
| /// the remote side's unique node identifier (`Cluster.Node.ID`). | ||
| /// | ||
| /// ### System name / human readable name | ||
| /// The `systemName` is NOT taken into account when comparing nodes. The system name is only utilized for human readability | ||
| /// and debugging purposes and participates neither in hashcode nor equality of a `Node`, as a node specifically is meant | ||
| /// to represent any unique node that can live on specific host & port. System names are useful for human operators, | ||
| /// intending to use some form of naming scheme, e.g. adopted from a cloud provider, to make it easier to map nodes in | ||
| /// actor system logs, to other external systems. | ||
| /// | ||
| /// - SeeAlso: For more details on unique node ids, refer to: ``Cluster/Node-struct``. | ||
| public struct Endpoint: Hashable, Sendable { | ||
| // TODO: collapse into one String and index into it? | ||
| public var `protocol`: String | ||
| public var systemName: String // TODO: some other name, to signify "this is just for humans"? | ||
| public var host: String | ||
| public var port: Int | ||
|
|
||
| public init(protocol: String, systemName: String, host: String, port: Int) { | ||
| precondition(port > 0, "port MUST be > 0") | ||
| self.protocol = `protocol` | ||
| self.systemName = systemName | ||
| self.host = host | ||
| self.port = port | ||
| } | ||
|
|
||
| public init(systemName: String, host: String, port: Int) { | ||
| self.init(protocol: "sact", systemName: systemName, host: host, port: port) | ||
| } | ||
|
|
||
| public init(host: String, port: Int) { | ||
| self.init(protocol: "sact", systemName: "", host: host, port: port) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Cluster.Endpoint: CustomStringConvertible, CustomDebugStringConvertible { | ||
| public var description: String { | ||
| "\(self.protocol)://\(self.systemName)@\(self.host):\(self.port)" | ||
| } | ||
|
|
||
| public var debugDescription: String { | ||
| self.description | ||
| } | ||
| } | ||
|
|
||
| extension Cluster.Endpoint: Comparable { | ||
| // Silly but good enough comparison for deciding "who is lower node" | ||
| // as we only use those for "tie-breakers" any ordering is fine to be honest here. | ||
| public static func < (lhs: Cluster.Endpoint, rhs: Cluster.Endpoint) -> Bool { | ||
| "\(lhs.protocol)\(lhs.host)\(lhs.port)" < "\(rhs.protocol)\(rhs.host)\(rhs.port)" | ||
| } | ||
|
|
||
| public func hash(into hasher: inout Hasher) { | ||
| hasher.combine(self.protocol) | ||
| hasher.combine(self.host) | ||
| hasher.combine(self.port) | ||
| } | ||
|
|
||
| public static func == (lhs: Cluster.Endpoint, rhs: Cluster.Endpoint) -> Bool { | ||
| lhs.protocol == rhs.protocol && lhs.host == rhs.host && lhs.port == rhs.port | ||
| } | ||
| } | ||
|
|
||
| // TODO: Needed for actorid now, refactor or remove when adding serialization | ||
| extension Cluster.Endpoint: Codable {} |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
that's pretty expected, keep is ok
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.
Yeah, put this comment at the very beginning of refactoring, should be just codable.