@@ -137,10 +137,10 @@ func (suite *StoreTestSuite) TestGetPartitionMetadata() {
137
137
CheckPartitionMetadata (suite .T (), metadata , cspann .LeafLevel , vector.T {0 , 0 },
138
138
cspann.PartitionStateDetails {State : cspann .ReadyState })
139
139
140
- // Non-root partition does not yet exist, expect error .
141
- _ , err = txn .GetPartitionMetadata (
140
+ // Non-root partition does not yet exist, expect Missing metadata .
141
+ metadata , err = txn .GetPartitionMetadata (
142
142
suite .ctx , treeKey , cspann .PartitionKey (99 ), false /* forUpdate */ )
143
- suite .ErrorIs ( err , cspann .ErrPartitionNotFound )
143
+ suite .Equal ( cspann.PartitionMetadata {}, metadata )
144
144
})
145
145
146
146
// Create non-root partition with some vectors in it.
@@ -160,21 +160,19 @@ func (suite *StoreTestSuite) TestGetPartitionMetadata() {
160
160
suite .NoError (store .TryUpdatePartitionMetadata (
161
161
suite .ctx , treeKey , partitionKey , metadata , expected ))
162
162
163
+ // Ensure latest metadata gets returned.
163
164
RunTransaction (suite .ctx , suite .T (), store , func (txn cspann.Txn ) {
164
- // If forUpdate = false, GetPartitionMetadata should not error.
165
165
metadata , err := txn .GetPartitionMetadata (
166
166
suite .ctx , treeKey , partitionKey , false /* forUpdate */ )
167
167
suite .NoError (err )
168
168
details := cspann.PartitionStateDetails {
169
169
State : cspann .DrainingForSplitState , Target1 : 20 , Target2 : 30 }
170
170
CheckPartitionMetadata (suite .T (), metadata , cspann .SecondLevel , vector.T {4 , 3 }, details )
171
171
172
- // If forUpdate = true, GetPartitionMetadata should error.
173
- var errConditionFailed * cspann.ConditionFailedError
174
- _ , err = txn .GetPartitionMetadata (suite .ctx , treeKey , partitionKey , true /* forUpdate */ )
175
- suite .ErrorAs (err , & errConditionFailed )
176
- CheckPartitionMetadata (suite .T (), errConditionFailed .Actual , cspann .SecondLevel ,
177
- vector.T {4 , 3 }, details )
172
+ metadata , err = txn .GetPartitionMetadata (
173
+ suite .ctx , treeKey , partitionKey , true /* forUpdate */ )
174
+ suite .NoError (err )
175
+ CheckPartitionMetadata (suite .T (), metadata , cspann .SecondLevel , vector.T {4 , 3 }, details )
178
176
})
179
177
suite .NoError (err )
180
178
}
@@ -329,16 +327,12 @@ func (suite *StoreTestSuite) TestRemoveFromPartition() {
329
327
suite .ctx , treeKey , partitionKey , metadata , expected ))
330
328
331
329
RunTransaction (suite .ctx , suite .T (), store , func (txn cspann.Txn ) {
332
- // Try to remove from partition, expect error due to its state.
333
- var errConditionFailed * cspann.ConditionFailedError
330
+ // Try to remove from draining partition, expect success.
334
331
err := txn .RemoveFromPartition (suite .ctx , treeKey , partitionKey , cspann .SecondLevel ,
335
332
partitionKey3 )
336
- suite .ErrorAs (err , & errConditionFailed )
337
- details := cspann.PartitionStateDetails {
338
- State : cspann .DrainingForSplitState , Target1 : 20 , Target2 : 30 }
339
- CheckPartitionMetadata (suite .T (), errConditionFailed .Actual , cspann .SecondLevel ,
340
- vector.T {4 , 3 }, details )
333
+ suite .NoError (err )
341
334
})
335
+ CheckPartitionCount (suite .ctx , suite .T (), store , treeKey , partitionKey , 1 )
342
336
}
343
337
344
338
suite .Run ("default tree" , func () {
@@ -1004,9 +998,27 @@ func (suite *StoreTestSuite) TestTryClearPartition() {
1004
998
// Create partition with some vectors.
1005
999
partitionKey , partition := suite .createTestPartition (store , treeKey )
1006
1000
1007
- // Now clear should work .
1001
+ // Clear should fail in Ready state .
1008
1002
expected := * partition .Metadata ()
1009
1003
count , err := store .TryClearPartition (suite .ctx , treeKey , partitionKey , expected )
1004
+ suite .Error (err )
1005
+ suite .Equal (0 , count )
1006
+
1007
+ // Move to draining state.
1008
+ metadata := * partition .Metadata ()
1009
+ metadata .StateDetails .MakeDrainingForSplit (20 , 30 )
1010
+ suite .NoError (store .TryUpdatePartitionMetadata (
1011
+ suite .ctx , treeKey , partitionKey , metadata , expected ))
1012
+
1013
+ // Try to clear with mismatched expected metadata.
1014
+ var errConditionFailed * cspann.ConditionFailedError
1015
+ _ , err = store .TryClearPartition (suite .ctx , treeKey , partitionKey , expected )
1016
+ suite .ErrorAs (err , & errConditionFailed )
1017
+ suite .True (errConditionFailed .Actual .Equal (& metadata ))
1018
+
1019
+ // Try again, this time with correct expected metadata.
1020
+ expected = metadata
1021
+ count , err = store .TryClearPartition (suite .ctx , treeKey , partitionKey , expected )
1010
1022
suite .NoError (err )
1011
1023
suite .Equal (3 , count )
1012
1024
@@ -1019,15 +1031,7 @@ func (suite *StoreTestSuite) TestTryClearPartition() {
1019
1031
suite .Len (partition .ChildKeys (), 0 )
1020
1032
suite .Len (partition .ValueBytes (), 0 )
1021
1033
1022
- // Try to clear with mismatched expected metadata.
1023
- var errConditionFailed * cspann.ConditionFailedError
1024
- metadata := expected
1025
- metadata .StateDetails .State = cspann .DrainingForMergeState
1026
- _ , err = store .TryClearPartition (suite .ctx , treeKey , partitionKey , metadata )
1027
- suite .ErrorAs (err , & errConditionFailed )
1028
- suite .True (errConditionFailed .Actual .Equal (& expected ))
1029
-
1030
- // Try again, this time with correct expected metadata.
1034
+ // Clear partition with zero vectors.
1031
1035
count , err = store .TryClearPartition (suite .ctx , treeKey , partitionKey , expected )
1032
1036
suite .NoError (err )
1033
1037
suite .Equal (0 , count )
0 commit comments