-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-5011. Introduce Java based ReplicationConfig implementation #2089
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
Merged
Changes from all commits
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
82 changes: 82 additions & 0 deletions
82
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/RatisReplicationConfig.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,82 @@ | ||
| /** | ||
| * 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.hdds.client; | ||
|
|
||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Replication configuration for EC replication. | ||
| */ | ||
| public class RatisReplicationConfig | ||
| implements ReplicationConfig { | ||
|
|
||
| private final ReplicationFactor replicationFactor; | ||
|
|
||
| public RatisReplicationConfig(ReplicationFactor replicationFactor) { | ||
| this.replicationFactor = replicationFactor; | ||
| } | ||
|
|
||
| public static boolean hasFactor(ReplicationConfig replicationConfig, | ||
| ReplicationFactor factor) { | ||
| if (replicationConfig instanceof RatisReplicationConfig) { | ||
| return ((RatisReplicationConfig) replicationConfig).getReplicationFactor() | ||
| .equals(factor); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public ReplicationType getReplicationType() { | ||
| return ReplicationType.RATIS; | ||
| } | ||
|
|
||
| @Override | ||
| public int getRequiredNodes() { | ||
| return replicationFactor.getNumber(); | ||
| } | ||
|
|
||
| public ReplicationFactor getReplicationFactor() { | ||
| return replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| RatisReplicationConfig that = (RatisReplicationConfig) o; | ||
| return replicationFactor == that.replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "RATIS/" + replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(replicationFactor); | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.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,98 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hdds.client; | ||
|
|
||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||
|
|
||
| /** | ||
| * Replication configuration for any ReplicationType with all the required | ||
| * parameters.. | ||
| */ | ||
| public interface ReplicationConfig { | ||
|
|
||
| /** | ||
| * Helper method to create proper replication method from old-style | ||
| * factor+type definition. | ||
| * <p> | ||
| * Note: it's never used for EC replication where config is created. | ||
| */ | ||
| static ReplicationConfig fromTypeAndFactor( | ||
| HddsProtos.ReplicationType type, | ||
| HddsProtos.ReplicationFactor factor | ||
| ) { | ||
| switch (type) { | ||
| case RATIS: | ||
| return new RatisReplicationConfig(factor); | ||
| case STAND_ALONE: | ||
| return new StandaloneReplicationConfig(factor); | ||
| default: | ||
| throw new UnsupportedOperationException( | ||
| "Not supported replication: " + type); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to serialize from proto. | ||
| * <p> | ||
| * This uses either the old type/factor or the new ecConfig depends on the | ||
| * type. | ||
| * <p> | ||
| * Note: It will support all the available replication types (including EC). | ||
| * <p> | ||
| * Separated to remain be synced with the EC feature branch, as later it | ||
| * will have different signature. | ||
| */ | ||
| static ReplicationConfig fromProto( | ||
| HddsProtos.ReplicationType type, | ||
| HddsProtos.ReplicationFactor factor) { | ||
| switch (type) { | ||
| case RATIS: | ||
| case STAND_ALONE: | ||
| return fromTypeAndFactor(type, factor); | ||
| default: | ||
| throw new UnsupportedOperationException( | ||
| "Not supported replication: " + type); | ||
| } | ||
| } | ||
|
|
||
| static HddsProtos.ReplicationFactor getLegacyFactor( | ||
| ReplicationConfig replicationConfig) { | ||
| if (replicationConfig instanceof RatisReplicationConfig) { | ||
| return ((RatisReplicationConfig) replicationConfig) | ||
| .getReplicationFactor(); | ||
| } else if (replicationConfig instanceof StandaloneReplicationConfig) { | ||
| return ((StandaloneReplicationConfig) replicationConfig) | ||
| .getReplicationFactor(); | ||
| } | ||
| throw new UnsupportedOperationException( | ||
| "factor is not valid property of replication " + replicationConfig | ||
| .getReplicationType()); | ||
| } | ||
|
|
||
| /** | ||
| * Replication type supported by the replication config. | ||
| */ | ||
| HddsProtos.ReplicationType getReplicationType(); | ||
|
|
||
| /** | ||
| * Number of required nodes for this replication. | ||
| */ | ||
| int getRequiredNodes(); | ||
|
|
||
| } |
72 changes: 72 additions & 0 deletions
72
...-hdds/common/src/main/java/org/apache/hadoop/hdds/client/StandaloneReplicationConfig.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,72 @@ | ||
| /** | ||
| * 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.hdds.client; | ||
|
|
||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Replication configuration for STANDALONE replication. | ||
| */ | ||
| public class StandaloneReplicationConfig implements ReplicationConfig { | ||
|
|
||
| private final ReplicationFactor replicationFactor; | ||
|
|
||
| public StandaloneReplicationConfig(ReplicationFactor replicationFactor) { | ||
| this.replicationFactor = replicationFactor; | ||
| } | ||
|
|
||
| public ReplicationFactor getReplicationFactor() { | ||
| return replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public int getRequiredNodes() { | ||
| return replicationFactor.getNumber(); | ||
| } | ||
|
|
||
| @Override | ||
| public ReplicationType getReplicationType() { | ||
| return ReplicationType.STAND_ALONE; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| StandaloneReplicationConfig that = (StandaloneReplicationConfig) o; | ||
| return replicationFactor == that.replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "STANDALONE/" + replicationFactor; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(replicationFactor); | ||
| } | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
...ds/framework/src/test/java/org/apache/hadoop/hdds/scm/protocol/TestReplicationConfig.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,66 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hdds.scm.protocol; | ||
|
|
||
| import org.apache.hadoop.hdds.client.RatisReplicationConfig; | ||
| import org.apache.hadoop.hdds.client.ReplicationConfig; | ||
| import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; | ||
| import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Test replicationConfig. | ||
| */ | ||
| public class TestReplicationConfig { | ||
|
|
||
| @Test | ||
| public void deserializeRatis() { | ||
| final ReplicationConfig replicationConfig = ReplicationConfig | ||
| .fromTypeAndFactor(ReplicationType.RATIS, ReplicationFactor.THREE); | ||
|
|
||
| Assert | ||
| .assertEquals(RatisReplicationConfig.class, | ||
| replicationConfig.getClass()); | ||
|
|
||
| RatisReplicationConfig ratisReplicationConfig = | ||
| (RatisReplicationConfig) replicationConfig; | ||
| Assert.assertEquals(ReplicationType.RATIS, | ||
| ratisReplicationConfig.getReplicationType()); | ||
| Assert.assertEquals(ReplicationFactor.THREE, | ||
| ratisReplicationConfig.getReplicationFactor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void deserializeStandalone() { | ||
| final ReplicationConfig replicationConfig = ReplicationConfig | ||
| .fromTypeAndFactor(ReplicationType.STAND_ALONE, ReplicationFactor.ONE); | ||
|
|
||
| Assert | ||
| .assertEquals(StandaloneReplicationConfig.class, | ||
| replicationConfig.getClass()); | ||
|
|
||
| StandaloneReplicationConfig standalone = | ||
| (StandaloneReplicationConfig) replicationConfig; | ||
| Assert.assertEquals(ReplicationType.STAND_ALONE, | ||
| standalone.getReplicationType()); | ||
| Assert.assertEquals(ReplicationFactor.ONE, | ||
| standalone.getReplicationFactor()); | ||
| } | ||
| } |
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.
Is Standalone by definition factor 1? Should we drop the replicationFactor parameter and just hardcode Factor.ONE ?
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.
Very good point. I agree that STANDALONE/THREE support should be removed if it's not available.
However, I am not sure about the backward compatibility: let's say I already have a STANDALONE/THREE key persisted in OM rocksdb. If we don't allow THREE for STANDALONE it means that we will change the persisted THREE to ONE during de-serialization.
I am not sure if it's good or not, but can be confusing.
What do you think about this problem?
I don't have a strong opinion. If we remove STANDALONE/THREE support, it seems to be a bigger change (we need to implement proper validation, fix unit tests where STANDALONE/THREE is used, etc. But I am closer to your suggestion, to do this cleanup together with the other changes.
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 am thinking about it, and I think we may have STANDALONE/THREE support. I think we upload the key only to one server but the key may be replicated to multiple nodes by
ReplicationManagerwhen the container is closed...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 did not realise we already had an option for a STANDALONE/THREE. I thought it was always STANDALONE/ONE or RATIS/THREE. If we already have STANDALONE/THREE then I believe you are correct and we need to keep the option to keep the factor.
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 think even have RATIS/ONE is a valid option. But I agree, it's quite confusing.
This is something what we can start to fix together with EC as we need to modify the client to define the replication config based on the replication type. For example in case of
replicationType=ECthe3:2can be a valid replication config, whilereplicationType=STANDALONEwe may accept onlyONEorONE/THREE.I think this kind of validation is definitely something what we should do...
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 agree. Changing options for existing things should be discussed if we really want to do that. Let's just scope this JIRA to ad ReplicationConfig.