Skip to content

Commit

Permalink
branch-2.1: [fix](catelog) Unifies partition items string #45669 (#45700
Browse files Browse the repository at this point in the history
)

Cherry-picked from #45669

---------

Co-authored-by: walter <[email protected]>
  • Loading branch information
github-actions[bot] and w41ter authored Dec 23, 2024
1 parent ca9f0ad commit 4a7e291
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
6 changes: 1 addition & 5 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -6168,11 +6168,7 @@ private static void getTableMeta(OlapTable olapTable, TGetMetaDBMeta dbMeta) {
long partitionId = partition.getId();
partitionMeta.setId(partitionId);
partitionMeta.setName(partition.getName());
String partitionRange = "";
if (tblPartitionInfo.getType() == PartitionType.RANGE
|| tblPartitionInfo.getType() == PartitionType.LIST) {
partitionRange = tblPartitionInfo.getItem(partitionId).getItems().toString();
}
String partitionRange = tblPartitionInfo.getPartitionRangeString(partitionId);
partitionMeta.setRange(partitionRange);
partitionMeta.setVisibleVersion(partition.getVisibleVersion());
// partitionMeta.setTemp(partition.isTemp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public List<PartitionKey> getItems() {
}

public String getItemsString() {
return 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 getItems().toString();
}

public String getItemsSql() {
Expand Down Expand Up @@ -119,9 +124,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 +184,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 @@ -47,7 +47,12 @@ public Range<PartitionKey> getItems() {
}

public String getItemsString() {
return 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();
}

public String getItemsSql() {
Expand Down Expand Up @@ -126,6 +131,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 @@ -93,7 +93,7 @@ public ProcResult fetchResult() throws AnalysisException {
}
partitionInfo.add(joiner.join(colNames)); // partition key
partitionInfo.add(
rangePartitionInfo.getItem(esShardPartitions.getPartitionId()).getItems().toString()); // range
rangePartitionInfo.getItem(esShardPartitions.getPartitionId()).getItemsString()); // range
partitionInfo.add("-"); // dis
partitionInfo.add(esShardPartitions.getShardRoutings().size()); // shards
partitionInfo.add(1); // replica num
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private List<Pair<List<Comparable>, TRow>> getPartitionInfosInrernal() throws An
String colNamesStr = joiner.join(colNames);
partitionInfo.add(colNamesStr);
trow.addToColumnValue(new TCell().setStringVal(colNamesStr));
String itemStr = tblPartitionInfo.getItem(partitionId).getItems().toString();
String itemStr = tblPartitionInfo.getPartitionRangeString(partitionId);
partitionInfo.add(itemStr);
trow.addToColumnValue(new TCell().setStringVal(itemStr));
} else {
Expand Down
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 4a7e291

Please sign in to comment.