Skip to content
Merged
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
20 changes: 11 additions & 9 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ on:
branches:
- main
paths:
- '**.swift'
- '**.yml'
- '**.swift'
- '**.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-benchmark
cancel-in-progress: true


env:
ENABLE_VALKEY_BENCHMARKS: true

jobs:
benchmark-delta:

runs-on: ${{ matrix.os }}
timeout-minutes: 15
continue-on-error: true
Expand All @@ -28,10 +30,10 @@ jobs:
matrix:
os: [ubuntu-latest]
image: ["swift:6.1"]

container:
image: ${{ matrix.image }}

steps:
- uses: actions/checkout@v4
with:
Expand All @@ -45,7 +47,7 @@ jobs:
# https://github.com/actions/checkout/issues/766
- name: Mark the workspace as safe
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}

- name: Miscellaneous
run: |
[ -d Benchmarks ] && echo "hasBenchmark=1" >> $GITHUB_ENV
Expand All @@ -56,7 +58,7 @@ jobs:
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request
- name: Checkout main
run: |
git checkout main
git checkout main
- name: Run benchmarks for branch 'main'
if: ${{ env.hasBenchmark == '1' }}
run: |
Expand All @@ -67,7 +69,7 @@ jobs:
run: |
set +e
# if we had access to fd 3 we could do this in one call eg { var=$(cmd 3>&2 2>&1 1>&3); } 2>&1
# but unfortunately we don't so we have to run the baseline check twice once to extract stdout
# but unfortunately we don't so we have to run the baseline check twice once to extract stdout
# and once to extract stderr
BENCHMARK_STDERR=$(swift package benchmark baseline check main pull_request 2>&1)
echo "exit-status=$?" >> $GITHUB_OUTPUT
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ name: CI

on:
push:
branches:
- main
paths:
- "**.swift"
- "**.yml"
branches: [main]
pull_request:
workflow_dispatch:
concurrency:
Expand All @@ -16,12 +12,12 @@ concurrency:
env:
VALKEY_HOSTNAME: valkey
jobs:
linux:
unit-tests:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
image: ["swift:6.1"]
image: ["swift:6.1", "swiftlang/swift:nightly-6.2-noble"]
container:
image: ${{ matrix.image }}
services:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/soundness.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Soundness

on:
pull_request:
workflow_dispatch:

