Skip to content

Commit

Permalink
[improvement](schema) indexes belong to base index (apache#32527)
Browse files Browse the repository at this point in the history
  • Loading branch information
dataroaring authored Mar 22, 2024
1 parent 8d966fa commit 296696f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Index;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.OlapTable;
Expand Down Expand Up @@ -182,6 +183,7 @@ private void createShadowIndexReplicaForPartition(OlapTable tbl) throws Exceptio
int shadowSchemaVersion = indexSchemaVersionAndHashMap.get(shadowIdxId).schemaVersion;
long originIndexId = indexIdMap.get(shadowIdxId);
KeysType originKeysType = tbl.getKeysTypeByIndexId(originIndexId);
List<Index> tabletIndexes = originIndexId == tbl.getBaseIndexId() ? indexes : null;

Cloud.CreateTabletsRequest.Builder requestBuilder =
Cloud.CreateTabletsRequest.newBuilder();
Expand All @@ -191,7 +193,7 @@ private void createShadowIndexReplicaForPartition(OlapTable tbl) throws Exceptio
.createTabletMetaBuilder(tableId, shadowIdxId,
partitionId, shadowTablet, tbl.getPartitionInfo().getTabletType(partitionId),
shadowSchemaHash, originKeysType, shadowShortKeyColumnCount, bfColumns,
bfFpp, indexes, shadowSchema, tbl.getDataSortInfo(), tbl.getCompressionType(),
bfFpp, tabletIndexes, shadowSchema, tbl.getDataSortInfo(), tbl.getCompressionType(),
tbl.getStoragePolicy(), tbl.isInMemory(), true,
tbl.getName(), tbl.getTTLSeconds(),
tbl.getEnableUniqueKeyMergeOnWrite(), tbl.storeRowColumn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ protected void createShadowIndexReplica() throws AlterCancelException {
int originSchemaHash = tbl.getSchemaHashByIndexId(originIndexId);
KeysType originKeysType = tbl.getKeysTypeByIndexId(originIndexId);

List<Index> tabletIndexes = originIndexId == tbl.getBaseIndexId() ? indexes : null;

for (Tablet shadowTablet : shadowIdx.getTablets()) {
long shadowTabletId = shadowTablet.getId();
List<Replica> shadowReplicas = shadowTablet.getReplicas();
Expand All @@ -259,7 +261,7 @@ protected void createShadowIndexReplica() throws AlterCancelException {
shadowReplicaId, shadowShortKeyColumnCount, shadowSchemaHash,
Partition.PARTITION_INIT_VERSION,
originKeysType, TStorageType.COLUMN, storageMedium,
shadowSchema, bfColumns, bfFpp, countDownLatch, indexes,
shadowSchema, bfColumns, bfFpp, countDownLatch, tabletIndexes,
tbl.isInMemory(),
tbl.getPartitionInfo().getTabletType(partitionId),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.EnvFactory;
import org.apache.doris.catalog.FsBroker;
import org.apache.doris.catalog.Index;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
import org.apache.doris.catalog.MaterializedIndexMeta;
Expand Down Expand Up @@ -1058,6 +1059,8 @@ private void createReplicas(Database db, AgentBatchTask batchTask, OlapTable loc
}
for (MaterializedIndex restoredIdx : restorePart.getMaterializedIndices(IndexExtState.VISIBLE)) {
MaterializedIndexMeta indexMeta = localTbl.getIndexMetaByIndexId(restoredIdx.getId());
List<Index> indexes = restoredIdx.getId() == localTbl.getBaseIndexId()
? localTbl.getCopiedIndexes() : null;
for (Tablet restoreTablet : restoredIdx.getTablets()) {
TabletMeta tabletMeta = new TabletMeta(db.getId(), localTbl.getId(), restorePart.getId(),
restoredIdx.getId(), indexMeta.getSchemaHash(), TStorageMedium.HDD);
Expand All @@ -1071,7 +1074,7 @@ private void createReplicas(Database db, AgentBatchTask batchTask, OlapTable loc
indexMeta.getKeysType(), TStorageType.COLUMN,
TStorageMedium.HDD /* all restored replicas will be saved to HDD */,
indexMeta.getSchema(), bfColumns, bfFpp, null,
localTbl.getCopiedIndexes(),
indexes,
localTbl.isInMemory(),
localTbl.getPartitionInfo().getTabletType(restorePart.getId()),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,17 @@ protected Partition createPartitionWithIndices(long dbId, OlapTable tbl, long pa
List<Column> columns = indexMeta.getSchema();
KeysType keysType = indexMeta.getKeysType();

List<Index> indexes;
if (index.getId() == tbl.getBaseIndexId()) {
indexes = tbl.getIndexes();
} else {
indexes = Lists.newArrayList();
}
Cloud.CreateTabletsRequest.Builder requestBuilder = Cloud.CreateTabletsRequest.newBuilder();
for (Tablet tablet : index.getTablets()) {
OlapFile.TabletMetaCloudPB.Builder builder = createTabletMetaBuilder(tbl.getId(), indexId,
partitionId, tablet, tabletType, schemaHash, keysType, shortKeyColumnCount,
bfColumns, tbl.getBfFpp(), tbl.getIndexes(), columns, tbl.getDataSortInfo(),
bfColumns, tbl.getBfFpp(), indexes, columns, tbl.getDataSortInfo(),
tbl.getCompressionType(), storagePolicy, isInMemory, false, tbl.getName(), tbl.getTTLSeconds(),
tbl.getEnableUniqueKeyMergeOnWrite(), tbl.storeRowColumn(), indexMeta.getSchemaVersion());
requestBuilder.addTabletMetas(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,7 @@ protected Partition createPartitionWithIndices(long dbId, OlapTable tbl, long pa
TStorageType storageType = indexMeta.getStorageType();
List<Column> schema = indexMeta.getSchema();
KeysType keysType = indexMeta.getKeysType();
List<Index> indexes = indexId == tbl.getBaseIndexId() ? tbl.getCopiedIndexes() : null;
int totalTaskNum = index.getTablets().size() * totalReplicaNum;
MarkedCountDownLatch<Long, Long> countDownLatch = new MarkedCountDownLatch<Long, Long>(totalTaskNum);
AgentBatchTask batchTask = new AgentBatchTask();
Expand All @@ -1940,7 +1941,7 @@ protected Partition createPartitionWithIndices(long dbId, OlapTable tbl, long pa
CreateReplicaTask task = new CreateReplicaTask(backendId, dbId, tbl.getId(), partitionId, indexId,
tabletId, replicaId, shortKeyColumnCount, schemaHash, version, keysType, storageType,
realStorageMedium, schema, bfColumns, tbl.getBfFpp(), countDownLatch,
tbl.getCopiedIndexes(), tbl.isInMemory(), tabletType,
indexes, tbl.isInMemory(), tabletType,
tbl.getDataSortInfo(), tbl.getCompressionType(),
tbl.getEnableUniqueKeyMergeOnWrite(), storagePolicy, tbl.disableAutoCompaction(),
tbl.enableSingleReplicaCompaction(), tbl.skipWriteIndexOnLoad(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.doris.catalog.ColocateTableIndex;
import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.Index;
import org.apache.doris.catalog.MaterializedIndex;
import org.apache.doris.catalog.MaterializedIndex.IndexState;
import org.apache.doris.catalog.MaterializedIndexMeta;
Expand Down Expand Up @@ -829,14 +830,16 @@ private static void deleteFromMeta(ListMultimap<Long, Long> tabletDeleteFromMeta
MaterializedIndexMeta indexMeta = olapTable.getIndexMetaByIndexId(indexId);
Set<String> bfColumns = olapTable.getCopiedBfColumns();
double bfFpp = olapTable.getBfFpp();
List<Index> indexes = indexId == olapTable.getBaseIndexId()
? olapTable.getCopiedIndexes() : null;
CreateReplicaTask createReplicaTask = new CreateReplicaTask(backendId, dbId,
tableId, partitionId, indexId, tabletId, replica.getId(),
indexMeta.getShortKeyColumnCount(),
indexMeta.getSchemaHash(), partition.getVisibleVersion(),
indexMeta.getKeysType(),
TStorageType.COLUMN,
TStorageMedium.HDD, indexMeta.getSchema(), bfColumns, bfFpp, null,
olapTable.getCopiedIndexes(),
indexes,
olapTable.isInMemory(),
olapTable.getPartitionInfo().getTabletType(partitionId),
null,
Expand Down

0 comments on commit 296696f

Please sign in to comment.