Skip to content

Commit fd954a4

Browse files
authored
Allow clone now for DBs with existing PITR configs (#298)
1 parent 0384f0b commit fd954a4

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

Diff for: cmd/cluster/pitr-config/pitr_config_ops.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,11 @@ var clonePitrConfigCmd = &cobra.Command{
427427
}
428428
cloneSpec.SetCloneNow(*ybmclient.NewDatabaseCloneNowSpec(namespaceId, cloneAs))
429429
} else {
430-
// We can only clone to PIT if a config is present for the {namespaceName, namespaceType}
431430
if cmd.Flags().Lookup("clone-at-millis").Changed {
432431
cloneAtMillis, _ := cmd.Flags().GetInt64("clone-at-millis")
433432
cloneSpec.SetClonePointInTime(*ybmclient.NewDatabaseClonePITSpec(cloneAtMillis, pitrConfigId, cloneAs))
434433
} else {
435-
logrus.Fatalf("clone-at-millis parameter must be specified to clone via existing PITR config for %s namespace %s in cluster %s\n", namespaceType, namespaceName, ClusterName)
434+
cloneSpec.SetCloneNow(*ybmclient.NewDatabaseCloneNowSpec(namespaceId, cloneAs))
436435
}
437436
}
438437

Diff for: cmd/pitr_config_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ test_ycql_db YCQL 6 ACTIVE 123456
680680
ysqlSession.Kill()
681681
})
682682

683-
It("Should fail to clone YSQL namespace via pre existing PITR Config if clone time is not specified", func() {
683+
It("Should successfully clone YSQL namespace to current time via specified pre existing PITR Config", func() {
684684
os.Setenv("YBM_FF_PITR_CLONE", "true")
685685
err := loadJson("./test/fixtures/namespaces.json", &responseNamespace)
686686
Expect(err).ToNot(HaveOccurred())
@@ -699,12 +699,21 @@ test_ycql_db YCQL 6 ACTIVE 123456
699699
),
700700
)
701701

702+
restoreErr := loadJson("./test/fixtures/clone-now-ysql-db-existing-pitr.json", &responseClone)
703+
Expect(restoreErr).ToNot(HaveOccurred())
704+
server.AppendHandlers(
705+
ghttp.CombineHandlers(
706+
ghttp.VerifyRequest(http.MethodPost, "/api/public/v1/accounts/340af43a-8a7c-4659-9258-4876fd6a207b/projects/78d4459c-0f45-47a5-899a-45ddf43eba6e/clusters/5f80730f-ba3f-4f7e-8c01-f8fa4c90dad8/clone-database"),
707+
ghttp.RespondWithJSONEncodedPtr(&statusCode, responseClone),
708+
),
709+
)
710+
702711
ysqlCmd := exec.Command(compiledCLIPath, "cluster", "pitr-config", "clone", "--cluster-name", "stunning-sole", "--namespace-name", "test_ysql_db", "--namespace-type", "YSQL", "--clone-as", "test_ysql_db_clone")
703712
ysqlSession, ysqlErr := gexec.Start(ysqlCmd, GinkgoWriter, GinkgoWriter)
704713
Expect(err).NotTo(HaveOccurred())
705714
Expect(ysqlErr).NotTo(HaveOccurred())
706715
ysqlSession.Wait(2)
707-
Expect(ysqlSession.Err).Should(gbytes.Say("clone-at-millis parameter must be specified to clone via existing PITR config for YSQL namespace test_ysql_db in cluster stunning-sole"))
716+
Expect(ysqlSession.Out).Should(gbytes.Say("The YSQL namespace test_ysql_db in cluster stunning-sole is being cloned via PITR Configuration."))
708717
ysqlSession.Kill()
709718
})
710719

Diff for: cmd/test/fixtures/clone-now-ysql-database.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"created_on": "2024-08-07T17:26:08.435Z"
1515
},
1616
"database_type": "YSQL",
17-
"database_name": "test_ysql_db",
17+
"database_name": "yugabyte",
1818
"id": "8e74ca8f-331b-4dec-89b0-4e59b81e905d",
1919
"state": "QUEUED"
2020
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"data": {
3+
"spec": {
4+
"clone_now": {
5+
"database_id": "00004002-0000-3000-8000-000000000000",
6+
"clone_as": "test_ysql_db_clone"
7+
},
8+
"clone_point_in_time": null
9+
},
10+
"info": {
11+
"cluster_id": "5f80730f-ba3f-4f7e-8c01-f8fa4c90dad8",
12+
"metadata": {
13+
"updated_on": "2024-08-07T17:26:08.435Z",
14+
"created_on": "2024-08-07T17:26:08.435Z"
15+
},
16+
"database_type": "YSQL",
17+
"database_name": "test_ysql_db",
18+
"id": "8e74ca8f-331b-4dec-89b0-4e59b81e905d",
19+
"state": "QUEUED"
20+
}
21+
}
22+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/spf13/cobra v1.8.0
2424
github.com/spf13/viper v1.17.0
2525
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
26-
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250201211410-51dcbc34e9a3
26+
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250314120043-8b25464e38ba
2727
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
2828
golang.org/x/mod v0.20.0
2929
golang.org/x/term v0.25.0

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
282282
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
283283
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
284284
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
285-
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250201211410-51dcbc34e9a3 h1:K+x7BoZbnpdq/3IXg8yOU5KoExlU6+1WTYhuHIlk2vM=
286-
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250201211410-51dcbc34e9a3/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
285+
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250314120043-8b25464e38ba h1:kveckCqCVUiC1J4BL9dfCNbWd51z2Eas2JTf4WBYAH8=
286+
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20250314120043-8b25464e38ba/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
287287
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
288288
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
289289
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

0 commit comments

Comments
 (0)