{"record":{"id":"215e1f66dda6e0f7","repo":"pentaho/pentaho-kettle","slug":"couldn-t-read-the-database-cache","errorCode":null,"errorMessage":"Couldn't read the database cache","messagePattern":"Couldn't read the database cache","errorType":"exception","errorClass":"KettleFileException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/DBCache.java","lineNumber":150,"sourceCode":"      clear( null );\n\n      // Serialization support for the DB cache\n      //\n      log = new LogChannel( \"DBCache\" );\n\n      String filename = fileNameSupplier.get();\n      File file = new File( filename );\n      if ( file.canRead() ) {\n        log.logDetailed( \"Loading database cache from file: [\" + filename + \"]\" );\n\n        try ( DataInputStream dis = new DataInputStream( new FileInputStream( file ) ) ) {\n          loadFileToCache( dis );\n        }\n      } else {\n        log.logDetailed( \"The database cache doesn't exist yet.\" );\n      }\n    } catch ( Exception e ) {\n      throw new KettleFileException( \"Couldn't read the database cache\", e );\n    }\n  }\n\n  @SuppressWarnings( { \"squid:S2189\", \"squid:S1451\" } )\n  private void loadFileToCache( DataInputStream dis ) throws KettleFileException, SocketTimeoutException {\n    int counter = 0;\n    try {\n      //noinspection InfiniteLoopStatement Only way to detect EOF on DataInputStream is with exception\n      while ( true ) {\n        DBCacheEntry entry = new DBCacheEntry( dis );\n        RowMetaInterface row = new RowMeta( dis );\n        cache.put( entry, row );\n        counter++;\n      }\n    } catch ( KettleEOFException eof ) {\n      log.logDetailed( \"We read \" + counter + \" cached rows from the database cache!\" );\n    }\n  }","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/DBCache.java#L132-L168","documentation":"DBCache.getInstance()/constructor loads a persisted database-prepared-statements cache file from disk; if reading or decoding the cache file fails at any point, the load is wrapped in KettleFileException 'Couldn't read the database cache'. The constructor throws, so getInstance converts it to a RuntimeException 'Unable to create the database cache'.","triggerScenarios":"Constructing DBCache when the cache file (db.cache in the Kettle local/system folder) exists but is unreadable: corrupt/truncated file, wrong format version, or I/O error during DataInputStream read of the header or entries.","commonSituations":"Leftover db.cache from an older Kettle version after an upgrade; disk corruption or crash during a previous cache write; read-permission problems on the cache file.","solutions":["Delete/rename the corrupt cache file (db.cache) and let Kettle rebuild it — the cache is purely an optimization","Check file read permissions and disk health for the cache file's directory","If it happens after an upgrade, it's a format-version mismatch; the cache file is not portable between versions"],"exampleFix":"// before\nDBCache dbCache = DBCache.getInstance(); // RuntimeException: Couldn't read the database cache\n// after\nFile cache = new File(System.getProperty(\"KETTLE_HOME\"), \"db.cache\");\nif (cache.exists() && cache.length() == 0) { cache.delete(); }\nDBCache dbCache = DBCache.getInstance();","handlingStrategy":"try-catch","validationCode":"File cacheFile = new File(cachePath);\nif (cacheFile.exists() && (cacheFile.length() == 0 || !cacheFile.canRead())) { cacheFile.delete(); }","typeGuard":null,"tryCatchPattern":"try { DBCache dbCache = DBCache.getInstance(); } catch (RuntimeException e) { log.warn(\"DB cache unavailable: \" + e.getMessage()); /* continue without cache */ }","preventionTips":["Delete db.cache after PDI version upgrades (format is not portable)","Monitor disk health; crashes corrupt the cache file","Treat the DB cache as disposable — never rely on its persisted state"],"tags":["file-read","cache","corruption","pentaho-kettle"],"backgroundTag":"file-read-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}