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.
In CouchDB, what does a revision ID primarily represent in the context 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.
Which scenario is most likely to create a conflict in CouchDB's distributed system?
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.
What is the primary purpose of CouchDB's revision tree for a document?
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.
When CouchDB detects multiple conflicting revisions for a document, what does it do by default?
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.
How can you manually resolve a conflict in CouchDB after fetching all 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.
What is an 'orphaned' revision in the context of CouchDB’s revision tree?
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.
Are timestamps included in CouchDB's revision IDs, and why or why not?
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.
What is the primary effect of compaction on CouchDB’s revision trees?
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.
Which factor primarily determines the 'winning' revision among conflicting versions in CouchDB?
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.
At what point does CouchDB detect conflicts during the document lifecycle?
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.