iilyak commented on code in PR #5611: URL: https://github.com/apache/couchdb/pull/5611#discussion_r2248619020
########## src/couch/src/couch_bt_engine_header.erl: ########## @@ -204,17 +204,16 @@ upgrade_tuple(Old) when is_record(Old, db_header) -> Old; upgrade_tuple(Old) when is_tuple(Old) -> NewSize = record_info(size, db_header), - if - tuple_size(Old) < NewSize -> ok; - true -> erlang:error({invalid_header_size, Old}) - end, - {_, New} = lists:foldl( - fun(Val, {Idx, Hdr}) -> - {Idx + 1, setelement(Idx, Hdr, Val)} + Upgrade = tuple_size(Old) < NewSize, + ProhibitDowngrade = config:get_boolean("couchdb", "prohibit_downgrade", true), + OldKVs = + case {Upgrade, ProhibitDowngrade} of + {true, AnyBool} when is_boolean(AnyBool) -> tuple_to_list(Old); + {false, true} -> error({invalid_header_size, Old}); + {false, false} -> lists:sublist(tuple_to_list(Old), NewSize) Review Comment: I think this only works if field was added at the end. How about the case when we remove one of the fields in the middle? The downgrade in general is not solvable problem if we don't maintain fields order for a previous version. We can try something like: ``` record_info(1) -> [ disk_version, update_seq, ... ]; ... record_info(7) -> [ disk_version, update_seq, unused, id_tree_state, seq_tree_state, local_tree_state, purge_tree_state, purge_seq_tree_state, security_ptr, revs_limit, uuid, epochs, compacted_seq, purge_infos_limit, props_ptr ]; record_info(?LATEST_DISK_VERSION) -> record_info(fields, db_header). ``` If we would maintain such info we should be able to figure out what has been changed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org