Skip to content
Merged
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 @@ -740,7 +740,7 @@ public Env(boolean isCheckpointCatalog) {
this.feSessionMgr = new FESessionMgr();
this.temporaryTableMgr = new TemporaryTableMgr();
this.aliveSessionSet = Sets.newConcurrentHashSet();
this.tabletInvertedIndex = new TabletInvertedIndex();
this.tabletInvertedIndex = EnvFactory.getInstance().createTabletInvertedIndex();
this.colocateTableIndex = new ColocateTableIndex();
this.recycleBin = new CatalogRecycleBin();
this.functionSet = new FunctionSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public SystemInfoService createSystemInfoService() {
return new SystemInfoService();
}

public TabletInvertedIndex createTabletInvertedIndex() {
return new LocalTabletInvertedIndex();
}

public Type getPartitionClass() {
return Partition.class;
}
Expand Down
1,046 changes: 1,046 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/LocalTabletInvertedIndex.java

Large diffs are not rendered by default.

1,003 changes: 31 additions & 972 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.doris.catalog.Replica;
import org.apache.doris.catalog.ReplicaAllocation;
import org.apache.doris.catalog.Tablet;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.cloud.common.util.CloudPropertyAnalyzer;
import org.apache.doris.cloud.datasource.CloudInternalCatalog;
import org.apache.doris.cloud.load.CleanCopyJobScheduler;
Expand Down Expand Up @@ -83,6 +84,11 @@ public SystemInfoService createSystemInfoService() {
return new CloudSystemInfoService();
}

@Override
public TabletInvertedIndex createTabletInvertedIndex() {
return new CloudTabletInvertedIndex();
}

@Override
public Type getPartitionClass() {
return CloudPartition.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// 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.cloud.catalog;

import org.apache.doris.catalog.Replica;
import org.apache.doris.catalog.TabletInvertedIndex;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;
import java.util.Map;

public class CloudTabletInvertedIndex extends TabletInvertedIndex {
private static final Logger LOG = LogManager.getLogger(CloudTabletInvertedIndex.class);

// tablet id -> replica
// for cloud mode, no need to know the replica's backend
private Map<Long, Replica> replicaMetaMap = Maps.newHashMap();

public CloudTabletInvertedIndex() {
super();
}

@Override
public List<Replica> getReplicas(Long tabletId) {
long stamp = readLock();
try {
if (replicaMetaMap.containsKey(tabletId)) {
return Lists.newArrayList(replicaMetaMap.get(tabletId));
}
return Lists.newArrayList();
} finally {
readUnlock(stamp);
}
}

@Override
public void deleteTablet(long tabletId) {
long stamp = writeLock();
try {
replicaMetaMap.remove(tabletId);
tabletMetaMap.remove(tabletId);
if (LOG.isDebugEnabled()) {
LOG.debug("delete tablet: {}", tabletId);
}
} finally {
writeUnlock(stamp);
}
}

@Override
public void addReplica(long tabletId, Replica replica) {
long stamp = writeLock();
try {
Preconditions.checkState(tabletMetaMap.containsKey(tabletId),
"tablet " + tabletId + " not exists, replica " + replica.getId());
replicaMetaMap.put(tabletId, replica);
if (LOG.isDebugEnabled()) {
LOG.debug("add replica {} of tablet {}", replica.getId(), tabletId);
}
} finally {
writeUnlock(stamp);
}
}

@Override
public void deleteReplica(long tabletId, long backendId) {
long stamp = writeLock();
try {
Preconditions.checkState(tabletMetaMap.containsKey(tabletId), "tablet " + tabletId + " not exists");
if (replicaMetaMap.containsKey(tabletId)) {
Replica replica = replicaMetaMap.remove(tabletId);
if (LOG.isDebugEnabled()) {
LOG.debug("delete replica {} of tablet {}", replica.getId(), tabletId);
}
} else {
// this may happen when fe restart after tablet is empty(bug cause)
// add log instead of assertion to observe
LOG.error("tablet[{}] contains no replica in inverted index", tabletId);
}
} finally {
writeUnlock(stamp);
}
}

@Override
public Replica getReplica(long tabletId, long backendId) {
long stamp = readLock();
try {
Preconditions.checkState(tabletMetaMap.containsKey(tabletId), "tablet " + tabletId + " not exists");
return replicaMetaMap.get(tabletId);
} finally {
readUnlock(stamp);
}
}

@Override
public List<Replica> getReplicasByTabletId(long tabletId) {
long stamp = readLock();
try {
if (replicaMetaMap.containsKey(tabletId)) {
return Lists.newArrayList(replicaMetaMap.get(tabletId));
}
return Lists.newArrayList();
} finally {
readUnlock(stamp);
}
}

@Override
protected void innerClear() {
replicaMetaMap.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.doris.catalog.BrokerMgr;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
import org.apache.doris.catalog.OlapTable;
Expand Down Expand Up @@ -92,7 +93,7 @@ public class BackupHandlerTest {

private String tmpPath = "./tmp" + System.currentTimeMillis();

private TabletInvertedIndex invertedIndex = new TabletInvertedIndex();
private TabletInvertedIndex invertedIndex = new LocalTabletInvertedIndex();

@Before
public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.junit.Assert;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -60,8 +59,6 @@ public void testDuplicateCreateTable() throws Exception {
+ "distributed by hash(k2) buckets 1\n" + "properties('replication_num' = '1','colocate_with'='test'); ";
createTable(sql);
Set<Long> tabletIdSetAfterCreateFirstTable = env.getTabletInvertedIndex().getReplicaMetaTable().rowKeySet();
Set<TabletMeta> tabletMetaSetBeforeCreateFirstTable =
new HashSet<>(env.getTabletInvertedIndex().getTabletMetaTable().values());
Set<Long> colocateTableIdBeforeCreateFirstTable = env.getColocateTableIndex().getTable2Group().keySet();
Assert.assertTrue(colocateTableIdBeforeCreateFirstTable.size() > 0);
Assert.assertTrue(tabletIdSetAfterCreateFirstTable.size() > 0);
Expand All @@ -71,13 +68,10 @@ public void testDuplicateCreateTable() throws Exception {
Set<Long> tabletIdSetAfterDuplicateCreateTable1 = env.getTabletInvertedIndex().getReplicaMetaTable().rowKeySet();
Set<Long> tabletIdSetAfterDuplicateCreateTable2 = env.getTabletInvertedIndex().getBackingReplicaMetaTable().columnKeySet();
Set<Long> tabletIdSetAfterDuplicateCreateTable3 = env.getTabletInvertedIndex().getTabletMetaMap().keySet();
Set<TabletMeta> tabletIdSetAfterDuplicateCreateTable4 =
new HashSet<>(env.getTabletInvertedIndex().getTabletMetaTable().values());

Assert.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable1);
Assert.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable2);
Assert.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable3);
Assert.assertEquals(tabletMetaSetBeforeCreateFirstTable, tabletIdSetAfterDuplicateCreateTable4);

// check whether table id is cleared from colocate group after duplicate create table
Set<Long> colocateTableIdAfterCreateFirstTable = env.getColocateTableIndex().getTable2Group().keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class TabletTest {

@Before
public void makeTablet() {
invertedIndex = new TabletInvertedIndex();
invertedIndex = new LocalTabletInvertedIndex();
infoService = new SystemInfoService();
for (long beId = 1L; beId <= 4L; beId++) {
Backend be = new Backend(beId, "127.0.0." + beId, 8030);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.DiskInfo;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.LocalReplica;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.Replica.ReplicaState;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.catalog.TabletMeta;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void setUp() {
systemInfoService.addBackend(be4);

// tablet
invertedIndex = new TabletInvertedIndex();
invertedIndex = new LocalTabletInvertedIndex();

invertedIndex.addTablet(50000, new TabletMeta(1, 2, 3, 4, 5, TStorageMedium.HDD));
invertedIndex.addReplica(50000, new LocalReplica(50001, be1.getId(), 0, ReplicaState.NORMAL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.clone;

import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.Config;
import org.apache.doris.common.ExceptionChecker;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class DecommissionTest {
private long id = 10086;

private final SystemInfoService systemInfoService = new SystemInfoService();
private final TabletInvertedIndex invertedIndex = new TabletInvertedIndex();
private final TabletInvertedIndex invertedIndex = new LocalTabletInvertedIndex();

@BeforeClass
public static void beforeClass() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.HashDistributionInfo;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
Expand Down Expand Up @@ -74,7 +75,7 @@ public class DiskRebalanceTest {
private OlapTable olapTable;

private final SystemInfoService systemInfoService = new SystemInfoService();
private final TabletInvertedIndex invertedIndex = new TabletInvertedIndex();
private final TabletInvertedIndex invertedIndex = new LocalTabletInvertedIndex();
private Map<Tag, LoadStatisticForTag> statisticMap;
private Map<Long, PathSlot> backendsWorkingSlots = Maps.newHashMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.HashDistributionInfo;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
Expand Down Expand Up @@ -85,7 +86,7 @@ public class RebalanceTest {
private OlapTable olapTable;

private final SystemInfoService systemInfoService = new SystemInfoService();
private final TabletInvertedIndex invertedIndex = new TabletInvertedIndex();
private final TabletInvertedIndex invertedIndex = new LocalTabletInvertedIndex();
private Map<Tag, LoadStatisticForTag> statisticMap;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.DiskInfo;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.Replica;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.Config;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class TabletReplicaTooSlowTest {
private long id = 10086;

private final SystemInfoService systemInfoService = new SystemInfoService();
private final TabletInvertedIndex invertedIndex = new TabletInvertedIndex();
private final TabletInvertedIndex invertedIndex = new LocalTabletInvertedIndex();
private Table<String, Tag, LoadStatisticForTag> statisticMap;

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.AnalysisException;
Expand Down Expand Up @@ -120,7 +121,7 @@ public void setUp() throws IOException {
minTimes = 0;
result = systemInfoService;

invertedIndex = new TabletInvertedIndex();
invertedIndex = new LocalTabletInvertedIndex();
Env.getCurrentInvertedIndex();
minTimes = 0;
result = invertedIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.LocalReplica;
import org.apache.doris.catalog.LocalTablet;
import org.apache.doris.catalog.LocalTabletInvertedIndex;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
Expand Down Expand Up @@ -364,7 +365,7 @@ public static void afterClass() {
public void setUp() {
Env env = newDelegateCatalog();
SystemInfoService systemInfoService = new SystemInfoService();
TabletInvertedIndex tabletInvertedIndex = new TabletInvertedIndex();
TabletInvertedIndex tabletInvertedIndex = new LocalTabletInvertedIndex();
new MockUp<Env>() {
@Mock
SchemaChangeHandler getSchemaChangeHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.ReplicaAllocation;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.TabletMeta;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.ConfigBase;
import org.apache.doris.common.ConfigException;
Expand All @@ -54,7 +53,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -89,8 +87,6 @@ public void testDuplicateCreateTable() throws Exception {
+ "properties('replication_num' = '1','colocate_with'='test'); ";
createTable(sql);
Set<Long> tabletIdSetAfterCreateFirstTable = env.getTabletInvertedIndex().getReplicaMetaTable().rowKeySet();
Set<TabletMeta> tabletMetaSetBeforeCreateFirstTable =
new HashSet<>(env.getTabletInvertedIndex().getTabletMetaTable().values());
Set<Long> colocateTableIdBeforeCreateFirstTable = env.getColocateTableIndex().getTable2Group().keySet();
Assertions.assertTrue(colocateTableIdBeforeCreateFirstTable.size() > 0);
Assertions.assertTrue(tabletIdSetAfterCreateFirstTable.size() > 0);
Expand All @@ -102,13 +98,10 @@ public void testDuplicateCreateTable() throws Exception {
Set<Long> tabletIdSetAfterDuplicateCreateTable2 = env.getTabletInvertedIndex().getBackingReplicaMetaTable()
.columnKeySet();
Set<Long> tabletIdSetAfterDuplicateCreateTable3 = env.getTabletInvertedIndex().getTabletMetaMap().keySet();
Set<TabletMeta> tabletIdSetAfterDuplicateCreateTable4 =
new HashSet<>(env.getTabletInvertedIndex().getTabletMetaTable().values());

Assertions.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable1);
Assertions.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable2);
Assertions.assertEquals(tabletIdSetAfterCreateFirstTable, tabletIdSetAfterDuplicateCreateTable3);
Assertions.assertEquals(tabletMetaSetBeforeCreateFirstTable, tabletIdSetAfterDuplicateCreateTable4);

// check whether table id is cleared from colocate group after duplicate create table
Set<Long> colocateTableIdAfterCreateFirstTable = env.getColocateTableIndex().getTable2Group().keySet();
Expand Down
Loading