-
Notifications
You must be signed in to change notification settings - Fork 78
#423 Op Replication based Receptionist #438
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ extension VersionVector: ProtobufRepresentable { | |
| throw SerializationError.missingField("replicaID", type: String(describing: ReplicaVersion.self)) | ||
| } | ||
| let replicaId = try ReplicaId(fromProto: replicaVersion.replicaID, context: context) | ||
| state[replicaId] = Int(replicaVersion.version) // TODO: safety? | ||
| state[replicaId] = replicaVersion.version | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As side effect of this work I needed / wanted UInt here so this also addressed the TODOs we had laying around |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -97,6 +97,6 @@ extension VersionDot: ProtobufRepresentable { | |
| throw SerializationError.missingField("replicaID", type: String(describing: VersionDot.self)) | ||
| } | ||
| self.replicaId = try ReplicaId(fromProto: proto.replicaID, context: context) | ||
| self.version = Int(proto.version) // TODO: safety? | ||
| self.version = proto.version | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,11 @@ | |
| public struct VersionVector { | ||
| // TODO: should we disallow mixing ReplicaId types somehow? | ||
|
|
||
| public typealias ReplicaVersion = (replicaId: ReplicaId, version: Int) // TODO: struct? // TODO: UInt? | ||
| public typealias Version = UInt64 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm kind of thinking we should be explicit with those... What's the right thing to do here you think @drexin ? |
||
| public typealias ReplicaVersion = (replicaId: ReplicaId, version: Version) // TODO: struct? | ||
|
|
||
| // Internal state is a dictionary of replicas and their corresponding version | ||
| internal var state: [ReplicaId: Int] = [:] | ||
| internal var state: [ReplicaId: Version] = [:] | ||
|
|
||
| public static let empty: VersionVector = .init() | ||
|
|
||
|
|
@@ -55,6 +56,10 @@ public struct VersionVector { | |
| self.init([replicaVersion]) | ||
| } | ||
|
|
||
| public init(_ version: Version, at replicaId: ReplicaId) { | ||
| self.init([(replicaId, version)]) | ||
| } | ||
|
|
||
| public init(_ replicaVersions: [ReplicaVersion]) { | ||
| for rv in replicaVersions { | ||
| precondition(rv.version > 0, "Version must be greater than 0") | ||
|
|
@@ -75,7 +80,7 @@ public struct VersionVector { | |
| /// - Parameter replicaId: The replica whose version is to be incremented. | ||
| /// - Returns: The replica's version after the increment. | ||
| @discardableResult | ||
| public mutating func increment(at replicaId: ReplicaId) -> Int { | ||
| public mutating func increment(at replicaId: ReplicaId) -> Version { | ||
| if let current = self.state[replicaId] { | ||
| let nextVersion = current + 1 | ||
| self.state[replicaId] = nextVersion | ||
|
|
@@ -102,16 +107,21 @@ public struct VersionVector { | |
| /// | ||
| /// - Parameter replicaId: The replica whose version is being queried. | ||
| /// - Returns: The replica's version or 0 if replica is unknown. | ||
| public subscript(replicaId: ReplicaId) -> Int { | ||
| return self.state[replicaId] ?? 0 | ||
| public subscript(replicaId: ReplicaId) -> Version { | ||
| self.state[replicaId] ?? 0 | ||
| } | ||
|
|
||
| /// Lists all replica ids that this version vector contains. | ||
| public var replicaIds: Dictionary<ReplicaId, Version>.Keys { | ||
| self.state.keys | ||
| } | ||
|
|
||
| /// Determine if this `VersionVector` contains a specific version at the given replica. | ||
| /// | ||
| /// - Parameter replicaId: The replica of interest | ||
| /// - Parameter version: The version of interest | ||
| /// - Returns: True if the replica's version in the `VersionVector` is greater than or equal to `version`. False otherwise. | ||
| public func contains(_ replicaId: ReplicaId, _ version: Int) -> Bool { | ||
| public func contains(_ replicaId: ReplicaId, _ version: Version) -> Bool { | ||
| self[replicaId] >= version | ||
| } | ||
|
|
||
|
|
@@ -192,9 +202,10 @@ extension VersionVector: Codable { | |
| /// to be `Hashable` we have to define a type. | ||
| public struct VersionDot { | ||
| public let replicaId: ReplicaId | ||
| public let version: Int // TODO: UInt? | ||
| public let version: Version | ||
| public typealias Version = UInt64 | ||
|
|
||
| init(_ replicaId: ReplicaId, _ version: Int) { | ||
| init(_ replicaId: ReplicaId, _ version: Version) { | ||
| self.replicaId = replicaId | ||
| self.version = version | ||
| } | ||
|
|
||
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.
Where are these methods actually implemented?
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.
In
ActorShellwhich extendsActorContext, it's our way of hiding some of the API.So the way we pass a context to anyone is basically just pass
selffrom the shell, and expose it only as the ContextPerhaps there's a better way but so far we have this way.
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.
They're implemented on
ActorShellwhich is "the actual actor impl" (in a way).So ActorShell extends ActorContext and when we pass context around we actually pass
selfand it happens to have all the right lifecycle properties -- context is valid only as long the actual actor is etc.