CouchDB Conflict Resolution and Revision Trees Quiz Quiz

Explore the core principles of CouchDB conflict resolution and revision trees. This quiz assesses your understanding of document versioning, conflict scenarios, and best practices for managing data consistency in distributed document databases.

  1. Understanding Document Revisions

    In CouchDB, what does a revision ID primarily represent in the context of a document?

    1. A timestamp marking when the document was created
    2. The document's storage location on the server
    3. The primary key used to access the document
    4. A unique identifier for a specific version of a document

    Explanation: A revision ID identifies a particular version of a document, especially important when tracking document history and resolving conflicts. The primary key for documents is usually the document ID, not the revision ID. Revision IDs do not contain timestamps and are unrelated to storage location; they help CouchDB distinguish between versions when updates occur.

  2. Conflict Creation Scenario

    Which scenario is most likely to create a conflict in CouchDB's distributed system?

    1. One user updates a document and no other users access it
    2. A document is accessed but not changed by multiple users
    3. Two users update the same document on separate devices while offline
    4. A user deletes a document and then immediately updates it on the same device

    Explanation: Conflicts typically occur when the same document is changed independently on different replicas before synchronization, such as two users editing offline. Deletion followed by an update on the same device is normally resolved sequentially with no conflict. Merely accessing documents doesn’t create conflicts, and single-user updates don’t result in conflicts.

  3. Purpose of the Revision Tree

    What is the primary purpose of CouchDB's revision tree for a document?

    1. To store user permissions for the document
    2. To list all documents in a database
    3. To track and manage all changes and resolve conflicts
    4. To increase the database storage size intentionally

    Explanation: The revision tree represents the history of document changes and is essential for conflict resolution. It does not store user permissions, which are managed separately. The tree tracks versions for a single document, not a database-wide listing, and is aimed at enabling efficient management, not increasing storage artificially.

  4. Automatic Conflict Resolution Behavior

    When CouchDB detects multiple conflicting revisions for a document, what does it do by default?

    1. It deletes all but the most recent revision automatically
    2. It marks one revision as the winning revision but keeps all conflict revisions
    3. It overwrites the document without saving previous changes
    4. It merges conflicting changes together automatically

    Explanation: By default, CouchDB picks a 'winning' revision to serve when the document is requested but retains other conflicting revisions for possible manual resolution. It does not delete conflicts, nor does it overwrite or merge conflicting revisions automatically. Automatic merges, if desired, require explicit implementation.

  5. Manual Conflict Resolution

    How can you manually resolve a conflict in CouchDB after fetching all conflicting revisions?

    1. Rename the conflicting revisions only
    2. Force replication to overwrite conflicts without review
    3. Change the document's primary key
    4. Merge the changes, save a single preferred revision, and delete the remaining conflicting revisions

    Explanation: Manual conflict resolution involves reviewing conflicting revisions, merging as necessary, saving the preferred revision, and removing conflicts to prevent reoccurrence. Merely renaming revisions, forcing replication, or altering the primary key does not resolve conflicts properly and may lead to data inconsistencies.

  6. Recognizing 'Orphaned' Revisions

    What is an 'orphaned' revision in the context of CouchDB’s revision tree?

    1. An entire deleted database
    2. A revision no longer reachable from the current winning revision
    3. A document without a parent database
    4. A user account without associated documents

    Explanation: In revision trees, orphaned revisions refer to those disconnected from the current winning revision due to previous changes. The term does not apply to user accounts, documents lacking databases, or entire databases. Orphaned revisions often await compaction for removal.

  7. Role of Timestamps in Revision IDs

    Are timestamps included in CouchDB's revision IDs, and why or why not?

    1. Yes, to track the exact update time of a revision
    2. No, because revision IDs are generated from document content and parent revision
    3. Yes, to ensure each revision is unique globally
    4. No, because only document IDs contain timestamps

    Explanation: CouchDB's revision IDs are deterministic hashes based on document content and parent revisions, not on timestamps. This means they reflect changes, not update times. Document IDs also don’t include timestamps by default. Uniqueness is ensured by the content-based approach, not by time.

  8. Result of Running Database Compaction

    What is the primary effect of compaction on CouchDB’s revision trees?

    1. It removes outdated and orphaned revisions to free up storage
    2. It creates more branches in the revision tree
    3. It merges all conflicts automatically
    4. It clears all documents from the database

    Explanation: Compaction aims to clear obsolete and orphaned revisions while retaining only necessary document versions, thus saving storage. It does not delete active documents or merge conflicts. Compaction reduces, not increases, the number of branches by removing unneeded history.

  9. Determining the Winning Revision

    Which factor primarily determines the 'winning' revision among conflicting versions in CouchDB?

    1. The revision containing the largest document
    2. The revision ID with the highest sort order
    3. The document ID's lexical order
    4. The user who created the revision

    Explanation: CouchDB compares the revision IDs and selects the one with the highest sort order as the winning revision. The creator, document size, or document ID are not considered in this context. This automatic selection process keeps resolution predictable.

  10. Conflict Detection Timing

    At what point does CouchDB detect conflicts during the document lifecycle?

    1. Only at the time of document creation
    2. During replication when different document revisions are synchronized
    3. After compaction is performed
    4. While documents are being displayed to users

    Explanation: Conflicts are detected mainly during replication when different versions of the same document are synchronized from distinct sources. They are not detected upon creation, display, or after compaction. Compaction only removes obsolete data; it does not identify conflicts.