{"record":{"id":"fd2d65ba8fe6dccf","repo":"apache/hadoop","slug":"cannot-start-trash-emptier-with-negative-interval","errorCode":null,"errorMessage":"Cannot start trash emptier with negative interval. Set fs.trash.interval to a positive value.","messagePattern":"Cannot start trash emptier with negative interval\\. Set fs\\.trash\\.interval to a positive value\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java","lineNumber":1066,"sourceCode":"    if (plugins != null) {\n      for (ServicePlugin p : plugins) {\n        try {\n          p.stop();\n        } catch (Throwable t) {\n          LOG.warn(\"ServicePlugin \" + p + \" could not be stopped\", t);\n        }\n      }\n    }   \n    stopHttpServer();\n  }\n  \n  private void startTrashEmptier(final Configuration conf) throws IOException {\n    long trashInterval =\n        conf.getLong(FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);\n    if (trashInterval == 0) {\n      return;\n    } else if (trashInterval < 0) {\n      throw new IOException(\"Cannot start trash emptier with negative interval.\"\n          + \" Set \" + FS_TRASH_INTERVAL_KEY + \" to a positive value.\");\n    }\n    \n    // This may be called from the transitionToActive code path, in which\n    // case the current user is the administrator, not the NN. The trash\n    // emptier needs to run as the NN. See HDFS-3972.\n    FileSystem fs = SecurityUtil.doAsLoginUser(\n        new PrivilegedExceptionAction<FileSystem>() {\n          @Override\n          public FileSystem run() throws IOException {\n            FileSystem dfs = new DistributedFileSystem();\n            dfs.initialize(FileSystem.getDefaultUri(conf), conf);\n            return dfs;\n          }\n        });\n    this.emptier = new Thread(new Trash(fs, conf).getEmptier(), \"Trash Emptier\");\n    this.emptier.setDaemon(true);\n    this.emptier.start();","sourceCodeStart":1048,"sourceCodeEnd":1084,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java#L1048-L1084","documentation":"NameNode.startTrashEmptier reads fs.trash.interval from the configuration: 0 disables the emptier (method returns), but any negative value throws IOException at startup because a trash-emptier thread cannot be scheduled with a negative interval. The NameNode refuses to start the background emptier with a nonsensical period.","triggerScenarios":"core-site.xml (or an equivalent config source) sets fs.trash.interval to a negative number and the NameNode starts or transitions to active (startTrashEmptier runs on the active NN; see also HDFS-3972 where it runs as the login user).","commonSituations":"Operators set -1 trying to 'disable' trash (the correct disable value is 0); configuration management templates that compute the interval and can emit negatives; copy-paste from docs of other systems where -1 means infinite.","solutions":["Set fs.trash.interval to 0 in core-site.xml to disable the trash emptier, or to a positive value in minutes (e.g., 60, 1440).","Restart the NameNode after fixing the configuration so startTrashEmptier re-reads it.","Fix the automation/template that produced the negative value so it can never emit one again."],"exampleFix":"<!-- before: core-site.xml -->\n<property><name>fs.trash.interval</name><value>-1</value></property>\n\n<!-- after -->\n<property><name>fs.trash.interval</name><value>0</value></property> <!-- 0 disables trash emptier; positive = retention minutes -->","handlingStrategy":"validation","validationCode":"// fail fast at deploy time, before the NN hits it at startup\nlong interval = conf.getLong(FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);\nPreconditions.checkArgument(interval >= 0,\n    \"fs.trash.interval must be >= 0 (0 disables), got %s\", interval);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint core-site.xml: fs.trash.interval must be 0 or positive minutes; -1 is never valid.","In configuration templates, clamp computed intervals to >= 0 with a sane default.","Use 'hdfs getconf -confKey fs.trash.interval' in smoke tests before starting services."],"tags":["hdfs","namenode","configuration","trash","startup"],"backgroundTag":"invalid-configuration-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}