Skip to content

Fix unaligned reads for graph links offsets - #5737

Closed
xzfc wants to merge 1 commit into
masterfrom
links-comp-fix-master
Closed

xzfc wants to merge 1 commit into
masterfrom
links-comp-fix-master

Conversation

@xzfc

@xzfc xzfc commented Jan 6, 2025

Copy link
Copy Markdown
Member

The change #5491 (included in version v1.12.5) introduced the following crash when reading some old snapshots.

Repro:

PUT collections/test/snapshots/recover?wait=true
{ "location": "https://snapshots.qdrant.io/qdrant-web-site-docs-2024-04-05.snapshot" }

POST /collections/test/points/recommend
{ "positive": [0], "limit": 10 }

Results in the following crash in graph_links.rs:490:

'Service internal error: 1 of 1 read operations failed:
Service internal error: task 128 panicked with message "called Option::unwrap() on a None value"

Reason: old versions of qdrant (before v1.8.2) did store graph links offsets in a non-aligned array, but the new code assumes it's aligned. For the reference, non-faulty code snippet in v0.12.4 uses u64::from_ne_bytes.

fn get_links_offset(offsets_data: &[u8], idx: usize) -> usize {
let begin = size_of::<u64>() * idx;
let end = begin + size_of::<u64>();
let bytes = &offsets_data[begin..end];
// unwrap is safe because we know that bytes slice is always 8 bytes
let bytes: [u8; 8] = bytes.try_into().unwrap();
u64::from_ne_bytes(bytes) as usize
}

This PR replaces usage of u64 with zerocopy::native_endian::U64 which doesn't require alignment. This is a fix for the master branch, there will be a separate PR for the dev branch.

@xzfc
xzfc requested review from generall and timvisee January 6, 2025 17:16
@generall

generall commented Jan 6, 2025

Copy link
Copy Markdown
Member

please rebase to latest dev, there are fixes for poetry version

@xzfc

xzfc commented Jan 6, 2025

Copy link
Copy Markdown
Member Author

This is a PR for master. The code in dev diverges significantly, so it would require a different fix/PR.

Perhaps, we need to cherry-pick that poetry fix to the master.

@generall

generall commented Jan 6, 2025

Copy link
Copy Markdown
Member

If we are going to patch release, it will likely be from dev, I don't think we need changes in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants