Skip to content

Commit 5f8aa3d

Browse files
committed
Set the metadata header when creating the lock file, not afterwards in a separate call.
1 parent 76affbd commit 5f8aa3d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

backend/remote-state/gcs/client.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ func (c *remoteClient) Delete() error {
111111
func (c *remoteClient) createLockFile(infoJson []byte) (int64, error) {
112112
w := c.lockFile().If(storage.Conditions{DoesNotExist: true}).NewWriter(c.storageContext)
113113
err := func() error {
114+
// Add metadata signalling to other clients that heartbeats will be
115+
// performed on this lock file.
116+
w.ObjectAttrs.Metadata = map[string]string{metadataHeaderHeartbeatEnabled: "true"}
117+
114118
if _, err := w.Write(infoJson); err != nil {
115119
return err
116120
}
@@ -121,14 +125,6 @@ func (c *remoteClient) createLockFile(infoJson []byte) (int64, error) {
121125
return 0, c.lockError(fmt.Errorf("writing %q failed: %v", c.lockFileURL(), err))
122126
}
123127

124-
// Add metadata signalling to other clients that heartbeats will be
125-
// performed on this lock file.
126-
uattrs := storage.ObjectAttrsToUpdate{Metadata: make(map[string]string)}
127-
uattrs.Metadata[metadataHeaderHeartbeatEnabled] = "true"
128-
if _, err := c.lockFile().Update(c.storageContext, uattrs); err != nil {
129-
return 0, c.lockError(err)
130-
}
131-
132128
return w.Attrs().Generation, nil
133129
}
134130

0 commit comments

Comments
 (0)