[fix](JDK17) The objects stored in PriorityQueue must implement the Comparable interface (#30050) (#30625)

Issue Number:  #30484 

The objects stored in PriorityQueue must implement the Comparable interface or passed into the customized `Comparator`. 

If we don't do this, run the program in the JDK17 environment will report an exception:
```java
Caused by: java.lang.AssertionError: Expect exception msg contains 'query wait timeout', but meet
'java.sql.SQLException: ClassCastException,
msg: class org.apache.doris.resource.workloadgroup.QueueToken cannot be cast to class java.lang.Comparable 
(org.apache.doris.resource.workloadgroup.QueueToken is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')'
```
This commit is contained in:
Tiewei Fang
2024-01-31 20:52:18 +08:00
committed by yiguolei
parent 9310dbf3fd
commit cc5205f6d1
2 changed files with 10 additions and 2 deletions

View File

@ -28,9 +28,14 @@ import java.util.concurrent.locks.ReentrantLock;
// used to mark QueryQueue offer result
// if offer failed, then need to cancel query
// and return failed reason to user client
public class QueueToken {
public class QueueToken implements Comparable<QueueToken> {
private static final Logger LOG = LogManager.getLogger(QueueToken.class);
@Override
public int compareTo(QueueToken other) {
return Long.compare(this.tokenId, other.getTokenId());
}
enum TokenState {
ENQUEUE_SUCCESS,
READY_TO_RUN
@ -136,4 +141,7 @@ public class QueueToken {
return tokenId == other.tokenId;
}
public long getTokenId() {
return tokenId;
}
}