{"record":{"id":"1a124ca4a0963f9c","repo":"apache/pulsar","slug":"error-init-metastore-state","errorCode":null,"errorMessage":"Error init metastore state","messagePattern":"Error init metastore state","errorType":"exception","errorClass":"MetadataStoreException","httpStatus":null,"severity":"error","filePath":"pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/RocksdbMetadataStore.java","lineNumber":244,"sourceCode":"            Set<PosixFilePermission> perms = PosixFilePermissions.fromString(\"rwxr-x---\");\n            Files.setPosixFilePermissions(dataPath, perms);\n        } catch (IOException e) {\n            throw new MetadataStoreException(\"Fail to create RocksDB file directory\", e);\n        }\n\n        db = openDB(dataPath.toString(), metadataStoreConfig.getConfigFilePath());\n\n        this.writeOptions = new WriteOptions().setSync(metadataStoreConfig.isFsyncEnable());\n        this.optionCache = new ReadOptions().setFillCache(true);\n        this.optionDontCache = new ReadOptions().setFillCache(false);\n\n        try {\n            sequentialIdGenerator = loadSequentialIdGenerator();\n            instanceId = loadInstanceId();\n        } catch (RocksDBException exception) {\n            log.error().exception(exception).log(\"Error while init metastore state\");\n            close();\n            throw new MetadataStoreException(\"Error init metastore state\", exception);\n        }\n        dbStateLock = new ReentrantReadWriteLock();\n        log.info().attr(\"url\", metadataStoreConfig).attr(\"instanceId\", instanceId).log(\"new RocksdbMetadataStore\");\n    }\n\n    private long loadInstanceId() throws RocksDBException {\n        long instanceId;\n        byte[] value = db.get(optionDontCache, INSTANCE_ID_KEY);\n        if (value != null) {\n            instanceId = toLong(value) + 1;\n        } else {\n            instanceId = 0;\n        }\n        db.put(writeOptions, INSTANCE_ID_KEY, toBytes(instanceId));\n        return instanceId;\n    }\n\n    private AtomicLong loadSequentialIdGenerator() throws RocksDBException {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/RocksdbMetadataStore.java#L226-L262","documentation":"At the end of construction the store loads its sequential-id generator state and instance id from RocksDB. If either read raises RocksDBException, the constructor closes the partially-open DB and rethrows as MetadataStoreException('Error init metastore state').","triggerScenarios":"loadSequentialIdGenerator() or loadInstanceId() fails on a RocksDB read (IO error, corruption, checksum mismatch) right after the DB was opened.","commonSituations":"Corrupt or partially-restored RocksDB directory; disk I/O errors; the directory was concurrently opened/closed by another process; interrupted prior shutdown.","solutions":["Read the wrapped RocksDBException cause (and RocksDB LOG) to identify the failing column/record.","Restore the data directory from a backup; RocksDB corruption usually cannot be repaired in place.","Ensure no other process holds the same data directory open (check for stale lock files).","If the state is expendable, remove the data directory and let the store re-initialize fresh."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    MetadataStore s = MetadataStoreFactory.create(rocksdbUrl);\n} catch (MetadataStoreException e) {\n    if (e.getMessage().equals(\"Error init metastore state\")) {\n        log.error(\"RocksDB state unreadable; restore from backup or wipe dir\", e.getCause());\n    } else throw e;\n}","preventionTips":["Ensure single-process ownership of the data directory","Back up the directory regularly with consistent checkpoints","Shut down cleanly; investigate crashes that interrupt WAL flushes"],"tags":["rocksdb","initialization","io"],"backgroundTag":"rocksdb-init-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}