21 ms·
You can compute the checksums outside of the lock. You just need to compare them inside the lock. The key thing here is that prior to the lock if data changes
by jacoblambda 6y ago
You can compute the checksums outside of the lock. You just need to compare them inside the lock.
The key thing here is that prior to the lock if data changes you recompute the checksums. As long as any change outside the lock triggers a recompute of the corresponding checksums and no changes can occur during the lock, there is no race condition.
I imagine that this may result in data getting de-synced/failing the checksum comparisons more often however it's still a net performance increase as long as the aggregate time spent re-syncing the data is less than the extra time spent waiting for checksums in the lock.
- kroolik 6y agoI think the crucial part are the retries, which havent been mentioned. In general, you cant assume your code will always read the new checksum before entering the critical section, unless you synchronize it. That is, when leaving the critical section you have to make sure that all threads waiting to enter it will recompute the hash. But, from the entering thread's perspective, you never know when youll be forced to recompute. So you've got to wait on the lock. And recompute when you are woken up. I'm not stating what they've written is wrong. Just for me it's a bit vague and looks like potential race condition.
- jacoblambda 6y agoI don't think that would enter a race condition. 1. All the zones start precomputing the checksums using a worker pool. Changes are fed into the pool with the change time stamped. The workers don't store the checksum if a newer checksum is already present. 2. The zones enter the lock/critical section. At this point new changes are no longer added to the work queue and must wait until the lock exits. The worker pool continues to process the queue. 3. The work queues are empty and the checksums are compared between zones. Those that match are "locked in" and those that don't are set aside for the next time the zones enter the lock/critical section. 4. The zones exit the lock, a timer starts, and step 1 starts again. At no point here would there be a race condition. As long as non-matching changes are pruned and retried in the next cycle, progress will be made. In certain conditions the retries could degrade overall performance but consensus is eventually achieved and the system continues to make progress.