def create_or_update_chain(pid, sid, obsoletes_pid, obsoleted_by_pid):
    chain_model = _get_chain_by_pid(pid)
    if chain_model:
        _set_chain_sid(chain_model, sid)
    else:
        _add_sciobj(pid, sid, obsoletes_pid, obsoleted_by_pid)
    _update_sid_to_last_existing_pid_map(pid)