{"record":{"id":"0ee7cf751cb941ba","repo":"cube-js/cube","slug":"impossible","errorCode":null,"errorMessage":"impossible","messagePattern":"impossible","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"rust/cubestore/cubestore/src/store/compaction.rs","lineNumber":1431,"sourceCode":"        ) > Ordering::Equal\n        {\n            *row_counts.last_mut().unwrap() += b.num_rows();\n            return WriteBatchTo::Current;\n        }\n        for i in 0..b.num_rows() {\n            if cmp_partition_key(key_size, keys[next_key].values().as_slice(), b.columns(), i)\n                <= Ordering::Equal\n            {\n                *row_counts.last_mut().unwrap() += i;\n                row_counts.push(0);\n\n                next_key += 1;\n                return WriteBatchTo::Next {\n                    rows_for_current: i,\n                };\n            }\n        }\n        panic!(\"impossible\")\n    };\n    let num_files = files.len();\n    write_to_files_impl(records, store, files, table, pick_writer).await?;\n\n    let mut row_counts: Vec<usize> = take(row_counts.lock().unwrap().as_mut());\n    assert!(\n        row_counts.len() <= num_files,\n        \"{} <= {}\",\n        row_counts.len(),\n        num_files\n    );\n    row_counts.resize(num_files, 0);\n    Ok(row_counts)\n}\n\n/// One chunk file produced by `write_chunks_split_into_children`: which child (index into the\n/// ordered children list) it belongs to, the temp file it was written to, its row count and the\n/// min/max sort-key rows. Empty children yield an entry with `num_rows == 0`.","sourceCodeStart":1413,"sourceCodeEnd":1449,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubestore/cubestore/src/store/compaction.rs#L1413-L1449","documentation":"An internal invariant panic in write_to_files_by_keys: the closure that picks which output file each record row should be written to during partition splitting must always return either a writer or a Next marker; if the loop exhausts all files without matching, the code concludes an impossible state and panics. It indicates a bug in split_single_partition's file-boundary logic, not user error.","triggerScenarios":"split_single_partition computing row/file boundaries such that a record's key falls beyond all precomputed writer ranges while iterating records in write_to_files_by_keys.","commonSituations":"Encountered only during compaction/partition splitting with an internal logic bug, corrupted partition metadata, or a version mismatch between metadata and data files; effectively unreachable for correct inputs.","solutions":["Upgrade CubeStore to the latest version (likely a fixed internal bug)","Reduce the affected partition's data or re-run compaction to see if it reproduces","Collect the partition/table identifiers and file a bug report with logs","Restore the affected partition from a backup if metadata is corrupted"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// panic aborts the process; supervise and retry, escalating after repeated failures\nsupervisor: on cubestored crash, capture logs; if panic 'impossible' at compaction.rs occurs >=3 times on the same partition, quarantine the partition and alert.","preventionTips":["Keep CubeStore upgraded to the latest patch release","Avoid mixing metastore/data produced by different CubeStore versions","Back up partitions before manual compaction operations","Report the panic with partition IDs to maintainers"],"tags":["panic","internal-bug","compaction","invariant"],"backgroundTag":"internal-invariant-panic","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}