database

package
v0.18.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package database is a database interface to publish.

Package database is a database interface to publish.

Index

Constants

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

Variables

View Source
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")
)

Functions

This section is empty.

Types

type InsertAndReviseExposuresRequest added in v0.8.0

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

	// If true, if a key is determined to be a revsion, it is skipped.
	SkipRevions bool
	// If true, only revisions will be processed.
	OnlyRevisions bool
	// Require matching Sync QueryID only allows revisions if they originated from the same query ID.
	RequireQueryID bool
	// When revising, require matching export-import-ID. For export file based import federation.
	RequireExportImportID bool
}

InsertAndReviseExposuresRequest is used as input to InsertAndReviseExposures.

type InsertAndReviseExposuresResponse added in v0.8.0

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

type IterateExposuresCriteria struct {
	IncludeRegions   []string
	IncludeTravelers bool // Include records in the IncludeRegions OR travalers
	OnlyNonTravelers bool
	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

	// If limit is > 0, a limit query will be set on the database query.
	Limit uint32
}

IterateExposuresCriteria is criteria to iterate exposures.

type IteratorFunction added in v0.11.0

type IteratorFunction func(*model.Exposure) error

type PublishDB

type PublishDB struct {
	// contains filtered or unexported fields
}

func New

func New(db *database.DB) *PublishDB

func (*PublishDB) BulkInsertExposures added in v0.8.0

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

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

DeleteExposure deletes exposure

func (*PublishDB) DeleteExposuresBefore

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

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

func (*PublishDB) IterateExposures

func (db *PublishDB) IterateExposures(ctx context.Context, criteria IterateExposuresCriteria, f IteratorFunction) (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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL