Skip to content

Add HA support for the Azure storage backend #8464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ensure non-nil io.ReadSeeker to make azure blob upload API happy
  • Loading branch information
sding3 committed Jul 17, 2021
commit 8bb35cff92943fb8e785e0a3d06ea49f28226199
1 change: 1 addition & 0 deletions physical/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func NewAzureBackend(conf map[string]string, logger log.Logger) (physical.Backen
haEnabled: haEnabled,
permitPool: physical.NewPermitPool(maxParInt),
}
fmt.Println("azure haEnabled", haEnabled)
return a, nil
}

Expand Down
8 changes: 6 additions & 2 deletions physical/azure/azure_ha.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package azure

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -383,11 +385,13 @@ func (l *Lock) writeLock() (bool, error) {
"lock": string(lockData),
})

if resp, err := blob.Upload(context.Background(), nil, headers, metadata, conds, azblob.DefaultAccessTier, nil); err != nil {
// blob.Upload needs a non-nil io.ReadSeeker, emptyLockFile satisfy that
emptyLockFile := io.NewSectionReader(&bytes.Reader{}, 0, 0)
if resp, err := blob.Upload(context.Background(), emptyLockFile, headers, metadata, conds, azblob.DefaultAccessTier, nil); err != nil {
if resp != nil && resp.StatusCode() == http.StatusPreconditionFailed {
return false, nil
}
return false, err
return false, errwrap.Wrapf("write lock: blob.Upload: {{err}}", err)
}

return true, nil
Expand Down