osd: Free the old object state in mark_object() only after inserting the new one #169
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:mark-object-reuse"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
mark_object()freed the object's old state entry (remove_object_from_state()+deref_object_state()) before it inserted the new one (add_object_to_set()). When the object is alone in its state and nothing else holds the entry, thestate_dictnode is freed and the very next insert gets the same block from malloc (glibc's tcache), so the new state has the old address. Callers detect a swap by comparing the pointers:continue_primary_read()retries a corrupted read only ifop_data->object_statechanged, so it sees "no change" and finishes with EIO although a healthy copy is left. The write path compares the same way. The read pin from3bf0b45adoesn't help:mark_object(ref=true)drops it before the insert.Example: replica 3, one copy already marked corrupted by an earlier read (the object alone in state {1 corrupted, 2, 3}); a read then gets EIO from the second copy. The second copy is marked, but the read returns EIO instead of reading the third one. Clients retry EIO after
client_eio_retry_interval, so the visible effect is a stall of about a second, not an error, unless the retry interval is 0.Fix: unlink the object from the old state, insert it into the new one, and release the old entry last, so the two can never share an address. Nothing between the two steps looks at the old entry:
state_dictis only walked at peering, and PG flags and counters come from the per-object maps thatremove_object_from_state()has already updated.The
if (ref)lines next to this change are the ones #158 touches; the hunks don't overlap.Tested: new
test_read_eio_retries_when_mark_reuses_stateinosd_test. Without the fix the second read fails with EIO and sends nothing to the third OSD (the old and new state pointers are equal); withGLIBC_TUNABLES=glibc.malloc.tcache_count=0the unfixed code passes, so the address reuse is the whole cause. With the fix the read retries on the third OSD and returns the data. The wholeosd_testpasses.Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA
Rebase
2b716f60b4to96418f0a68