Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
IoTV2: Fix the issue of resend lots of replicated files when DN restarts.#15600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
99 changes: 94 additions & 5 deletions
99 ...e/extractor/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionExtractor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,6 +21,9 @@ | ||
| import org.apache.iotdb.commons.consensus.DataRegionId; | ||
| import org.apache.iotdb.commons.consensus.index.ProgressIndex; | ||
| import org.apache.iotdb.commons.consensus.index.ProgressIndexType; | ||
| import org.apache.iotdb.commons.consensus.index.impl.HybridProgressIndex; | ||
| import org.apache.iotdb.commons.consensus.index.impl.RecoverProgressIndex; | ||
| import org.apache.iotdb.commons.consensus.index.impl.StateProgressIndex; | ||
| import org.apache.iotdb.commons.consensus.index.impl.TimeWindowStateProgressIndex; | ||
| import org.apache.iotdb.commons.exception.IllegalPathException; | ||
| @@ -34,6 +37,7 @@ | ||
| import org.apache.iotdb.commons.pipe.datastructure.resource.PersistentResource; | ||
| import org.apache.iotdb.commons.utils.PathUtils; | ||
| import org.apache.iotdb.consensus.pipe.PipeConsensus; | ||
| import org.apache.iotdb.db.conf.IoTDBDescriptor; | ||
| import org.apache.iotdb.db.consensus.DataRegionConsensusImpl; | ||
| import org.apache.iotdb.db.pipe.consensus.ReplicateProgressDataNodeManager; | ||
| import org.apache.iotdb.db.pipe.consensus.deletion.DeletionResource; | ||
| @@ -304,7 +308,12 @@ public void customize( | ||
| pipeName = environment.getPipeName(); | ||
| creationTime = environment.getCreationTime(); | ||
| pipeTaskMeta = environment.getPipeTaskMeta(); | ||
| startIndex = environment.getPipeTaskMeta().getProgressIndex(); | ||
| if (pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX)) { | ||
| startIndex = | ||
| tryToExtractLocalProgressIndexForIoTV2(environment.getPipeTaskMeta().getProgressIndex()); | ||
| } else { | ||
| startIndex = environment.getPipeTaskMeta().getProgressIndex(); | ||
| } | ||
| dataRegionId = environment.getRegionId(); | ||
| synchronized (DATA_REGION_ID_TO_PIPE_FLUSHED_TIME_MAP) { | ||
| @@ -426,6 +435,61 @@ private void flushDataRegionAllTsFiles() { | ||
| } | ||
| } | ||
| /** | ||
| * IoTV2 will only resend event that contains un-replicated local write data. So we only extract | ||
| * ProgressIndex containing local writes for comparison to prevent misjudgment on whether | ||
| * high-level tsFiles with mixed progressIndexes need to be retransmitted | ||
| * | ||
| * @return recoverProgressIndex dedicated in local DataNodeId or origin for fallback. | ||
| */ | ||
| private ProgressIndex tryToExtractLocalProgressIndexForIoTV2(ProgressIndex origin) { | ||
| // There are only 2 cases: | ||
| // 1. origin is RecoverProgressIndex | ||
| if (origin instanceof RecoverProgressIndex) { | ||
| RecoverProgressIndex toBeTransformed = (RecoverProgressIndex) origin; | ||
| return extractRecoverProgressIndex(toBeTransformed); | ||
| } | ||
| // 2. origin is HybridProgressIndex | ||
| else if (origin instanceof HybridProgressIndex) { | ||
| HybridProgressIndex toBeTransformed = (HybridProgressIndex) origin; | ||
| // if hybridProgressIndex contains recoverProgressIndex, which is what we expected. | ||
| if (toBeTransformed | ||
| .getType2Index() | ||
| .containsKey(ProgressIndexType.RECOVER_PROGRESS_INDEX.getType())) { | ||
| // 2.1. transform recoverProgressIndex | ||
| RecoverProgressIndex specificToBeTransformed = | ||
| (RecoverProgressIndex) | ||
| toBeTransformed | ||
| .getType2Index() | ||
| .get(ProgressIndexType.RECOVER_PROGRESS_INDEX.getType()); | ||
| return extractRecoverProgressIndex(specificToBeTransformed); | ||
| } | ||
| // if hybridProgressIndex doesn't contain recoverProgressIndex, which is not what we expected, | ||
| // fallback. | ||
| return origin; | ||
| } else { | ||
| // fallback | ||
| LOGGER.warn( | ||
| "Pipe {}@{}: unexpected ProgressIndex type {}, fallback to origin {}.", | ||
| pipeName, | ||
| dataRegionId, | ||
| origin.getType(), | ||
| origin); | ||
| return origin; | ||
| } | ||
| } | ||
| private ProgressIndex extractRecoverProgressIndex(RecoverProgressIndex toBeTransformed) { | ||
| return new RecoverProgressIndex( | ||
| toBeTransformed.getDataNodeId2LocalIndex().entrySet().stream() | ||
| .filter( | ||
| entry -> | ||
| entry | ||
| .getKey() | ||
| .equals(IoTDBDescriptor.getInstance().getConfig().getDataNodeId())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); | ||
| } | ||
| @Override | ||
| public synchronized void start() { | ||
| if (!shouldExtractInsertion) { | ||
| @@ -617,8 +681,19 @@ private boolean mayTsFileContainUnprocessedData(final TsFileResource resource) { | ||
| if (startIndex instanceof StateProgressIndex) { | ||
| startIndex = ((StateProgressIndex) startIndex).getInnerProgressIndex(); | ||
| } | ||
| return !startIndex.isAfter(resource.getMaxProgressIndexAfterClose()) | ||
| && !startIndex.equals(resource.getMaxProgressIndexAfterClose()); | ||
| if (pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX)) { | ||
Pengzna marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // For consensus pipe, we only focus on the progressIndex that is generated from local write | ||
| // instead of replication or something else. | ||
| ProgressIndex dedicatedProgressIndex = | ||
| tryToExtractLocalProgressIndexForIoTV2(resource.getMaxProgressIndexAfterClose()); | ||
| return greaterThanStartIndex(dedicatedProgressIndex); | ||
| } | ||
| return greaterThanStartIndex(resource.getMaxProgressIndexAfterClose()); | ||
| } | ||
| private boolean greaterThanStartIndex(ProgressIndex progressIndex) { | ||
| return !startIndex.isAfter(progressIndex) && !startIndex.equals(progressIndex); | ||
| } | ||
| private boolean mayTsFileResourceOverlappedWithPattern(final TsFileResource resource) { | ||
| @@ -712,12 +787,26 @@ private void extractDeletions( | ||
| // For deletions that are filtered and will not be sent, we should manually decrease its | ||
| // reference count. Because the initial value of referenceCount is `ReplicaNum - 1` | ||
| allDeletionResources.stream() | ||
| .filter(resource -> startIndex.isAfter(resource.getProgressIndex())) | ||
| .filter( | ||
| resource -> { | ||
| ProgressIndex toBeCompared = resource.getProgressIndex(); | ||
| if (pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX)) { | ||
| toBeCompared = tryToExtractLocalProgressIndexForIoTV2(toBeCompared); | ||
| } | ||
| return !greaterThanStartIndex(toBeCompared); | ||
| }) | ||
| .forEach(DeletionResource::decreaseReference); | ||
| // Get deletions that should be sent. | ||
| allDeletionResources = | ||
| allDeletionResources.stream() | ||
| .filter(resource -> !startIndex.isAfter(resource.getProgressIndex())) | ||
| .filter( | ||
| resource -> { | ||
| ProgressIndex toBeCompared = resource.getProgressIndex(); | ||
| if (pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX)) { | ||
| toBeCompared = tryToExtractLocalProgressIndexForIoTV2(toBeCompared); | ||
| } | ||
| return greaterThanStartIndex(toBeCompared); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
| resourceList.addAll(allDeletionResources); | ||
| LOGGER.info( | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.