syncbase: store log entries chronologically

This change makes it easier for clients to iterate over log entries
chronologically, which is the common case (both for client watch and for sync
watch). Originally I used reverse chronological order because it was more
efficient for determining the most recent sequence number (done once, at
startup time) - but that's not what we should optimize for.

Change-Id: I84879054ed5617f23f8d717e0e363aee12ea2873
diff --git a/services/syncbase/server/watchable/transaction.go b/services/syncbase/server/watchable/transaction.go
index 17c899f..1be1b85 100644
--- a/services/syncbase/server/watchable/transaction.go
+++ b/services/syncbase/server/watchable/transaction.go
@@ -6,6 +6,7 @@
 
 import (
 	"fmt"
+	"math"
 	"sync"
 
 	"v.io/syncbase/x/ref/services/syncbase/server/util"
@@ -109,17 +110,18 @@
 	tx.st.mu.Lock()
 	defer tx.st.mu.Unlock()
 	// Check sequence numbers.
-	if uint64(len(tx.ops)) > MaxUint16 {
+	if uint64(len(tx.ops)) > math.MaxUint16 {
 		return verror.New(verror.ErrInternal, nil, "too many ops")
 	}
-	if tx.st.seq == MaxUint64 {
+	if tx.st.seq == math.MaxUint64 {
 		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", MaxUint64-tx.st.seq))
+	keyPrefix := join(util.LogPrefix, fmt.Sprintf("%016x", tx.st.seq))
 	for txSeq, op := range tx.ops {
-		key := join(keyPrefix, fmt.Sprintf("%04x", MaxUint16-uint64(txSeq)))
+		key := join(keyPrefix, fmt.Sprintf("%04x", txSeq))
 		value := &LogEntry{
 			Op: op,
 			// TODO(sadovsky): This information is also captured in LogEntry keys.