Skip to content

Commit

Permalink
datastore/postgres: make xid8 type package private
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedt committed Oct 4, 2022
1 parent f4af252 commit 02a06a4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion internal/datastore/postgres/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (pgd *pgDatastore) TxIDBefore(ctx context.Context, before time.Time) (datas
return datastore.NoRevision, err
}

value := XID8{}
value := xid8{}
err = pgd.dbpool.QueryRow(
datastore.SeparateContextWithTracing(ctx), sql, args...,
).Scan(&value)
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (pgd *pgDatastore) ReadWriteTx(
) (datastore.Revision, error) {
var err error
for i := uint8(0); i <= pgd.maxRetries; i++ {
var newXID XID8
var newXID xid8
err = pgd.dbpool.BeginTxFunc(ctx, pgx.TxOptions{IsoLevel: pgx.Serializable}, func(tx pgx.Tx) error {
var err error
newXID, err = createNewTransaction(ctx, tx)
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func QuantizedRevisionTest(t *testing.T, b testdatastore.RunningEngineForTest) {
tc.quantization.Nanoseconds(),
)

var revision XID8
var revision xid8
var validFor time.Duration
err = conn.QueryRow(ctx, queryRevision).Scan(&revision, &validFor)
require.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/postgres/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func loadNamespace(ctx context.Context, namespace string, tx pgx.Tx, baseQuery s
}

var config []byte
var version XID8
var version xid8
err = tx.QueryRow(ctx, sql, args...).Scan(&config, &version)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
Expand Down
2 changes: 1 addition & 1 deletion internal/datastore/postgres/readwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type pgReadWriteTXN struct {
*pgReader
ctx context.Context
tx pgx.Tx
newXID XID8
newXID xid8
}

func (rwt *pgReadWriteTXN) WriteRelationships(mutations []*core.RelationTupleUpdate) error {
Expand Down
20 changes: 10 additions & 10 deletions internal/datastore/postgres/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
)

func (pgd *pgDatastore) optimizedRevisionFunc(ctx context.Context) (datastore.Revision, time.Duration, error) {
var revision XID8
var revision xid8
var validForNanos time.Duration
if err := pgd.dbpool.QueryRow(
datastore.SeparateContextWithTracing(ctx), pgd.optimizedRevisionQuery,
Expand Down Expand Up @@ -98,39 +98,39 @@ func (pgd *pgDatastore) CheckRevision(ctx context.Context, revision datastore.Re
return nil
}

func (pgd *pgDatastore) loadRevision(ctx context.Context) (XID8, error) {
func (pgd *pgDatastore) loadRevision(ctx context.Context) (xid8, error) {
ctx, span := tracer.Start(ctx, "loadRevision")
defer span.End()

sql, args, err := getRevision.ToSql()
if err != nil {
return XID8{}, fmt.Errorf(errRevision, err)
return xid8{}, fmt.Errorf(errRevision, err)
}

var revision XID8
var revision xid8
err = pgd.dbpool.QueryRow(datastore.SeparateContextWithTracing(ctx), sql, args...).Scan(&revision)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return XID8{}, nil
return xid8{}, nil
}
return XID8{}, fmt.Errorf(errRevision, err)
return xid8{}, fmt.Errorf(errRevision, err)
}

return revision, nil
}

func revisionFromTransaction(txID XID8) datastore.Revision {
func revisionFromTransaction(txID xid8) datastore.Revision {
return decimal.NewFromInt(int64(txID.Uint))
}

func transactionFromRevision(revision datastore.Revision) XID8 {
return XID8{
func transactionFromRevision(revision datastore.Revision) xid8 {
return xid8{
Uint: uint64(revision.IntPart()),
Status: pgtype.Present,
}
}

func createNewTransaction(ctx context.Context, tx pgx.Tx) (newXID XID8, err error) {
func createNewTransaction(ctx context.Context, tx pgx.Tx) (newXID xid8, err error) {
ctx, span := tracer.Start(ctx, "createNewTransaction")
defer span.End()

Expand Down
12 changes: 6 additions & 6 deletions internal/datastore/postgres/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ func (pgd *pgDatastore) Watch(

func (pgd *pgDatastore) getNewRevisions(
ctx context.Context,
afterTX XID8,
) ([]XID8, error) {
afterTX xid8,
) ([]xid8, error) {
rows, err := pgd.dbpool.Query(context.Background(), newRevisionsQuery, afterTX)
if err != nil {
return nil, fmt.Errorf("unable to load new revisions: %w", err)
}
defer rows.Close()

var ids []XID8
var ids []xid8
for rows.Next() {
var nextXID XID8
var nextXID xid8
if err := rows.Scan(&nextXID); err != nil {
return nil, fmt.Errorf("unable to decode new revision: %w", err)
}
Expand All @@ -129,7 +129,7 @@ func (pgd *pgDatastore) getNewRevisions(
return ids, nil
}

func (pgd *pgDatastore) loadChanges(ctx context.Context, revision XID8) (*datastore.RevisionChanges, error) {
func (pgd *pgDatastore) loadChanges(ctx context.Context, revision xid8) (*datastore.RevisionChanges, error) {
sql, args, err := queryChanged.Where(sq.Or{
sq.Eq{colCreatedXid: revision},
sq.Eq{colDeletedXid: revision},
Expand All @@ -150,7 +150,7 @@ func (pgd *pgDatastore) loadChanges(ctx context.Context, revision XID8) (*datast
Subject: &core.ObjectAndRelation{},
}

var createdXID, deletedXID XID8
var createdXID, deletedXID xid8
if err := changes.Scan(
&nextTuple.ResourceAndRelation.Namespace,
&nextTuple.ResourceAndRelation.ObjectId,
Expand Down
20 changes: 10 additions & 10 deletions internal/datastore/postgres/xid8.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@ var errUndefined = errors.New("cannot encode status undefined")
// xid8 represents the xid8 postgres type, which is a 64-bit transaction ID that is *NOT*
// subject to transaction wraparound limitations.
// https://www.postgresql.org/docs/current/datatype-oid.html
type XID8 pguint64
type xid8 pguint64

func (txid *XID8) Set(src interface{}) error {
func (txid *xid8) Set(src interface{}) error {
return (*pguint64)(txid).Set(src)
}

func (txid XID8) Get() interface{} {
func (txid xid8) Get() interface{} {
return (pguint64)(txid).Get()
}

func (txid *XID8) AssignTo(dst interface{}) error {
func (txid *xid8) AssignTo(dst interface{}) error {
return (*pguint64)(txid).AssignTo(dst)
}

func (txid *XID8) DecodeText(ci *pgtype.ConnInfo, src []byte) error {
func (txid *xid8) DecodeText(ci *pgtype.ConnInfo, src []byte) error {
return (*pguint64)(txid).DecodeText(ci, src)
}

func (txid *XID8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error {
func (txid *xid8) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error {
return (*pguint64)(txid).DecodeBinary(ci, src)
}

func (txid XID8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
func (txid xid8) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
return (pguint64)(txid).EncodeText(ci, buf)
}

func (txid XID8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
func (txid xid8) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) ([]byte, error) {
return (pguint64)(txid).EncodeBinary(ci, buf)
}

func (txid *XID8) Scan(src interface{}) error {
func (txid *xid8) Scan(src interface{}) error {
return (*pguint64)(txid).Scan(src)
}

func (txid XID8) Value() (driver.Value, error) {
func (txid xid8) Value() (driver.Value, error) {
return (pguint64)(txid).Value()
}

Expand Down

0 comments on commit 02a06a4

Please sign in to comment.