Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ let products: [PackageDescription.Product] = [
.library(
name: "DistributedCluster",
targets: ["DistributedCluster"]
)
),
.library(
name: "NewDistributedCluster",
targets: ["NewDistributedCluster"]
),
]

// ==== ----------------------------------------------------------------------------------------------------------------
Expand All @@ -41,15 +45,27 @@ var targets: [PackageDescription.Target] = [
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOExtras", package: "swift-nio-extras"),
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "Logging", package: "swift-log"),
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "ServiceDiscovery", package: "swift-service-discovery"),
.product(name: "Backtrace", package: "swift-backtrace"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [.swiftLanguageMode(.v5)]
),

// MARK: New Cluster

.target(
name: "NewDistributedCluster",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
],
swiftSettings: [
// .enableUpcomingFeature("NonisolatedNonsendingByDefault"),
// .enableUpcomingFeature("InferIsolatedConformances"),
]
),
// ==== ------------------------------------------------------------------------------------------------------------
// MARK: TestKit

Expand Down Expand Up @@ -86,6 +102,10 @@ var targets: [PackageDescription.Target] = [
swiftSettings: [.swiftLanguageMode(.v5)]
),

.testTarget(
name: "NewDistributedClusterTests",
dependencies: ["NewDistributedCluster"]
),
// ==== ------------------------------------------------------------------------------------------------------------
// MARK: MultiNodeTestKit

Expand All @@ -108,7 +128,6 @@ var targets: [PackageDescription.Target] = [
dependencies: [
"DistributedCluster",
// "DistributedActorsTestKit", // can't depend on it because it'll pull in XCTest, and that crashes in executable then
.product(name: "Backtrace", package: "swift-backtrace"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "OrderedCollections", package: "swift-collections"),
Expand Down Expand Up @@ -185,36 +204,33 @@ var targets: [PackageDescription.Target] = [
]

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-atomics", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-atomics", from: "1.3.0"),

// .package(url: "https://github.com/apple/swift-cluster-membership", from: "0.3.0"),
// .package(name: "swift-cluster-membership", path: "Packages/swift-cluster-membership"), // FIXME: just work in progress
// ~~~ Swift NIO ~~~
// FIXME: just work in progress
.package(url: "https://github.com/apple/swift-cluster-membership", branch: "main"),

.package(url: "https://github.com/apple/swift-nio", from: "2.61.1"),
.package(url: "https://github.com/apple/swift-nio-extras", from: "1.20.0"),
.package(url: "https://github.com/apple/swift-nio-ssl", from: "2.25.0"),

.package(url: "https://github.com/apple/swift-protobuf", from: "1.25.1"),
// ~~~ Swift NIO ~~~
.package(url: "https://github.com/apple/swift-nio", from: "2.87.0"),
.package(url: "https://github.com/apple/swift-nio-extras", from: "1.29.0"),
.package(url: "https://github.com/apple/swift-nio-ssl", from: "2.35.0"),

// ~~~ backtraces ~~~
// TODO: optimally, library should not pull swift-backtrace
.package(url: "https://github.com/swift-server/swift-backtrace", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-protobuf", from: "1.32.0"),

// ~~~ Swift libraries ~~~
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0-beta"),
.package(url: "https://github.com/apple/swift-collections", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.4"),
.package(url: "https://github.com/apple/swift-collections", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-log", from: "1.6.0"),

// ~~~ Observability ~~~
.package(url: "https://github.com/apple/swift-log", from: "1.0.0"),
// swift-metrics 1.x and 2.x are almost API compatible, so most clients should use
.package(url: "https://github.com/apple/swift-metrics", "1.0.0"..<"3.0.0"),
.package(url: "https://github.com/apple/swift-service-discovery", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-service-discovery", from: "1.4.0"),

// ~~~ SwiftPM Plugins ~~~

// ~~~ Command Line ~~~~
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.3"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.6.0"),
]

if ProcessInfo.processInfo.environment["VALIDATE_DOCS"] != nil {
Expand Down
9 changes: 5 additions & 4 deletions Sources/DistributedCluster/Behaviors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ extension _Behavior {
func receiveSignalAsync(
context: _ActorContext<Message>,
signal: _Signal,
handleSignal: @escaping @Sendable (
_ActorContext<Message>,
_Signal
) async throws -> _Behavior<Message>
handleSignal:
@escaping @Sendable (
_ActorContext<Message>,
_Signal
) async throws -> _Behavior<Message>
) -> _Behavior<Message> {
.setup { context in
receiveSignalAsync0(handleSignal, context: context, signal: signal)
Expand Down
1 change: 0 additions & 1 deletion Sources/DistributedCluster/ClusterSystem+Clusterd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//

import Atomics
import Backtrace
import CDistributedActorsMailbox
import Dispatch
import Distributed
Expand Down
1 change: 0 additions & 1 deletion Sources/DistributedCluster/ClusterSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//

import Atomics
import Backtrace
import CDistributedActorsMailbox
import Dispatch
@_exported import Distributed
Expand Down
36 changes: 36 additions & 0 deletions Sources/NewDistributedCluster/ActorID.swift
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 {}
Copy link

@ktoso ktoso Oct 16, 2025

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

Copy link
Owner Author

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.

91 changes: 91 additions & 0 deletions Sources/NewDistributedCluster/Cluster/Cluster+Endpoint.swift
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 {}
Loading
Loading