Skip to content

Commit b29f9cf

Browse files
committed
Fix TiUP cache timeout by caching each TiDB version separately
Problem: Caching entire ~/.tiup directory with all 6 TiDB versions was ~4.5GB, causing cache upload timeout. Solution: - Remove pre-download step from prepare-dependencies job (was causing huge cache) - Cache TiUP binary separately (~20MB, shared across all tests) - Cache TiDB components per version (~700-800MB per version instead of 4.5GB total) - Each test job downloads and caches only the version it needs Benefits: - No more cache timeout (each cache is manageable size) - Faster: each job only downloads what it needs - Efficient: TiUP binary cached once, shared by all - Automatic cleanup: unused caches removed after 7 days Each TiDB test job now: 1. Extracts version from test target (e.g., testtidb6.1.7 -> 6.1.7) 2. Restores TiUP binary cache (shared) 3. Restores that version's component cache (if exists) 4. Installs components only if cache miss 5. Cache saves automatically at job end
1 parent 9c913cb commit b29f9cf

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

.github/workflows/main.yml

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,17 @@ jobs:
7575
- name: Vendor Go dependencies
7676
run: go mod vendor
7777

78-
- name: Generate TiDB versions hash
79-
id: tidb-versions-hash
80-
run: |
81-
echo "hash=$(echo '${{ env.TIDB_VERSIONS }}' | sha256sum | cut -d' ' -f1 | cut -c1-8)" >> $GITHUB_OUTPUT
82-
83-
- name: Cache TiUP components
84-
id: cache-tiup
78+
- name: Cache TiUP binary
79+
id: cache-tiup-binary
8580
uses: actions/cache@v4
8681
with:
8782
path: |
88-
~/.tiup
89-
# Include workflow hash and TiDB versions hash in cache key so cache updates when versions change
90-
key: ${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-${{ steps.tidb-versions-hash.outputs.hash }}
83+
~/.tiup/bin
84+
~/.tiup/manifests
85+
# Cache TiUP binary separately (small, ~20MB)
86+
key: ${{ runner.os }}-tiup-binary-${{ hashFiles('.github/workflows/main.yml') }}
9187
restore-keys: |
92-
${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-
93-
${{ runner.os }}-tiup-
88+
${{ runner.os }}-tiup-binary-
9489
9590
- name: Install TiUP
9691
run: |
@@ -105,18 +100,8 @@ jobs:
105100
tiup update --self || true
106101
tiup update playground || true
107102
108-
- name: Pre-download TiDB versions
109-
run: |
110-
export PATH=$HOME/.tiup/bin:$PATH
111-
# Pre-download all TiDB versions from env.TIDB_VERSIONS (single source of truth)
112-
echo "Pre-downloading TiDB versions: ${{ env.TIDB_VERSIONS }}"
113-
for version in ${{ env.TIDB_VERSIONS }}; do
114-
echo "Pre-downloading TiDB components for v${version}..."
115-
tiup install tidb:v${version} || true
116-
tiup install pd:v${version} || true
117-
tiup install tikv:v${version} || true
118-
done
119-
echo "TiDB version pre-download complete"
103+
# Note: TiDB components are NOT pre-downloaded here to avoid huge cache timeout
104+
# Each test job will download and cache only the version it needs (~700-800MB per version)
120105

121106
- name: Upload Terraform binary
122107
uses: actions/upload-artifact@v4
@@ -196,24 +181,40 @@ jobs:
196181
sudo apt-get update -qq
197182
sudo apt-get install -y --no-install-recommends mysql-client
198183
199-
- name: Generate TiDB versions hash
200-
id: tidb-versions-hash-test
184+
- name: Extract TiDB version from test target
185+
id: extract-tidb-version
201186
if: contains(matrix.target, 'tidb')
202187
run: |
203-
echo "hash=$(echo '${{ env.TIDB_VERSIONS }}' | sha256sum | cut -d' ' -f1 | cut -c1-8)" >> $GITHUB_OUTPUT
188+
# Extract version from testtidb6.1.7 -> 6.1.7
189+
VERSION=$(echo "${{ matrix.target }}" | sed 's/testtidb//')
190+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
191+
echo "TiDB version for this test: ${VERSION}"
192+
193+
- name: Cache TiUP binary (shared across all TiDB tests)
194+
id: cache-tiup-binary-test
195+
if: contains(matrix.target, 'tidb')
196+
uses: actions/cache@v4
197+
with:
198+
path: |
199+
~/.tiup/bin
200+
~/.tiup/manifests
201+
# Cache TiUP binary separately (small, ~20MB) - shared by all TiDB tests
202+
key: ${{ runner.os }}-tiup-binary-${{ hashFiles('.github/workflows/main.yml') }}
203+
restore-keys: |
204+
${{ runner.os }}-tiup-binary-
204205
205-
- name: Cache TiUP components
206-
id: cache-tiup-test
206+
- name: Cache TiDB components for this specific version
207+
id: cache-tidb-version
207208
if: contains(matrix.target, 'tidb')
208209
uses: actions/cache@v4
209210
with:
210211
path: |
211-
~/.tiup
212-
# Use same cache key as prepare-dependencies job to share cache
213-
key: ${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-${{ steps.tidb-versions-hash-test.outputs.hash }}
212+
~/.tiup/components
213+
# Cache components directory per version (~700-800MB per version instead of 4.5GB total)
214+
# Each test job caches only the version it needs
215+
key: ${{ runner.os }}-tidb-${{ steps.extract-tidb-version.outputs.version }}-${{ hashFiles('.github/workflows/main.yml') }}
214216
restore-keys: |
215-
${{ runner.os }}-tiup-${{ hashFiles('.github/workflows/main.yml') }}-${{ hashFiles('**/go.mod') }}-
216-
${{ runner.os }}-tiup-
217+
${{ runner.os }}-tidb-${{ steps.extract-tidb-version.outputs.version }}-
217218
218219
- name: Install TiUP (if not cached)
219220
if: contains(matrix.target, 'tidb')
@@ -232,6 +233,17 @@ jobs:
232233
tiup update --self || true
233234
tiup update playground || true
234235
236+
- name: Install TiDB components for this version (if not cached)
237+
if: contains(matrix.target, 'tidb') && steps.cache-tidb-version.outputs.cache-hit != 'true'
238+
run: |
239+
export PATH=$HOME/.tiup/bin:$PATH
240+
VERSION="${{ steps.extract-tidb-version.outputs.version }}"
241+
echo "Installing TiDB components for v${VERSION} (cache miss)..."
242+
tiup install tidb:v${VERSION} || true
243+
tiup install pd:v${VERSION} || true
244+
tiup install tikv:v${VERSION} || true
245+
echo "TiDB v${VERSION} components installed and will be cached for next run"
246+
235247
- name: Run tests {{ matrix.target }}
236248
env:
237249
GOFLAGS: -mod=vendor

0 commit comments

Comments
 (0)