jobs:
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
api_breakage_check_container_image: swift:latest
unacceptable_language_check_enabled: false # Valkey commands contain unacceptable language
license_header_check_enabled: false # Temporarily disable
format_check_enabled: false # Temporarily disable
13 changes: 13 additions & 0 deletions .license_header_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@@===----------------------------------------------------------------------===@@
@@
@@ This source file is part of the valkey-swift open source project
@@
@@ Copyright (c) YEARS the valkey-swift authors
@@ Licensed under Apache License v2.0
@@
@@ See LICENSE.txt for license information
@@ See CONTRIBUTORS.txt for the list of valkey-swift project authors
@@
@@ SPDX-License-Identifier: Apache-2.0
@@
@@===----------------------------------------------------------------------===@@
36 changes: 36 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.gitignore
**/.gitignore
.licenseignore
.gitattributes
.git-blame-ignore-revs
.mailfilter
.mailmap
.spi.yml
.swift-format
.swiftformatignore
.editorconfig
.github/*
*.md
*.txt
*.yml
*.yaml
*.json
Package.swift
**/Package.swift
Package@-*.swift
**/Package@-*.swift
Package.resolved
**/Package.resolved
Makefile
*.modulemap
**/*.modulemap
**/*.docc/*
*.xcprivacy
**/*.xcprivacy
*.symlink
**/*.symlink
Dockerfile
**/Dockerfile
Snippets/*
dev/git.commit.template
.unacceptablelanguageignore
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
Expand Down
41 changes: 24 additions & 17 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swift-tools-version: 6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import Foundation
import PackageDescription

let defaultSwiftSettings: [SwiftSetting] =
Expand Down Expand Up @@ -29,8 +30,6 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.29.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.23.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.8.0"),

.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.0.0"),
],
targets: [
.target(
Expand Down Expand Up @@ -72,21 +71,6 @@ let package = Package(
resources: [.process("Resources")],
swiftSettings: defaultSwiftSettings
),
.executableTarget(
name: "ValkeyBenchmarks",
dependencies: [
"Valkey",
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
],
path: "Benchmarks/ValkeyBenchmarks",
swiftSettings: defaultSwiftSettings,
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
),
.testTarget(
name: "IntegrationTests",
dependencies: [
Expand All @@ -113,3 +97,26 @@ let package = Package(
),
]
)

if ProcessInfo.processInfo.environment["ENABLE_VALKEY_BENCHMARKS"] != nil {
package.dependencies.append(
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.0.0"),
)
package.targets.append(
.executableTarget(
name: "ValkeyBenchmarks",
dependencies: [
"Valkey",
.product(name: "Benchmark", package: "package-benchmark"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
],
path: "Benchmarks/ValkeyBenchmarks",
swiftSettings: defaultSwiftSettings,
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
)
)
}
55 changes: 30 additions & 25 deletions Sources/Valkey/Cluster/ValkeyClusterClientStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,16 @@ package struct ValkeyClusterClientStateMachine<
useCase: .circuitBreaker,
duration: self.configuration.circuitBreakerDuration
)
self.clusterState = .degraded(.init(
start: self.clock.now,
pendingSuccessNotifiers: [:],
circuitBreakerTimer: .init(id: circuitBreakerTimerID),
hashSlotShardMap: healthyContext.hashSlotShardMap,
lastHealthyState: healthyContext.clusterDescription,
lastError: error
))
self.clusterState = .degraded(
.init(
start: self.clock.now,
pendingSuccessNotifiers: [:],
circuitBreakerTimer: .init(id: circuitBreakerTimerID),
hashSlotShardMap: healthyContext.hashSlotShardMap,
lastHealthyState: healthyContext.clusterDescription,
lastError: error
)
)
failedAction = ClusterDiscoveryFailedAction(
circuitBreakerTimer: timerTillUnavailable
)
Expand Down Expand Up @@ -466,7 +468,7 @@ package struct ValkeyClusterClientStateMachine<
start: degradedContext.start,
pendingSuccessNotifiers: [:],
lastHealthyState: degradedContext.lastHealthyState,
lastError: degradedContext.lastError,
lastError: degradedContext.lastError
)
)
return .init(
Expand Down Expand Up @@ -611,14 +613,16 @@ package struct ValkeyClusterClientStateMachine<

let circuitBreakerTimerID = self.nextTimerID()

self.clusterState = .degraded(.init(
start: self.clock.now,
pendingSuccessNotifiers: [:],
circuitBreakerTimer: .init(id: circuitBreakerTimerID),
hashSlotShardMap: healthyContext.hashSlotShardMap,
lastHealthyState: healthyContext.clusterDescription,
lastError: ValkeyClusterError.clusterIsMissingMovedErrorNode
))
self.clusterState = .degraded(
.init(
start: self.clock.now,
pendingSuccessNotifiers: [:],
circuitBreakerTimer: .init(id: circuitBreakerTimerID),
hashSlotShardMap: healthyContext.hashSlotShardMap,
lastHealthyState: healthyContext.clusterDescription,
lastError: ValkeyClusterError.clusterIsMissingMovedErrorNode
)
)

// move into degraded state.
let cancelTimer: TimerCancellationToken?
Expand All @@ -630,14 +634,16 @@ package struct ValkeyClusterClientStateMachine<
cancelTimer = context.cancellationToken
}

return .moveToDegraded(.init(
runDiscoveryAndCancelTimer: cancelTimer,
circuitBreakerTimer: .init(
timerID: circuitBreakerTimerID,
useCase: .circuitBreaker,
duration: self.configuration.circuitBreakerDuration
return .moveToDegraded(
.init(
runDiscoveryAndCancelTimer: cancelTimer,
circuitBreakerTimer: .init(
timerID: circuitBreakerTimerID,
useCase: .circuitBreaker,
duration: self.configuration.circuitBreakerDuration
)
)
))
)

case .shutdown:
throw ValkeyClusterError.clusterClientIsShutDown
Expand Down Expand Up @@ -675,7 +681,6 @@ package struct ValkeyClusterClientStateMachine<
}
}


package mutating func updateValkeyServiceNodes(
_ description: ValkeyClusterDescription
) -> UpdateValkeyNodesAction {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Valkey/ValkeyConnectionFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ package final class ValkeyConnectionFactory: Sendable {
commandTimeout: self.configuration.commandTimeout,
blockingCommandTimeout: self.configuration.blockingCommandTimeout,
tls: tls,
clientName: nil,
clientName: nil
)
}
}
2 changes: 1 addition & 1 deletion Tests/IntegrationTests/ValkeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ struct GeneratedCommands {
.hostname(valkeyHostname, port: 6379),
configuration: .init(
commandTimeout: .milliseconds(200),
blockingCommandTimeout: .milliseconds(500),
blockingCommandTimeout: .milliseconds(500)
),
logger: logger
) { connection in
Expand Down
18 changes: 9 additions & 9 deletions dev/generate-multi-command-encoder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ function genWithoutContextParameter() {

echo " @inlinable"
echo -n " public mutating func encodeArray<T0: RESPRenderable"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", T$(($n)): RESPRenderable"
for ((n = 1; n<how_many; n +=1)); do
echo -n ", T$((n)): RESPRenderable"
done

echo -n ">(_ t0: T0"
for ((n = 1; n<$how_many; n +=1)); do
echo -n ", _ t$(($n)): T$(($n))"
for ((n = 1; n<how_many; n +=1)); do
echo -n ", _ t$((n)): T$((n))"
done
echo ") {"

echo " self.encodeIdentifier(.array)"
echo -n " let count = t0.respEntries"
for ((n = 1; n<$how_many; n +=1)); do
echo -n " + t$(($n)).respEntries"
for ((n = 1; n<how_many; n +=1)); do
echo -n " + t$((n)).respEntries"
done
echo
echo " self.buffer.writeString(\"\\(count)\")"
echo " self.buffer.writeStaticString(\"\\r\\n\")"
for ((n = 0; n<$how_many; n +=1)); do
echo " t$(($n)).encode(into: &self)"
printf " self.buffer.writeStaticString(\"\\r\\n\")"
for ((n = 0; n<how_many; n +=1)); do
echo " t$((n)).encode(into: &self)"
done
echo " }"
}
Expand Down
Loading
Loading