diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java index a7c19ddafecd3a..9d8ee1bcb750b9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java +++ b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java @@ -30,6 +30,7 @@ import org.apache.doris.catalog.EnvFactory; import org.apache.doris.catalog.FsBroker; import org.apache.doris.catalog.Index; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MaterializedIndex.IndexExtState; import org.apache.doris.catalog.MaterializedIndexMeta; @@ -1537,8 +1538,8 @@ protected Partition resetTabletForRestore(OlapTable localTbl, OlapTable remoteTb for (Map.Entry> entry : beIds.entrySet()) { for (Long beId : entry.getValue()) { long newReplicaId = env.getNextId(); - Replica newReplica = new Replica(newReplicaId, beId, ReplicaState.NORMAL, visibleVersion, - schemaHash); + Replica newReplica = new LocalReplica(newReplicaId, beId, ReplicaState.NORMAL, + visibleVersion, schemaHash); newTablet.addReplica(newReplica, true /* is restore */); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java index de3d092373239a..12f39db81d57b1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.java @@ -107,11 +107,11 @@ public Tablet createTablet(long tabletId) { } public Replica createReplica() { - return new Replica(); + return new LocalReplica(); } public Replica createReplica(Replica.ReplicaContext context) { - return new Replica(context); + return new LocalReplica(context); } public ReplicaAllocation createDefReplicaAllocation() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/LocalReplica.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/LocalReplica.java new file mode 100644 index 00000000000000..86aeac885dab0e --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/LocalReplica.java @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.catalog; + +import org.apache.doris.thrift.TUniqueId; + +import com.google.gson.annotations.SerializedName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class LocalReplica extends Replica { + private static final Logger LOG = LogManager.getLogger(LocalReplica.class); + + @SerializedName(value = "rds", alternate = {"remoteDataSize"}) + private volatile long remoteDataSize = 0; + @SerializedName(value = "ris", alternate = {"remoteInvertedIndexSize"}) + private Long remoteInvertedIndexSize = 0L; + @SerializedName(value = "rss", alternate = {"remoteSegmentSize"}) + private Long remoteSegmentSize = 0L; + + private TUniqueId cooldownMetaId; + private long cooldownTerm = -1; + + public LocalReplica() { + super(); + } + + public LocalReplica(ReplicaContext context) { + super(context); + } + + // for rollup + // the new replica's version is -1 and last failed version is -1 + public LocalReplica(long replicaId, long backendId, int schemaHash, ReplicaState state) { + super(replicaId, backendId, schemaHash, state); + } + + // for create tablet and restore + public LocalReplica(long replicaId, long backendId, ReplicaState state, long version, int schemaHash) { + super(replicaId, backendId, state, version, schemaHash); + } + + public LocalReplica(long replicaId, long backendId, long version, int schemaHash, long dataSize, + long remoteDataSize, long rowCount, ReplicaState state, long lastFailedVersion, long lastSuccessVersion) { + super(replicaId, backendId, version, schemaHash, dataSize, remoteDataSize, rowCount, state, lastFailedVersion, + lastSuccessVersion); + this.remoteDataSize = remoteDataSize; + } + + @Override + public long getRemoteDataSize() { + return remoteDataSize; + } + + @Override + public void setRemoteDataSize(long remoteDataSize) { + this.remoteDataSize = remoteDataSize; + } + + @Override + public Long getRemoteInvertedIndexSize() { + return remoteInvertedIndexSize; + } + + @Override + public void setRemoteInvertedIndexSize(long remoteInvertedIndexSize) { + this.remoteInvertedIndexSize = remoteInvertedIndexSize; + } + + @Override + public Long getRemoteSegmentSize() { + return remoteSegmentSize; + } + + @Override + public void setRemoteSegmentSize(long remoteSegmentSize) { + this.remoteSegmentSize = remoteSegmentSize; + } + + @Override + public TUniqueId getCooldownMetaId() { + return cooldownMetaId; + } + + @Override + public void setCooldownMetaId(TUniqueId cooldownMetaId) { + this.cooldownMetaId = cooldownMetaId; + } + + @Override + public long getCooldownTerm() { + return cooldownTerm; + } + + @Override + public void setCooldownTerm(long cooldownTerm) { + this.cooldownTerm = cooldownTerm; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index aab1597a6ac2f7..adf1d794056ee0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -969,7 +969,7 @@ && getTableProperty().getDynamicPartitionProperty().getBuckets() for (Map.Entry> entry3 : tag2beIds.entrySet()) { for (Long beId : entry3.getValue()) { long newReplicaId = env.getNextId(); - Replica replica = new Replica(newReplicaId, beId, ReplicaState.NORMAL, + Replica replica = new LocalReplica(newReplicaId, beId, ReplicaState.NORMAL, visibleVersion, schemaHash); newTablet.addReplica(replica, true /* is restore */); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java index 207fd6a8e8a0a1..58ebdf4f5f3be1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.java @@ -96,8 +96,6 @@ public static class ReplicaContext { private int schemaHash = -1; @SerializedName(value = "ds", alternate = {"dataSize"}) private volatile long dataSize = 0; - @SerializedName(value = "rds", alternate = {"remoteDataSize"}) - private volatile long remoteDataSize = 0; @SerializedName(value = "rc", alternate = {"rowCount"}) private volatile long rowCount = 0; @SerializedName(value = "st", alternate = {"state"}) @@ -120,14 +118,6 @@ public static class ReplicaContext { @Getter @SerializedName(value = "lss", alternate = {"localSegmentSize"}) private Long localSegmentSize = 0L; - @Setter - @Getter - @SerializedName(value = "ris", alternate = {"remoteInvertedIndexSize"}) - private Long remoteInvertedIndexSize = 0L; - @Setter - @Getter - @SerializedName(value = "rss", alternate = {"remoteSegmentSize"}) - private Long remoteSegmentSize = 0L; private volatile long totalVersionCount = -1; private volatile long visibleVersionCount = -1; @@ -137,9 +127,6 @@ public static class ReplicaContext { // bad means this Replica is unrecoverable, and we will delete it private boolean bad = false; - private TUniqueId cooldownMetaId; - private long cooldownTerm = -1; - // A replica version should increase monotonically, // but backend may missing some versions due to disk failure or bugs. // FE should found these and mark the replica as missing versions. @@ -217,7 +204,6 @@ public Replica(long replicaId, long backendId, long version, int schemaHash, this.schemaHash = schemaHash; this.dataSize = dataSize; - this.remoteDataSize = remoteDataSize; this.rowCount = rowCount; this.state = state; if (this.state == null) { @@ -280,11 +266,33 @@ public void setDataSize(long dataSize) { } public long getRemoteDataSize() { - return remoteDataSize; + return 0; } public void setRemoteDataSize(long remoteDataSize) { - this.remoteDataSize = remoteDataSize; + if (remoteDataSize > 0) { + throw new UnsupportedOperationException("setRemoteDataSize is not supported in Replica"); + } + } + + public Long getRemoteInvertedIndexSize() { + return 0L; + } + + public void setRemoteInvertedIndexSize(long remoteInvertedIndexSize) { + if (remoteInvertedIndexSize > 0) { + throw new UnsupportedOperationException("setRemoteInvertedIndexSize is not supported in Replica"); + } + } + + public Long getRemoteSegmentSize() { + return 0L; + } + + public void setRemoteSegmentSize(long remoteSegmentSize) { + if (remoteSegmentSize > 0) { + throw new UnsupportedOperationException("setRemoteSegmentSize is not supported in Replica"); + } } public long getRowCount() { @@ -344,19 +352,19 @@ public boolean setBad(boolean bad) { } public TUniqueId getCooldownMetaId() { - return cooldownMetaId; + return null; } public void setCooldownMetaId(TUniqueId cooldownMetaId) { - this.cooldownMetaId = cooldownMetaId; + throw new UnsupportedOperationException("setCooldownMetaId is not supported in Replica"); } public long getCooldownTerm() { - return cooldownTerm; + return -1; } public void setCooldownTerm(long cooldownTerm) { - this.cooldownTerm = cooldownTerm; + throw new UnsupportedOperationException("setCooldownTerm is not supported in Replica"); } public boolean needFurtherRepair() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java index 9e63a4fa1c4835..bc1809d1a511ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java +++ b/fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.java @@ -19,6 +19,7 @@ import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Partition; @@ -1017,7 +1018,7 @@ public CloneTask createCloneReplicaAndTask() throws SchedException { || tabletHealth.status == TabletStatus.REPLICA_RELOCATING || type == Type.BALANCE || tabletHealth.status == TabletStatus.COLOCATE_MISMATCH || tabletHealth.status == TabletStatus.REPLICA_MISSING_FOR_TAG) { - replica = new Replica( + replica = new LocalReplica( Env.getCurrentEnv().getNextId(), destBackendId, -1 /* version */, schemaHash, -1 /* data size */, -1, -1 /* row count */, diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 6302dbc9d18b4e..ef84c7a1853fc0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -49,6 +49,7 @@ import org.apache.doris.catalog.JdbcTable; import org.apache.doris.catalog.KeysType; import org.apache.doris.catalog.ListPartitionItem; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MTMV; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MaterializedIndex.IndexExtState; @@ -1112,7 +1113,7 @@ private void unprotectAddReplica(OlapTable olapTable, ReplicaPersistInfo info) { schemaHash = olapTable.getSchemaHashByIndexId(info.getIndexId()); } - Replica replica = new Replica(info.getReplicaId(), info.getBackendId(), info.getVersion(), schemaHash, + Replica replica = new LocalReplica(info.getReplicaId(), info.getBackendId(), info.getVersion(), schemaHash, info.getDataSize(), info.getRemoteDataSize(), info.getRowCount(), ReplicaState.NORMAL, info.getLastFailedVersion(), info.getLastSuccessVersion()); @@ -3350,7 +3351,7 @@ public TStorageMedium createTablets(MaterializedIndex index, ReplicaState replic for (List backendIds : chosenBackendIds.values()) { for (long backendId : backendIds) { long replicaId = idGeneratorBuffer.getNextId(); - Replica replica = new Replica(replicaId, backendId, replicaState, version, + Replica replica = new LocalReplica(replicaId, backendId, replicaState, version, tabletMeta.getOldSchemaHash()); tablet.addReplica(replica); totalReplicaNum++; diff --git a/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java b/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java index d12853e1d55232..93d0d10b0553fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.java @@ -25,6 +25,7 @@ import org.apache.doris.catalog.DiskInfo; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.Index; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MaterializedIndex.IndexState; import org.apache.doris.catalog.MaterializedIndexMeta; @@ -1573,7 +1574,7 @@ private static boolean addReplica(long tabletId, TabletMeta tabletMeta, TTabletI } // use replicaId reported by BE to maintain replica meta consistent between FE and BE - Replica replica = new Replica(replicaId, backendId, version, schemaHash, + Replica replica = new LocalReplica(replicaId, backendId, version, schemaHash, dataSize, remoteDataSize, rowCount, ReplicaState.NORMAL, lastFailedVersion, version); tablet.addReplica(replica); diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/gson/GsonUtils.java b/fe/fe-core/src/main/java/org/apache/doris/persist/gson/GsonUtils.java index aae6852eaf5926..4e5bf10b5c7dca 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/gson/GsonUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/gson/GsonUtils.java @@ -85,6 +85,7 @@ import org.apache.doris.catalog.JdbcTable; import org.apache.doris.catalog.ListPartitionInfo; import org.apache.doris.catalog.ListPartitionItem; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.LocalTablet; import org.apache.doris.catalog.MTMV; import org.apache.doris.catalog.MapType; @@ -522,8 +523,7 @@ public class GsonUtils { // runtime adapter for class "CloudReplica". private static RuntimeTypeAdapterFactory replicaTypeAdapterFactory = RuntimeTypeAdapterFactory .of(Replica.class, "clazz") - .registerDefaultSubtype(Replica.class) - .registerSubtype(Replica.class, Replica.class.getSimpleName()) + .registerSubtype(LocalReplica.class, LocalReplica.class.getSimpleName()) .registerSubtype(CloudReplica.class, CloudReplica.class.getSimpleName()); private static RuntimeTypeAdapterFactory tabletTypeAdapterFactory; @@ -536,9 +536,12 @@ public class GsonUtils { if (Config.isNotCloudMode()) { tabletTypeAdapterFactory.registerDefaultSubtype(LocalTablet.class); tabletTypeAdapterFactory.registerCompatibleSubtype(LocalTablet.class, Tablet.class.getSimpleName()); + replicaTypeAdapterFactory.registerDefaultSubtype(LocalReplica.class); + replicaTypeAdapterFactory.registerCompatibleSubtype(LocalReplica.class, Replica.class.getSimpleName()); } else { // compatible with old cloud code. tabletTypeAdapterFactory.registerDefaultSubtype(CloudTablet.class); + replicaTypeAdapterFactory.registerDefaultSubtype(CloudReplica.class); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java b/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java index 67ac384a5375b3..bbf77f992a9dfe 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java +++ b/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java @@ -27,6 +27,7 @@ import org.apache.doris.catalog.FakeEditLog; import org.apache.doris.catalog.HashDistributionInfo; import org.apache.doris.catalog.KeysType; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.LocalTablet; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MaterializedIndex.IndexState; @@ -252,9 +253,9 @@ public static Database mockDb() throws UserException { TabletMeta tabletMeta = new TabletMeta(TEST_DB_ID, TEST_TBL_ID, TEST_SINGLE_PARTITION_ID, TEST_TBL_ID, SCHEMA_HASH, TStorageMedium.HDD); baseIndex.addTablet(tablet0, tabletMeta); - Replica replica0 = new Replica(TEST_REPLICA0_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); - Replica replica1 = new Replica(TEST_REPLICA1_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); - Replica replica2 = new Replica(TEST_REPLICA2_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); + Replica replica0 = new LocalReplica(TEST_REPLICA0_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); + Replica replica1 = new LocalReplica(TEST_REPLICA1_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); + Replica replica2 = new LocalReplica(TEST_REPLICA2_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); tablet0.addReplica(replica0); tablet0.addReplica(replica1); @@ -326,9 +327,9 @@ public static Database mockDb() throws UserException { TabletMeta tabletMetaBaseTabletP1 = new TabletMeta(TEST_DB_ID, TEST_TBL2_ID, TEST_PARTITION1_ID, TEST_TBL2_ID, SCHEMA_HASH, TStorageMedium.HDD); baseIndexP1.addTablet(baseTabletP1, tabletMetaBaseTabletP1); - Replica replica3 = new Replica(TEST_REPLICA3_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); - Replica replica4 = new Replica(TEST_REPLICA4_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); - Replica replica5 = new Replica(TEST_REPLICA5_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); + Replica replica3 = new LocalReplica(TEST_REPLICA3_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); + Replica replica4 = new LocalReplica(TEST_REPLICA4_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); + Replica replica5 = new LocalReplica(TEST_REPLICA5_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); baseTabletP1.addReplica(replica3); baseTabletP1.addReplica(replica4); @@ -338,9 +339,9 @@ public static Database mockDb() throws UserException { TabletMeta tabletMetaBaseTabletP2 = new TabletMeta(TEST_DB_ID, TEST_TBL2_ID, TEST_PARTITION2_ID, TEST_TBL2_ID, SCHEMA_HASH, TStorageMedium.HDD); baseIndexP2.addTablet(baseTabletP2, tabletMetaBaseTabletP2); - Replica replica6 = new Replica(TEST_REPLICA6_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); - Replica replica7 = new Replica(TEST_REPLICA7_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); - Replica replica8 = new Replica(TEST_REPLICA8_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); + Replica replica6 = new LocalReplica(TEST_REPLICA6_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); + Replica replica7 = new LocalReplica(TEST_REPLICA7_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); + Replica replica8 = new LocalReplica(TEST_REPLICA8_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); baseTabletP2.addReplica(replica6); baseTabletP2.addReplica(replica7); @@ -359,9 +360,9 @@ public static Database mockDb() throws UserException { TEST_ROLLUP_TABLET_P1_ID, ROLLUP_SCHEMA_HASH, TStorageMedium.HDD); rollupIndexP1.addTablet(rollupTabletP1, tabletMetaRollupTabletP1); - Replica replica9 = new Replica(TEST_REPLICA9_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); - Replica replica10 = new Replica(TEST_REPLICA10_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); - Replica replica11 = new Replica(TEST_REPLICA11_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); + Replica replica9 = new LocalReplica(TEST_REPLICA9_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); + Replica replica10 = new LocalReplica(TEST_REPLICA10_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); + Replica replica11 = new LocalReplica(TEST_REPLICA11_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); rollupTabletP1.addReplica(replica9); rollupTabletP1.addReplica(replica10); @@ -376,9 +377,9 @@ public static Database mockDb() throws UserException { TEST_ROLLUP_TABLET_P2_ID, ROLLUP_SCHEMA_HASH, TStorageMedium.HDD); rollupIndexP2.addTablet(rollupTabletP2, tabletMetaRollupTabletP2); - Replica replica12 = new Replica(TEST_REPLICA12_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); - Replica replica13 = new Replica(TEST_REPLICA13_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); - Replica replica14 = new Replica(TEST_REPLICA14_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); + Replica replica12 = new LocalReplica(TEST_REPLICA12_ID, BACKEND1_ID, 0, ReplicaState.NORMAL); + Replica replica13 = new LocalReplica(TEST_REPLICA13_ID, BACKEND2_ID, 0, ReplicaState.NORMAL); + Replica replica14 = new LocalReplica(TEST_REPLICA14_ID, BACKEND3_ID, 0, ReplicaState.NORMAL); rollupTabletP2.addReplica(replica12); rollupTabletP2.addReplica(replica13); rollupTabletP2.addReplica(replica14); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.java index 3d7efdc96c709d..5e4f90d2251ea5 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.java @@ -188,11 +188,11 @@ public static Database createSimpleDb(long dbId, long tableId, long partitionId, replica3 = new CloudReplica(testReplicaId3, testBackendId3, Replica.ReplicaState.NORMAL, version, 0, dbId, tableId, partitionId, indexId, 2); } else { - replica1 = new Replica(testReplicaId1, testBackendId1, version, 0, 0L, 0L, 0L, + replica1 = new LocalReplica(testReplicaId1, testBackendId1, version, 0, 0L, 0L, 0L, Replica.ReplicaState.NORMAL, -1, 0); - replica2 = new Replica(testReplicaId2, testBackendId2, version, 0, 0L, 0L, 0L, + replica2 = new LocalReplica(testReplicaId2, testBackendId2, version, 0, 0L, 0L, 0L, Replica.ReplicaState.NORMAL, -1, 0); - replica3 = new Replica(testReplicaId3, testBackendId3, version, 0, 0L, 0L, 0L, + replica3 = new LocalReplica(testReplicaId3, testBackendId3, version, 0, 0L, 0L, 0L, Replica.ReplicaState.NORMAL, -1, 0); } @@ -263,7 +263,7 @@ public static void createDupTable(Database db) { replica = new CloudReplica(testReplicaId4, testBackendId1, Replica.ReplicaState.NORMAL, testStartVersion, 0, db.getId(), testTableId2, testPartitionId2, testIndexId2, 0); } else { - replica = new Replica(testReplicaId4, testBackendId1, testStartVersion, 0, 0L, 0L, 0L, + replica = new LocalReplica(testReplicaId4, testBackendId1, testStartVersion, 0, 0L, 0L, 0L, Replica.ReplicaState.NORMAL, -1, 0); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.java index 101ec619e765a6..2c7d32a599d65c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.java @@ -54,7 +54,7 @@ public void setUp() { version = 2; dataSize = 9999; rowCount = 1024; - replica = new Replica(replicaId, backendId, version, 0, dataSize, 0, rowCount, ReplicaState.NORMAL, 0, version); + replica = new LocalReplica(replicaId, backendId, version, 0, dataSize, 0, rowCount, ReplicaState.NORMAL, 0, version); } @Test @@ -84,13 +84,13 @@ public void testSerialization() throws Exception { List list1 = new ArrayList(); List list2 = new ArrayList(); for (int count = 0; count < 10; ++count) { - Replica olapReplica = new Replica(100L * count, 100L * count, 100L * count, 0, + Replica olapReplica = new LocalReplica(100L * count, 100L * count, 100L * count, 0, 100L * count, 0, 100 * count, ReplicaState.NORMAL, 0, 100L * count); list1.add(olapReplica); Text.writeString(dos, GsonUtils.GSON.toJson(olapReplica)); } - Replica replica = new Replica(10L, 20L, 0, null); + Replica replica = new LocalReplica(10L, 20L, 0, null); list1.add(replica); Text.writeString(dos, GsonUtils.GSON.toJson(replica)); dos.flush(); @@ -125,7 +125,7 @@ public void testSerialization() throws Exception { @Test public void testUpdateVersion1() { - Replica originalReplica = new Replica(10000, 20000, 3, 0, 100, 0, 78, ReplicaState.NORMAL, 0, 3); + Replica originalReplica = new LocalReplica(10000, 20000, 3, 0, 100, 0, 78, ReplicaState.NORMAL, 0, 3); // new version is little than original version, it is invalid the version will not update originalReplica.updateVersion(2); Assert.assertEquals(3, originalReplica.getVersion()); @@ -133,7 +133,7 @@ public void testUpdateVersion1() { @Test public void testUpdateVersion2() { - Replica originalReplica = new Replica(10000, 20000, 3, 0, 100, 0, 78, ReplicaState.NORMAL, 0, 0); + Replica originalReplica = new LocalReplica(10000, 20000, 3, 0, 100, 0, 78, ReplicaState.NORMAL, 0, 0); originalReplica.updateVersion(3); // if new version >= current version and last success version <= new version, then last success version should be updated Assert.assertEquals(3, originalReplica.getLastSuccessVersion()); @@ -143,7 +143,7 @@ public void testUpdateVersion2() { @Test public void testUpdateVersion3() { // version(3) ---> last failed version (8) ---> last success version(10) - Replica originalReplica = new Replica(10000, 20000, 3, 111, 0, 0, 78, ReplicaState.NORMAL, 0, 0); + Replica originalReplica = new LocalReplica(10000, 20000, 3, 111, 0, 0, 78, ReplicaState.NORMAL, 0, 0); originalReplica.updateLastFailedVersion(8); Assert.assertEquals(3, originalReplica.getLastSuccessVersion()); Assert.assertEquals(3, originalReplica.getVersion()); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletTest.java index ba3b4729bd5c02..6d20800b52bf02 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/TabletTest.java @@ -83,9 +83,9 @@ public void makeTablet() { tablet = new LocalTablet(1); TabletMeta tabletMeta = new TabletMeta(10, 20, 30, 40, 1, TStorageMedium.HDD); invertedIndex.addTablet(1, tabletMeta); - replica1 = new Replica(1L, 1L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); - replica2 = new Replica(2L, 2L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); - replica3 = new Replica(3L, 3L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + replica1 = new LocalReplica(1L, 1L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + replica2 = new LocalReplica(2L, 2L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + replica3 = new LocalReplica(3L, 3L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); tablet.addReplica(replica1); tablet.addReplica(replica2); tablet.addReplica(replica3); @@ -147,9 +147,9 @@ public void testSerialization() throws Exception { Assert.assertEquals(rTablet1, rTablet1); Tablet tablet2 = new LocalTablet(1); - Replica replica1 = new Replica(1L, 1L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); - Replica replica2 = new Replica(2L, 2L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); - Replica replica3 = new Replica(3L, 3L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + Replica replica1 = new LocalReplica(1L, 1L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + Replica replica2 = new LocalReplica(2L, 2L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); + Replica replica3 = new LocalReplica(3L, 3L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0); tablet2.addReplica(replica1); tablet2.addReplica(replica2); Assert.assertNotEquals(tablet2, tablet); @@ -159,7 +159,7 @@ public void testSerialization() throws Exception { Tablet tablet3 = new LocalTablet(1); tablet3.addReplica(replica1); tablet3.addReplica(replica2); - tablet3.addReplica(new Replica(4L, 4L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0)); + tablet3.addReplica(new LocalReplica(4L, 4L, 100L, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, 0, 0)); Assert.assertNotEquals(tablet3, tablet); dis.close(); @@ -182,7 +182,7 @@ private final void testTabletColocateHealthStatus0(Tablet.TabletStatus exceptedT versionAndSuccessVersion = 99L; lastFailVersion = 100L; } - tablet.addReplica(new Replica(replicaId++, pair.first, versionAndSuccessVersion, 0, + tablet.addReplica(new LocalReplica(replicaId++, pair.first, versionAndSuccessVersion, 0, 200000L, 0, 3000L, ReplicaState.NORMAL, lastFailVersion, versionAndSuccessVersion)); } Assert.assertEquals(tablet.getColocateHealth(100L, new ReplicaAllocation((short) 3), @@ -222,7 +222,7 @@ public void testGetMinReplicaRowCount() { long row = t.getMinReplicaRowCount(1); Assert.assertEquals(0, row); - Replica r1 = new Replica(1, 1, 10, 0, 0, 0, 100, ReplicaState.NORMAL, 0, 10); + Replica r1 = new LocalReplica(1, 1, 10, 0, 0, 0, 100, ReplicaState.NORMAL, 0, 10); t.addReplica(r1); row = t.getMinReplicaRowCount(10); Assert.assertEquals(100, row); @@ -230,8 +230,8 @@ public void testGetMinReplicaRowCount() { row = t.getMinReplicaRowCount(11); Assert.assertEquals(0, row); - Replica r2 = new Replica(2, 2, 10, 0, 0, 0, 110, ReplicaState.NORMAL, 0, 10); - Replica r3 = new Replica(3, 3, 10, 0, 0, 0, 90, ReplicaState.NORMAL, 0, 10); + Replica r2 = new LocalReplica(2, 2, 10, 0, 0, 0, 110, ReplicaState.NORMAL, 0, 10); + Replica r3 = new LocalReplica(3, 3, 10, 0, 0, 0, 90, ReplicaState.NORMAL, 0, 10); t.addReplica(r2); t.addReplica(r3); row = t.getMinReplicaRowCount(11); diff --git a/fe/fe-core/src/test/java/org/apache/doris/clone/ClusterLoadStatisticsTest.java b/fe/fe-core/src/test/java/org/apache/doris/clone/ClusterLoadStatisticsTest.java index f1c3a5c8b38680..118018f3b58269 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/clone/ClusterLoadStatisticsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/clone/ClusterLoadStatisticsTest.java @@ -19,7 +19,7 @@ import org.apache.doris.catalog.DiskInfo; import org.apache.doris.catalog.Env; -import org.apache.doris.catalog.Replica; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.Replica.ReplicaState; import org.apache.doris.catalog.TabletInvertedIndex; import org.apache.doris.catalog.TabletMeta; @@ -151,17 +151,17 @@ public void setUp() { invertedIndex = new TabletInvertedIndex(); invertedIndex.addTablet(50000, new TabletMeta(1, 2, 3, 4, 5, TStorageMedium.HDD)); - invertedIndex.addReplica(50000, new Replica(50001, be1.getId(), 0, ReplicaState.NORMAL)); - invertedIndex.addReplica(50000, new Replica(50002, be2.getId(), 0, ReplicaState.NORMAL)); - invertedIndex.addReplica(50000, new Replica(50003, be3.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(50000, new LocalReplica(50001, be1.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(50000, new LocalReplica(50002, be2.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(50000, new LocalReplica(50003, be3.getId(), 0, ReplicaState.NORMAL)); invertedIndex.addTablet(60000, new TabletMeta(1, 2, 3, 4, 5, TStorageMedium.HDD)); - invertedIndex.addReplica(60000, new Replica(60002, be2.getId(), 0, ReplicaState.NORMAL)); - invertedIndex.addReplica(60000, new Replica(60003, be3.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(60000, new LocalReplica(60002, be2.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(60000, new LocalReplica(60003, be3.getId(), 0, ReplicaState.NORMAL)); invertedIndex.addTablet(70000, new TabletMeta(1, 2, 3, 4, 5, TStorageMedium.HDD)); - invertedIndex.addReplica(70000, new Replica(70002, be2.getId(), 0, ReplicaState.NORMAL)); - invertedIndex.addReplica(70000, new Replica(70003, be3.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(70000, new LocalReplica(70002, be2.getId(), 0, ReplicaState.NORMAL)); + invertedIndex.addReplica(70000, new LocalReplica(70003, be3.getId(), 0, ReplicaState.NORMAL)); } @Test diff --git a/fe/fe-core/src/test/java/org/apache/doris/clone/RebalancerTestUtil.java b/fe/fe-core/src/test/java/org/apache/doris/clone/RebalancerTestUtil.java index 1f55c6fd0d9ae6..6f1d14ebf59cce 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/clone/RebalancerTestUtil.java +++ b/fe/fe-core/src/test/java/org/apache/doris/clone/RebalancerTestUtil.java @@ -20,6 +20,7 @@ import org.apache.doris.catalog.Database; import org.apache.doris.catalog.DiskInfo; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.LocalTablet; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MysqlCompatibleDatabase; @@ -100,7 +101,8 @@ public static void createReplicasAndAddToIndex(TabletInvertedIndex invertedIndex invertedIndex.addTablet(tablet.getId(), tabletMeta); IntStream.range(0, beIds.size()).forEach(i -> { - Replica replica = new Replica(tablet.getId() + i, beIds.get(i), Replica.ReplicaState.NORMAL, 1, tabletMeta.getOldSchemaHash()); + Replica replica = new LocalReplica(tablet.getId() + i, beIds.get(i), Replica.ReplicaState.NORMAL, 1, + tabletMeta.getOldSchemaHash()); // We've set pathHash to beId for simplicity replica.setPathHash(beIds.get(i)); if (replicaSizes != null) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletHealthTest.java b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletHealthTest.java index 320bff45229fba..bea57e3d6fcce2 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletHealthTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletHealthTest.java @@ -21,6 +21,7 @@ import org.apache.doris.catalog.ColocateTableIndex.GroupId; import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex.IndexExtState; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Partition; @@ -333,7 +334,7 @@ public void testColocateTabletHealth() throws Exception { // temporary delete replica 1 tablet.deleteReplica(tablet.getReplicas().get(1)); Assertions.assertFalse(tablet.getBackendIds().contains(deleteBeId)); - Replica replica = new Replica(1234567890L, deleteBeId, Replica.ReplicaState.NORMAL, 8L, 0); + Replica replica = new LocalReplica(1234567890L, deleteBeId, Replica.ReplicaState.NORMAL, 8L, 0); // add a `error` replica on other backend tablet.addReplica(replica); // colocate don't relocate because no be dead diff --git a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java index 8b316c474a867e..f10031f91f3400 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.java @@ -19,6 +19,7 @@ import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Partition; @@ -163,31 +164,31 @@ public void testVersionCountComparator() { TabletSchedCtx.CloneSrcComparator countComparator = new TabletSchedCtx.CloneSrcComparator(); List replicaList = Lists.newArrayList(); - Replica replica1 = new Replica(); + Replica replica1 = new LocalReplica(); replica1.setVisibleVersionCount(100); replica1.setState(Replica.ReplicaState.NORMAL); // user drop true replica1.setUserDropTime(System.currentTimeMillis()); - Replica replica2 = new Replica(); + Replica replica2 = new LocalReplica(); replica2.setVisibleVersionCount(50); replica2.setState(Replica.ReplicaState.NORMAL); // user drop false replica2.setUserDropTime(-1); - Replica replica3 = new Replica(); + Replica replica3 = new LocalReplica(); replica3.setVisibleVersionCount(-1); replica3.setState(Replica.ReplicaState.NORMAL); // user drop false replica3.setUserDropTime(-1); - Replica replica4 = new Replica(); + Replica replica4 = new LocalReplica(); replica4.setVisibleVersionCount(200); replica4.setState(Replica.ReplicaState.NORMAL); // user drop false replica4.setUserDropTime(-1); - Replica replica5 = new Replica(); + Replica replica5 = new LocalReplica(); replica5.setVisibleVersionCount(-1); replica5.setState(Replica.ReplicaState.NORMAL); // user drop true diff --git a/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java b/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java index 7f7ee401fa6eb3..d8557843d895b6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.java @@ -19,6 +19,7 @@ import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Partition; @@ -308,7 +309,7 @@ public void testDecommissionBackendWithLeakyTablets() throws Exception { TabletInvertedIndex invertIndex = Env.getCurrentInvertedIndex(); long fakeTabletId = 123123123L; TabletMeta fakeTabletMeta = new TabletMeta(1234567L, 1234568L, 1234569L, 1234570L, 0, TStorageMedium.HDD); - Replica fakeReplica = new Replica(1234571L, srcBackend.getId(), 0, Replica.ReplicaState.NORMAL); + Replica fakeReplica = new LocalReplica(1234571L, srcBackend.getId(), 0, Replica.ReplicaState.NORMAL); Supplier> getNotInRecycleBinTablets = () -> { List tabletIds = Lists.newArrayList(); diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/UnitTestUtil.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/UnitTestUtil.java index 9c81c279fc0e5d..6133688e158346 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/UnitTestUtil.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/UnitTestUtil.java @@ -22,6 +22,7 @@ import org.apache.doris.catalog.DataProperty; import org.apache.doris.catalog.Database; import org.apache.doris.catalog.KeysType; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.LocalTablet; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.MaterializedIndex.IndexState; @@ -72,9 +73,9 @@ public static OlapTable createTable(Database db, long tableId, String tableName, long tabletId, long backendId, long version) { // replica long replicaId = 0; - Replica replica1 = new Replica(replicaId, backendId, ReplicaState.NORMAL, version, 0); - Replica replica2 = new Replica(replicaId + 1, backendId + 1, ReplicaState.NORMAL, version, 0); - Replica replica3 = new Replica(replicaId + 2, backendId + 2, ReplicaState.NORMAL, version, 0); + Replica replica1 = new LocalReplica(replicaId, backendId, ReplicaState.NORMAL, version, 0); + Replica replica2 = new LocalReplica(replicaId + 1, backendId + 1, ReplicaState.NORMAL, version, 0); + Replica replica3 = new LocalReplica(replicaId + 2, backendId + 2, ReplicaState.NORMAL, version, 0); // tablet Tablet tablet = new LocalTablet(tabletId); diff --git a/fe/fe-core/src/test/java/org/apache/doris/http/DorisHttpTestCase.java b/fe/fe-core/src/test/java/org/apache/doris/http/DorisHttpTestCase.java index bd42f7568285c3..a57f3b497e9750 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/http/DorisHttpTestCase.java +++ b/fe/fe-core/src/test/java/org/apache/doris/http/DorisHttpTestCase.java @@ -26,6 +26,7 @@ import org.apache.doris.catalog.EsResource; import org.apache.doris.catalog.EsTable; import org.apache.doris.catalog.KeysType; +import org.apache.doris.catalog.LocalReplica; import org.apache.doris.catalog.LocalTablet; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.OlapTable; @@ -145,12 +146,12 @@ public static OlapTable newTable(String name) { columns.add(k1); columns.add(k2); - Replica replica1 = new Replica(testReplicaId1, testBackendId1, testStartVersion, testSchemaHash, 1024000L, 0, 2000L, - Replica.ReplicaState.NORMAL, -1, 0); - Replica replica2 = new Replica(testReplicaId2, testBackendId2, testStartVersion, testSchemaHash, 1024000L, 0, 2000L, - Replica.ReplicaState.NORMAL, -1, 0); - Replica replica3 = new Replica(testReplicaId3, testBackendId3, testStartVersion, testSchemaHash, 1024000L, 0, 2000L, - Replica.ReplicaState.NORMAL, -1, 0); + Replica replica1 = new LocalReplica(testReplicaId1, testBackendId1, testStartVersion, testSchemaHash, 1024000L, + 0, 2000L, Replica.ReplicaState.NORMAL, -1, 0); + Replica replica2 = new LocalReplica(testReplicaId2, testBackendId2, testStartVersion, testSchemaHash, 1024000L, + 0, 2000L, Replica.ReplicaState.NORMAL, -1, 0); + Replica replica3 = new LocalReplica(testReplicaId3, testBackendId3, testStartVersion, testSchemaHash, 1024000L, + 0, 2000L, Replica.ReplicaState.NORMAL, -1, 0); // tablet Tablet tablet = new LocalTablet(tabletId);