Skip to content

Commit fb5c39d

Browse files
authored
Use more inclusive language (#109)
1 parent 7b4fd37 commit fb5c39d

10 files changed

+137
-145
lines changed

Sources/Valkey/Cluster/HashSlotShardMap.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
/// Represents the mapping of nodes in a Valkey shard, consisting of a master node and optional replicas.
15+
/// Represents the mapping of nodes in a Valkey shard, consisting of a primary node and optional replicas.
1616
///
17-
/// In a Valkey cluster, each shard consists of one master node and zero or more replica nodes.
17+
/// In a Valkey cluster, each shard consists of one primary node and zero or more replica nodes.
1818
@usableFromInline
1919
package struct ValkeyShardNodeIDs: Hashable, Sendable {
20-
/// The master node responsible for handling write operations for this shard.
20+
/// The primary node responsible for handling write operations for this shard.
2121
@usableFromInline
22-
package var master: ValkeyNodeID
22+
package var primary: ValkeyNodeID
2323

24-
/// The replica nodes that maintain copies of the master's data.
24+
/// The replica nodes that maintain copies of the primary's data.
2525
/// Replicas can handle read operations but not writes.
2626
@usableFromInline
2727
package var replicas: [ValkeyNodeID]
2828

29-
/// Creates a new shard node mapping with the specified master and optional replicas.
29+
/// Creates a new shard node mapping with the specified primary and optional replicas.
3030
///
3131
/// - Parameters:
32-
/// - master: The master node ID for this shard
32+
/// - primary: The primary node ID for this shard
3333
/// - replicas: An array of replica node IDs, defaults to empty
34-
package init(master: ValkeyNodeID, replicas: [ValkeyNodeID] = []) {
35-
self.master = master
34+
package init(primary: ValkeyNodeID, replicas: [ValkeyNodeID] = []) {
35+
self.primary = primary
3636
self.replicas = replicas
3737
}
3838
}
@@ -43,8 +43,8 @@ extension ValkeyShardNodeIDs: ExpressibleByArrayLiteral {
4343

4444
@usableFromInline
4545
package init(arrayLiteral elements: ValkeyNodeID...) {
46-
precondition(!elements.isEmpty, "ValkeyShardNodeIDs requires at least one node ID for the master")
47-
self.master = elements.first!
46+
precondition(!elements.isEmpty, "ValkeyShardNodeIDs requires at least one node ID for the primary")
47+
self.primary = elements.first!
4848
self.replicas = Array(elements.dropFirst())
4949
}
5050
}
@@ -121,8 +121,8 @@ package struct HashSlotShardMap: Sendable {
121121
/// It performs the following operations:
122122
/// 1. Resets the slot-to-shard mapping (all slots become unassigned)
123123
/// 2. Clears the current shard collection
124-
/// 3. For each valid shard (that has a master node):
125-
/// - Creates a `ValkeyShardNodeIDs` object with the master and its replicas
124+
/// 3. For each valid shard (that has a primary node):
125+
/// - Creates a `ValkeyShardNodeIDs` object with the primary and its replicas
126126
/// - Assigns all slots belonging to this shard in the mapping
127127
///
128128
/// - Parameter shards: A collection of shard descriptions containing slot assignments and node information
@@ -133,26 +133,26 @@ package struct HashSlotShardMap: Sendable {
133133

134134
var shardID = 0
135135
for shard in shards {
136-
var master: ValkeyNodeID?
136+
var primary: ValkeyNodeID?
137137
var replicas = [ValkeyNodeID]()
138138
replicas.reserveCapacity(shard.nodes.count - 1)
139139

140140
for node in shard.nodes {
141141
switch node.role.base {
142-
case .master:
143-
master = node.nodeID
142+
case .primary:
143+
primary = node.nodeID
144144

145145
case .replica:
146146
replicas.append(node.nodeID)
147147
}
148148
}
149149

150-
guard let master else {
150+
guard let primary else {
151151
continue
152152
}
153153

154154
let nodeIDs = ValkeyShardNodeIDs(
155-
master: master,
155+
primary: primary,
156156
replicas: replicas
157157
)
158158

@@ -194,22 +194,22 @@ package struct HashSlotShardMap: Sendable {
194194
var shard = self.shardIDToShard[shardIndex]
195195

196196
// 1. No change
197-
if shard.master == movedError.nodeID {
197+
if shard.primary == movedError.nodeID {
198198
return .updatedSlotToExistingNode
199199
}
200200

201201
// 2. Failover
202202
if shard.replicas.contains(movedError.nodeID) {
203203
// lets promote the replica to be the primary and remove the old primary for now
204-
shard.master = movedError.nodeID
204+
shard.primary = movedError.nodeID
205205
shard.replicas.removeAll { $0 == movedError.nodeID }
206206
self.shardIDToShard[shardIndex] = shard
207207
return .updatedSlotToExistingNode
208208
}
209209
}
210210

211211
// 3. Slot migration to an existing primary
212-
if let newShardIndex = self.shardIDToShard.firstIndex(where: { $0.master == movedError.nodeID }) {
212+
if let newShardIndex = self.shardIDToShard.firstIndex(where: { $0.primary == movedError.nodeID }) {
213213
self.slotToShardID[Int(movedError.slot.rawValue)] = .init(newShardIndex)
214214
return .updatedSlotToExistingNode
215215
}
@@ -220,14 +220,14 @@ package struct HashSlotShardMap: Sendable {
220220
self.shardIDToShard[ogShardIndexOfNewPrimary].replicas.removeAll(where: { $0 == movedError.nodeID })
221221
// create a new shard with the replica
222222
let newShardIndex = self.shardIDToShard.endIndex
223-
self.shardIDToShard.append(.init(master: movedError.nodeID))
223+
self.shardIDToShard.append(.init(primary: movedError.nodeID))
224224
self.slotToShardID[Int(movedError.slot.rawValue)] = .init(newShardIndex)
225225
return .updatedSlotToExistingNode
226226
}
227227

228228
// 5. totally new node
229229
let newShardIndex = self.shardIDToShard.endIndex
230-
self.shardIDToShard.append(.init(master: movedError.nodeID))
230+
self.shardIDToShard.append(.init(primary: movedError.nodeID))
231231
self.slotToShardID[Int(movedError.slot.rawValue)] = .init(newShardIndex)
232232
return .updatedSlotToUnknownNode
233233
}

Sources/Valkey/Cluster/ValkeyClusterClientStateMachine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ package struct ValkeyClusterClientStateMachine<
537537

538538
case .degraded(let context):
539539
let shardID = try context.hashSlotShardMap.nodeID(for: slots)
540-
if let pool = self.runningClients[shardID.master]?.pool {
540+
if let pool = self.runningClients[shardID.primary]?.pool {
541541
return pool
542542
}
543543
// If we don't have a node for a shard, that means that this shard got created from
@@ -547,7 +547,7 @@ package struct ValkeyClusterClientStateMachine<
547547

548548
case .healthy(let context):
549549
let shardID = try context.hashSlotShardMap.nodeID(for: slots)
550-
if let pool = self.runningClients[shardID.master]?.pool {
550+
if let pool = self.runningClients[shardID.primary]?.pool {
551551
return pool
552552
}
553553
// If we don't have a node for a shard, that means that this shard got created from

Sources/Valkey/Cluster/ValkeyClusterError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package enum ValkeyClusterError: Error {
1717
case clusterIsMissingSlotAssignment
1818
case clusterIsMissingMovedErrorNode
19-
case shardIsMissingMasterNode
20-
case shardHasMultipleMasterNodes
19+
case shardIsMissingPrimaryNode
20+
case shardHasMultiplePrimaryNodes
2121
case noNodeToTalkTo
2222
case serverDiscoveryFailedNoKnownNode
2323
case keysInCommandRequireMultipleNodes

Sources/Valkey/Cluster/ValkeyTopologyCandidate.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
package struct ValkeyTopologyCandidate: Hashable {
2222
/// Represents a shard (hash slot range) within a Valkey cluster topology.
2323
///
24-
/// A shard consists of a set of hash slots assigned to a master node and optional replica nodes.
24+
/// A shard consists of a set of hash slots assigned to a primary node and optional replica nodes.
2525
package struct Shard: Hashable {
2626
/// The hash slots assigned to this shard.
2727
package var slots: HashSlots
2828

29-
/// The master node responsible for this shard.
30-
package var master: Node
29+
/// The primary node responsible for this shard.
30+
package var primary: Node
3131

3232
/// The replica nodes for this shard, sorted by endpoint, port, and TLS status for consistent equality checking.
3333
package var replicas: [Node]
3434
}
3535

36-
/// Represents a node (either master or replica) in the Valkey cluster topology.
36+
/// Represents a node (either primary or replica) in the Valkey cluster topology.
3737
///
3838
/// Contains only the essential connection properties needed to identify and connect to a node.
3939
package struct Node: Hashable {
@@ -70,17 +70,17 @@ package struct ValkeyTopologyCandidate: Hashable {
7070
package init(_ description: ValkeyClusterDescription) throws(ValkeyClusterError) {
7171

7272
self.shards = try description.shards.map({ shard throws(ValkeyClusterError) in
73-
var master: Node?
73+
var primary: Node?
7474
var replicas = [Node]()
7575
replicas.reserveCapacity(shard.nodes.count)
7676

7777
for node in shard.nodes {
7878
switch node.role.base {
79-
case .master:
80-
if master != nil {
81-
throw ValkeyClusterError.shardHasMultipleMasterNodes
79+
case .primary:
80+
if primary != nil {
81+
throw ValkeyClusterError.shardHasMultiplePrimaryNodes
8282
}
83-
master = Node(node)
83+
primary = Node(node)
8484
case .replica:
8585
replicas.append(Node(node))
8686
}
@@ -99,13 +99,13 @@ package struct ValkeyTopologyCandidate: Hashable {
9999
return true
100100
})
101101

102-
guard let master else {
103-
throw ValkeyClusterError.shardIsMissingMasterNode
102+
guard let primary else {
103+
throw ValkeyClusterError.shardIsMissingPrimaryNode
104104
}
105105

106106
return Shard(
107107
slots: shard.slots.sorted(by: { $0.startIndex < $1.startIndex }),
108-
master: master,
108+
primary: primary,
109109
replicas: sorted
110110
)
111111
})

Sources/Valkey/Commands/Custom/ClusterCustomCommands.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ package struct ValkeyClusterParseError: Error, Equatable {
4444
public struct ValkeyClusterDescription: Hashable, Sendable, RESPTokenDecodable {
4545
/// Details for a node within a cluster shard
4646
public struct Node: Hashable, Sendable {
47-
/// Replication role of a given shard (master or replica)
47+
/// Replication role of a given node within a shard (primary or replica)
4848
public struct Role: Sendable, Hashable, RawRepresentable {
49-
public static let master = Role(base: .master)
49+
public static let primary = Role(base: .primary)
5050
public static let replica = Role(base: .replica)
5151

5252
public init?(rawValue: String) {
@@ -61,7 +61,7 @@ public struct ValkeyClusterDescription: Hashable, Sendable, RESPTokenDecodable {
6161
}
6262

6363
enum Base: String {
64-
case master
64+
case primary = "master"
6565
case replica
6666
}
6767

@@ -140,14 +140,6 @@ public struct ValkeyClusterDescription: Hashable, Sendable, RESPTokenDecodable {
140140
public var slots: HashSlots
141141
public var nodes: [Node]
142142

143-
public var master: Node? {
144-
self.nodes.first
145-
}
146-
147-
public var replicas: ArraySlice<Node> {
148-
self.nodes.dropFirst(1)
149-
}
150-
151143
public init(slots: HashSlots, nodes: [Node]) {
152144
self.slots = slots
153145
self.nodes = nodes

0 commit comments

Comments
 (0)