Skip to content

borg2: avoid doing an unnecessary rebuild of the index #8476

Closed

Description

@ThomasWaldmann

Note: updated for situation WITH packs.

For high-latency stores (sftp: and a lot of what's available via rclone:) a full index rebuild needs to list all objects in all packs in the store and there are potentially a lot of objects. This is slow as it needs to scan over each pack file - only borg check --repair-index shall do that.

Most commands will use the existing chunks index. Most commands only add objects, so they will just write an additional partial index to index/sha256(partial_index) with just the new index entries.

For borg create:

  • it's not a big problem if the index does not have all objects that exist in the repo. If that happens, borg create will just store something to the repo that's already there.
  • it would be a severe problem though if the index would falsely say "we have that object" and borg would not store it to the repo. the archive would then reference a non-existing object.
  • similarly it is fatal if the index points to a wrong pack_id

Activity

  1. added this to the 2.0.0b13 milestone on Oct 15, 2024
  2. changed the title [-]borg2: which commands shall rebuild a completely new ChunkIndex?[/-] [+]borg2: which commands shall do a complete rebuild of the ChunkIndex?[/+] on Oct 15, 2024
  3. ThomasWaldmann commented on Nov 16, 2024

    @ThomasWaldmann
    MemberAuthor

    borg compact emits some stats and for that it needs the stored sizes of the repository objects.

    With packs, we have pack_id, obj_offset and obj_size in the chunks index - that is enough to do stats for compact.

    As borg compact moves object to other pack ids, it needs to write the complete updated index and get rid of old index files.

  4. ThomasWaldmann commented on Nov 19, 2024

    @ThomasWaldmann
    MemberAuthor

    borg check could just try to work with the existing chunks index and not rebuild a new one.

    repository check: hash all index files, hash all pack files - if it does not find issues we assume all is fine on the repository level.

    If borg check finds index issues it would already terminate at that step.
    Otherwise it would continue with hashing the packs and report all corrupted pack ids.

    borg check --repair-index would rebuild the index by scanning packs (slow). it could either read the full pack (and then also hash it) or iterate only over the object headers.

    borg check --repair-pack <pack_ids> could repair just the given pack ids without doing a full scan over all packs. repairing a pack means determining defective objects in the pack (by reading and decrypting them, if AEAD decryption fails, the object is corrupted). all non-corrupt objects will be written to a new pack, index fixed with the new pack_id.

  5. removed this from the 2.0.0b17 milestone on May 17, 2025
  6. 59 remaining items

  7. ThomasWaldmann commented on Sep 11, 2026

    @ThomasWaldmann
    MemberAuthor

    @mr-raj12 There is a ton of commits referencing this issue, but it is still open. Please check.

  8. mr-raj12 commented on Sep 11, 2026

    @mr-raj12
    Contributor

    I checked all the commits referencing this are already in master, most of the timeline noise is from the #10094 rebases. The main parts are done: partial index writes, the read-only check without a rebuild, the header-based index rebuild in check --repair, and finish() keeping the index.
    Only two things are pending:
    pack repair (#10026) and avoiding the extra rebuilds in check --repair (#10318)
    so we can close this one and track the rest there, or would you prefer to keep it open till pack repair is done?

  9. ThomasWaldmann commented on Sep 11, 2026

    @ThomasWaldmann
    MemberAuthor

    Guess we rather keep this one open until all these places are fixed.

  10. mr-raj12 commented on Sep 27, 2026

    @mr-raj12
    Contributor

    Current state on master (f1ca9f8):

    So after #10445 what is left here is #10026 plus that --repair rebuild. Should I handle the rebuild under #8466, or do you want --repair to always rebuild, so this issue only waits on #10026?

  11. ThomasWaldmann commented on Oct 5, 2026

    @ThomasWaldmann
    MemberAuthor

    This is done on master:

    check --repair still rebuilds the index from all packs once per run, even if the stored index is intact. We accept that for now: the full walk is what finds archives that reference chunks in missing packs.

    @mr-raj12 this answers your question: --repair keeps doing that one rebuild.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions