Data Structure Versioning for Consistent Lock-Free Range Reads
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Concurrent reader and writer operations in index data structures like B-trees can lead to inconsistencies, where a reader may miss newly written items due to the direction of the scan and the completion times of write operations, necessitating locks that hinder performance.
Innovation Solution
Implement a system with two global version numbers - a global write version and a global read version, allowing writers to publish updates without blocking readers, and readers to ignore items with higher versions, ensuring consistent snapshots without waiting for locks.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If locks are used to ensure consistency during concurrent read and write operations, then data consistency is improved, but performance deteriorates due to wait times and blocking
Solution Approach 1:
The patent segments the versioning mechanism into two independent counters: a global write version maintained by writers and a global read version maintained by readers. This segmentation allows independent tracking of write and read operations without requiring mutual exclusion locks, thereby maintaining data consistency while eliminating performance degradation from locking.
Solution Approach 2:
The patent introduces version numbers as an intermediary mechanism between readers and writers. Instead of direct interaction requiring locks, the version numbers mediate the synchronization: writers increment the global write version for each update, and readers compare this against their cached version to determine consistency, eliminating the need for blocking locks.
2Reliability
If readers wait for locks to ensure they capture all committed writes, then consistency is improved, but response time deteriorates
Solution Approach 1:
The patent applies preliminary action by having readers proactively cache the global read version at the start of their operation and use this cached value throughout. This preliminary caching eliminates the need for continuous waiting or repeated lock acquisition, as readers can independently determine consistency by comparing the cached version with item versions without blocking.
Solution Approach 2:
The system enables self-service consistency checking where readers independently verify data consistency using the version comparison mechanism. Readers service their own consistency requirements by comparing item versions against their cached global read version, eliminating the need to wait for writer locks or external synchronization.
3Ease of operation
If the reader scans in a fixed direction (e.g., upwards from 1 to 100), then scan simplicity is improved, but consistency deteriorates when writers operate concurrently in the same direction
Solution Approach 1:
The patent changes the consistency verification parameter from position-based (relying on scan direction and completion) to version-based (comparing global read version with item versions). This parameter change allows readers to maintain simple unidirectional scanning while ensuring consistency through version comparison, independent of scan direction or writer timing.
Data Source
Figure 1~3
Figure 4
Figure 5~6
AI summary
A system comprising: memory storing a data structure comprising a plurality of items, each item comprising a key-value pair; a writer arranged to perform a plurality of write operations each to write a respective item, either a new item being added to the data structure or an existing item being modified in the data structure; and a reader configured to perform a group-read operation to read from the data structure any items having keys in a specified range. The writer is configured to maintain a global write version and the reader is configured to maintain a global read version.