Skip to content

Commit

Permalink
[chore](fe) Add ATTN logs about partition range (#37338)
Browse files Browse the repository at this point in the history
The CCR syncer relies on the value of the partition range to determine
the mapping relationship between the upstream partition and the
downstream partition. This PR records this behavior in the corresponding
code.
  • Loading branch information
w41ter committed Dec 20, 2024
1 parent 37c4de3 commit dc51c19
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ public boolean isGreaterThanSpecifiedTime(int pos, Optional<String> dateFormatOp
partitionKey.toString(),
pos));
}
if (!isDefaultPartition() && MTMVUtil.getExprTimeSec(partitionKey.getKeys().get(pos), dateFormatOptional)
>= nowTruncSubSec) {
// As long as one of the partitionKeys meets the requirements, this partition needs to be retained
if (!isDefaultPartition()
&& MTMVUtil.getExprTimeSec(partitionKey.getKeys().get(pos), dateFormatOptional) >= nowTruncSubSec) {
// As long as one of the partitionKeys meets the requirements, this partition
// needs to be retained
return true;
}
}
Expand Down Expand Up @@ -178,6 +179,11 @@ public int hashCode() {

@Override
public String toString() {
// ATTN: DO NOT EDIT unless unless you explicitly guarantee compatibility
// between different versions.
//
// the ccr syncer depends on this string to identify partitions between two
// clusters (cluster versions may be different).
StringBuilder builder = new StringBuilder();
builder.append("partitionKeys: [");
for (PartitionKey partitionKey : partitionKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ public PartitionItem getItem(long partitionId) {
return item;
}

// Get the unique string of the partition range.
public String getPartitionRangeString(long partitionId) {
String partitionRange = "";
if (getType() == PartitionType.RANGE || getType() == PartitionType.LIST) {
PartitionItem item = getItem(partitionId);
partitionRange = item.getItemsString();
}
return partitionRange;
}

public PartitionItem getItemOrAnalysisException(long partitionId) throws AnalysisException {
PartitionItem item = idToItem.get(partitionId);
if (item == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public abstract class PartitionItem implements Comparable<PartitionItem>, Writab
public static final Comparator<Map.Entry<Long, PartitionItem>> ITEM_MAP_ENTRY_COMPARATOR =
Comparator.comparing(o -> ((ListPartitionItem) o.getValue()).getItems().iterator().next());

// get the unique string of the partition item.
public abstract String getItemsString();

public abstract <T> T getItems();

public abstract PartitionItem getIntersect(PartitionItem newItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public String toSql() {

@Override
public String toString() {
// ATTN: DO NOT EDIT unless unless you explicitly guarantee compatibility
// between different versions.
//
// the ccr syncer depends on this string to identify partitions between two
// clusters (cluster versions may be different).
StringBuilder builder = new StringBuilder();
builder.append("types: [");
builder.append(Joiner.on(", ").join(types));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public boolean equals(Object obj) {

@Override
public String toString() {
// ATTN: DO NOT EDIT unless unless you explicitly guarantee compatibility
// between different versions.
//
// the ccr syncer depends on this string to identify partitions between two
// clusters (cluster versions may be different).
return partitionKeyRange.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.doris.catalog.Partition;
import org.apache.doris.catalog.Partition.PartitionState;
import org.apache.doris.catalog.PartitionInfo;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.catalog.Replica;
import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf;
Expand Down Expand Up @@ -1433,12 +1432,9 @@ protected void unprotectedPreCommitTransaction2PC(TransactionState transactionSt
TableCommitInfo tableCommitInfo = new TableCommitInfo(tableId);
PartitionInfo tblPartitionInfo = table.getPartitionInfo();
for (long partitionId : tableToPartition.get(tableId)) {
String partitionRange = "";
if (tblPartitionInfo.getType() == PartitionType.RANGE
|| tblPartitionInfo.getType() == PartitionType.LIST) {
partitionRange = tblPartitionInfo.getItem(partitionId).getItems().toString();
}
PartitionCommitInfo partitionCommitInfo = new PartitionCommitInfo(partitionId, partitionRange, -1, -1,
String partitionRange = tblPartitionInfo.getPartitionRangeString(partitionId);
PartitionCommitInfo partitionCommitInfo = new PartitionCommitInfo(
partitionId, partitionRange, -1, -1,
table.isTemporaryPartition(partitionId));
tableCommitInfo.addPartitionCommitInfo(partitionCommitInfo);
}
Expand Down Expand Up @@ -1475,11 +1471,7 @@ protected void unprotectedCommitTransaction(TransactionState transactionState, S
PartitionInfo tblPartitionInfo = table.getPartitionInfo();
for (long partitionId : tableToPartition.get(tableId)) {
Partition partition = table.getPartition(partitionId);
String partitionRange = "";
if (tblPartitionInfo.getType() == PartitionType.RANGE
|| tblPartitionInfo.getType() == PartitionType.LIST) {
partitionRange = tblPartitionInfo.getItem(partitionId).getItems().toString();
}
String partitionRange = tblPartitionInfo.getPartitionRangeString(partitionId);
PartitionCommitInfo partitionCommitInfo = new PartitionCommitInfo(partitionId, partitionRange,
partition.getNextVersion(),
System.currentTimeMillis() /* use as partition visible time */,
Expand Down

0 comments on commit dc51c19

Please sign in to comment.