TangSiyang2001 commented on code in PR #17704: URL: https://github.com/apache/doris/pull/17704#discussion_r1133365045
########## fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java: ########## @@ -1845,6 +1868,61 @@ public int getAsInt() { } } + private synchronized void enableLightSchemaChange(Database db, OlapTable olapTable) throws DdlException { + //TODO: alter light schema change + // 1. rpc read columnUniqueIds from BE + // 2. refresh table meta data + // 3. write table property + Map<Long, MaterializedIndex> tabletIdToIdx = new HashMap<>(); + olapTable.getAllPartitions() + .stream() + .findFirst() + .orElseThrow(() -> new DdlException(String.format("No partition available for %s.%s", + db.getFullName(), olapTable.getName()))) + .getMaterializedIndices(IndexExtState.ALL) + .forEach(materializedIndex -> { + final long tabletId = materializedIndex.getTablets().get(0).getId(); + tabletIdToIdx.put(tabletId, materializedIndex); + }); + + // TODO: think about can we select the right BE in this way + BeSelectionPolicy policy = new BeSelectionPolicy + .Builder() + .setCluster(db.getClusterName()) + .needLoadAvailable() + .needQueryAvailable() + .build(); + List<Long> beIds = Env.getCurrentSystemInfo().selectBackendIdsByPolicy(policy, 1); + Backend backend = Env.getCurrentSystemInfo().getIdToBackend().get(beIds.get(0)); + final TFetchColIdsResponse response; + try { + final Client client = ClientPool.backendPool.borrowObject( + new TNetworkAddress(backend.getIp(), backend.getBePort())); + response = client.getColumnIdsByTabletIds( + new TFetchColIdsRequest(tabletIdToIdx.keySet())); + } catch (Exception e) { + throw new DdlException("RPC for " + backend.toString() + "failed", e); + } + final List<TFetchColIdsEntry> resultList = response.getResultList(); + + // write meta + resultList.forEach(entry -> { + final long tabletId = entry.getTabletId(); + final List<Integer> colIds = entry.getColIds(); + final MaterializedIndex index = tabletIdToIdx.get(tabletId); + final MaterializedIndexMeta indexMeta = olapTable.getIndexMetaByIndexId(index.getId()); + final List<Column> columns = indexMeta.getSchema(); + // TODO: think about can we ensure the order consistency of columns? Review Comment: Thank you for resolving what I've concerned. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org