Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ public ZNRecord toZNRecord() {

/**
* Returns a json representation of the segment lineage.
* Segment lineage entries are sorted in chronological order by default.
* Segment lineage entries are sorted by timestamp, with the entry id as a tiebreaker so that entries
* sharing the same millisecond are still ordered deterministically (instead of by HashMap iteration).
*/
public ObjectNode toJsonObject() {
ObjectNode jsonObject = JsonUtils.newObjectNode();
jsonObject.put("tableNameWithType", _tableNameWithType);
LinkedHashMap<String, LineageEntry> sortedLineageEntries = new LinkedHashMap<>();
_lineageEntries.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.comparingLong(LineageEntry::getTimestamp)))
.sorted(Map.Entry.<String, LineageEntry>comparingByValue(
Comparator.comparingLong(LineageEntry::getTimestamp))
.thenComparing(Map.Entry.comparingByKey()))
.forEachOrdered(x -> sortedLineageEntries.put(x.getKey(), x.getValue()));
jsonObject.set("lineageEntries", JsonUtils.objectToJsonNode(sortedLineageEntries));
if (_customMap != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
package org.apache.pinot.controller.api;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.apache.pinot.client.admin.PinotAdminClient;
import org.apache.pinot.common.lineage.SegmentLineage;
import org.apache.pinot.common.lineage.SegmentLineageAccessHelper;
import org.apache.pinot.controller.helix.ControllerTest;
import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
import org.apache.pinot.controller.utils.SegmentMetadataMockUtils;
Expand Down Expand Up @@ -99,8 +103,15 @@ public void testListSegmentLineage()
assertTrue(segmentLineageResponse.contains("\"segmentsTo\":[\"some_segment\"]"));
assertTrue(segmentLineageResponse.contains("\"segmentsFrom\":[\"s2\",\"s3\"]"));
assertTrue(segmentLineageResponse.contains("\"segmentsTo\":[\"another_segment\"]"));
SegmentLineage lineage =
SegmentLineageAccessHelper.getSegmentLineage(resourceManager.getPropertyStore(), offlineTableName);
// Sort the two entry ids the same way toJsonObject does -- by timestamp, then by id.
List<String> orderedIds = Stream.of(segmentLineageId, nextSegmentLineageId)
.sorted(Comparator.comparingLong((String id) -> lineage.getLineageEntry(id).getTimestamp())
.thenComparing(Comparator.naturalOrder()))
.toList();
// Ensures the two entries are sorted in chronological order by timestamp.
assertTrue(segmentLineageResponse.indexOf(segmentLineageId) < segmentLineageResponse.indexOf(nextSegmentLineageId));
assertTrue(segmentLineageResponse.indexOf(orderedIds.get(0)) < segmentLineageResponse.indexOf(orderedIds.get(1)));

// List segment lineage should fail for non-existing table
assertThrows(Exception.class,
Expand Down
Loading