Timestamp, clock api and bugfix.
1) Add timestamp to values committed via watchable store.
2) Introduce a vanadium clock interface which provides
an estimated UTC timestamp.
3) Fix bug related to sequence number read by Wrap() method
while creating a watchable store. The bug would end up
reassigning the sequence number of the last commited tx
to a new tx to be committed by a newly created wstore
wrapper object.
This change adds a timestamp field to the LogEntry struct
which is stored for each operation that is committed as
part of a transaction using watchable store. Note that keys
that are not managed by store do not have a LogEntry
associated with them and hence will not have a timestamp.
The clock interface is introduced in this CL but for now
the implementation just uses the system time directly. This
will be addressed in the next CL to come.
Change-Id: I4e0e30ace5efc4388bbc9611d59964ac8ad59cc3
diff --git a/services/syncbase/server/watchable/transaction.go b/services/syncbase/server/watchable/transaction.go
index ace48de..e3d8422 100644
--- a/services/syncbase/server/watchable/transaction.go
+++ b/services/syncbase/server/watchable/transaction.go
@@ -117,13 +117,13 @@
return verror.New(verror.ErrInternal, nil, "seq maxed out")
}
// Write LogEntry records.
- // Note, MaxUint16 is 0xffff and MaxUint64 is 0xffffffffffffffff.
- // TODO(sadovsky): Use a more space-efficient lexicographic number encoding.
- keyPrefix := join(util.LogPrefix, fmt.Sprintf("%016x", tx.st.seq))
+ timestamp := tx.st.clock.Now()
+ keyPrefix := getLogEntryKeyPrefix(tx.st.seq)
for txSeq, op := range tx.ops {
key := join(keyPrefix, fmt.Sprintf("%04x", txSeq))
value := &LogEntry{
- Op: op,
+ Op: op,
+ CommitTimestamp: timestamp,
// TODO(sadovsky): This information is also captured in LogEntry keys.
// Optimize to avoid redundancy.
Continued: txSeq < len(tx.ops)-1,
@@ -149,3 +149,10 @@
tx.err = verror.New(verror.ErrCanceled, nil, store.ErrMsgAbortedTxn)
return tx.itx.Abort()
}
+
+// Used for testing
+func getLogEntryKeyPrefix(seq uint64) string {
+ // Note, MaxUint16 is 0xffff and MaxUint64 is 0xffffffffffffffff.
+ // TODO(sadovsky): Use a more space-efficient lexicographic number encoding.
+ return join(util.LogPrefix, fmt.Sprintf("%016x", seq))
+}