Skip to content

Commit

Permalink
Disable cache backup/restore if cloudcache is used (#4125)
Browse files Browse the repository at this point in the history

Signed-off-by: Ben Sherman <[email protected]>
Signed-off-by: Paolo Di Tommaso <[email protected]>
Co-authored-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
bentsherman and pditommaso authored Jul 25, 2023
1 parent b14674d commit 46e828e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class CacheCommand implements PluginAbstractExec {

protected void cacheBackup() {
log.debug "Running Nextflow cache backup"
new CacheManager(System.getenv()).saveCacheFiles()
final manager = new CacheManager(System.getenv())
manager.saveCacheFiles()
manager.saveMiscFiles()
}

protected void archiveLogs(Session sess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class CacheManager {
if( !sessionUuid )
throw new AbortOperationException("Missing target uuid - cache sync cannot be performed")

this.localCachePath = Paths.get(".nextflow/cache/${sessionUuid}")
// ignore the `localCachePath` when the `NXF_CLOUDCACHE_PATH` variable is set because
// the nextflow cache metadata is going to be managed (and stored) via the nf-cloudcache plugin
if( !env.containsKey('NXF_CLOUDCACHE_PATH') )
this.localCachePath = Paths.get(".nextflow/cache/${sessionUuid}")

if( env.NXF_OUT_FILE )
localOutFile = Paths.get(env.NXF_OUT_FILE)
Expand All @@ -80,7 +83,7 @@ class CacheManager {
}

protected void restoreCacheFiles() {
if( !remoteWorkDir || !sessionUuid )
if( !remoteWorkDir || !sessionUuid || !localCachePath )
return

if(!Files.exists(remoteCachePath)) {
Expand All @@ -100,7 +103,7 @@ class CacheManager {
}

protected void saveCacheFiles() {
if( !remoteWorkDir || !sessionUuid )
if( !remoteWorkDir || !sessionUuid || !localCachePath )
return

if( !Files.exists(localCachePath) ) {
Expand All @@ -118,7 +121,9 @@ class CacheManager {
catch (Throwable e) {
log.warn "Failed to backup resume metadata to remote store path: ${remoteCachePath.toUriString()} — cause: ${e}", e
}
}

protected void saveMiscFiles() {
// — upload out file
try {
if( localOutFile?.exists() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CacheManagerTest extends Specification {
tower.localCachePath.resolve('db/yyy').text = 'data yyy'
and:
tower.saveCacheFiles()
tower.saveMiscFiles()
then:
tower.remoteCachePath.resolve('index-foo').text == 'index foo'
tower.remoteCachePath.resolve('db/xxx').text == 'data xxx'
Expand All @@ -99,6 +100,7 @@ class CacheManagerTest extends Specification {
tower.localCachePath.resolve('db/delta').text = 'data delta'
and:
tower.saveCacheFiles()
tower.saveMiscFiles()
then:
tower.remoteCachePath.resolve('index-bar').text == 'index bar'
tower.remoteCachePath.resolve('db/alpha').text == 'data alpha'
Expand Down Expand Up @@ -154,4 +156,26 @@ class CacheManagerTest extends Specification {
cleanup:
folder?.deleteDir()
}

def 'should not backup/restore cache if cloudcache is enabled' () {
given:
def ENV = [
NXF_UUID: 'uuid',
NXF_WORK: '/work',
NXF_CLOUDCACHE_PATH: 's3://my-bucket/cache'
]
and:
def tower = new CacheManager(ENV)

when:
tower.saveCacheFiles()
then:
0 * tower.getRemoteCachePath()

when:
tower.restoreCacheFiles()
then:
0 * tower.getRemoteCachePath()

}
}

0 comments on commit 46e828e

Please sign in to comment.