Skip to content

Commit

Permalink
[core] BranchManager lists branches in the order of create time (#3155)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzelin authored Apr 7, 2024
1 parent 2a928b9 commit 08025dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.SortedMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -164,7 +166,8 @@ public List<TableBranch> branches() {
listVersionedFileStatus(fileIO, branchDirectory(), BRANCH_PREFIX)
.map(status -> Pair.of(status.getPath(), status.getModificationTime()))
.collect(Collectors.toList());
List<TableBranch> branches = new ArrayList<>();
PriorityQueue<TableBranch> pq =
new PriorityQueue<>(Comparator.comparingLong(TableBranch::getCreateTime));
for (Pair<Path, Long> path : paths) {
String branchName = path.getLeft().getName().substring(BRANCH_PREFIX.length());
FileStoreTable branchTable =
Expand All @@ -175,10 +178,13 @@ public List<TableBranch> branches() {
Snapshot snapshot = snapshotTags.firstKey();
List<String> tags = snapshotTags.get(snapshot);
checkArgument(tags.size() == 1);
branches.add(
new TableBranch(branchName, tags.get(0), snapshot.id(), path.getValue()));
pq.add(new TableBranch(branchName, tags.get(0), snapshot.id(), path.getValue()));
}

List<TableBranch> branches = new ArrayList<>(pq.size());
while (!pq.isEmpty()) {
branches.add(pq.poll());
}
return branches;
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void testTagBranchesTable() throws Exception {
if (tag.equals("2023-07-17")) {
return Collections.singletonList("2023-07-17-branch1");
} else if (tag.equals("2023-07-18")) {
return Arrays.asList("2023-07-18-branch2", "2023-07-18-branch1");
return Arrays.asList("2023-07-18-branch1", "2023-07-18-branch2");
} else {
return new ArrayList<>();
}
Expand Down

0 comments on commit 08025dd

Please sign in to comment.