exposure-notifications-server: github.com/google/exposure-notifications-server/internal/publish/database Index | Files

package database

import "github.com/google/exposure-notifications-server/internal/publish/database"

Package database is a database interface to publish.

Package database is a database interface to publish.


Package Files

exposure.go performance_test_utils.go


const (
    // InsertExposuresBatchSize is the maximum number of exposures that can be inserted at once.
    InsertExposuresBatchSize = 500


var (
    // ErrExistingKeyNotInToken is returned when attempting to present an exposure that already exists, but
    // isn't in the provided revision token.
    ErrExistingKeyNotInToken = errors.New("sent existing exposure key that is not in revision token")

    // ErrNoRevisionToken is returned when presenting exposures that already exists, but no revision
    // token was presented.
    ErrNoRevisionToken = errors.New("sent existing exposures but no revision token present")

    // ErrRevisionTokenMetadataMismatch is returned when a revision token has the correct TEK in it,
    // but the new request is attempting to change the metadata of the key (intervalNumber/Count)
    ErrRevisionTokenMetadataMismatch = errors.New("changing exposure key metadata is not allowed")

    // ErrIncomingMetadataMismatch is returned when incoming data has a known TEK
    // in it, but the new request is attempting to change the metadata of the key
    // (intervalNumber/Count).
    ErrIncomingMetadataMismatch = errors.New("incoming exposure key metadata does not match expected values")

type InsertAndReviseExposuresRequest Uses

type InsertAndReviseExposuresRequest struct {
    Incoming []*model.Exposure
    Token    *pb.RevisionTokenData

    // RequireToken requires that the request supply a revision token to re-upload
    // existing keys.
    RequireToken bool

    // AllowPartialRevisions allows revising a subset of exposures if other
    // exposures are included that are not part of the revision token. This exists
    // to support roaming scenarios. This is only used if RequireToken is true.
    AllowPartialRevisions bool

InsertAndReviseExposuresRequest is used as input to InsertAndReviseExposures.

type InsertAndReviseExposuresResponse Uses

type InsertAndReviseExposuresResponse struct {
    // Inserted is the number of new exposures that were inserted into the
    // database.
    Inserted uint64

    // Revised is the number of exposures that matched an existing TEK and were
    // subsequently revised.
    Revised uint64

    // Dropped is the number of exposures that were not inserted or updated. This
    // could be because they weren't present in the revision token, etc.
    Dropped uint64

    // Exposures is the actual exposures that were inserted or updated in this
    // call.
    Exposures []*model.Exposure

InsertAndReviseExposuresResponse is the response from an InsertAndReviseExposures call.

type IterateExposuresCriteria Uses

type IterateExposuresCriteria struct {
    IncludeRegions   []string
    IncludeTravelers bool // Include records in the IncludeRegions OR travalers
    OnlyTravelers    bool // Only includes records marked as travelers.
    ExcludeRegions   []string
    SinceTimestamp   time.Time
    UntilTimestamp   time.Time
    LastCursor       string
    OnlyRevisedKeys  bool // If true, only revised keys that match will be selected.

    // OnlyLocalProvenance indicates that only exposures with LocalProvenance=true will be returned.
    OnlyLocalProvenance bool

IterateExposuresCriteria is criteria to iterate exposures.

type PublishDB Uses

type PublishDB struct {
    // contains filtered or unexported fields

func New Uses

func New(db *database.DB) *PublishDB

func (*PublishDB) BulkInsertExposures Uses

func (db *PublishDB) BulkInsertExposures(ctx context.Context, incoming []*model.Exposure) (int, error)

BulkInsertExposures performs a large key copy at once allowing for quick population of exposure keys *this should NOT be used for anything but testing, validation and checks were removed

func (*PublishDB) DeleteExposure Uses

func (db *PublishDB) DeleteExposure(ctx context.Context, exposureKey []byte) (int64, error)

DeleteExposure deletes exposure

func (*PublishDB) DeleteExposuresBefore Uses

func (db *PublishDB) DeleteExposuresBefore(ctx context.Context, before time.Time) (int64, error)

DeleteExposuresBefore deletes exposures created before "before" date. Returns the number of records deleted.

func (*PublishDB) InsertAndReviseExposures Uses

func (db *PublishDB) InsertAndReviseExposures(ctx context.Context, req *InsertAndReviseExposuresRequest) (*InsertAndReviseExposuresResponse, error)

InsertAndReviseExposures transactionally revises and inserts a set of keys as necessary.

func (*PublishDB) IterateExposures Uses

func (db *PublishDB) IterateExposures(ctx context.Context, criteria IterateExposuresCriteria, f func(*model.Exposure) error) (cur string, err error)

IterateExposures calls f on each Exposure in the database that matches the given criteria. If f returns an error, the iteration stops, and the returned error will match f's error with errors.Is.

If an error occurs during the query, IterateExposures will return a non-empty string along with a non-nil error. That string, when passed as criteria.LastCursor in a subsequent call to IterateExposures, will continue the iteration at the failed row. If IterateExposures returns a nil error, the first return value will be the empty string.

func (*PublishDB) ReadExposures Uses

func (db *PublishDB) ReadExposures(ctx context.Context, tx pgx.Tx, b64keys []string) (map[string]*model.Exposure, error)

ReadExposures will read an existing set of exposures from the database. This is necessary in case a key needs to be revised. In the return map, the key is the base64 of the ExposureKey. The keys are read for update in a provided transaction.

Package database imports 15 packages (graph) and is imported by 6 packages. Updated 2020-09-27. Refresh now. Tools for package owners.