Compare commits
1 Commits
v0.3.8-bet
...
v0.4.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2cef2f16b |
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@@ -37,26 +37,26 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
LITESTREAM_S3_ACCESS_KEY_ID: ${{ secrets.LITESTREAM_S3_ACCESS_KEY_ID }}
|
LITESTREAM_S3_ACCESS_KEY_ID: ${{ secrets.LITESTREAM_S3_ACCESS_KEY_ID }}
|
||||||
LITESTREAM_S3_SECRET_ACCESS_KEY: ${{ secrets.LITESTREAM_S3_SECRET_ACCESS_KEY }}
|
LITESTREAM_S3_SECRET_ACCESS_KEY: ${{ secrets.LITESTREAM_S3_SECRET_ACCESS_KEY }}
|
||||||
LITESTREAM_S3_REGION: us-east-1
|
LITESTREAM_S3_REGION: ${{ secrets.LITESTREAM_S3_REGION }}
|
||||||
LITESTREAM_S3_BUCKET: integration.litestream.io
|
LITESTREAM_S3_BUCKET: ${{ secrets.LITESTREAM_S3_BUCKET }}
|
||||||
|
|
||||||
- name: Run google cloud storage (gcs) tests
|
- name: Run google cloud storage (gcs) tests
|
||||||
run: go test -v -run=TestReplicaClient . -integration gcs
|
run: go test -v -run=TestReplicaClient . -integration gcs
|
||||||
env:
|
env:
|
||||||
GOOGLE_APPLICATION_CREDENTIALS: /opt/gcp.json
|
GOOGLE_APPLICATION_CREDENTIALS: /opt/gcp.json
|
||||||
LITESTREAM_GCS_BUCKET: integration.litestream.io
|
LITESTREAM_GCS_BUCKET: ${{ secrets.LITESTREAM_GCS_BUCKET }}
|
||||||
|
|
||||||
- name: Run azure blob storage (abs) tests
|
- name: Run azure blob storage (abs) tests
|
||||||
run: go test -v -run=TestReplicaClient . -integration abs
|
run: go test -v -run=TestReplicaClient . -integration abs
|
||||||
env:
|
env:
|
||||||
LITESTREAM_ABS_ACCOUNT_NAME: ${{ secrets.LITESTREAM_ABS_ACCOUNT_NAME }}
|
LITESTREAM_ABS_ACCOUNT_NAME: ${{ secrets.LITESTREAM_ABS_ACCOUNT_NAME }}
|
||||||
LITESTREAM_ABS_ACCOUNT_KEY: ${{ secrets.LITESTREAM_ABS_ACCOUNT_KEY }}
|
LITESTREAM_ABS_ACCOUNT_KEY: ${{ secrets.LITESTREAM_ABS_ACCOUNT_KEY }}
|
||||||
LITESTREAM_ABS_BUCKET: integration
|
LITESTREAM_ABS_BUCKET: ${{ secrets.LITESTREAM_ABS_BUCKET }}
|
||||||
|
|
||||||
- name: Run sftp tests
|
- name: Run sftp tests
|
||||||
run: go test -v -run=TestReplicaClient . -integration sftp
|
run: go test -v -run=TestReplicaClient . -integration sftp
|
||||||
env:
|
env:
|
||||||
LITESTREAM_SFTP_HOST: litestream-test-sftp.fly.dev:2222
|
LITESTREAM_SFTP_HOST: ${{ secrets.LITESTREAM_SFTP_HOST }}
|
||||||
LITESTREAM_SFTP_USER: litestream
|
LITESTREAM_SFTP_USER: ${{ secrets.LITESTREAM_SFTP_USER }}
|
||||||
LITESTREAM_SFTP_KEY_PATH: /opt/id_ed25519
|
LITESTREAM_SFTP_KEY_PATH: /opt/id_ed25519
|
||||||
LITESTREAM_SFTP_PATH: /litestream
|
LITESTREAM_SFTP_PATH: ${{ secrets.LITESTREAM_SFTP_PATH }}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
resp, err := c.containerURL.ListBlobsHierarchySegment(ctx, marker, "/", azblob.ListBlobsSegmentOptions{
|
resp, err := c.containerURL.ListBlobsHierarchySegment(ctx, marker, "/", azblob.ListBlobsSegmentOptions{
|
||||||
Prefix: litestream.GenerationsPath(c.Path) + "/",
|
Prefix: path.Join(c.Path, "generations") + "/",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -125,18 +125,17 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := litestream.GenerationPath(c.Path, generation)
|
prefix := path.Join(c.Path, "generations", generation) + "/"
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine generation path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var marker azblob.Marker
|
var marker azblob.Marker
|
||||||
for marker.NotDone() {
|
for marker.NotDone() {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
resp, err := c.containerURL.ListBlobsFlatSegment(ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: dir + "/"})
|
resp, err := c.containerURL.ListBlobsFlatSegment(ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: prefix})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -171,12 +170,11 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (lites
|
|||||||
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
rc := internal.NewReadCounter(rd)
|
rc := internal.NewReadCounter(rd)
|
||||||
@@ -206,12 +204,11 @@ func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, in
|
|||||||
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
blobURL := c.containerURL.NewBlobURL(key)
|
blobURL := c.containerURL.NewBlobURL(key)
|
||||||
resp, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{})
|
resp, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{})
|
||||||
@@ -231,12 +228,11 @@ func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, i
|
|||||||
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "DELETE").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "DELETE").Inc()
|
||||||
|
|
||||||
@@ -261,12 +257,11 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (lit
|
|||||||
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
rc := internal.NewReadCounter(rd)
|
rc := internal.NewReadCounter(rd)
|
||||||
@@ -296,12 +291,11 @@ func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos,
|
|||||||
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
blobURL := c.containerURL.NewBlobURL(key)
|
blobURL := c.containerURL.NewBlobURL(key)
|
||||||
resp, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{})
|
resp, err := blobURL.Download(ctx, 0, 0, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{})
|
||||||
@@ -324,11 +318,12 @@ func (c *ReplicaClient) DeleteWALSegments(ctx context.Context, a []litestream.Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pos := range a {
|
for _, pos := range a {
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
if pos.Generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
|
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "DELETE").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "DELETE").Inc()
|
||||||
|
|
||||||
blobURL := c.containerURL.NewBlobURL(key)
|
blobURL := c.containerURL.NewBlobURL(key)
|
||||||
@@ -372,24 +367,24 @@ func newSnapshotIterator(ctx context.Context, generation string, client *Replica
|
|||||||
func (itr *snapshotIterator) fetch() error {
|
func (itr *snapshotIterator) fetch() error {
|
||||||
defer close(itr.ch)
|
defer close(itr.ch)
|
||||||
|
|
||||||
dir, err := litestream.SnapshotsPath(itr.client.Path, itr.generation)
|
if itr.generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine snapshots path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix := path.Join(itr.client.Path, "generations", itr.generation) + "/"
|
||||||
|
|
||||||
var marker azblob.Marker
|
var marker azblob.Marker
|
||||||
for marker.NotDone() {
|
for marker.NotDone() {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
resp, err := itr.client.containerURL.ListBlobsFlatSegment(itr.ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: dir + "/"})
|
resp, err := itr.client.containerURL.ListBlobsFlatSegment(itr.ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: prefix})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
marker = resp.NextMarker
|
marker = resp.NextMarker
|
||||||
|
|
||||||
for _, item := range resp.Segment.BlobItems {
|
for _, item := range resp.Segment.BlobItems {
|
||||||
key := path.Base(item.Name)
|
index, err := internal.ParseSnapshotPath(path.Base(item.Name))
|
||||||
index, err := litestream.ParseSnapshotPath(key)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -478,24 +473,24 @@ func newWALSegmentIterator(ctx context.Context, generation string, client *Repli
|
|||||||
func (itr *walSegmentIterator) fetch() error {
|
func (itr *walSegmentIterator) fetch() error {
|
||||||
defer close(itr.ch)
|
defer close(itr.ch)
|
||||||
|
|
||||||
dir, err := litestream.WALPath(itr.client.Path, itr.generation)
|
if itr.generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
prefix := path.Join(itr.client.Path, "generations", itr.generation, "wal")
|
||||||
|
|
||||||
var marker azblob.Marker
|
var marker azblob.Marker
|
||||||
for marker.NotDone() {
|
for marker.NotDone() {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
resp, err := itr.client.containerURL.ListBlobsFlatSegment(itr.ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: dir + "/"})
|
resp, err := itr.client.containerURL.ListBlobsFlatSegment(itr.ctx, marker, azblob.ListBlobsSegmentOptions{Prefix: prefix})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
marker = resp.NextMarker
|
marker = resp.NextMarker
|
||||||
|
|
||||||
for _, item := range resp.Segment.BlobItems {
|
for _, item := range resp.Segment.BlobItems {
|
||||||
key := path.Base(item.Name)
|
key := strings.TrimPrefix(item.Name, prefix+"/")
|
||||||
index, offset, err := litestream.ParseWALSegmentPath(key)
|
index, offset, err := internal.ParseWALSegmentPath(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
40
db.go
40
db.go
@@ -16,6 +16,8 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -168,7 +170,7 @@ func (db *DB) ShadowWALDir(generation string) string {
|
|||||||
// Panics if generation is blank or index is negative.
|
// Panics if generation is blank or index is negative.
|
||||||
func (db *DB) ShadowWALPath(generation string, index int) string {
|
func (db *DB) ShadowWALPath(generation string, index int) string {
|
||||||
assert(index >= 0, "shadow wal index cannot be negative")
|
assert(index >= 0, "shadow wal index cannot be negative")
|
||||||
return filepath.Join(db.ShadowWALDir(generation), FormatWALPath(index))
|
return filepath.Join(db.ShadowWALDir(generation), FormatIndex(index)+".wal")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentShadowWALPath returns the path to the last shadow WAL in a generation.
|
// CurrentShadowWALPath returns the path to the last shadow WAL in a generation.
|
||||||
@@ -191,8 +193,8 @@ func (db *DB) CurrentShadowWALIndex(generation string) (index int, size int64, e
|
|||||||
|
|
||||||
// Find highest wal index.
|
// Find highest wal index.
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
if v, err := ParseWALPath(fi.Name()); err != nil {
|
if v, err := parseWALPath(fi.Name()); err != nil {
|
||||||
continue // invalid wal filename
|
continue // invalid filename
|
||||||
} else if v > index {
|
} else if v > index {
|
||||||
index = v
|
index = v
|
||||||
}
|
}
|
||||||
@@ -584,7 +586,7 @@ func (db *DB) cleanWAL() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
if idx, err := ParseWALPath(fi.Name()); err != nil || idx >= min {
|
if idx, err := parseWALPath(fi.Name()); err != nil || idx >= min {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := os.Remove(filepath.Join(dir, fi.Name())); err != nil {
|
if err := os.Remove(filepath.Join(dir, fi.Name())); err != nil {
|
||||||
@@ -928,13 +930,13 @@ func (db *DB) syncWAL(info syncInfo) (newSize int64, err error) {
|
|||||||
|
|
||||||
// Parse index of current shadow WAL file.
|
// Parse index of current shadow WAL file.
|
||||||
dir, base := filepath.Split(info.shadowWALPath)
|
dir, base := filepath.Split(info.shadowWALPath)
|
||||||
index, err := ParseWALPath(base)
|
index, err := parseWALPath(base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("cannot parse shadow wal filename: %s", base)
|
return 0, fmt.Errorf("cannot parse shadow wal filename: %s", base)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a new shadow WAL file with next index.
|
// Start a new shadow WAL file with next index.
|
||||||
newShadowWALPath := filepath.Join(dir, FormatWALPath(index+1))
|
newShadowWALPath := filepath.Join(dir, formatWALPath(index+1))
|
||||||
newSize, err = db.initShadowWALFile(newShadowWALPath)
|
newSize, err = db.initShadowWALFile(newShadowWALPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("cannot init shadow wal file: name=%s err=%w", newShadowWALPath, err)
|
return 0, fmt.Errorf("cannot init shadow wal file: name=%s err=%w", newShadowWALPath, err)
|
||||||
@@ -1298,13 +1300,13 @@ func (db *DB) checkpoint(ctx context.Context, generation, mode string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse index of current shadow WAL file.
|
// Parse index of current shadow WAL file.
|
||||||
index, err := ParseWALPath(shadowWALPath)
|
index, err := parseWALPath(shadowWALPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot parse shadow wal filename: %s", shadowWALPath)
|
return fmt.Errorf("cannot parse shadow wal filename: %s", shadowWALPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a new shadow WAL file with next index.
|
// Start a new shadow WAL file with next index.
|
||||||
newShadowWALPath := filepath.Join(filepath.Dir(shadowWALPath), FormatWALPath(index+1))
|
newShadowWALPath := filepath.Join(filepath.Dir(shadowWALPath), formatWALPath(index+1))
|
||||||
if _, err := db.initShadowWALFile(newShadowWALPath); err != nil {
|
if _, err := db.initShadowWALFile(newShadowWALPath); err != nil {
|
||||||
return fmt.Errorf("cannot init shadow wal file: name=%s err=%w", newShadowWALPath, err)
|
return fmt.Errorf("cannot init shadow wal file: name=%s err=%w", newShadowWALPath, err)
|
||||||
}
|
}
|
||||||
@@ -1481,6 +1483,28 @@ func (db *DB) CRC64(ctx context.Context) (uint64, Pos, error) {
|
|||||||
return h.Sum64(), pos, nil
|
return h.Sum64(), pos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseWALPath returns the index for the WAL file.
|
||||||
|
// Returns an error if the path is not a valid WAL path.
|
||||||
|
func parseWALPath(s string) (index int, err error) {
|
||||||
|
s = filepath.Base(s)
|
||||||
|
|
||||||
|
a := walPathRegex.FindStringSubmatch(s)
|
||||||
|
if a == nil {
|
||||||
|
return 0, fmt.Errorf("invalid wal path: %s", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
||||||
|
return int(i64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// formatWALPath formats a WAL filename with a given index.
|
||||||
|
func formatWALPath(index int) string {
|
||||||
|
assert(index >= 0, "wal index must be non-negative")
|
||||||
|
return FormatIndex(index) + ".wal"
|
||||||
|
}
|
||||||
|
|
||||||
|
var walPathRegex = regexp.MustCompile(`^([0-9a-f]{8})\.wal$`)
|
||||||
|
|
||||||
// DefaultRestoreParallelism is the default parallelism when downloading WAL files.
|
// DefaultRestoreParallelism is the default parallelism when downloading WAL files.
|
||||||
const DefaultRestoreParallelism = 8
|
const DefaultRestoreParallelism = 8
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/benbjohnson/litestream"
|
"github.com/benbjohnson/litestream"
|
||||||
"github.com/benbjohnson/litestream/internal"
|
"github.com/benbjohnson/litestream/internal"
|
||||||
@@ -84,7 +85,7 @@ func (c *ReplicaClient) SnapshotPath(generation string, index int) (string, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return filepath.Join(dir, litestream.FormatSnapshotPath(index)), nil
|
return filepath.Join(dir, litestream.FormatIndex(index)+".snapshot.lz4"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WALDir returns the path to a generation's WAL directory
|
// WALDir returns the path to a generation's WAL directory
|
||||||
@@ -102,7 +103,7 @@ func (c *ReplicaClient) WALSegmentPath(generation string, index int, offset int6
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return filepath.Join(dir, litestream.FormatWALSegmentPath(index, offset)), nil
|
return filepath.Join(dir, litestream.FormatIndex(index), fmt.Sprintf("%08x.wal.lz4", offset)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generations returns a list of available generation names.
|
// Generations returns a list of available generation names.
|
||||||
@@ -168,7 +169,7 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (lites
|
|||||||
infos := make([]litestream.SnapshotInfo, 0, len(fis))
|
infos := make([]litestream.SnapshotInfo, 0, len(fis))
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
// Parse index from filename.
|
// Parse index from filename.
|
||||||
index, err := litestream.ParseSnapshotPath(fi.Name())
|
index, err := internal.ParseSnapshotPath(filepath.Base(fi.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -281,26 +282,18 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (lit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over every file and convert to metadata.
|
// Iterate over every file and convert to metadata.
|
||||||
infos := make([]litestream.WALSegmentInfo, 0, len(fis))
|
indexes := make([]int, 0, len(fis))
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
// Parse index from filename.
|
index, err := litestream.ParseIndex(fi.Name())
|
||||||
index, offset, err := litestream.ParseWALSegmentPath(fi.Name())
|
if err != nil || !fi.IsDir() {
|
||||||
if err != nil {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
indexes = append(indexes, index)
|
||||||
infos = append(infos, litestream.WALSegmentInfo{
|
|
||||||
Generation: generation,
|
|
||||||
Index: index,
|
|
||||||
Offset: offset,
|
|
||||||
Size: fi.Size(),
|
|
||||||
CreatedAt: fi.ModTime().UTC(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(litestream.WALSegmentInfoSlice(infos))
|
sort.Ints(indexes)
|
||||||
|
|
||||||
return litestream.NewWALSegmentInfoSliceIterator(infos), nil
|
return newWALSegmentIterator(dir, generation, indexes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
||||||
@@ -379,3 +372,97 @@ func (c *ReplicaClient) DeleteWALSegments(ctx context.Context, a []litestream.Po
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type walSegmentIterator struct {
|
||||||
|
dir string
|
||||||
|
generation string
|
||||||
|
indexes []int
|
||||||
|
|
||||||
|
infos []litestream.WALSegmentInfo
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWALSegmentIterator(dir, generation string, indexes []int) *walSegmentIterator {
|
||||||
|
return &walSegmentIterator{
|
||||||
|
dir: dir,
|
||||||
|
generation: generation,
|
||||||
|
indexes: indexes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Close() (err error) {
|
||||||
|
return itr.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Next() bool {
|
||||||
|
// Exit if an error has already occurred.
|
||||||
|
if itr.err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Move to the next segment in cache, if available.
|
||||||
|
if len(itr.infos) > 1 {
|
||||||
|
itr.infos = itr.infos[1:]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
itr.infos = itr.infos[:0] // otherwise clear infos
|
||||||
|
|
||||||
|
// Move to the next index unless this is the first time initializing.
|
||||||
|
if itr.infos != nil && len(itr.indexes) > 0 {
|
||||||
|
itr.indexes = itr.indexes[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no indexes remain, stop iteration.
|
||||||
|
if len(itr.indexes) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read segments into a cache for the current index.
|
||||||
|
index := itr.indexes[0]
|
||||||
|
f, err := os.Open(filepath.Join(itr.dir, litestream.FormatIndex(index)))
|
||||||
|
if err != nil {
|
||||||
|
itr.err = err
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
fis, err := f.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
itr.err = err
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, fi := range fis {
|
||||||
|
filename := filepath.Base(fi.Name())
|
||||||
|
if fi.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
offset, err := litestream.ParseOffset(strings.TrimSuffix(filename, ".wal.lz4"))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
itr.infos = append(itr.infos, litestream.WALSegmentInfo{
|
||||||
|
Generation: itr.generation,
|
||||||
|
Index: index,
|
||||||
|
Offset: offset,
|
||||||
|
Size: fi.Size(),
|
||||||
|
CreatedAt: fi.ModTime().UTC(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(itr.infos) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Err() error { return itr.err }
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) WALSegment() litestream.WALSegmentInfo {
|
||||||
|
if len(itr.infos) == 0 {
|
||||||
|
return litestream.WALSegmentInfo{}
|
||||||
|
}
|
||||||
|
return itr.infos[0]
|
||||||
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func TestReplicaClient_WALSegmentPath(t *testing.T) {
|
|||||||
t.Run("OK", func(t *testing.T) {
|
t.Run("OK", func(t *testing.T) {
|
||||||
if got, err := file.NewReplicaClient("/foo").WALSegmentPath("0123456701234567", 1000, 1001); err != nil {
|
if got, err := file.NewReplicaClient("/foo").WALSegmentPath("0123456701234567", 1000, 1001); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if want := "/foo/generations/0123456701234567/wal/000003e8_000003e9.wal.lz4"; got != want {
|
} else if want := "/foo/generations/0123456701234567/wal/000003e8/000003e9.wal.lz4"; got != want {
|
||||||
t.Fatalf("WALPath()=%v, want %v", got, want)
|
t.Fatalf("WALPath()=%v, want %v", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
// Construct query to only pull generation directory names.
|
// Construct query to only pull generation directory names.
|
||||||
query := &storage.Query{
|
query := &storage.Query{
|
||||||
Delimiter: "/",
|
Delimiter: "/",
|
||||||
Prefix: litestream.GenerationsPath(c.Path) + "/",
|
Prefix: path.Join(c.Path, "generations") + "/",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over results and only build list of generation-formatted names.
|
// Loop over results and only build list of generation-formatted names.
|
||||||
@@ -96,16 +96,15 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := litestream.GenerationPath(c.Path, generation)
|
prefix := path.Join(c.Path, "generations", generation) + "/"
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine generation path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over every object in generation and delete it.
|
// Iterate over every object in generation and delete it.
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
for it := c.bkt.Objects(ctx, &storage.Query{Prefix: dir + "/"}); ; {
|
for it := c.bkt.Objects(ctx, &storage.Query{Prefix: prefix}); ; {
|
||||||
attrs, err := it.Next()
|
attrs, err := it.Next()
|
||||||
if err == iterator.Done {
|
if err == iterator.Done {
|
||||||
break
|
break
|
||||||
@@ -130,24 +129,22 @@ func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string)
|
|||||||
func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (litestream.SnapshotIterator, error) {
|
func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (litestream.SnapshotIterator, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
dir, err := litestream.SnapshotsPath(c.Path, generation)
|
prefix := path.Join(c.Path, "generations", generation) + "/"
|
||||||
if err != nil {
|
return newSnapshotIterator(generation, c.bkt.Objects(ctx, &storage.Query{Prefix: prefix})), nil
|
||||||
return nil, fmt.Errorf("cannot determine snapshots path: %w", err)
|
|
||||||
}
|
|
||||||
return newSnapshotIterator(generation, c.bkt.Objects(ctx, &storage.Query{Prefix: dir + "/"})), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteSnapshot writes LZ4 compressed data from rd to the object storage.
|
// WriteSnapshot writes LZ4 compressed data from rd to the object storage.
|
||||||
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
w := c.bkt.Object(key).NewWriter(ctx)
|
w := c.bkt.Object(key).NewWriter(ctx)
|
||||||
@@ -177,12 +174,11 @@ func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, in
|
|||||||
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := c.bkt.Object(key).NewReader(ctx)
|
r, err := c.bkt.Object(key).NewReader(ctx)
|
||||||
if isNotExists(err) {
|
if isNotExists(err) {
|
||||||
@@ -201,12 +197,11 @@ func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, i
|
|||||||
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index), ".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.bkt.Object(key).Delete(ctx); err != nil && !isNotExists(err) {
|
if err := c.bkt.Object(key).Delete(ctx); err != nil && !isNotExists(err) {
|
||||||
return fmt.Errorf("cannot delete snapshot %q: %w", key, err)
|
return fmt.Errorf("cannot delete snapshot %q: %w", key, err)
|
||||||
@@ -220,24 +215,22 @@ func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, i
|
|||||||
func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (litestream.WALSegmentIterator, error) {
|
func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (litestream.WALSegmentIterator, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
dir, err := litestream.WALPath(c.Path, generation)
|
prefix := path.Join(c.Path, "generations", generation, "wal") + "/"
|
||||||
if err != nil {
|
return newWALSegmentIterator(generation, prefix, c.bkt.Objects(ctx, &storage.Query{Prefix: prefix})), nil
|
||||||
return nil, fmt.Errorf("cannot determine wal path: %w", err)
|
|
||||||
}
|
|
||||||
return newWALSegmentIterator(generation, c.bkt.Objects(ctx, &storage.Query{Prefix: dir + "/"})), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
||||||
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
w := c.bkt.Object(key).NewWriter(ctx)
|
w := c.bkt.Object(key).NewWriter(ctx)
|
||||||
@@ -267,12 +260,11 @@ func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos,
|
|||||||
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := c.bkt.Object(key).NewReader(ctx)
|
r, err := c.bkt.Object(key).NewReader(ctx)
|
||||||
if isNotExists(err) {
|
if isNotExists(err) {
|
||||||
@@ -294,11 +286,11 @@ func (c *ReplicaClient) DeleteWALSegments(ctx context.Context, a []litestream.Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pos := range a {
|
for _, pos := range a {
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
if pos.Generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err := c.bkt.Object(key).Delete(ctx); err != nil && !isNotExists(err) {
|
if err := c.bkt.Object(key).Delete(ctx); err != nil && !isNotExists(err) {
|
||||||
return fmt.Errorf("cannot delete wal segment %q: %w", key, err)
|
return fmt.Errorf("cannot delete wal segment %q: %w", key, err)
|
||||||
}
|
}
|
||||||
@@ -344,7 +336,7 @@ func (itr *snapshotIterator) Next() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse index, otherwise skip to the next object.
|
// Parse index, otherwise skip to the next object.
|
||||||
index, err := litestream.ParseSnapshotPath(path.Base(attrs.Name))
|
index, err := internal.ParseSnapshotPath(path.Base(attrs.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -366,15 +358,17 @@ func (itr *snapshotIterator) Snapshot() litestream.SnapshotInfo { return itr.inf
|
|||||||
|
|
||||||
type walSegmentIterator struct {
|
type walSegmentIterator struct {
|
||||||
generation string
|
generation string
|
||||||
|
prefix string
|
||||||
|
|
||||||
it *storage.ObjectIterator
|
it *storage.ObjectIterator
|
||||||
info litestream.WALSegmentInfo
|
info litestream.WALSegmentInfo
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWALSegmentIterator(generation string, it *storage.ObjectIterator) *walSegmentIterator {
|
func newWALSegmentIterator(generation, prefix string, it *storage.ObjectIterator) *walSegmentIterator {
|
||||||
return &walSegmentIterator{
|
return &walSegmentIterator{
|
||||||
generation: generation,
|
generation: generation,
|
||||||
|
prefix: prefix,
|
||||||
it: it,
|
it: it,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,7 +394,7 @@ func (itr *walSegmentIterator) Next() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse index & offset, otherwise skip to the next object.
|
// Parse index & offset, otherwise skip to the next object.
|
||||||
index, offset, err := litestream.ParseWALSegmentPath(path.Base(attrs.Name))
|
index, offset, err := internal.ParseWALSegmentPath(strings.TrimPrefix(attrs.Name, itr.prefix))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
12
go.mod
12
go.mod
@@ -4,14 +4,16 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go/storage v1.15.0
|
cloud.google.com/go/storage v1.15.0
|
||||||
github.com/Azure/azure-storage-blob-go v0.13.0
|
github.com/Azure/azure-storage-blob-go v0.13.0 // indirect
|
||||||
|
github.com/Azure/go-autorest/autorest v0.9.0 // indirect
|
||||||
github.com/aws/aws-sdk-go v1.27.0
|
github.com/aws/aws-sdk-go v1.27.0
|
||||||
github.com/mattn/go-shellwords v1.0.11
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.12
|
github.com/mattn/go-shellwords v1.0.11 // indirect
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.5
|
||||||
github.com/pierrec/lz4/v4 v4.1.3
|
github.com/pierrec/lz4/v4 v4.1.3
|
||||||
github.com/pkg/sftp v1.13.0
|
github.com/pkg/sftp v1.13.0 // indirect
|
||||||
github.com/prometheus/client_golang v1.9.0
|
github.com/prometheus/client_golang v1.9.0
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
|
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750
|
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750
|
||||||
google.golang.org/api v0.45.0
|
google.golang.org/api v0.45.0
|
||||||
|
|||||||
32
go.sum
32
go.sum
@@ -43,14 +43,17 @@ github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVt
|
|||||||
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
|
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
|
||||||
github.com/Azure/azure-storage-blob-go v0.13.0 h1:lgWHvFh+UYBNVQLFHXkvul2f6yOPA9PIH82RTG2cSwc=
|
github.com/Azure/azure-storage-blob-go v0.13.0 h1:lgWHvFh+UYBNVQLFHXkvul2f6yOPA9PIH82RTG2cSwc=
|
||||||
github.com/Azure/azure-storage-blob-go v0.13.0/go.mod h1:pA9kNqtjUeQF2zOSu4s//nUdBD+e64lEuc4sVnuOfNs=
|
github.com/Azure/azure-storage-blob-go v0.13.0/go.mod h1:pA9kNqtjUeQF2zOSu4s//nUdBD+e64lEuc4sVnuOfNs=
|
||||||
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
|
|
||||||
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
|
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
|
||||||
github.com/Azure/go-autorest/autorest/adal v0.9.2 h1:Aze/GQeAN1RRbGmnUJvUj+tFGBzFdIg3293/A9rbxC4=
|
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||||
|
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
|
||||||
github.com/Azure/go-autorest/autorest/adal v0.9.2/go.mod h1:/3SMAM86bP6wC9Ev35peQDUeqFZBMH07vvUOmg4z/fE=
|
github.com/Azure/go-autorest/autorest/adal v0.9.2/go.mod h1:/3SMAM86bP6wC9Ev35peQDUeqFZBMH07vvUOmg4z/fE=
|
||||||
github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw=
|
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
|
||||||
github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74=
|
github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74=
|
||||||
|
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||||
|
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||||
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
|
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
|
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
|
||||||
|
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
|
||||||
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
|
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
@@ -102,7 +105,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||||
@@ -164,6 +166,7 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
|
|||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
|
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
|
||||||
@@ -182,13 +185,10 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
|
||||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||||
github.com/google/martian/v3 v3.1.0 h1:wCKgOCHuUEVfsaQLpPSJb7VdYCdTVZQAuOdYm1yc/60=
|
|
||||||
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||||
@@ -266,7 +266,6 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
|||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||||
@@ -279,8 +278,8 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
|
|||||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-shellwords v1.0.11 h1:vCoR9VPpsk/TZFW2JwK5I9S0xdrtUq2bph6/YjEPnaw=
|
github.com/mattn/go-shellwords v1.0.11 h1:vCoR9VPpsk/TZFW2JwK5I9S0xdrtUq2bph6/YjEPnaw=
|
||||||
github.com/mattn/go-shellwords v1.0.11/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
github.com/mattn/go-shellwords v1.0.11/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
|
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
|
||||||
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
@@ -304,7 +303,6 @@ github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzE
|
|||||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||||
@@ -328,6 +326,7 @@ github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9
|
|||||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
|
github.com/pierrec/lz4 v2.6.0+incompatible h1:Ix9yFKn1nSPBLFl/yZknTp8TU5G4Ps0JDmguYK6iH1A=
|
||||||
github.com/pierrec/lz4/v4 v4.1.3 h1:/dvQpkb0o1pVlSgKNQqfkavlnXaIK+hJ0LXsKRUN9D4=
|
github.com/pierrec/lz4/v4 v4.1.3 h1:/dvQpkb0o1pVlSgKNQqfkavlnXaIK+hJ0LXsKRUN9D4=
|
||||||
github.com/pierrec/lz4/v4 v4.1.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@@ -337,7 +336,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||||
github.com/pkg/sftp v1.13.0 h1:Riw6pgOKK41foc1I1Uu03CjvbLZDXeGpInycM4shXoI=
|
github.com/pkg/sftp v1.13.0 h1:Riw6pgOKK41foc1I1Uu03CjvbLZDXeGpInycM4shXoI=
|
||||||
github.com/pkg/sftp v1.13.0/go.mod h1:41g+FIPlQUTDCveupEmEA65IoiQFrtgCeDopC4ajGIM=
|
github.com/pkg/sftp v1.13.0/go.mod h1:41g+FIPlQUTDCveupEmEA65IoiQFrtgCeDopC4ajGIM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
@@ -393,7 +391,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
@@ -430,6 +427,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
|||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
|
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
|
||||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||||
@@ -581,6 +579,7 @@ golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e h1:AyodaIpKjppX+cBfTASF2E1US3H2JFBj920Ot3rtDjs=
|
||||||
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -591,7 +590,6 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog=
|
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog=
|
||||||
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
@@ -770,6 +768,7 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
|
|||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||||
@@ -778,10 +777,10 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
|||||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
@@ -798,7 +797,6 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@@ -127,6 +130,33 @@ func MkdirAll(path string, fi os.FileInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseSnapshotPath parses the index from a snapshot filename. Used by path-based replicas.
|
||||||
|
func ParseSnapshotPath(s string) (index int, err error) {
|
||||||
|
a := snapshotPathRegex.FindStringSubmatch(s)
|
||||||
|
if a == nil {
|
||||||
|
return 0, fmt.Errorf("invalid snapshot path")
|
||||||
|
}
|
||||||
|
|
||||||
|
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
||||||
|
return int(i64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var snapshotPathRegex = regexp.MustCompile(`^([0-9a-f]{8})\.snapshot\.lz4$`)
|
||||||
|
|
||||||
|
// ParseWALSegmentPath parses the index/offset from a segment filename. Used by path-based replicas.
|
||||||
|
func ParseWALSegmentPath(s string) (index int, offset int64, err error) {
|
||||||
|
a := walSegmentPathRegex.FindStringSubmatch(s)
|
||||||
|
if a == nil {
|
||||||
|
return 0, 0, fmt.Errorf("invalid wal segment path")
|
||||||
|
}
|
||||||
|
|
||||||
|
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
||||||
|
off64, _ := strconv.ParseUint(a[2], 16, 64)
|
||||||
|
return int(i64), int64(off64), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var walSegmentPathRegex = regexp.MustCompile(`^([0-9a-f]{8})\/([0-9a-f]{8})\.wal\.lz4$`)
|
||||||
|
|
||||||
// Shared replica metrics.
|
// Shared replica metrics.
|
||||||
var (
|
var (
|
||||||
OperationTotalCounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
|
OperationTotalCounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
|||||||
61
internal/internal_test.go
Normal file
61
internal/internal_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package internal_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/benbjohnson/litestream/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseSnapshotPath(t *testing.T) {
|
||||||
|
for _, tt := range []struct {
|
||||||
|
s string
|
||||||
|
index int
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{"00bc614e.snapshot.lz4", 12345678, nil},
|
||||||
|
{"xxxxxxxx.snapshot.lz4", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
{"00bc614.snapshot.lz4", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
{"00bc614e.snapshot.lz", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
{"00bc614e.snapshot", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
{"00bc614e", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
{"", 0, fmt.Errorf("invalid snapshot path")},
|
||||||
|
} {
|
||||||
|
t.Run("", func(t *testing.T) {
|
||||||
|
index, err := internal.ParseSnapshotPath(tt.s)
|
||||||
|
if got, want := index, tt.index; got != want {
|
||||||
|
t.Errorf("index=%#v, want %#v", got, want)
|
||||||
|
} else if got, want := err, tt.err; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("err=%#v, want %#v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseWALSegmentPath(t *testing.T) {
|
||||||
|
for _, tt := range []struct {
|
||||||
|
s string
|
||||||
|
index int
|
||||||
|
offset int64
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
{"00bc614e/000003e8.wal.lz4", 12345678, 1000, nil},
|
||||||
|
{"00000000/00000000.wal", 0, 0, fmt.Errorf("invalid wal segment path")},
|
||||||
|
{"00000000/00000000", 0, 0, fmt.Errorf("invalid wal segment path")},
|
||||||
|
{"00000000/", 0, 0, fmt.Errorf("invalid wal segment path")},
|
||||||
|
{"00000000", 0, 0, fmt.Errorf("invalid wal segment path")},
|
||||||
|
{"", 0, 0, fmt.Errorf("invalid wal segment path")},
|
||||||
|
} {
|
||||||
|
t.Run("", func(t *testing.T) {
|
||||||
|
index, offset, err := internal.ParseWALSegmentPath(tt.s)
|
||||||
|
if got, want := index, tt.index; got != want {
|
||||||
|
t.Errorf("index=%#v, want %#v", got, want)
|
||||||
|
} else if got, want := offset, tt.offset; got != want {
|
||||||
|
t.Errorf("offset=%#v, want %#v", got, want)
|
||||||
|
} else if got, want := err, tt.err; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("err=%#v, want %#v", got, want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
144
litestream.go
144
litestream.go
@@ -7,9 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -207,13 +205,11 @@ func FilterSnapshotsAfter(a []SnapshotInfo, t time.Time) []SnapshotInfo {
|
|||||||
// FindMinSnapshotByGeneration finds the snapshot with the lowest index in a generation.
|
// FindMinSnapshotByGeneration finds the snapshot with the lowest index in a generation.
|
||||||
func FindMinSnapshotByGeneration(a []SnapshotInfo, generation string) *SnapshotInfo {
|
func FindMinSnapshotByGeneration(a []SnapshotInfo, generation string) *SnapshotInfo {
|
||||||
var min *SnapshotInfo
|
var min *SnapshotInfo
|
||||||
for i := range a {
|
for _, snapshot := range a {
|
||||||
snapshot := &a[i]
|
|
||||||
|
|
||||||
if snapshot.Generation != generation {
|
if snapshot.Generation != generation {
|
||||||
continue
|
continue
|
||||||
} else if min == nil || snapshot.Index < min.Index {
|
} else if min == nil || snapshot.Index < min.Index {
|
||||||
min = snapshot
|
min = &snapshot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return min
|
return min
|
||||||
@@ -386,134 +382,34 @@ func IsGenerationName(s string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerationsPath returns the path to a generation root directory.
|
// FormatIndex formats an index as an 8-character hex value.
|
||||||
func GenerationsPath(root string) string {
|
func FormatIndex(index int) string {
|
||||||
return path.Join(root, "generations")
|
return fmt.Sprintf("%08x", index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerationPath returns the path to a generation's root directory.
|
// ParseIndex parses a hex-formatted index into an integer.
|
||||||
func GenerationPath(root, generation string) (string, error) {
|
func ParseIndex(s string) (int, error) {
|
||||||
dir := GenerationsPath(root)
|
v, err := strconv.ParseUint(s, 16, 32)
|
||||||
if generation == "" {
|
|
||||||
return "", fmt.Errorf("generation required")
|
|
||||||
}
|
|
||||||
return path.Join(dir, generation), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SnapshotsPath returns the path to a generation's snapshot directory.
|
|
||||||
func SnapshotsPath(root, generation string) (string, error) {
|
|
||||||
dir, err := GenerationPath(root, generation)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return -1, fmt.Errorf("cannot parse index: %q", s)
|
||||||
}
|
}
|
||||||
return path.Join(dir, "snapshots"), nil
|
return int(v), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SnapshotPath returns the path to an uncompressed snapshot file.
|
// FormatOffset formats an offset as an 8-character hex value.
|
||||||
func SnapshotPath(root, generation string, index int) (string, error) {
|
func FormatOffset(offset int64) string {
|
||||||
dir, err := SnapshotsPath(root, generation)
|
return fmt.Sprintf("%08x", offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseOffset parses a hex-formatted offset into an integer.
|
||||||
|
func ParseOffset(s string) (int64, error) {
|
||||||
|
v, err := strconv.ParseInt(s, 16, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return -1, fmt.Errorf("cannot parse index: %q", s)
|
||||||
}
|
}
|
||||||
return path.Join(dir, FormatSnapshotPath(index)), nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WALPath returns the path to a generation's WAL directory
|
|
||||||
func WALPath(root, generation string) (string, error) {
|
|
||||||
dir, err := GenerationPath(root, generation)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return path.Join(dir, "wal"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WALSegmentPath returns the path to a WAL segment file.
|
|
||||||
func WALSegmentPath(root, generation string, index int, offset int64) (string, error) {
|
|
||||||
dir, err := WALPath(root, generation)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return path.Join(dir, FormatWALSegmentPath(index, offset)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsSnapshotPath returns true if s is a path to a snapshot file.
|
|
||||||
func IsSnapshotPath(s string) bool {
|
|
||||||
return snapshotPathRegex.MatchString(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseSnapshotPath returns the index for the snapshot.
|
|
||||||
// Returns an error if the path is not a valid snapshot path.
|
|
||||||
func ParseSnapshotPath(s string) (index int, err error) {
|
|
||||||
s = filepath.Base(s)
|
|
||||||
|
|
||||||
a := snapshotPathRegex.FindStringSubmatch(s)
|
|
||||||
if a == nil {
|
|
||||||
return 0, fmt.Errorf("invalid snapshot path: %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
|
||||||
return int(i64), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormatSnapshotPath formats a snapshot filename with a given index.
|
|
||||||
func FormatSnapshotPath(index int) string {
|
|
||||||
assert(index >= 0, "snapshot index must be non-negative")
|
|
||||||
return fmt.Sprintf("%08x%s", index, SnapshotExt)
|
|
||||||
}
|
|
||||||
|
|
||||||
var snapshotPathRegex = regexp.MustCompile(`^([0-9a-f]{8})\.snapshot\.lz4$`)
|
|
||||||
|
|
||||||
// IsWALPath returns true if s is a path to a WAL file.
|
|
||||||
func IsWALPath(s string) bool {
|
|
||||||
return walPathRegex.MatchString(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseWALPath returns the index for the WAL file.
|
|
||||||
// Returns an error if the path is not a valid WAL path.
|
|
||||||
func ParseWALPath(s string) (index int, err error) {
|
|
||||||
s = filepath.Base(s)
|
|
||||||
|
|
||||||
a := walPathRegex.FindStringSubmatch(s)
|
|
||||||
if a == nil {
|
|
||||||
return 0, fmt.Errorf("invalid wal path: %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
|
||||||
return int(i64), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormatWALPath formats a WAL filename with a given index.
|
|
||||||
func FormatWALPath(index int) string {
|
|
||||||
assert(index >= 0, "wal index must be non-negative")
|
|
||||||
return fmt.Sprintf("%08x%s", index, WALExt)
|
|
||||||
}
|
|
||||||
|
|
||||||
var walPathRegex = regexp.MustCompile(`^([0-9a-f]{8})\.wal$`)
|
|
||||||
|
|
||||||
// ParseWALSegmentPath returns the index & offset for the WAL segment file.
|
|
||||||
// Returns an error if the path is not a valid wal segment path.
|
|
||||||
func ParseWALSegmentPath(s string) (index int, offset int64, err error) {
|
|
||||||
s = filepath.Base(s)
|
|
||||||
|
|
||||||
a := walSegmentPathRegex.FindStringSubmatch(s)
|
|
||||||
if a == nil {
|
|
||||||
return 0, 0, fmt.Errorf("invalid wal segment path: %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
i64, _ := strconv.ParseUint(a[1], 16, 64)
|
|
||||||
off64, _ := strconv.ParseUint(a[2], 16, 64)
|
|
||||||
return int(i64), int64(off64), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FormatWALSegmentPath formats a WAL segment filename with a given index & offset.
|
|
||||||
func FormatWALSegmentPath(index int, offset int64) string {
|
|
||||||
assert(index >= 0, "wal index must be non-negative")
|
|
||||||
assert(offset >= 0, "wal offset must be non-negative")
|
|
||||||
return fmt.Sprintf("%08x_%08x%s", index, offset, WALSegmentExt)
|
|
||||||
}
|
|
||||||
|
|
||||||
var walSegmentPathRegex = regexp.MustCompile(`^([0-9a-f]{8})(?:_([0-9a-f]{8}))\.wal\.lz4$`)
|
|
||||||
|
|
||||||
// isHexChar returns true if ch is a lowercase hex character.
|
// isHexChar returns true if ch is a lowercase hex character.
|
||||||
func isHexChar(ch rune) bool {
|
func isHexChar(ch rune) bool {
|
||||||
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')
|
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')
|
||||||
|
|||||||
@@ -40,104 +40,6 @@ func TestChecksum(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerationsPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, want := litestream.GenerationsPath("foo"), "foo/generations"; got != want {
|
|
||||||
t.Fatalf("GenerationsPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("NoPath", func(t *testing.T) {
|
|
||||||
if got, want := litestream.GenerationsPath(""), "generations"; got != want {
|
|
||||||
t.Fatalf("GenerationsPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGenerationPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, err := litestream.GenerationPath("foo", "0123456701234567"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
} else if want := "foo/generations/0123456701234567"; got != want {
|
|
||||||
t.Fatalf("GenerationPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("ErrNoGeneration", func(t *testing.T) {
|
|
||||||
if _, err := litestream.GenerationPath("foo", ""); err == nil || err.Error() != `generation required` {
|
|
||||||
t.Fatalf("expected error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSnapshotsPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, err := litestream.SnapshotsPath("foo", "0123456701234567"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
} else if want := "foo/generations/0123456701234567/snapshots"; got != want {
|
|
||||||
t.Fatalf("SnapshotsPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("ErrNoGeneration", func(t *testing.T) {
|
|
||||||
if _, err := litestream.SnapshotsPath("foo", ""); err == nil || err.Error() != `generation required` {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSnapshotPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, err := litestream.SnapshotPath("foo", "0123456701234567", 1000); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
} else if want := "foo/generations/0123456701234567/snapshots/000003e8.snapshot.lz4"; got != want {
|
|
||||||
t.Fatalf("SnapshotPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("ErrNoGeneration", func(t *testing.T) {
|
|
||||||
if _, err := litestream.SnapshotPath("foo", "", 1000); err == nil || err.Error() != `generation required` {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWALPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, err := litestream.WALPath("foo", "0123456701234567"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
} else if want := "foo/generations/0123456701234567/wal"; got != want {
|
|
||||||
t.Fatalf("WALPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("ErrNoGeneration", func(t *testing.T) {
|
|
||||||
if _, err := litestream.WALPath("foo", ""); err == nil || err.Error() != `generation required` {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWALSegmentPath(t *testing.T) {
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
|
||||||
if got, err := litestream.WALSegmentPath("foo", "0123456701234567", 1000, 1001); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
} else if want := "foo/generations/0123456701234567/wal/000003e8_000003e9.wal.lz4"; got != want {
|
|
||||||
t.Fatalf("WALPath()=%v, want %v", got, want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("ErrNoGeneration", func(t *testing.T) {
|
|
||||||
if _, err := litestream.WALSegmentPath("foo", "", 1000, 0); err == nil || err.Error() != `generation required` {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFindMinSnapshotByGeneration(t *testing.T) {
|
|
||||||
infos := []litestream.SnapshotInfo{
|
|
||||||
{Generation: "29cf4bced74e92ab", Index: 0},
|
|
||||||
{Generation: "5dfeb4aa03232553", Index: 24},
|
|
||||||
}
|
|
||||||
if got, want := litestream.FindMinSnapshotByGeneration(infos, "29cf4bced74e92ab"), &infos[0]; got != want {
|
|
||||||
t.Fatalf("info=%#v, want %#v", got, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MustDecodeHexString(s string) []byte {
|
func MustDecodeHexString(s string) []byte {
|
||||||
b, err := hex.DecodeString(s)
|
b, err := hex.DecodeString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
32
replica.go
32
replica.go
@@ -159,21 +159,22 @@ func (r *Replica) Sync(ctx context.Context) (err error) {
|
|||||||
|
|
||||||
Tracef("%s(%s): replica sync: db.pos=%s", r.db.Path(), r.Name(), dpos)
|
Tracef("%s(%s): replica sync: db.pos=%s", r.db.Path(), r.Name(), dpos)
|
||||||
|
|
||||||
// Create a new snapshot and update the current replica position if
|
// Create snapshot if no snapshots exist for generation.
|
||||||
// the generation on the database has changed.
|
snapshotN, err := r.snapshotN(generation)
|
||||||
if r.Pos().Generation != generation {
|
if err != nil {
|
||||||
// Create snapshot if no snapshots exist for generation.
|
return err
|
||||||
snapshotN, err := r.snapshotN(generation)
|
} else if snapshotN == 0 {
|
||||||
if err != nil {
|
if info, err := r.Snapshot(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if snapshotN == 0 {
|
} else if info.Generation != generation {
|
||||||
if info, err := r.Snapshot(ctx); err != nil {
|
return fmt.Errorf("generation changed during snapshot, exiting sync")
|
||||||
return err
|
|
||||||
} else if info.Generation != generation {
|
|
||||||
return fmt.Errorf("generation changed during snapshot, exiting sync")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
snapshotN = 1
|
||||||
|
}
|
||||||
|
replicaSnapshotTotalGaugeVec.WithLabelValues(r.db.Path(), r.Name()).Set(float64(snapshotN))
|
||||||
|
|
||||||
|
// Determine position, if necessary.
|
||||||
|
if r.Pos().Generation != generation {
|
||||||
pos, err := r.calcPos(ctx, generation)
|
pos, err := r.calcPos(ctx, generation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot determine replica position: %s", err)
|
return fmt.Errorf("cannot determine replica position: %s", err)
|
||||||
@@ -1306,6 +1307,13 @@ func (r *Replica) downloadWAL(ctx context.Context, generation string, index int,
|
|||||||
|
|
||||||
// Replica metrics.
|
// Replica metrics.
|
||||||
var (
|
var (
|
||||||
|
replicaSnapshotTotalGaugeVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
|
Namespace: "litestream",
|
||||||
|
Subsystem: "replica",
|
||||||
|
Name: "snapshot_total",
|
||||||
|
Help: "The current number of snapshots",
|
||||||
|
}, []string{"db", "name"})
|
||||||
|
|
||||||
replicaWALBytesCounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
|
replicaWALBytesCounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "litestream",
|
Namespace: "litestream",
|
||||||
Subsystem: "replica",
|
Subsystem: "replica",
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ func TestReplicaClient_Snapshots(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = itr.Close()
|
err = itr.Close()
|
||||||
}
|
}
|
||||||
if err == nil || err.Error() != `cannot determine snapshots path: generation required` {
|
if err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -204,7 +204,7 @@ func TestReplicaClient_WriteSnapshot(t *testing.T) {
|
|||||||
|
|
||||||
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if _, err := c.WriteSnapshot(context.Background(), "", 0, nil); err == nil || err.Error() != `cannot determine snapshot path: generation required` {
|
if _, err := c.WriteSnapshot(context.Background(), "", 0, nil); err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -242,13 +242,13 @@ func TestReplicaClient_SnapshotReader(t *testing.T) {
|
|||||||
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if _, err := c.SnapshotReader(context.Background(), "", 1); err == nil || err.Error() != `cannot determine snapshot path: generation required` {
|
if _, err := c.SnapshotReader(context.Background(), "", 1); err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplicaClient_WALs(t *testing.T) {
|
func TestReplicaClient_WALSegments(t *testing.T) {
|
||||||
RunWithReplicaClient(t, "OK", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "OK", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ func TestReplicaClient_WALs(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
err = itr.Close()
|
err = itr.Close()
|
||||||
}
|
}
|
||||||
if err == nil || err.Error() != `cannot determine wal path: generation required` {
|
if err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -389,13 +389,13 @@ func TestReplicaClient_WriteWALSegment(t *testing.T) {
|
|||||||
|
|
||||||
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if _, err := c.WriteWALSegment(context.Background(), litestream.Pos{Generation: "", Index: 0, Offset: 0}, nil); err == nil || err.Error() != `cannot determine wal segment path: generation required` {
|
if _, err := c.WriteWALSegment(context.Background(), litestream.Pos{Generation: "", Index: 0, Offset: 0}, nil); err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplicaClient_WALReader(t *testing.T) {
|
func TestReplicaClient_WALSegmentReader(t *testing.T) {
|
||||||
|
|
||||||
RunWithReplicaClient(t, "OK", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "OK", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -451,7 +451,7 @@ func TestReplicaClient_DeleteWALSegments(t *testing.T) {
|
|||||||
|
|
||||||
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
RunWithReplicaClient(t, "ErrNoGeneration", func(t *testing.T, c litestream.ReplicaClient) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if err := c.DeleteWALSegments(context.Background(), []litestream.Pos{{}}); err == nil || err.Error() != `cannot determine wal segment path: generation required` {
|
if err := c.DeleteWALSegments(context.Background(), []litestream.Pos{{}}); err == nil || err.Error() != `generation required` {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
var generations []string
|
var generations []string
|
||||||
if err := c.s3.ListObjectsPagesWithContext(ctx, &s3.ListObjectsInput{
|
if err := c.s3.ListObjectsPagesWithContext(ctx, &s3.ListObjectsInput{
|
||||||
Bucket: aws.String(c.Bucket),
|
Bucket: aws.String(c.Bucket),
|
||||||
Prefix: aws.String(litestream.GenerationsPath(c.Path) + "/"),
|
Prefix: aws.String(path.Join(c.Path, "generations") + "/"),
|
||||||
Delimiter: aws.String("/"),
|
Delimiter: aws.String("/"),
|
||||||
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
@@ -178,18 +179,15 @@ func (c *ReplicaClient) Generations(ctx context.Context) ([]string, error) {
|
|||||||
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
dir, err := litestream.GenerationPath(c.Path, generation)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine generation path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect all files for the generation.
|
// Collect all files for the generation.
|
||||||
var objIDs []*s3.ObjectIdentifier
|
var objIDs []*s3.ObjectIdentifier
|
||||||
if err := c.s3.ListObjectsPagesWithContext(ctx, &s3.ListObjectsInput{
|
if err := c.s3.ListObjectsPagesWithContext(ctx, &s3.ListObjectsInput{
|
||||||
Bucket: aws.String(c.Bucket),
|
Bucket: aws.String(c.Bucket),
|
||||||
Prefix: aws.String(dir),
|
Prefix: aws.String(path.Join(c.Path, "generations", generation)),
|
||||||
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
@@ -236,12 +234,11 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (lites
|
|||||||
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, index int, rd io.Reader) (info litestream.SnapshotInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
rc := internal.NewReadCounter(rd)
|
rc := internal.NewReadCounter(rd)
|
||||||
@@ -270,12 +267,11 @@ func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, in
|
|||||||
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := c.s3.GetObjectWithContext(ctx, &s3.GetObjectInput{
|
out, err := c.s3.GetObjectWithContext(ctx, &s3.GetObjectInput{
|
||||||
Bucket: aws.String(c.Bucket),
|
Bucket: aws.String(c.Bucket),
|
||||||
@@ -296,12 +292,11 @@ func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, i
|
|||||||
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, index int) error {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.SnapshotPath(c.Path, generation, index)
|
key := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := c.s3.DeleteObjectsWithContext(ctx, &s3.DeleteObjectsInput{
|
if _, err := c.s3.DeleteObjectsWithContext(ctx, &s3.DeleteObjectsInput{
|
||||||
Bucket: aws.String(c.Bucket),
|
Bucket: aws.String(c.Bucket),
|
||||||
@@ -326,12 +321,11 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (lit
|
|||||||
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos, rd io.Reader) (info litestream.WALSegmentInfo, err error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
rc := internal.NewReadCounter(rd)
|
rc := internal.NewReadCounter(rd)
|
||||||
@@ -360,12 +354,11 @@ func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos,
|
|||||||
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos) (io.ReadCloser, error) {
|
||||||
if err := c.Init(ctx); err != nil {
|
if err := c.Init(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := c.s3.GetObjectWithContext(ctx, &s3.GetObjectInput{
|
out, err := c.s3.GetObjectWithContext(ctx, &s3.GetObjectInput{
|
||||||
Bucket: aws.String(c.Bucket),
|
Bucket: aws.String(c.Bucket),
|
||||||
@@ -397,10 +390,10 @@ func (c *ReplicaClient) DeleteWALSegments(ctx context.Context, a []litestream.Po
|
|||||||
|
|
||||||
// Generate a batch of object IDs for deleting the WAL segments.
|
// Generate a batch of object IDs for deleting the WAL segments.
|
||||||
for i, pos := range a[:n] {
|
for i, pos := range a[:n] {
|
||||||
key, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
if pos.Generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
key := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
objIDs[i] = &s3.ObjectIdentifier{Key: &key}
|
objIDs[i] = &s3.ObjectIdentifier{Key: &key}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,11 +491,12 @@ func newSnapshotIterator(ctx context.Context, client *ReplicaClient, generation
|
|||||||
func (itr *snapshotIterator) fetch() error {
|
func (itr *snapshotIterator) fetch() error {
|
||||||
defer close(itr.ch)
|
defer close(itr.ch)
|
||||||
|
|
||||||
dir, err := litestream.SnapshotsPath(itr.client.Path, itr.generation)
|
if itr.generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine snapshots path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dir := path.Join(itr.client.Path, "generations", itr.generation, "snapshots")
|
||||||
|
|
||||||
return itr.client.s3.ListObjectsPagesWithContext(itr.ctx, &s3.ListObjectsInput{
|
return itr.client.s3.ListObjectsPagesWithContext(itr.ctx, &s3.ListObjectsInput{
|
||||||
Bucket: aws.String(itr.client.Bucket),
|
Bucket: aws.String(itr.client.Bucket),
|
||||||
Prefix: aws.String(dir + "/"),
|
Prefix: aws.String(dir + "/"),
|
||||||
@@ -511,8 +505,7 @@ func (itr *snapshotIterator) fetch() error {
|
|||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
for _, obj := range page.Contents {
|
for _, obj := range page.Contents {
|
||||||
key := path.Base(*obj.Key)
|
index, err := internal.ParseSnapshotPath(path.Base(*obj.Key))
|
||||||
index, err := litestream.ParseSnapshotPath(key)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -601,21 +594,20 @@ func newWALSegmentIterator(ctx context.Context, client *ReplicaClient, generatio
|
|||||||
func (itr *walSegmentIterator) fetch() error {
|
func (itr *walSegmentIterator) fetch() error {
|
||||||
defer close(itr.ch)
|
defer close(itr.ch)
|
||||||
|
|
||||||
dir, err := litestream.WALPath(itr.client.Path, itr.generation)
|
if itr.generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix := path.Join(itr.client.Path, "generations", itr.generation, "wal") + "/"
|
||||||
|
|
||||||
return itr.client.s3.ListObjectsPagesWithContext(itr.ctx, &s3.ListObjectsInput{
|
return itr.client.s3.ListObjectsPagesWithContext(itr.ctx, &s3.ListObjectsInput{
|
||||||
Bucket: aws.String(itr.client.Bucket),
|
Bucket: aws.String(itr.client.Bucket),
|
||||||
Prefix: aws.String(dir + "/"),
|
Prefix: aws.String(prefix),
|
||||||
Delimiter: aws.String("/"),
|
|
||||||
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
}, func(page *s3.ListObjectsOutput, lastPage bool) bool {
|
||||||
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "LIST").Inc()
|
||||||
|
|
||||||
for _, obj := range page.Contents {
|
for _, obj := range page.Contents {
|
||||||
key := path.Base(*obj.Key)
|
index, offset, err := internal.ParseWALSegmentPath(strings.TrimPrefix(*obj.Key, prefix))
|
||||||
index, offset, err := litestream.ParseWALSegmentPath(key)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ func (c *ReplicaClient) Generations(ctx context.Context) (_ []string, err error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fis, err := sftpClient.ReadDir(litestream.GenerationsPath(c.Path))
|
fis, err := sftpClient.ReadDir(path.Join(c.Path, "generations"))
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@@ -153,12 +154,11 @@ func (c *ReplicaClient) DeleteGeneration(ctx context.Context, generation string)
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := litestream.GenerationPath(c.Path, generation)
|
dir := path.Join(c.Path, "generations", generation)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine generation path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dirs []string
|
var dirs []string
|
||||||
walker := sftpClient.Walk(dir)
|
walker := sftpClient.Walk(dir)
|
||||||
@@ -198,12 +198,11 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (_ lit
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := litestream.SnapshotsPath(c.Path, generation)
|
dir := path.Join(c.Path, "generations", generation, "snapshots")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine snapshots path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fis, err := sftpClient.ReadDir(dir)
|
fis, err := sftpClient.ReadDir(dir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@@ -216,7 +215,7 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (_ lit
|
|||||||
infos := make([]litestream.SnapshotInfo, 0, len(fis))
|
infos := make([]litestream.SnapshotInfo, 0, len(fis))
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
// Parse index from filename.
|
// Parse index from filename.
|
||||||
index, err := litestream.ParseSnapshotPath(path.Base(fi.Name()))
|
index, err := internal.ParseSnapshotPath(path.Base(fi.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -241,12 +240,11 @@ func (c *ReplicaClient) WriteSnapshot(ctx context.Context, generation string, in
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, err := litestream.SnapshotPath(c.Path, generation, index)
|
filename := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
if err := sftpClient.MkdirAll(path.Dir(filename)); err != nil {
|
if err := sftpClient.MkdirAll(path.Dir(filename)); err != nil {
|
||||||
@@ -286,12 +284,11 @@ func (c *ReplicaClient) SnapshotReader(ctx context.Context, generation string, i
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, err := litestream.SnapshotPath(c.Path, generation, index)
|
filename := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := sftpClient.Open(filename)
|
f, err := sftpClient.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -310,12 +307,11 @@ func (c *ReplicaClient) DeleteSnapshot(ctx context.Context, generation string, i
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if generation == "" {
|
||||||
|
return fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, err := litestream.SnapshotPath(c.Path, generation, index)
|
filename := path.Join(c.Path, "generations", generation, "snapshots", litestream.FormatIndex(index)+".snapshot.lz4")
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot determine snapshot path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := sftpClient.Remove(filename); err != nil && !os.IsNotExist(err) {
|
if err := sftpClient.Remove(filename); err != nil && !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("cannot delete snapshot %q: %w", filename, err)
|
return fmt.Errorf("cannot delete snapshot %q: %w", filename, err)
|
||||||
@@ -332,12 +328,11 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (_ l
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := litestream.WALPath(c.Path, generation)
|
dir := path.Join(c.Path, "generations", generation, "wal")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine wal path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fis, err := sftpClient.ReadDir(dir)
|
fis, err := sftpClient.ReadDir(dir)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@@ -347,25 +342,18 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (_ l
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over every file and convert to metadata.
|
// Iterate over every file and convert to metadata.
|
||||||
infos := make([]litestream.WALSegmentInfo, 0, len(fis))
|
indexes := make([]int, 0, len(fis))
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
index, offset, err := litestream.ParseWALSegmentPath(path.Base(fi.Name()))
|
index, err := litestream.ParseIndex(fi.Name())
|
||||||
if err != nil {
|
if err != nil || !fi.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
indexes = append(indexes, index)
|
||||||
infos = append(infos, litestream.WALSegmentInfo{
|
|
||||||
Generation: generation,
|
|
||||||
Index: index,
|
|
||||||
Offset: offset,
|
|
||||||
Size: fi.Size(),
|
|
||||||
CreatedAt: fi.ModTime().UTC(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(litestream.WALSegmentInfoSlice(infos))
|
sort.Ints(indexes)
|
||||||
|
|
||||||
return litestream.NewWALSegmentInfoSliceIterator(infos), nil
|
return newWALSegmentIterator(ctx, c, dir, generation, indexes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
// WriteWALSegment writes LZ4 compressed data from rd into a file on disk.
|
||||||
@@ -375,12 +363,11 @@ func (c *ReplicaClient) WriteWALSegment(ctx context.Context, pos litestream.Pos,
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return info, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
filename := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
if err := sftpClient.MkdirAll(path.Dir(filename)); err != nil {
|
if err := sftpClient.MkdirAll(path.Dir(filename)); err != nil {
|
||||||
@@ -420,12 +407,11 @@ func (c *ReplicaClient) WALSegmentReader(ctx context.Context, pos litestream.Pos
|
|||||||
sftpClient, err := c.Init(ctx)
|
sftpClient, err := c.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if pos.Generation == "" {
|
||||||
|
return nil, fmt.Errorf("generation required")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
filename := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := sftpClient.Open(filename)
|
f, err := sftpClient.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -447,11 +433,12 @@ func (c *ReplicaClient) DeleteWALSegments(ctx context.Context, a []litestream.Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pos := range a {
|
for _, pos := range a {
|
||||||
filename, err := litestream.WALSegmentPath(c.Path, pos.Generation, pos.Index, pos.Offset)
|
if pos.Generation == "" {
|
||||||
if err != nil {
|
return fmt.Errorf("generation required")
|
||||||
return fmt.Errorf("cannot determine wal segment path: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filename := path.Join(c.Path, "generations", pos.Generation, "wal", litestream.FormatIndex(pos.Index), litestream.FormatOffset(pos.Offset)+".wal.lz4")
|
||||||
|
|
||||||
if err := sftpClient.Remove(filename); err != nil && !os.IsNotExist(err) {
|
if err := sftpClient.Remove(filename); err != nil && !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("cannot delete wal segment %q: %w", filename, err)
|
return fmt.Errorf("cannot delete wal segment %q: %w", filename, err)
|
||||||
}
|
}
|
||||||
@@ -470,7 +457,7 @@ func (c *ReplicaClient) Cleanup(ctx context.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sftpClient.RemoveDirectory(litestream.GenerationsPath(c.Path)); err != nil && !os.IsNotExist(err) {
|
if err := sftpClient.RemoveDirectory(path.Join(c.Path, "generations")); err != nil && !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("cannot delete generations path: %w", err)
|
return fmt.Errorf("cannot delete generations path: %w", err)
|
||||||
} else if err := sftpClient.RemoveDirectory(c.Path); err != nil && !os.IsNotExist(err) {
|
} else if err := sftpClient.RemoveDirectory(c.Path); err != nil && !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("cannot delete path: %w", err)
|
return fmt.Errorf("cannot delete path: %w", err)
|
||||||
@@ -493,3 +480,101 @@ func (c *ReplicaClient) resetOnConnError(err error) {
|
|||||||
c.sshClient = nil
|
c.sshClient = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type walSegmentIterator struct {
|
||||||
|
ctx context.Context
|
||||||
|
client *ReplicaClient
|
||||||
|
dir string
|
||||||
|
generation string
|
||||||
|
indexes []int
|
||||||
|
|
||||||
|
infos []litestream.WALSegmentInfo
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWALSegmentIterator(ctx context.Context, client *ReplicaClient, dir, generation string, indexes []int) *walSegmentIterator {
|
||||||
|
return &walSegmentIterator{
|
||||||
|
ctx: ctx,
|
||||||
|
client: client,
|
||||||
|
dir: dir,
|
||||||
|
generation: generation,
|
||||||
|
indexes: indexes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Close() (err error) {
|
||||||
|
return itr.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Next() bool {
|
||||||
|
sftpClient, err := itr.client.Init(itr.ctx)
|
||||||
|
if err != nil {
|
||||||
|
itr.err = err
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit if an error has already occurred.
|
||||||
|
if itr.err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Move to the next segment in cache, if available.
|
||||||
|
if len(itr.infos) > 1 {
|
||||||
|
itr.infos = itr.infos[1:]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
itr.infos = itr.infos[:0] // otherwise clear infos
|
||||||
|
|
||||||
|
// Move to the next index unless this is the first time initializing.
|
||||||
|
if itr.infos != nil && len(itr.indexes) > 0 {
|
||||||
|
itr.indexes = itr.indexes[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no indexes remain, stop iteration.
|
||||||
|
if len(itr.indexes) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read segments into a cache for the current index.
|
||||||
|
index := itr.indexes[0]
|
||||||
|
fis, err := sftpClient.ReadDir(path.Join(itr.dir, litestream.FormatIndex(index)))
|
||||||
|
if err != nil {
|
||||||
|
itr.err = err
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fi := range fis {
|
||||||
|
filename := path.Base(fi.Name())
|
||||||
|
if fi.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
offset, err := litestream.ParseOffset(strings.TrimSuffix(filename, ".wal.lz4"))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
itr.infos = append(itr.infos, litestream.WALSegmentInfo{
|
||||||
|
Generation: itr.generation,
|
||||||
|
Index: index,
|
||||||
|
Offset: offset,
|
||||||
|
Size: fi.Size(),
|
||||||
|
CreatedAt: fi.ModTime().UTC(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(itr.infos) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) Err() error { return itr.err }
|
||||||
|
|
||||||
|
func (itr *walSegmentIterator) WALSegment() litestream.WALSegmentInfo {
|
||||||
|
if len(itr.infos) == 0 {
|
||||||
|
return litestream.WALSegmentInfo{}
|
||||||
|
}
|
||||||
|
return itr.infos[0]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user