use writer for database reads on TokenUpdate (#11605)

Related to #11604
This commit is contained in:
Roberto Dip 2023-05-10 09:40:11 -03:00 committed by GitHub
parent c1b7953f8c
commit e635eb19fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

1
changes/11604-use-writer Normal file
View File

@ -0,0 +1 @@
* Fixed a bug that prevented bootstrap packages and the `fleetd` agent from being installed when the server had a database replica configured.

View File

@ -922,7 +922,8 @@ func unionSelectDevices(devices []godep.Device) (stmt string, args []interface{}
func (ds *Datastore) GetNanoMDMEnrollment(ctx context.Context, id string) (*fleet.NanoEnrollment, error) {
var nanoEnroll fleet.NanoEnrollment
err := sqlx.GetContext(ctx, ds.reader, &nanoEnroll, `SELECT id, device_id, type, enabled, token_update_tally
// use writer as it is used just after creation in some cases
err := sqlx.GetContext(ctx, ds.writer, &nanoEnroll, `SELECT id, device_id, type, enabled, token_update_tally
FROM nano_enrollments WHERE id = ?`, id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {

View File

@ -2803,7 +2803,9 @@ func (ds *Datastore) GetHostMDM(ctx context.Context, hostID uint) (*fleet.HostMD
func (ds *Datastore) GetHostMDMCheckinInfo(ctx context.Context, hostUUID string) (*fleet.HostMDMCheckinInfo, error) {
var hmdm fleet.HostMDMCheckinInfo
err := sqlx.GetContext(ctx, ds.reader, &hmdm, `
// use writer as it is used just after creation in some cases
err := sqlx.GetContext(ctx, ds.writer, &hmdm, `
SELECT
h.hardware_serial,
COALESCE(hm.installed_from_dep, false) as installed_from_dep,
@ -2820,9 +2822,9 @@ func (ds *Datastore) GetHostMDMCheckinInfo(ctx context.Context, hostUUID string)
WHERE h.uuid = ? LIMIT 1`, hostUUID)
if err != nil {
if err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("MDM").WithMessage(hostUUID))
return nil, ctxerr.Wrap(ctx, notFound("Host").WithMessage(fmt.Sprintf("with UUID: %s", hostUUID)))
}
return nil, ctxerr.Wrapf(ctx, err, "getting data from host_mdm for host_uuid %s", hostUUID)
return nil, ctxerr.Wrapf(ctx, err, "host mdm checkin info for host UUID %s", hostUUID)
}
return &hmdm, nil
}