Skip to content

Instantly share code, notes, and snippets.

@vagetablechicken
Last active April 8, 2024 08:13
Show Gist options
  • Save vagetablechicken/bbd5d084987e975f31d5723dcd908e1c to your computer and use it in GitHub Desktop.
Save vagetablechicken/bbd5d084987e975f31d5723dcd908e1c to your computer and use it in GitHub Desktop.
TTL Merge Logic

stdTTL: to avoid ttl like absorlat(10,0), the simpler form should be abs(10). If not standard, we may get too large merged ttl, otherwise we should check the values if == 0. Standard is better.

so after std, we may get two ttl, abs(0), abs(x), lat(0), lat(x), absandlat(x,y), absorlat(x,y), x>0 and y>0.

lat(0) to abs(0)?

If two ttl are the same type, it's ok to merge the value, 0 means never exipres.

If different types, I'll try my best to set a small ttl to cover the two ttl. 4 type merge 2, so there're 6 cases.

  1. absandlat + ?: 3 cases

absandlat(x,y)+abs(z), absandlat(x,y)+abs(0): don't merge lat(cuz abs type lat is0), so just merge abs, 0 means max.

absandlat(x,y)+lat(z), absandlat(x,y)+lat(0): the same

absandlat(x,y)+absorlat(k,j): we need to store more to avoid delete valid records, so use absandlat. e.g. when k>x, j>y, we must use absandlat, otherwise, try to use absorlat, the record in x(absandlat=0, no expires) will be expired if it is the j+1 record.

  1. absorlat + ?: 2 cases

absorlat(x,y)+abs(z), absorlat(x,y)+abs(0): leave abs, lat should be removed, even z<x, the records size in z may > y, but it shouldn't be expired.

absorlat(x,y)+lat(z), absorlat(x,y)+lat(0): the same

  1. abs + lat: 1 case

just absandlat, set values, don't merge abs(x,0) with lat(0,y) considering 0=max, it'll be both 0, never exipres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment