3

According to their pager, it says "The TT.after() and TT.before() methods are convenience wrappers around TT.now()."

And according to What is the TrueTime API in Google's Spanner?

It also provides two functions:

  1. after(t) returns true if t has definitely passed. E.g. t < now().earliest.
  2. before(t) returns true if t has definitely not arrived, or t > now().latest.

My question are:

  1. On all servers in spanner, does TT.now() return the same result?
  2. For a given time t, is possible that on server A before(t) is true and on server B is false?
  3. Are they monotonic? e.g. On server A, TT.after(t) is true, sometime later, is it possible that TT.after(t) is false?
Community
  • 1
  • 1
Tim
  • 475
  • 3
  • 15
  • Since Google Cloud Spanner is proprietary, most of the information about the specifics of its implementation is internal. It is very likely that what you are looking for is outside the scope of the documentation available to the public, which means we wouldn’t be able to accurately answer the questions posed here. In any case, is there a use case for this question? Are you implementing some service which relies on having this information in order to properly work? – George Jul 04 '19 at 21:46
  • @George I'm just curious. "before(t) returns true if t has definitely not arrived" means for that server or for the entire cluster? – Tim Jul 05 '19 at 01:15

2 Answers2

3

For details of how Truetime and Spanner work, look at section 3 of the Spanner Whitpaper (1).

A discussion of how it could be implemented is in the question "Why is Google's TrueTime API hard to duplicate?" (2)

From the Spanner Whitepaper, a TrueTime value is not a single value but a timestamp range which is guaranteed to contain the absolute value. This range takes into account the potential clock drift - which in Google's network, with syncing the server clocks to the atomic/GPS reference time every 30secs is up to 7ms (from the whitepaper).

So if TTstamp1 is the range (t1_lo, t1_hi) and TTstamp2 is the range (t2_lo, t2_hi), then before() and after() simply compare the extremes of these ranges to confirm that they do not overlap.

TTstamp1.before(TTValue2) = t1_hi < t2_lo
TTstamp1.after(TTValue2) = t1_lo > t2_hi

The answer to your questions are therefore:

  1. No, TT.now() does not return the same result on all servers even if called at the exact same instant. However the values obtained on all servers when called at that instant will overlap each other, meaning that none of them are before nor after each other.

  2. So for a given TrueTime t, it is technically possible that on server A t.before(now) is true and on server B t.before(now) is false due to the overlap comparison and the differences between the possible ranges. This is not an problem for Spanner because it will wait until there is no overlap (t.before(now)==true) before committing a transaction and storing its timestamp.

(Note: this information is derived from the public whitepapers and documentation)

RedPandaCurios
  • 2,264
  • 12
  • 20
0

According to the picture below , TT.after(t) is TT.now().earliest > t, so I think it's quite possible that TT.before(t) is TT.now().latest < t.

Try to answer my own question:

  1. TT.now() does not return the same result on all servers at the same time.
  2. Yes, it's possbile. Even though for case of TT.after(),this means time t has definitely passed only on some servers.
  3. I don't know. If it is possbile, then it means t has definitely passed, and then not sure about that, which sounds a little weird

I think "definitely" in their description is a little misleading, they should simply be "higher than the latest" or "lower than the earliest”

enter image description here

Tim
  • 475
  • 3
  • 15