Documentation ¶
Overview ¶
Package database is a database interface to publish.
Package database is a database interface to publish.
Index ¶
- Constants
- Variables
- type InsertAndReviseExposuresRequest
- type InsertAndReviseExposuresResponse
- type IterateExposuresCriteria
- type IteratorFunction
- type PublishDB
- func (db *PublishDB) BulkInsertExposures(ctx context.Context, incoming []*model.Exposure) (int, error)
- func (db *PublishDB) DeleteExposuresBefore(ctx context.Context, before time.Time) (int64, error)
- func (db *PublishDB) DeleteStatsBefore(ctx context.Context, before time.Time) (int64, error)
- func (db *PublishDB) InsertAndReviseExposures(ctx context.Context, req *InsertAndReviseExposuresRequest) (*InsertAndReviseExposuresResponse, error)
- func (db *PublishDB) IterateExposures(ctx context.Context, criteria IterateExposuresCriteria, f IteratorFunction) (cur string, err error)
- func (db *PublishDB) ReadExposures(ctx context.Context, tx pgx.Tx, b64keys []string) (map[string]*model.Exposure, error)
- func (db *PublishDB) ReadStats(ctx context.Context, healthAuthorityID int64) ([]*model.HealthAuthorityStats, error)
- func (db *PublishDB) UpdateStats(ctx context.Context, hour time.Time, healthAuthorityID int64, ...) error
- func (db *PublishDB) UpdateStatsInTx(ctx context.Context, tx pgx.Tx, hour time.Time, healthAuthorityID int64, ...) error
Constants ¶
const (
// InsertExposuresBatchSize is the maximum number of exposures that can be inserted at once.
InsertExposuresBatchSize = 500
)
Variables ¶
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 // Optional: if provided stats will be updated transactionally with the TEKs. PublishInfo *model.PublishInfo // 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. SkipRevisions 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 uint32 // Revised is the number of exposures that matched an existing TEK and were // subsequently revised. Revised uint32 // 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 uint32 // 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 PublishDB ¶
type PublishDB struct {
// contains filtered or unexported fields
}
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) DeleteExposuresBefore ¶
DeleteExposuresBefore deletes exposures created before "before" date. Returns the number of records deleted.
func (*PublishDB) DeleteStatsBefore ¶ added in v0.19.0
DeleteStatsBefore deletes exposure publish stats created before "before" date. Returns the number of records deleted.
func (*PublishDB) InsertAndReviseExposures ¶
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 ¶
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.
func (*PublishDB) ReadStats ¶ added in v0.19.0
func (db *PublishDB) ReadStats(ctx context.Context, healthAuthorityID int64) ([]*model.HealthAuthorityStats, error)
ReadStats will return all stats before the current hour, ordered in ascending time.
func (*PublishDB) UpdateStats ¶ added in v0.19.0
func (db *PublishDB) UpdateStats(ctx context.Context, hour time.Time, healthAuthorityID int64, info *model.PublishInfo) error
UpdateStats performance a read-modify-write to update the requested stats.
func (*PublishDB) UpdateStatsInTx ¶ added in v0.19.0
func (db *PublishDB) UpdateStatsInTx(ctx context.Context, tx pgx.Tx, hour time.Time, healthAuthorityID int64, info *model.PublishInfo) error
UpdateStatsInTx records information for the health authority during a publish request, in an existing database transaction.