Skip to content

Commit 6058030

Browse files
committed
Revert "Call CLIENT SETINFO on initialisation of connection (#170)"
This reverts commit 5106ebf. Signed-off-by: Adam Fowler <[email protected]>
1 parent 5106ebf commit 6058030

File tree

7 files changed

+22
-105
lines changed

7 files changed

+22
-105
lines changed

Benchmarks/ValkeyBenchmarks/Shared.swift

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,29 @@ let defaultMetrics: [BenchmarkMetric] =
3333
.throughput,
3434
]
3535

36-
struct BenchmarkGetHandler: BenchmarkCommandHandler {
37-
static let expectedCommand = RESPToken.Value.bulkString(ByteBuffer(string: "GET"))
38-
static let response = ByteBuffer(string: "$3\r\nBar\r\n")
39-
func handle(command: RESPToken.Value, parameters: RESPToken.Array.Iterator, write: (ByteBuffer) -> Void) {
40-
switch command {
41-
case Self.expectedCommand:
42-
write(Self.response)
43-
case .bulkString(let string):
44-
fatalError("Unexpected command: \(String(buffer: string))")
45-
default:
46-
fatalError("Unexpected value: \(command)")
36+
func makeLocalServer() async throws -> Channel {
37+
struct GetHandler: BenchmarkCommandHandler {
38+
static let expectedCommand = RESPToken.Value.bulkString(ByteBuffer(string: "GET"))
39+
static let response = ByteBuffer(string: "$3\r\nBar\r\n")
40+
func handle(command: RESPToken.Value, parameters: RESPToken.Array.Iterator, write: (ByteBuffer) -> Void) {
41+
switch command {
42+
case Self.expectedCommand:
43+
write(Self.response)
44+
case .bulkString(ByteBuffer(string: "PING")):
45+
write(ByteBuffer(string: "$4\r\nPONG\r\n"))
46+
case .bulkString(let string):
47+
fatalError("Unexpected command: \(String(buffer: string))")
48+
default:
49+
fatalError("Unexpected value: \(command)")
50+
}
4751
}
4852
}
49-
}
50-
func makeLocalServer(commandHandler: some BenchmarkCommandHandler = BenchmarkGetHandler()) async throws -> Channel {
51-
try await ServerBootstrap(group: NIOSingletons.posixEventLoopGroup)
53+
return try await ServerBootstrap(group: NIOSingletons.posixEventLoopGroup)
5254
.serverChannelOption(.socketOption(.so_reuseaddr), value: 1)
5355
.childChannelInitializer { channel in
5456
do {
5557
try channel.pipeline.syncOperations.addHandler(
56-
ValkeyServerChannelHandler(commandHandler: commandHandler)
58+
ValkeyServerChannelHandler(commandHandler: GetHandler())
5759
)
5860
return channel.eventLoop.makeSucceededVoidFuture()
5961
} catch {
@@ -64,7 +66,7 @@ func makeLocalServer(commandHandler: some BenchmarkCommandHandler = BenchmarkGet
6466
.get()
6567
}
6668

67-
protocol BenchmarkCommandHandler: Sendable {
69+
protocol BenchmarkCommandHandler {
6870
func handle(command: RESPToken.Value, parameters: RESPToken.Array.Iterator, write: (ByteBuffer) -> Void)
6971
}
7072

@@ -76,11 +78,6 @@ final class ValkeyServerChannelHandler<Handler: BenchmarkCommandHandler>: Channe
7678
private var decoder = NIOSingleStepByteToMessageProcessor(RESPTokenDecoder())
7779
private let helloCommand = RESPToken.Value.bulkString(ByteBuffer(string: "HELLO"))
7880
private let helloResponse = ByteBuffer(string: "%1\r\n+server\r\n+fake\r\n")
79-
private let pingCommand = RESPToken.Value.bulkString(ByteBuffer(string: "PING"))
80-
private let pongResponse = ByteBuffer(string: "$4\r\nPONG\r\n")
81-
private let clientCommand = RESPToken.Value.bulkString(ByteBuffer(string: "CLIENT"))
82-
private let setInfoSubCommand = RESPToken.Value.bulkString(ByteBuffer(string: "SETINFO"))
83-
private let okResponse = ByteBuffer(string: "+2OK\r\n")
8481
private let commandHandler: Handler
8582

8683
init(commandHandler: Handler) {
@@ -105,20 +102,6 @@ final class ValkeyServerChannelHandler<Handler: BenchmarkCommandHandler>: Channe
105102
case helloCommand:
106103
context.writeAndFlush(self.wrapOutboundOut(helloResponse), promise: nil)
107104

108-
case pingCommand:
109-
context.writeAndFlush(self.wrapOutboundOut(pongResponse), promise: nil)
110-
111-
case clientCommand:
112-
var subCommandIterator = iterator
113-
switch subCommandIterator.next()?.value {
114-
case setInfoSubCommand:
115-
context.writeAndFlush(self.wrapOutboundOut(okResponse), promise: nil)
116-
default:
117-
commandHandler.handle(command: command, parameters: iterator) {
118-
context.writeAndFlush(self.wrapOutboundOut($0), promise: nil)
119-
}
120-
}
121-
122105
default:
123106
commandHandler.handle(command: command, parameters: iterator) {
124107
context.writeAndFlush(self.wrapOutboundOut($0), promise: nil)

Sources/Valkey/Connection/ValkeyChannelHandler+stateMachine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extension ValkeyChannelHandler {
225225
case .nio(let promise):
226226
self = .connected(state)
227227
return .waitForPromise(promise)
228-
case .swift, .forget:
228+
case .swift:
229229
preconditionFailure("Connected state cannot be setup with a Swift continuation")
230230
}
231231
case .active(let state):

Sources/Valkey/Connection/ValkeyChannelHandler.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ import NIOCore
2020
enum ValkeyPromise<T: Sendable>: Sendable {
2121
case nio(EventLoopPromise<T>)
2222
case swift(CheckedContinuation<T, any Error>)
23-
case forget
2423

2524
func succeed(_ t: T) {
2625
switch self {
2726
case .nio(let eventLoopPromise):
2827
eventLoopPromise.succeed(t)
2928
case .swift(let checkedContinuation):
3029
checkedContinuation.resume(returning: t)
31-
case .forget:
32-
break
3330
}
3431
}
3532

@@ -39,8 +36,6 @@ enum ValkeyPromise<T: Sendable>: Sendable {
3936
eventLoopPromise.fail(e)
4037
case .swift(let checkedContinuation):
4138
checkedContinuation.resume(throwing: e)
42-
case .forget:
43-
break
4439
}
4540
}
4641
}
@@ -159,33 +154,6 @@ final class ValkeyChannelHandler: ChannelInboundHandler {
159154
}
160155
}
161156

162-
/// Write valkey command/commands to channel
163-
/// - Parameters:
164-
/// - request: Valkey command request
165-
/// - promise: Promise to fulfill when command is complete
166-
@inlinable
167-
func writeAndForget<Command: ValkeyCommand>(command: Command, requestID: Int) {
168-
self.eventLoop.assertInEventLoop()
169-
let pendingCommand = PendingCommand(
170-
promise: .forget,
171-
requestID: requestID,
172-
deadline: .now() + self.configuration.commandTimeout
173-
)
174-
switch self.stateMachine.sendCommand(pendingCommand) {
175-
case .sendCommand(let context):
176-
self.encoder.reset()
177-
command.encode(into: &self.encoder)
178-
let buffer = self.encoder.buffer
179-
context.writeAndFlush(self.wrapOutboundOut(buffer), promise: nil)
180-
if self.deadlineCallback == nil {
181-
self.scheduleDeadlineCallback(deadline: .now() + self.configuration.commandTimeout)
182-
}
183-
184-
case .throwError:
185-
break
186-
}
187-
}
188-
189157
@usableFromInline
190158
func write(request: ValkeyRequest) {
191159
self.eventLoop.assertInEventLoop()

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
132132
}
133133
}
134134
let connection = try await future.get()
135-
try await connection.initialHandshake()
135+
try await connection.waitOnActive()
136136
return connection
137137
}
138138

@@ -144,10 +144,8 @@ public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
144144
self.channel.close(mode: .all, promise: nil)
145145
}
146146

147-
func initialHandshake() async throws {
147+
func waitOnActive() async throws {
148148
try await self.channelHandler.waitOnActive().get()
149-
self.executeAndForget(command: CLIENT.SETINFO(attr: .libname(valkeySwiftLibraryName)))
150-
self.executeAndForget(command: CLIENT.SETINFO(attr: .libver(valkeySwiftLibraryVersion)))
151149
}
152150

153151
/// Send RESP command to Valkey connection
@@ -174,10 +172,6 @@ public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
174172
}
175173
}
176174

177-
func executeAndForget<Command: ValkeyCommand>(command: Command) {
178-
self.channelHandler.writeAndForget(command: command, requestID: Self.requestIDGenerator.next())
179-
}
180-
181175
/// Pipeline a series of commands to Valkey connection
182176
///
183177
/// Once all the responses for the commands have been received the function returns

Sources/Valkey/ValkeyConnectionFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ package final class ValkeyConnectionFactory: Sendable {
9494
logger: logger
9595
)
9696
}.get()
97-
try await connection.initialHandshake()
97+
try await connection.waitOnActive()
9898
return connection
9999
}
100100
}

Sources/Valkey/Version.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

Tests/IntegrationTests/ValkeyTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,16 +859,4 @@ struct GeneratedCommands {
859859
}
860860
}
861861
}
862-
863-
@available(valkeySwift 1.0, *)
864-
@Test
865-
func testClientInfo() async throws {
866-
var logger = Logger(label: "Valkey")
867-
logger.logLevel = .trace
868-
try await withValkeyClient(.hostname(valkeyHostname, port: 6379), logger: logger) { client in
869-
let clients = try await String(buffer: client.clientList())
870-
#expect(clients.firstRange(of: "lib-name=\(valkeySwiftLibraryName)") != nil)
871-
#expect(clients.firstRange(of: "lib-ver=\(valkeySwiftLibraryVersion)") != nil)
872-
}
873-
}
874862
}

0 commit comments

Comments
 (0)