{"record":{"id":"7739fd2a553e6051","repo":"spacejam/sled","slug":"sled-was-already-opened-with-a-leaf-fanout-const-generic-of","errorCode":null,"errorMessage":"sled was already opened with a LEAF_FANOUT const generic of {}, and this may not be changed after initial creation. Please use Db::import / Db::export to migrate, if you wish to change the system's format.","messagePattern":"sled was already opened with a LEAF_FANOUT const generic of (.+?), and this may not be changed after initial creation\\. Please use Db::import / Db::export to migrate, if you wish to change the system's format\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/heap.rs","lineNumber":292,"sourceCode":"                Ok(PersistentSettings::V1 { leaf_fanout })\n            }\n            _ => Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                \"encountered unknown version number when reading settings cookie\",\n            )),\n        }\n    }\n\n    fn check_compatibility(\n        &self,\n        other: &PersistentSettings,\n    ) -> io::Result<()> {\n        use PersistentSettings::*;\n\n        match (self, other) {\n            (V1 { leaf_fanout: lf1 }, V1 { leaf_fanout: lf2 }) => {\n                if lf1 != lf2 {\n                    Err(io::Error::new(\n                        io::ErrorKind::Unsupported,\n                        format!(\n                            \"sled was already opened with a LEAF_FANOUT const generic of {}, \\\n                                and this may not be changed after initial creation. Please use \\\n                                Db::import / Db::export to migrate, if you wish to change the \\\n                                system's format.\",\n                            lf2\n                        ),\n                    ))\n                } else {\n                    Ok(())\n                }\n            }\n        }\n    }\n\n    fn serialize(&self) -> Vec<u8> {\n        // format: 64 bytes in total, with the last 4 being a LE crc32","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/spacejam/sled/blob/e449d17111f4a097e1c66b6db241962ccb6a4136/src/heap.rs#L274-L310","documentation":"A sled database persists the LEAF_FANOUT it was created with, and the on-disk format depends on it. check_compatibility (via verify_or_store) compares the const generic used at this open against the stored value and fails if they differ, because changing fanout in place would corrupt the layout.","triggerScenarios":"Opening an existing database directory with Config::open::<N>() where N differs from the fanout used when the database was first created (e.g. originally open::<8>(), now open::<4>()).","commonSituations":"Refactoring code and tweaking the const generic; switching branches where the fanout constant differs; running an older/newer deployment of the same app against the same data directory.","solutions":["Open the database with the same LEAF_FANOUT it was created with (match the original constant)","Use Db::export on the old-fanout database and Db::import into a database opened with the new fanout to migrate","If the data is disposable, delete the data directory and re-open with the new fanout"],"exampleFix":"// before\nlet db = config.open::<4>()?; // db was created with 8\n// after\nlet db = config.open::<8>()?; // match creation-time fanout, or export/import to migrate","handlingStrategy":"validation","validationCode":"// read the persisted fanout before opening, or centralize the constant\npub const DB_LEAF_FANOUT: usize = 4; // single source of truth, never change for existing data","typeGuard":null,"tryCatchPattern":"match Db::open(&path) {\n    Ok(db) => db,\n    Err(e) if e.to_string().contains(\"LEAF_FANOUT\") => {\n        eprintln!(\"open with the fanout the db was created with, or export/import\");\n        return Err(e.into());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Use one shared constant for LEAF_FANOUT across the codebase and never change it for existing deployments","Never hardcode the fanout at multiple call sites","Use Db::export/Db::import for any intentional format migration","Tag deployments with the fanout they require"],"tags":["rust","compatibility","const-generics","persistence"],"backgroundTag":"incompatible-configuration-value","analyzedSha":"e449d17111f4a097e1c66b6db241962ccb6a4136","analyzedAt":"2026-09-12T01:23:10.985Z","contentChangedAt":"2026-09-12T01:23:10.985Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}