OmCheeLin commented on PR #656:
URL: 
https://github.com/apache/skywalking-banyandb/pull/656#issuecomment-2829613666

   I found a new small bug in banyand/measure/topn.go
   this bug will be triggered when update topn which `field_value_sort` is 
`SORT_UNSPECIFIED`.
   for example:
   ``` shell
   bydbctl-cli topn update -f - <<EOF
   metadata:
     name: name2
     group: group1
   source_measure:
     name: name1
     group: group1
   field_name: value
   field_value_sort: SORT_UNSPECIFIED
   group_by_tag_names:
     - id
     - entity_id
   counters_number: 10000
   lru_size: 10
   EOF
   ```
   It will cause: panic: runtime error: index out of range [1] with length 1
   
   line 455 the func removeProcessors(), I I should have changed the in-order 
traversal to the reverse in-order traversal.
   
![企业微信截图_17455582848724](https://github.com/user-attachments/assets/7695693b-db8d-4a5f-8115-e1a20e024d6b)
   
   
![企业微信截图_174555835221](https://github.com/user-attachments/assets/bd23e4c5-0453-4ae3-9acd-4f149fbf6632)
   Here is what happens:
   Assuming processorList = [ASC, DESC] (length 2)
   When i=0 matches and removes ASC → the list becomes [DESC] (length 1)
   At this point, DESC is matched again and an attempt is made to 
remove:manager.
   processorList[i+1:] attempts to access index 1
   But the list length is already 1, so i+1=1 is out of range
   
   So I change the line 457 to:
   `for i := len(manager.processorList) - 1; i >= 0; i-- {`
   Start processing from the last element (i=len-1)
   When an element is removed, only indexes that have already been processed 
are affected
   Unprocessed element indexes are not affected
   For example:
   Original list: [A, B]
   Processing Order:
   i=1 Check B → Remove → The list becomes [A]
   i=0 Check A → Remove → list becomes []


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to