Skip to content

Commit

Permalink
Update for mongodb archiver (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
Signed-off-by: Tamal Saha <[email protected]>
Co-authored-by: Mohammad Fahim Abrar <[email protected]>
Co-authored-by: Tamal Saha <[email protected]>
  • Loading branch information
3 people committed May 24, 2024
1 parent 2d18d88 commit d91565a
Show file tree
Hide file tree
Showing 12 changed files with 897 additions and 160 deletions.
32 changes: 32 additions & 0 deletions cmd/mongo/oplog_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ import (
"github.com/wal-g/wal-g/internal/databases/mongo/stats"
"github.com/wal-g/wal-g/internal/webserver"
"github.com/wal-g/wal-g/utility"
"k8s.io/client-go/tools/clientcmd"
"kubedb.dev/apimachinery/pkg/factory"
controllerclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var (
snapshotName string
snapshotNamespace string
kubeconfig string
)

// oplogPushCmd represents the continuous oplog archiving procedure
Expand Down Expand Up @@ -50,6 +59,12 @@ var oplogPushCmd = &cobra.Command{

func init() {
cmd.AddCommand(oplogPushCmd)
oplogPushCmd.PersistentFlags().StringVarP(
&snapshotName, "snapshot-name", "", "", "Name of the snapshot")
oplogPushCmd.PersistentFlags().StringVarP(
&snapshotNamespace, "snapshot-namespace", "n", "", "Namespace of the snapshot")
oplogPushCmd.PersistentFlags().StringVarP(
&kubeconfig, "kubeconfig", "", "", "Path of the kubeconfig")
}

func runOplogPush(ctx context.Context, pushArgs oplogPushRunArgs, statsArgs oplogPushStatsArgs) error {
Expand All @@ -61,6 +76,8 @@ func runOplogPush(ctx context.Context, pushArgs oplogPushRunArgs, statsArgs oplo
}
uplProvider.ChangeDirectory(models.OplogArchBasePath)
uploader := archive.NewStorageUploader(uplProvider)
uploader.SetKubeClient(pushArgs.kubeClient)
uploader.SetSnapshot(snapshotName, snapshotNamespace)

// set up mongodb client and oplog fetcher
mongoClient, err := client.NewMongoClient(ctx, pushArgs.mongodbURL)
Expand Down Expand Up @@ -129,6 +146,7 @@ type oplogPushRunArgs struct {
primaryWait bool
primaryWaitTimeout time.Duration
lwUpdate time.Duration
kubeClient controllerclient.Client
}

func buildOplogPushRunArgs() (args oplogPushRunArgs, err error) {
Expand Down Expand Up @@ -160,6 +178,20 @@ func buildOplogPushRunArgs() (args oplogPushRunArgs, err error) {
}

args.lwUpdate, err = conf.GetDurationSetting(conf.MongoDBLastWriteUpdateInterval)
if err != nil {
return
}

clientConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return
}

args.kubeClient, err = factory.NewUncachedClient(clientConfig)
if err != nil {
return
}

return
}

Expand Down
12 changes: 12 additions & 0 deletions cmd/mongo/oplog_replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func buildOplogReplayRunArgs(cmdargs []string) (args oplogReplayRunArgs, err err
if err != nil {
return
}
args.since, err = models.TimestampFromTime(cmdargs[0])
if err != nil {
return
}
args.until, err = models.TimestampFromTime(cmdargs[1])
if err != nil {
return
}

// TODO: fix ugly config
if ignoreErrCodesStr, ok := conf.GetSetting(conf.OplogReplayIgnoreErrorCodes); ok {
Expand Down Expand Up @@ -152,6 +160,10 @@ func runOplogReplay(ctx context.Context, replayArgs oplogReplayRunArgs) error {
if err != nil {
return err
}

// update since and until. since = matched archive start ts , until = matched archiver end ts
replayArgs.since, replayArgs.until = archive.GetUpdatedBackupTimes(archives, replayArgs.since, replayArgs.until)
dbApplier.SetUntilTime(replayArgs.until)
path, err := archive.SequenceBetweenTS(archives, replayArgs.since, replayArgs.until)
if err != nil {
return err
Expand Down
191 changes: 130 additions & 61 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ module github.com/wal-g/wal-g
go 1.20

require (
cloud.google.com/go/storage v1.10.0
cloud.google.com/go/storage v1.30.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
github.com/Azure/go-autorest/autorest v0.11.21
github.com/Azure/go-autorest/autorest v0.11.28
github.com/RoaringBitmap/roaring v0.4.21
github.com/aws/aws-sdk-go v1.44.7
github.com/aws/aws-sdk-go v1.44.149
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cucumber/godog v0.12.5
github.com/cyberdelia/lzo v0.0.0-20171006181345-d85071271a6f
github.com/denisenkom/go-mssqldb v0.10.0
github.com/docker/docker v1.13.1
github.com/docker/docker v20.10.20+incompatible
github.com/go-mysql-org/go-mysql v1.7.0
github.com/go-redis/redis v6.15.6+incompatible
github.com/go-sql-driver/mysql v1.6.0
github.com/gofrs/flock v0.8.0
github.com/golang/mock v1.4.4
github.com/golang/mock v1.5.0
github.com/google/uuid v1.3.0
github.com/greenplum-db/gp-common-go-libs v1.0.4
github.com/hashicorp/golang-lru v0.5.4
Expand All @@ -29,113 +29,152 @@ require (
github.com/jackc/pgproto3/v2 v2.0.7
github.com/jackc/pgx v3.6.0+incompatible
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/magiconair/properties v1.8.1 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/minio/sio v0.2.0
github.com/mongodb/mongo-tools-common v2.0.1+incompatible
github.com/pierrec/lz4/v4 v4.1.11
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.11.0
github.com/spf13/cobra v1.4.0
github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.8.2
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.8.3
github.com/ulikunitz/xz v0.5.8
github.com/wal-g/json v0.3.1
github.com/wal-g/tracelog v0.0.0-20231219102105-60dcd9126592
github.com/yandex-cloud/go-genproto v0.0.0-20230918115514-93a99045c9de
github.com/yandex-cloud/go-sdk v0.0.0-20230918120620-9e95f0816d79
go.mongodb.org/mongo-driver v1.9.1
golang.org/x/crypto v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/api v0.30.0
gopkg.in/ini.v1 v1.51.0
golang.org/x/crypto v0.14.0
golang.org/x/sync v0.4.0
golang.org/x/time v0.3.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
google.golang.org/api v0.126.0
gopkg.in/ini.v1 v1.66.2
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230426101702-58e86b294756
github.com/cactus/go-statsd-client/v5 v5.0.0
github.com/google/brotli/go/cbrotli v0.0.0-20220110100810-f4153a09f87c
github.com/klauspost/compress v1.15.12
github.com/klauspost/compress v1.16.5
github.com/ncw/swift/v2 v2.0.2
github.com/pkg/profile v1.6.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/client_model v0.2.0
golang.org/x/mod v0.8.0
golang.org/x/sys v0.6.0
golang.org/x/mod v0.9.0
golang.org/x/sys v0.13.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.3
kmodules.xyz/client-go v0.25.41
kubedb.dev/apimachinery v0.37.1-0.20231121085114-0a987940309d
kubestash.dev/apimachinery v0.2.0-rc.0.0.20231114115833-0b99d5ce666e
sigs.k8s.io/controller-runtime v0.13.1
)

require (
cloud.google.com/go v0.65.0 // indirect
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.21 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cert-manager/cert-manager v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.1.0 // indirect
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/errors v0.19.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/strfmt v0.19.4 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gofrs/uuid v4.3.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.2-0.20190904063534-ff6b7dc882cf // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-containerregistry v0.13.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect
github.com/hashicorp/go-memdb v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmoiron/sqlx v1.3.3 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/jmoiron/sqlx v1.3.4 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect
github.com/onsi/gomega v1.8.1 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.59.1 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/client v0.59.1 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 // indirect
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tinylib/msgp v1.1.0 // indirect
Expand All @@ -144,17 +183,47 @@ require (
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.opencensus.io v0.22.4 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20211021150943-2b146023228c // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.7.0 // indirect
gomodules.xyz/encoding v0.0.7 // indirect
gomodules.xyz/envsubst v0.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
gomodules.xyz/mergo v0.3.13 // indirect
gomodules.xyz/pointer v0.1.0 // indirect
gomodules.xyz/sets v0.2.1 // indirect
gomodules.xyz/x v0.0.15 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.25.3 // indirect
k8s.io/apiextensions-apiserver v0.25.3 // indirect
k8s.io/component-base v0.25.3 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-aggregator v0.25.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/metrics v0.25.1 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
kmodules.xyz/custom-resources v0.25.2 // indirect
kmodules.xyz/monitoring-agent-api v0.25.5 // indirect
kmodules.xyz/objectstore-api v0.25.1 // indirect
kmodules.xyz/offshoot-api v0.25.5-0.20231004063620-dff8fb030d57 // indirect
kmodules.xyz/prober v0.25.0 // indirect
kubeops.dev/sidekick v0.0.2-0.20230304025549-a99a1477617d // indirect
sigs.k8s.io/gateway-api v0.4.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
stash.appscode.dev/apimachinery v0.32.0 // indirect
)
Loading

0 comments on commit d91565a

Please sign in to comment.