-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HLC timer support for Proxy #1110
base: next
Are you sure you want to change the base?
Conversation
b7506a1
to
64d7a0b
Compare
was excited to finish this today but felt like shit all day. pushing up what I can and finishing tomorrow I hope. Think my plan will be to let this sit for at least one extra week to think about it and make adjustments. Should cap the wait time at two weeks though. |
Yeah don't have any API's at all for parsing meta responses, which has finally come to bite me :) Might be best to do that then split into another PR and upstream sooner. |
Was sick for a few days :'( I'm going to do a brute force method for the parse-from-res for now and get on with tests and integration. |
Basic roundtripping works. Basic tests are in. Still not doing amazing right now so working pretty slowly. Next step is to fill in more tests and see about adding to routelib. |
tempted to slow roll this and come back to it in a week. Got some bugs out just now but I am again off-schedule for releases and need to go cut down the PR/issue backlog some. |
Next goal: squash and rebase, split CAS work and upstream that first. |
#1115 has been split off of this. Test lib updates and Going to hold this change for one more week for adjustments/tests. The CAS change it depends on should upstream shortly. |
Note to self: need to document that this should only be used with a local clock that doesn't experience daylight savings time. or else it could throw errors for an hour once a year. |
Provides a basic "hybrid logical clock" object for use mainly in overriding CAS values with a descriptive value.
rebased now that going to hold this PR until I can use it with routelib. |
@@ -0,0 +1,14 @@ | |||
#ifndef PROXY_HLC_H | |||
#define PROXY_HLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: PROXY_HLC_H
While working on replication support for routelib, I want to:
For this, I want:
The problem with timestamps
REALTIME
clocks can go backwards on computers: often small microsecond or millisecond adjustments, and occasionally by whole seconds.MONOTONIC
clocks will always go forward, but do not represent real time. They represent the uptime of the system or start time of a process, and will slowly drift out of sync.Monotonic clocks are useful, but cannot easily be compared cross-machine and do not represent "real time" so we cannot "loosely order" lists of items or know when items were created.
Hybrid Logical Clocks
HLC's are a well used pattern and can (as we'll show later) usefully be compressed to 64bits. UUID's could also solve this problem but are 128bits or longer.
We don't need or use (at least right now) the gossip synchronization part of HLC's. Instead we use them to do loose global ordering and strict local ordering.
In this case, an HLC is defined as:
In the proxy we use
REALTIME
clock as the source for Physical Time. When a timestamp is requested we:If realtime is the same or has gone backwards:
If the logical counter would overflow:
Properties of the HLC
This gives us:
Implementation via CAS
However, our CAS value is a 64bit opaque. So long as a CAS value is generally increasing for the same item, it does not matter what the number is or if it's globally unique.
CAS ID's are generated per memcached node via a 64bit number, incrementing by one each time an item is updated. Thus CAS ID's across nodes cannot relate to each other. We also cannot set our own CAS.
Setting our own CAS
E
flag to the meta protocol, which means "if operation is successful, use this value as your new CAS"The CAS value is still opaque and does NOT directly relate to an HLC. This leaves flexibility in the system for other kinds of data consistency models:
HLC's in the proxy
HLC's are standard lua objects. They use a global data structure that is synchronized across all worker VM's in a proxy.
You can thus either have one HLC for all sets going through a proxy, or one HLC per namespace if the proxy handles many unrelated pools of data, or so on. Having many HLC's means more logical capacity for time errors.
Advanced break-fix resolution
Basically:
TODO:
Time estimate: two days of work. Likely less.