luci: go.chromium.org/luci/server/tq/internal/db Index | Files

package db

import "go.chromium.org/luci/server/tq/internal/db"

Package db defines common database interface.

Index

Package Files

db.go

func Kinds Uses

func Kinds() []string

Kinds returns IDs of registered database implementations.

func Register Uses

func Register(db Impl)

Register registers a database implementation.

Must be called during init() time.

type DB Uses

type DB interface {
    // Kind identifies this particular database implementation.
    //
    // Among other things it is used in Cloud Tasks messages involved in the
    // implementation of the distributed sweeping.
    Kind() string

    // Defer defers the execution of the callback until the transaction lands.
    //
    // Panics if called outside of a transaction.
    //
    // The callback will receive the original non-transactional context.
    Defer(context.Context, func(context.Context))

    // SaveReminder persists reminder in a transaction context.
    //
    // Tags retriable errors as transient.
    SaveReminder(context.Context, *reminder.Reminder) error

    // DeleteReminder deletes reminder in a non-transaction context.
    DeleteReminder(context.Context, *reminder.Reminder) error

    // FetchRemindersMeta fetches Reminders with Ids in [low..high) range.
    //
    // RawPayload of Reminders should not be fetched.
    // Both fresh & stale reminders should be fetched.
    // The reminders should be returned in order of ascending Id.
    //
    // In case of error, partial result of fetched Reminders so far should be
    // returned alongside the error. The caller will later call this method again
    // to fetch the remaining of Reminders in range of [<lastReturned.Id+1> .. high).
    FetchRemindersMeta(ctx context.Context, low, high string, limit int) ([]*reminder.Reminder, error)

    // FetchReminderRawPayloads fetches raw payloads of a batch of Reminders.
    //
    // The Reminder objects are re-used in the returned batch.
    // If any Reminder is no longer found, it is silently omitted in the returned
    // batch.
    // In case of any other error, partial result of fetched Reminders so far
    // should be returned alongside the error.
    FetchReminderRawPayloads(context.Context, []*reminder.Reminder) ([]*reminder.Reminder, error)
}

DB abstracts out specific storage implementation.

func NonTxnDB Uses

func NonTxnDB(ctx context.Context, id string) DB

NonTxnDB returns a database with given ID or nil if not registered.

func TxnDB Uses

func TxnDB(ctx context.Context) (db DB)

TxnDB returns a Database that matches the context or nil.

The process has a list of database engines registered via Register. Given a context, TxnDB examines if it carries a transaction with any of the registered DBs.

Panics if more than one database matches the context.

type Impl Uses

type Impl struct {
    // Kind identifies this particular DB implementation.
    //
    // Must match Kind() of the produced DB instance.
    Kind string

    // ProbeForTxn "probes" a context for an active transaction, returning a DB
    // that can be used to transactionally submit reminders or nil if this is not
    // a transactional context.
    ProbeForTxn func(context.Context) DB

    // NonTxn returns an instance of DB that can be used outside of
    // transactions.
    //
    // This is used by the sweeper to enumerate reminders.
    NonTxn func(context.Context) DB
}

Impl knows how to instantiate DB instances.

Package db imports 3 packages (graph) and is imported by 9 packages. Updated 2020-09-30. Refresh now. Tools for package owners.