Skip to content

Commit 19fbe6c

Browse files
fix restore tests
1 parent 2778b9e commit 19fbe6c

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"--security",
1616
"whitelist=0.0.0.0/0;"
1717
],
18-
"showLog": true
18+
"showLog": false
1919
},
2020
{
2121
"name": "Zero",
@@ -25,7 +25,7 @@
2525
"program": "${workspaceRoot}/dgraph/",
2626
"env": {},
2727
"args": ["zero"],
28-
"showLog": true
28+
"showLog": false
2929
},
3030
{
3131
"name": "AlphaACL",

systest/vector/backup_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ func (vsuite *VectorTestSuite) TestVectorIncrBackupRestore() {
4141
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
4242
dgraphapi.DefaultPassword, x.RootNamespace))
4343

44-
require.NoError(t, gc.SetupSchema(vsuite.schemaVecDimesion10))
45-
46-
numVectors := 1000
44+
numVectors := 1500
4745
allVectors := make([][][]float32, 0, 5)
4846
allRdfs := make([]string, 0, 5)
4947
for i := 1; i <= 5; i++ {
@@ -55,6 +53,7 @@ func (vsuite *VectorTestSuite) TestVectorIncrBackupRestore() {
5553
mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
5654
_, err := gc.Mutate(mu)
5755
require.NoError(t, err)
56+
require.NoError(t, gc.SetupSchema(vsuite.schemaVecDimesion10))
5857

5958
t.Logf("taking backup #%v\n", i)
6059
require.NoError(t, hc.Backup(c, i == 1, dgraphtest.DefaultBackupDir))
@@ -76,10 +75,8 @@ func (vsuite *VectorTestSuite) TestVectorIncrBackupRestore() {
7675

7776
require.JSONEq(t, fmt.Sprintf(`{"vector":[{"count":%v}]}`, numVectors*i), string(result.GetJson()))
7877
var allSpredVec [][]float32
79-
for i, vecArr := range allVectors {
80-
if i <= i {
81-
allSpredVec = append(allSpredVec, vecArr...)
82-
}
78+
for _, vecArr := range allVectors {
79+
allSpredVec = append(allSpredVec, vecArr...)
8380
}
8481
for p, vector := range allVectors[i-1] {
8582
triple := strings.Split(allRdfs[i-1], "\n")[p]
@@ -88,7 +85,6 @@ func (vsuite *VectorTestSuite) TestVectorIncrBackupRestore() {
8885
require.NoError(t, err)
8986

9087
require.Equal(t, allVectors[i-1][p], queriedVector[0])
91-
9288
similarVectors, err := gc.QueryMultipleVectorsUsingSimilarTo(vector, pred, numVectors)
9389
require.NoError(t, err)
9490
require.GreaterOrEqual(t, len(similarVectors), 10)
@@ -99,7 +95,7 @@ func (vsuite *VectorTestSuite) TestVectorIncrBackupRestore() {
9995
}
10096
}
10197

102-
func (vsuite *VectorTestSuite) TestVectorBackupRestore() {
98+
func (vsuite *VectorTestSuite) TestVectorBackupRestore12() {
10399
t := vsuite.T()
104100
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour)
105101
c, err := dgraphtest.NewLocalCluster(conf)
@@ -118,15 +114,13 @@ func (vsuite *VectorTestSuite) TestVectorBackupRestore() {
118114
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
119115
dgraphapi.DefaultPassword, x.RootNamespace))
120116

121-
require.NoError(t, gc.SetupSchema(vsuite.schema))
122-
123-
numVectors := 1000
124-
pred := "project_description_v"
117+
numVectors := 1001
125118
rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 100, pred)
126119

127120
mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
128121
_, err = gc.Mutate(mu)
129122
require.NoError(t, err)
123+
require.NoError(t, gc.SetupSchema(vsuite.schema))
130124

131125
t.Log("taking backup \n")
132126
require.NoError(t, hc.Backup(c, false, dgraphtest.DefaultBackupDir))
@@ -135,7 +129,14 @@ func (vsuite *VectorTestSuite) TestVectorBackupRestore() {
135129
require.NoError(t, hc.Restore(c, dgraphtest.DefaultBackupDir, "", 0, 0))
136130
require.NoError(t, dgraphapi.WaitForRestore(c))
137131

138-
testVectorQuery(t, gc, vectors, rdfs, pred, numVectors)
132+
for _, vector := range vectors {
133+
similarVectors, err := gc.QueryMultipleVectorsUsingSimilarTo(vector, pred, 100)
134+
require.NoError(t, err)
135+
require.GreaterOrEqual(t, len(similarVectors), 100)
136+
for _, similarVector := range similarVectors {
137+
require.Contains(t, vectors, similarVector)
138+
}
139+
}
139140
}
140141

141142
func (vsuite *VectorTestSuite) TestVectorBackupRestoreDropIndex() {

worker/backup.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"math"
1515
"net/url"
1616
"reflect"
17+
"strconv"
1718
"strings"
1819
"sync"
1920
"time"
@@ -32,6 +33,8 @@ import (
3233
"github.com/hypermodeinc/dgraph/v25/posting"
3334
"github.com/hypermodeinc/dgraph/v25/protos/pb"
3435
"github.com/hypermodeinc/dgraph/v25/tok/hnsw"
36+
"github.com/hypermodeinc/dgraph/v25/tok/kmeans"
37+
"github.com/hypermodeinc/dgraph/v25/tok/partitioned_hnsw"
3538
"github.com/hypermodeinc/dgraph/v25/x"
3639
)
3740

@@ -299,7 +302,27 @@ func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest) error {
299302
for _, pred := range schema {
300303
if pred.Type == "float32vector" && len(pred.IndexSpecs) != 0 {
301304
vecPredMap[gid] = append(predMap[gid], pred.Predicate+hnsw.VecEntry, pred.Predicate+hnsw.VecKeyword,
302-
pred.Predicate+hnsw.VecDead)
305+
pred.Predicate+hnsw.VecDead, pred.Predicate+kmeans.CentroidPrefix)
306+
for _, spec := range pred.IndexSpecs {
307+
if spec.Name == partitioned_hnsw.PartitionedHNSW {
308+
for _, opt := range spec.Options {
309+
310+
if opt.Key == partitioned_hnsw.NumClustersOpt {
311+
numClusters, err := strconv.Atoi(opt.Value)
312+
if err != nil {
313+
return fmt.Errorf(`unable to parse number of clusters %s for predicate %s: %w`,
314+
opt.Value, pred.Predicate, err)
315+
}
316+
for i := range numClusters {
317+
vecEntryKey := hnsw.ConcatStrings(pred.Predicate, fmt.Sprintf("%s_%d", hnsw.VecEntry, i))
318+
vecKey := hnsw.ConcatStrings(pred.Predicate, fmt.Sprintf("%s_%d", hnsw.VecKeyword, i))
319+
vecDead := hnsw.ConcatStrings(pred.Predicate, fmt.Sprintf("%s_%d", hnsw.VecDead, i))
320+
vecPredMap[gid] = append(vecPredMap[gid], vecEntryKey, vecKey, vecDead)
321+
}
322+
}
323+
}
324+
}
325+
}
303326
}
304327
}
305328
}
@@ -602,6 +625,9 @@ func (pr *BackupProcessor) WriteBackup(ctx context.Context) (*pb.BackupResponse,
602625
err, hex.EncodeToString(item.Key()))
603626
continue
604627
}
628+
629+
fmt.Println("Backup key:", parsedKey.Attr, "isType:", parsedKey.IsType())
630+
605631
// This check makes sense only for the schema keys. The types are not stored in it.
606632
if _, ok := predMap[parsedKey.Attr]; !parsedKey.IsType() && !ok {
607633
continue

0 commit comments

Comments
 (0)