Skip to content

Commit d9615dc

Browse files
rokpitrou
andauthored
GH-50046: [CI][C++] Improve caching with apache/infrastructure-actions/stash and more general cache keys (#50047)
### Rationale for this change C++ CI jobs currently key `ccache`/Docker volume caches with `hashFiles('cpp/**')`. This creates new immutable GitHub Actions cache entries whenever any C++ file changes, even though `ccache` already handles per-file invalidation internally. Recent CI logs show that when caches are restored, C++ jobs get high ccache hit rates, but GitHub cache restore misses are common and cause large CI runtime regressions. ### What changes are included in this PR? * Replace `actions/cache` with `apache/infrastructure-actions/stash/restore` and `apache/infrastructure-actions/stash/save`. * Remove `hashFiles('cpp/**')` from cache keys. * Use stable restore prefixes per job/config. ### Are these changes tested? By CI? ### Are there any user-facing changes? CI users should see faster builds.. * GitHub Issue: #50046 Lead-authored-by: Rok Mihevc <rok@mihevc.org> Co-authored-by: Antoine Pitrou <pitrou@free.fr> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent d0c59fa commit d9615dc

3 files changed

Lines changed: 110 additions & 40 deletions

File tree

.github/workflows/cpp.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ concurrency:
6363
cancel-in-progress: true
6464

6565
permissions:
66+
actions: read
6667
contents: read
6768

6869
env:
@@ -119,12 +120,11 @@ jobs:
119120
persist-credentials: false
120121
fetch-depth: 0
121122
submodules: recursive
122-
- name: Cache Docker Volumes
123-
uses: actions/cache@v5
123+
- name: Restore Docker Volumes
124+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
124125
with:
125126
path: .docker
126-
key: ${{ matrix.image }}-${{ hashFiles('cpp/**') }}
127-
restore-keys: ${{ matrix.image }}-
127+
key: cpp-${{ matrix.image }}
128128
- name: Setup Python on hosted runner
129129
if: |
130130
matrix.runs-on == 'ubuntu-latest'
@@ -149,6 +149,14 @@ jobs:
149149
sudo sysctl -w vm.mmap_rnd_bits=28
150150
source ci/scripts/util_enable_core_dumps.sh
151151
archery docker run ${{ matrix.image }}
152+
- name: Save Docker Volumes
153+
if: ${{ !cancelled() }}
154+
continue-on-error: true
155+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
156+
with:
157+
path: .docker
158+
key: cpp-${{ matrix.image }}
159+
include-hidden-files: true
152160
- name: Docker Push
153161
if: >-
154162
success() &&
@@ -254,12 +262,11 @@ jobs:
254262
id: ccache-info
255263
run: |
256264
echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT
257-
- name: Cache ccache
258-
uses: actions/cache@v5
265+
- name: Restore ccache
266+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
259267
with:
260268
path: ${{ steps.ccache-info.outputs.cache-dir }}
261-
key: cpp-ccache-macos-${{ matrix.macos-version }}-${{ hashFiles('cpp/**') }}
262-
restore-keys: cpp-ccache-macos-${{ matrix.macos-version }}-
269+
key: cpp-ccache-macos-${{ matrix.macos-version }}
263270
- name: Build
264271
run: |
265272
if [ "${{ matrix.macos-version }}" = "15-intel" ]; then
@@ -276,6 +283,13 @@ jobs:
276283
export BUILD_WARNING_LEVEL=PRODUCTION
277284
fi
278285
ci/scripts/cpp_build.sh $(pwd) $(pwd)/build
286+
- name: Save ccache
287+
if: ${{ !cancelled() }}
288+
continue-on-error: true
289+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
290+
with:
291+
path: ${{ steps.ccache-info.outputs.cache-dir }}
292+
key: cpp-ccache-macos-${{ matrix.macos-version }}
279293
- name: Test
280294
shell: bash
281295
run: |
@@ -361,17 +375,23 @@ jobs:
361375
- name: Setup MSYS2
362376
shell: msys2 {0}
363377
run: ci/scripts/msys2_setup.sh cpp
364-
- name: Cache ccache
365-
uses: actions/cache@v5
378+
- name: Restore ccache
379+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
366380
with:
367381
path: ccache
368-
key: cpp-ccache-${{ matrix.msystem_lower}}-${{ hashFiles('cpp/**') }}
369-
restore-keys: cpp-ccache-${{ matrix.msystem_lower}}-
382+
key: cpp-ccache-${{ matrix.msystem_lower}}
370383
- name: Build
371384
shell: msys2 {0}
372385
run: |
373386
export CMAKE_BUILD_PARALLEL_LEVEL=$NUMBER_OF_PROCESSORS
374387
ci/scripts/cpp_build.sh "$(pwd)" "$(pwd)/build"
388+
- name: Save ccache
389+
if: ${{ !cancelled() }}
390+
continue-on-error: true
391+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
392+
with:
393+
path: ccache
394+
key: cpp-ccache-${{ matrix.msystem_lower}}
375395
- name: Download Timezone Database
376396
if: matrix.msystem_upper == 'CLANG64'
377397
shell: bash

.github/workflows/cpp_extra.yml

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,11 @@ jobs:
141141
persist-credentials: false
142142
fetch-depth: 0
143143
submodules: recursive
144-
- name: Cache Docker Volumes
145-
uses: actions/cache@v5
144+
- name: Restore Docker Volumes
145+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
146146
with:
147147
path: .docker
148-
key: extra-${{ matrix.image }}-${{ hashFiles('cpp/**') }}
149-
restore-keys: extra-${{ matrix.image }}-
148+
key: cpp-extra-${{ matrix.image }}
150149
- name: Setup Python
151150
uses: actions/setup-python@v6
152151
with:
@@ -169,6 +168,14 @@ jobs:
169168
done
170169
fi
171170
archery docker run ${{ matrix.run-options || '' }} ${{ matrix.image }}
171+
- name: Save Docker Volumes
172+
if: ${{ !cancelled() }}
173+
continue-on-error: true
174+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
175+
with:
176+
path: .docker
177+
key: cpp-extra-${{ matrix.image }}
178+
include-hidden-files: true
172179
- name: Docker Push
173180
if: >-
174181
success() &&
@@ -204,6 +211,8 @@ jobs:
204211
contains(fromJSON(needs.check-labels.outputs.ci-extra-labels || '[]'), 'CI: Extra: C++')
205212
timeout-minutes: 240
206213
permissions:
214+
actions: read
215+
contents: read
207216
# This is for using GitHub Packages for vcpkg cache
208217
packages: write
209218
strategy:
@@ -227,12 +236,11 @@ jobs:
227236
- name: Free up disk space
228237
run: |
229238
ci/scripts/util_free_space.sh
230-
- name: Cache Docker Volumes
231-
uses: actions/cache@v5
239+
- name: Restore Docker Volumes
240+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
232241
with:
233242
path: .docker
234-
key: jni-${{ matrix.platform.runs-on }}-${{ hashFiles('cpp/**') }}
235-
restore-keys: jni-${{ matrix.platform.runs-on }}-
243+
key: jni-${{ matrix.platform.runs-on }}
236244
- name: Setup Python
237245
uses: actions/setup-python@v6
238246
with:
@@ -248,6 +256,14 @@ jobs:
248256
run: |
249257
source ci/scripts/util_enable_core_dumps.sh
250258
archery docker run cpp-jni
259+
- name: Save Docker Volumes
260+
if: ${{ !cancelled() }}
261+
continue-on-error: true
262+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
263+
with:
264+
path: .docker
265+
key: jni-${{ matrix.platform.runs-on }}
266+
include-hidden-files: true
251267
- name: Docker Push
252268
if: >-
253269
success() &&
@@ -300,12 +316,11 @@ jobs:
300316
- name: Prepare ccache
301317
run: |
302318
echo "CCACHE_DIR=${PWD}/ccache" >> ${GITHUB_ENV}
303-
- name: Cache ccache
304-
uses: actions/cache@v5
319+
- name: Restore ccache
320+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
305321
with:
306322
path: ccache
307-
key: jni-macos-${{ hashFiles('cpp/**') }}
308-
restore-keys: jni-macos-
323+
key: jni-macos
309324
- name: CMake
310325
run: |
311326
cmake \
@@ -347,6 +362,13 @@ jobs:
347362
cmake --build cpp/examples/minimal_build.build
348363
cd cpp/examples/minimal_build
349364
../minimal_build.build/arrow-example
365+
- name: Save ccache
366+
if: ${{ !cancelled() }}
367+
continue-on-error: true
368+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
369+
with:
370+
path: ccache
371+
key: jni-macos
350372

351373
odbc-linux:
352374
needs: check-labels
@@ -372,12 +394,11 @@ jobs:
372394
persist-credentials: false
373395
fetch-depth: 0
374396
submodules: recursive
375-
- name: Cache Docker Volumes
376-
uses: actions/cache@v5
397+
- name: Restore Docker Volumes
398+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
377399
with:
378400
path: .docker
379-
key: ubuntu-cpp-odbc-${{ hashFiles('cpp/**') }}
380-
restore-keys: ubuntu-cpp-odbc-
401+
key: ubuntu-cpp-odbc
381402
- name: Setup Python on hosted runner
382403
uses: actions/setup-python@v6
383404
with:
@@ -393,6 +414,14 @@ jobs:
393414
sudo sysctl -w vm.mmap_rnd_bits=28
394415
source ci/scripts/util_enable_core_dumps.sh
395416
archery docker run ubuntu-cpp-odbc
417+
- name: Save Docker Volumes
418+
if: ${{ !cancelled() }}
419+
continue-on-error: true
420+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
421+
with:
422+
path: .docker
423+
key: ubuntu-cpp-odbc
424+
include-hidden-files: true
396425
- name: Docker Push
397426
if: >-
398427
success() &&
@@ -464,12 +493,11 @@ jobs:
464493
id: ccache-info
465494
run: |
466495
echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT
467-
- name: Cache ccache
468-
uses: actions/cache@v5.0.2
496+
- name: Restore ccache
497+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
469498
with:
470499
path: ${{ steps.ccache-info.outputs.cache-dir }}
471-
key: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }}-${{ hashFiles('cpp/**') }}
472-
restore-keys: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }}-
500+
key: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }}
473501
- name: Build
474502
run: |
475503
# Homebrew uses /usr/local as prefix. So packages
@@ -486,6 +514,13 @@ jobs:
486514
export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR"
487515
export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR"
488516
ci/scripts/cpp_build.sh $(pwd) $(pwd)/build
517+
- name: Save ccache
518+
if: ${{ !cancelled() }}
519+
continue-on-error: true
520+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
521+
with:
522+
path: ${{ steps.ccache-info.outputs.cache-dir }}
523+
key: cpp-odbc-ccache-macos-${{ matrix.macos-version }}-${{ matrix.build-type }}
489524
- name: Setup Python
490525
uses: actions/setup-python@v6
491526
with:
@@ -541,6 +576,8 @@ jobs:
541576
contains(fromJSON(needs.check-labels.outputs.ci-extra-labels || '[]'), 'CI: Extra: C++')
542577
timeout-minutes: 240
543578
permissions:
579+
actions: read
580+
contents: read
544581
packages: write
545582
env:
546583
ARROW_BUILD_SHARED: ON
@@ -589,12 +626,11 @@ jobs:
589626
shell: bash
590627
run: |
591628
echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT
592-
- name: Cache ccache
593-
uses: actions/cache@v5
629+
- name: Restore ccache
630+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
594631
with:
595632
path: ${{ steps.ccache-info.outputs.cache-dir }}
596-
key: cpp-odbc-ccache-windows-x64-${{ hashFiles('cpp/**') }}
597-
restore-keys: cpp-odbc-ccache-windows-x64-
633+
key: cpp-odbc-ccache-windows-x64
598634
- name: Checkout vcpkg
599635
uses: actions/checkout@v6
600636
with:
@@ -630,6 +666,13 @@ jobs:
630666
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
631667
set VCPKG_ROOT=%VCPKG_ROOT_KEEP%
632668
bash -c "ci/scripts/cpp_build.sh $(pwd) $(pwd)/build"
669+
- name: Save ccache
670+
if: ${{ !cancelled() }}
671+
continue-on-error: true
672+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
673+
with:
674+
path: ${{ steps.ccache-info.outputs.cache-dir }}
675+
key: cpp-odbc-ccache-windows-x64
633676
- name: Register Flight SQL ODBC Driver
634677
shell: cmd
635678
run: |

