code: func generateInvocationID(c context.Context) (int64, error) {
  	// See http://play.golang.org/p/POpQzpT4Up.
  	invTs := int64(clock.Now(c).UTC().Sub(invocationIDEpoch) / time.Millisecond)
  	invTs = ^invTs & 8796093022207 // 0b111....1, 42 bits (clear highest bit)
  	invTs = invTs << 20
  
  	randSuffix := mathrand.Int63n(c, 65536)
  	invID := invTs | (randSuffix << 4)
  	exists, err := datastore.Exists(c, datastore.NewKey(c, "Invocation", "", invID, nil))
  	if err != nil {
  		return 0, transient.Tag.Apply(err)
  	}
  	if !exists.All() {
  		return invID, nil
  	}
  
  	return 0, errInvocationIDConflict
  }
docs: // generateInvocationID is called within a transaction to pick a new Invocation
  // ID and ensure it isn't taken yet.
  //
  // This function essentially pick root key for a new entity group, checking
  // that it hasn't been taken yet.
  //
  // Format of the invocation ID:
  //   - highest order bit set to 0 to keep the value positive.
  //   - next 43 bits set to negated time since some predefined epoch, in ms.
  //   - next 16 bits are generated by math.Rand
  //   - next 4 bits set to 0. They indicate ID format.
  //
  // Makes one attempt at allocating an ID. If it fails (should be extremely
  // rare), the entire transaction should be retried. We do it to avoid
  // unnecessarily hitting multiple entity groups from a single transaction.
  //
  // Returns only transient errors.