Skip to content

Commit dc6ae45

Browse files
jorgeebentsherman
authored andcommitted
Enable global caching via NXF_GLOBALCACHE_PATH environment variable
Signed-off-by: jorgee <[email protected]> Signed-off-by: Ben Sherman <[email protected]>
1 parent 5d36e89 commit dc6ae45

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

docs/reference/env-vars.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ The following environment variables control the configuration of the Nextflow ru
118118
: The file storage path against which relative file paths are resolved.
119119
: For example, with `NXF_FILE_ROOT=/some/root/path`, the use of `file('hello')` will be resolved to the absolute path `/some/root/path/hello`. A remote root path can be specified using the usual protocol prefix, e.g. `NXF_FILE_ROOT=s3://my-bucket/data`. Files defined using an absolute path are not affected by this setting.
120120

121+
`NXF_GLOBALCACHE_PATH`
122+
: :::{versionadded} 26.04.0
123+
:::
124+
: Enable global caching, using the given path as cache root.
125+
: This allows cached tasks to be re-used by different runs. Enabling global caching implicitly enables resume, and sets the work directory to `${NXF_GLOBALCACHE_PATH}/work`.
126+
121127
`NXF_HOME`
122128
: Nextflow home directory (default: `$HOME/.nextflow`).
123129

modules/nextflow/src/main/groovy/nextflow/Session.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class Session implements ISession {
426426
return null
427427
final String path = cloudcache.path
428428
final result = path ? FileHelper.asPath(path) : workDir
429-
if( result.scheme !in ['s3','az','gs'] ) {
429+
if( result.scheme !in ['file','s3','az','gs'] ) {
430430
throw new IllegalArgumentException("Storage path not supported by Cloud-cache - offending value: '${result}'")
431431
}
432432
return result

modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import nextflow.cli.CmdNode
3333
import nextflow.cli.CmdRun
3434
import nextflow.exception.AbortOperationException
3535
import nextflow.exception.ConfigParseException
36+
import nextflow.file.FileHelper
3637
import nextflow.secret.SecretsLoader
3738
import nextflow.secret.SecretsProvider
3839
import nextflow.util.HistoryFile
@@ -754,6 +755,24 @@ class ConfigBuilder {
754755
if( cliParams )
755756
config.params = mergeMaps( (Map)config.params, cliParams, NF.strictMode )
756757

758+
// -- use global cache if specified
759+
final globalCachePath = env.get('NXF_GLOBALCACHE_PATH')
760+
if( globalCachePath ) {
761+
final sessionId = new UUID(0L, 0L).toString()
762+
config.resume = sessionId
763+
config.cloudcache = [
764+
enabled: true,
765+
path: "${globalCachePath}/cache"
766+
]
767+
config.workDir = "${globalCachePath}/work"
768+
769+
log.warn "Enabling global cache. This will enable resume, set the cache path to ${config.cloudcache.path}, and set the work directory to ${config.workDir}"
770+
771+
final cachePath = FileHelper.asPath(globalCachePath)
772+
cachePath.resolve("cache/${sessionId}").mkdirs()
773+
}
774+
775+
// -- set container options
757776
if( cmdRun.withoutDocker && config.docker instanceof Map ) {
758777
// disable docker execution
759778
log.debug "Disabling execution in Docker container as requested by command-line option `-without-docker`"

modules/nextflow/src/main/groovy/nextflow/processor/TaskHasher.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class TaskHasher {
5050

5151
final keys = new ArrayList<Object>()
5252

53-
// add session UUID
54-
keys << session.uniqueId
55-
56-
// add fully-qualified process name
57-
keys << task.processor.name
53+
// add session id and process name if global caching is not enabled
54+
if( session.uniqueId != new UUID(0L, 0L) ) {
55+
keys << session.uniqueId
56+
keys << task.processor.name
57+
}
5858

5959
// add source code of `script:` or `exec:` block
6060
//

modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class ScriptRunner {
260260
}
261261

262262
// -- when resume, make sure the session id exists in the executions history
263-
if( session.resumeMode && !HistoryFile.DEFAULT.checkExistsById(session.uniqueId.toString()) ) {
263+
if( session.resumeMode && session.uniqueId != new UUID(0L, 0L) && !HistoryFile.DEFAULT.checkExistsById(session.uniqueId.toString()) ) {
264264
throw new AbortOperationException("Can't find a run with the specified id: ${session.uniqueId} -- Execution can't be resumed")
265265
}
266266

0 commit comments

Comments
 (0)