.github/workflows/cpp_windows.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434
type: string
3535

3636
permissions:
37+
actions: read
3738
contents: read
3839

3940
jobs:
@@ -107,19 +108,25 @@ jobs:
107108
shell: bash
108109
run: |
109110
echo "cache-dir=$(ccache --get-config cache_dir)" >> $GITHUB_OUTPUT
110-
- name: Cache ccache
111-
uses: actions/cache@v5
111+
- name: Restore ccache
112+
uses: apache/infrastructure-actions/stash/restore@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
112113
with:
113114
path: ${{ steps.ccache-info.outputs.cache-dir }}
114-
key: cpp-ccache-windows-${{ inputs.arch }}-${{ hashFiles('cpp/**') }}
115-
restore-keys: cpp-ccache-windows-${{ inputs.arch }}-
115+
key: cpp-ccache-windows-${{ inputs.arch }}
116116
- name: Build
117117
shell: cmd
118118
env:
119119
VCVARS_ARCH: ${{ inputs.arch }}
120120
run: |
121121
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %VCVARS_ARCH%
122122
bash -c "ci/scripts/cpp_build.sh $(pwd) $(pwd)/build"
123+
- name: Save ccache
124+
if: ${{ !cancelled() }}
125+
continue-on-error: true
126+
uses: apache/infrastructure-actions/stash/save@0ba14156c9f4c3cfbe4b0c9f36339ab0f8d81e53
127+
with:
128+
path: ${{ steps.ccache-info.outputs.cache-dir }}
129+
key: cpp-ccache-windows-${{ inputs.arch }}
123130
- name: Test
124131
shell: cmd
125132
env:

0 commit comments

Comments
 (0)