Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
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();

}
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) {
Copy link
Contributor

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 ?

Copy link
Member Author

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.

Copy link
Member Author

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 ReplicationManager when the container is closed...

Copy link
Contributor

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.

Copy link
Member Author

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=EC the 3:2 can be a valid replication config, while replicationType=STANDALONE we may accept only ONE or ONE/THREE.

I think this kind of validation is definitely something what we should do...

Copy link
Contributor

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.

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);
}
}
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());
}
}