-
Notifications
You must be signed in to change notification settings - Fork 615
HDDS-15601. Coalesce contiguous container IDs into range deletes in ContainerHealthSchemaManager #10549
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
Open
umesh9794
wants to merge
2
commits into
apache:master
Choose a base branch
from
umesh9794:HDDS-15582
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+327
−16
Open
HDDS-15601. Coalesce contiguous container IDs into range deletes in ContainerHealthSchemaManager #10549
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
161 changes: 161 additions & 0 deletions
161
...test/java/org/apache/hadoop/ozone/recon/persistence/TestContainerHealthSchemaManager.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 |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * 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.hadoop.ozone.recon.persistence; | ||
|
|
||
| import static org.apache.ozone.recon.schema.generated.tables.UnhealthyContainersTable.UNHEALTHY_CONTAINERS; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager.UnhealthyContainerRecord; | ||
| import org.apache.ozone.recon.schema.ContainerSchemaDefinition; | ||
| import org.apache.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates; | ||
| import org.jooq.DSLContext; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Functional tests for {@link ContainerHealthSchemaManager} delete handling. | ||
| * | ||
| * <p>{@code deleteScmStatesForContainers} coalesces long contiguous container | ||
| * id runs into single range ({@code BETWEEN}) deletes while folding shorter | ||
| * runs and scattered ids into chunked {@code IN} deletes. These tests assert | ||
| * that both paths remove exactly the requested rows for contiguous, scattered, | ||
| * and mixed id distributions, and that non-SCM states are never removed.</p> | ||
| */ | ||
| public class TestContainerHealthSchemaManager extends AbstractReconSqlDBTest { | ||
|
|
||
| private ContainerSchemaDefinition schemaDefinition; | ||
| private ContainerHealthSchemaManager schemaManager; | ||
|
|
||
| @BeforeEach | ||
| public void setUpSchemaManager() { | ||
| schemaDefinition = getSchemaDefinition(ContainerSchemaDefinition.class); | ||
| schemaManager = | ||
| new ContainerHealthSchemaManager(schemaDefinition, new OzoneConfiguration()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeleteContiguousRangeRemovesExactlyRequestedRows() { | ||
| // A run long enough to be removed through the range-delete path. | ||
| int runLength = ContainerHealthSchemaManager.MIN_RANGE_DELETE_RUN + 200; | ||
| insertRange(1, runLength, UnHealthyContainerStates.UNDER_REPLICATED); | ||
| // Survivors that are not part of the delete list. | ||
| insertIds(UnHealthyContainerStates.UNDER_REPLICATED, 5000L, 5002L, 5004L); | ||
|
|
||
| List<Long> idsToDelete = contiguous(1, runLength); | ||
| idsToDelete.add(1L); // duplicate -> must be de-duplicated | ||
| Collections.shuffle(idsToDelete); // unsorted -> must be sorted internally | ||
|
|
||
| schemaManager.batchDeleteSCMStatesForContainers(idsToDelete); | ||
|
|
||
| assertEquals(Arrays.asList(5000L, 5002L, 5004L), remainingContainerIds()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeleteScatteredIdsRemovesExactlyRequestedRows() { | ||
| for (long id = 1; id <= 10; id++) { | ||
| insertIds(UnHealthyContainerStates.MISSING, id); | ||
| } | ||
|
|
||
| // Delete only the odd ids, supplied out of order. | ||
| schemaManager.batchDeleteSCMStatesForContainers( | ||
| new ArrayList<>(Arrays.asList(9L, 1L, 5L, 7L, 3L))); | ||
|
|
||
| assertEquals(Arrays.asList(2L, 4L, 6L, 8L, 10L), remainingContainerIds()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeleteMixedRunAndScatteredRemovesExactlyRequestedRows() { | ||
| int runLength = ContainerHealthSchemaManager.MIN_RANGE_DELETE_RUN + 100; | ||
| insertRange(1, runLength, UnHealthyContainerStates.UNDER_REPLICATED); | ||
| insertIds(UnHealthyContainerStates.UNDER_REPLICATED, 9001L, 9003L, 9005L); | ||
| // Survivor not present in the delete list. | ||
| insertIds(UnHealthyContainerStates.UNDER_REPLICATED, 9004L); | ||
|
|
||
| List<Long> idsToDelete = contiguous(1, runLength); | ||
| idsToDelete.add(9001L); | ||
| idsToDelete.add(9003L); | ||
| idsToDelete.add(9005L); | ||
|
|
||
| schemaManager.batchDeleteSCMStatesForContainers(idsToDelete); | ||
|
|
||
| assertEquals(Collections.singletonList(9004L), remainingContainerIds()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeletePreservesNonScmStateInsideRange() { | ||
| int runLength = ContainerHealthSchemaManager.MIN_RANGE_DELETE_RUN + 100; | ||
| insertRange(1, runLength, UnHealthyContainerStates.UNDER_REPLICATED); | ||
| // ALL_REPLICAS_BAD is not an SCM-generated state, so it must survive even | ||
| // though container 50 falls inside the deleted [1, runLength] range. | ||
| insertIds(UnHealthyContainerStates.ALL_REPLICAS_BAD, 50L); | ||
|
|
||
| schemaManager.batchDeleteSCMStatesForContainers(contiguous(1, runLength)); | ||
|
|
||
| assertEquals(Collections.singletonList(50L), remainingContainerIds()); | ||
| assertEquals(0L, countByState(UnHealthyContainerStates.UNDER_REPLICATED)); | ||
| assertEquals(1L, countByState(UnHealthyContainerStates.ALL_REPLICAS_BAD)); | ||
| } | ||
|
|
||
| private void insertRange(long startInclusive, long endInclusive, | ||
| UnHealthyContainerStates state) { | ||
| List<UnhealthyContainerRecord> records = new ArrayList<>(); | ||
| for (long id = startInclusive; id <= endInclusive; id++) { | ||
| records.add(record(id, state)); | ||
| } | ||
| schemaManager.insertUnhealthyContainerRecords(records); | ||
| } | ||
|
|
||
| private void insertIds(UnHealthyContainerStates state, long... ids) { | ||
| List<UnhealthyContainerRecord> records = new ArrayList<>(); | ||
| for (long id : ids) { | ||
| records.add(record(id, state)); | ||
| } | ||
| schemaManager.insertUnhealthyContainerRecords(records); | ||
| } | ||
|
|
||
| private UnhealthyContainerRecord record(long id, UnHealthyContainerStates state) { | ||
| return new UnhealthyContainerRecord(id, state.toString(), 1L, 3, 2, 1, "test"); | ||
| } | ||
|
|
||
| private List<Long> contiguous(long startInclusive, long endInclusive) { | ||
| List<Long> ids = new ArrayList<>(); | ||
| for (long id = startInclusive; id <= endInclusive; id++) { | ||
| ids.add(id); | ||
| } | ||
| return ids; | ||
| } | ||
|
|
||
| private List<Long> remainingContainerIds() { | ||
| DSLContext dsl = schemaDefinition.getDSLContext(); | ||
| return dsl.selectDistinct(UNHEALTHY_CONTAINERS.CONTAINER_ID) | ||
| .from(UNHEALTHY_CONTAINERS) | ||
| .orderBy(UNHEALTHY_CONTAINERS.CONTAINER_ID.asc()) | ||
| .fetch(UNHEALTHY_CONTAINERS.CONTAINER_ID); | ||
| } | ||
|
|
||
| private long countByState(UnHealthyContainerStates state) { | ||
| DSLContext dsl = schemaDefinition.getDSLContext(); | ||
| return dsl.fetchCount(dsl.selectFrom(UNHEALTHY_CONTAINERS) | ||
| .where(UNHEALTHY_CONTAINERS.CONTAINER_STATE.eq(state.toString()))); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the suggestion to include multiple
BETWEENranges in the same delete statement?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to keep the
DELETEstatements withBETWEENandINclause separate to issue 2DELETEstatements. So in the worst case it falls back to the same IN chunking the code used before this change, so it's never worse than the old baseline of ceil(n / 1000). In best case it will issue just 1 statement for a fully contiguous block.As the comments says above combining both might overflow Derby's per-statement bytecode limit (
Bytecode per method).If you prefer, I can combine it both into one. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
BETWEENinstead ofINfor contiguous range of IDs is a good idea.But I don't think the current change has much effect on production behavior, a range of 1000+ "unhealthy" containers in Recon is not real life scenario. So it adds complexity without benefit.
We should apply this logic for shorter ranges, without executing too many small statements. For that, we need to find the threshold (number of container IDs) over which
BETWEEN n AND n+k ORyields shorter code than the correspondingINclause. Any number of IDs beyond that is a win.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me apply that change here, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adoroszlai I have applied the changes, please take a look. Thanks!