@@ -76,10 +76,11 @@ type MakeStoreFunc func(quantizer quantize.Quantizer) TestStore
76
76
type StoreTestSuite struct {
77
77
suite.Suite
78
78
79
- ctx context.Context
80
- makeStore MakeStoreFunc
81
- rootQuantizer quantize.Quantizer
82
- quantizer quantize.Quantizer
79
+ ctx context.Context
80
+ makeStore MakeStoreFunc
81
+ rootQuantizer quantize.Quantizer
82
+ quantizer quantize.Quantizer
83
+ nextPartitionKey cspann.PartitionKey
83
84
}
84
85
85
86
// NewStoreTestSuite constructs a new suite of tests that run against
@@ -88,10 +89,12 @@ type StoreTestSuite struct {
88
89
// tests.
89
90
func NewStoreTestSuite (ctx context.Context , makeStore MakeStoreFunc ) * StoreTestSuite {
90
91
return & StoreTestSuite {
91
- ctx : ctx ,
92
- makeStore : makeStore ,
93
- rootQuantizer : quantize .NewUnQuantizer (2 , vecpb .L2SquaredDistance ),
94
- quantizer : quantize .NewRaBitQuantizer (2 , 42 , vecpb .L2SquaredDistance )}
92
+ ctx : ctx ,
93
+ makeStore : makeStore ,
94
+ rootQuantizer : quantize .NewUnQuantizer (2 , vecpb .L2SquaredDistance ),
95
+ quantizer : quantize .NewRaBitQuantizer (2 , 42 , vecpb .L2SquaredDistance ),
96
+ nextPartitionKey : cspann .RootKey + 1 ,
97
+ }
95
98
}
96
99
97
100
func (suite * StoreTestSuite ) TestRunTransaction () {
@@ -700,31 +703,38 @@ func (suite *StoreTestSuite) TestTryGetPartitionMetadata() {
700
703
701
704
doTest := func (treeID int ) {
702
705
treeKey := store .MakeTreeKey (suite .T (), treeID )
703
- partitionKey := cspann .PartitionKey (10 )
704
-
705
- // Partition does not yet exist.
706
- _ , err := store .TryGetPartitionMetadata (suite .ctx , treeKey , partitionKey )
707
- suite .ErrorIs (err , cspann .ErrPartitionNotFound )
708
706
709
- // Create partition with some vectors in it.
710
- partitionKey , partition := suite .createTestPartition (store , treeKey )
707
+ // Create two partition with vectors in them.
708
+ partitionKey1 , partition1 := suite .createTestPartition (store , treeKey )
709
+ partitionKey2 , partition2 := suite .createTestPartition (store , treeKey )
711
710
712
- // Fetch back only the metadata and validate it.
713
- partitionMetadata , err := store .TryGetPartitionMetadata (suite .ctx , treeKey , partitionKey )
711
+ // Fetch metadata for the partitions, along with one that doesn't exist.
712
+ toGet := []cspann.PartitionMetadataToGet {
713
+ {Key : partitionKey1 },
714
+ {Key : cspann .PartitionKey (9999 )},
715
+ {Key : partitionKey2 },
716
+ }
717
+ err := store .TryGetPartitionMetadata (suite .ctx , treeKey , toGet )
714
718
suite .NoError (err )
715
- suite .True (partitionMetadata .Equal (partition .Metadata ()))
719
+
720
+ // Validate that partition 9999 does not exist.
721
+ suite .Equal (cspann.PartitionMetadata {}, toGet [1 ].Metadata )
722
+
723
+ // Validate metadata for other partitions.
724
+ suite .True (partition1 .Metadata ().Equal (& toGet [0 ].Metadata ))
725
+ suite .True (partition2 .Metadata ().Equal (& toGet [2 ].Metadata ))
716
726
717
727
// Update the metadata and verify we get the updated values.
718
- expected := * partition .Metadata ()
728
+ expected := toGet [ 0 ] .Metadata
719
729
metadata := expected
720
730
metadata .StateDetails .MakeUpdating (30 )
721
731
suite .NoError (store .TryUpdatePartitionMetadata (
722
- suite .ctx , treeKey , partitionKey , metadata , expected ))
732
+ suite .ctx , treeKey , partitionKey1 , metadata , expected ))
723
733
724
734
// Fetch updated metadata and validate.
725
- partitionMetadata , err = store .TryGetPartitionMetadata (suite .ctx , treeKey , partitionKey )
735
+ err = store .TryGetPartitionMetadata (suite .ctx , treeKey , toGet [: 1 ] )
726
736
suite .NoError (err )
727
- suite .True (partitionMetadata .Equal (& metadata ))
737
+ suite .True (toGet [ 0 ]. Metadata .Equal (& metadata ))
728
738
}
729
739
730
740
suite .Run ("default tree" , func () {
@@ -1043,7 +1053,8 @@ func (suite *StoreTestSuite) TestTryClearPartition() {
1043
1053
func (suite * StoreTestSuite ) createTestPartition (
1044
1054
store TestStore , treeKey cspann.TreeKey ,
1045
1055
) (cspann.PartitionKey , * cspann.Partition ) {
1046
- partitionKey := cspann .PartitionKey (10 )
1056
+ partitionKey := suite .nextPartitionKey
1057
+ suite .nextPartitionKey ++
1047
1058
metadata := cspann .MakeReadyPartitionMetadata (cspann .SecondLevel , vector.T {4 , 3 })
1048
1059
suite .NoError (store .TryCreateEmptyPartition (suite .ctx , treeKey , partitionKey , metadata ))
1049
1060
vectors := vector .MakeSet (2 )
0 commit comments