TsukiokaKogane commented on code in PR #63850:
URL: https://github.com/apache/doris/pull/63850#discussion_r3362316379
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStream.java:
##########
Review Comment:
ok
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/TableStreamManager.java:
##########
@@ -97,7 +128,129 @@ public Set<Long> getTableStreamIds(DatabaseIf db) {
return result;
}
- public void fillTableStreamValuesMetadataResult(List<TRow> dataBatch) {
+ public void cleanupStalePartitionOffsets() {
+ List<Long> staleDbIds = new ArrayList<>();
+ List<Pair<Long, Long>> staleStreamIds = new ArrayList<>();
+ List<PruneTableStreamPartitionOffsetInfo.Entry> pruneEntries = new
ArrayList<>();
+ for (Map.Entry<Long, Set<Long>> entry : copyDbStreamMap().entrySet()) {
+ Optional<Database> db =
Env.getCurrentInternalCatalog().getDb(entry.getKey());
+ if (!db.isPresent()) {
+ staleDbIds.add(entry.getKey());
+ continue;
+ }
+ for (Long tableId : entry.getValue()) {
+ Optional<Table> table = db.get().getTable(tableId);
+ if (!table.isPresent()) {
+ staleStreamIds.add(Pair.of(db.get().getId(), tableId));
+ continue;
+ }
+ if (!(table.get() instanceof OlapTableStream)) {
+ staleStreamIds.add(Pair.of(db.get().getId(), tableId));
+ continue;
+ }
+ cleanupStalePartitionOffsets((OlapTableStream)
table.get()).ifPresent(pruneEntries::add);
+ }
+ }
+ removeStaleDbAndStream(staleDbIds, staleStreamIds);
+ if (!pruneEntries.isEmpty()) {
+
Env.getCurrentEnv().getEditLog().logPruneTableStreamPartitionOffsets(
+ new PruneTableStreamPartitionOffsetInfo(pruneEntries));
+ }
+ }
+
+ private Optional<PruneTableStreamPartitionOffsetInfo.Entry>
cleanupStalePartitionOffsets(OlapTableStream stream) {
+ if (stream.isDisabled() || stream.isStale()) {
+ return Optional.empty();
+ }
+ OlapTable baseTable = stream.getBaseTableNullable();
+ if (baseTable == null) {
+ return Optional.empty();
+ }
+ Set<Long> validPartitionIds;
+ if (!baseTable.tryReadLock(Table.TRY_LOCK_TIMEOUT_MS,
TimeUnit.MILLISECONDS)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("skip cleaning stream {} because base table {} read
lock is busy",
+ stream.getName(), baseTable.getName());
+ }
+ return Optional.empty();
+ }
+ try {
+ if (baseTable.isDropped) {
+ return Optional.empty();
+ }
+ validPartitionIds = new HashSet<>(baseTable.getPartitionIds());
+ } finally {
+ baseTable.readUnlock();
+ }
+ if (!stream.tryWriteLockIfExist(Table.TRY_LOCK_TIMEOUT_MS,
TimeUnit.MILLISECONDS)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("skip cleaning stream {} because stream write lock
is busy", stream.getName());
+ }
+ return Optional.empty();
+ }
+ try {
+ if (stream.isDisabled() || stream.isStale()) {
+ return Optional.empty();
+ }
+ Set<Long> stalePartitionIds =
stream.unprotectedCollectStalePartitionOffsetIds(validPartitionIds);
+ if (stalePartitionIds.isEmpty()) {
+ return Optional.empty();
+ }
+ int removedPartitionCount =
stream.unprotectedPrunePartitionOffsets(stalePartitionIds);
+ if (removedPartitionCount > 0) {
Review Comment:
ok
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]