{"record":{"id":"e50ec744d6764f19","repo":"v2rayA/v2rayA","slug":"system-config-count-mismatch-boltdb-d-sqlite-d","errorCode":null,"errorMessage":"system config count mismatch: BoltDB=%d, SQLite=%d","messagePattern":"system config count mismatch: BoltDB=(.+?), SQLite=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/db/migrate.go","lineNumber":530,"sourceCode":"// verifyMigration compares data counts between BoltDB and SQLite\nfunc verifyMigration(boltDB *bbolt.DB, sqldb *sql.DB) error {\n\tlog.Info(\"Verifying migration integrity...\")\n\n\terr := boltDB.View(func(btx *bbolt.Tx) error {\n\t\t// Verify system config\n\t\tsystemBkt := btx.Bucket([]byte(\"system\"))\n\t\tif systemBkt != nil {\n\t\t\tvar boltCount int\n\t\t\tsystemBkt.ForEach(func(_, _ []byte) error {\n\t\t\t\tboltCount++\n\t\t\t\treturn nil\n\t\t\t})\n\n\t\t\tvar sqlCount int\n\t\t\tsqldb.QueryRow(\"SELECT COUNT(*) FROM system_config\").Scan(&sqlCount)\n\n\t\t\tif boltCount != sqlCount {\n\t\t\t\treturn fmt.Errorf(\"system config count mismatch: BoltDB=%d, SQLite=%d\", boltCount, sqlCount)\n\t\t\t}\n\t\t\tlog.Info(\"System config: %d entries verified\", boltCount)\n\t\t}\n\n\t\t// Verify servers\n\t\ttouchBkt := btx.Bucket([]byte(\"touch\"))\n\t\tif touchBkt != nil {\n\t\t\tserversData := touchBkt.Get([]byte(\"servers\"))\n\t\t\tif serversData != nil {\n\t\t\t\tboltServerCount := len(gjson.ParseBytes(serversData).Array())\n\t\t\t\tvar sqlServerCount int\n\t\t\t\tsqldb.QueryRow(\"SELECT COUNT(*) FROM servers WHERE type = 'server'\").Scan(&sqlServerCount)\n\t\t\t\tif boltServerCount != sqlServerCount {\n\t\t\t\t\treturn fmt.Errorf(\"server count mismatch: BoltDB=%d, SQLite=%d\", boltServerCount, sqlServerCount)\n\t\t\t\t}\n\t\t\t\tlog.Info(\"Servers: %d entries verified\", boltServerCount)\n\t\t\t}\n","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/service/db/migrate.go#L512-L548","documentation":"Post-migration integrity check in verifyMigration: the number of rows migrated into system_config differs from the count of entries in the BoltDB \"system\" bucket, meaning the migration dropped or duplicated system configuration; both counts are reported and the migration is treated as failed.","triggerScenarios":"Thrown at service/db/migrate.go:530 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete the SQLite DB and rerun migration","Restore BoltDB from backup before retrying","Manually diff system keys to find missing entries"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}