Skip to content
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

[HELIX-599] Support creating/maintaining/routing resources with same names in different instance groups. #31

Merged
merged 1 commit into from
Jul 16, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void process(ClusterEvent event) throws Exception {

for (String resourceName : resourceMap.keySet()) {
Resource resource = resourceMap.get(resourceName);
int bucketSize = resource.getBucketSize();

StateModelDefinition stateModelDef = cache.getStateModelDef(resource.getStateModelDefRef());

Expand Down Expand Up @@ -125,9 +124,8 @@ public void process(ClusterEvent event) throws Exception {
} else {

Message message =
createMessage(manager, resourceName, partition.getPartitionName(), instanceName,
currentState, nextState, sessionIdMap.get(instanceName), stateModelDef.getId(),
resource.getStateModelFactoryname(), bucketSize);
createMessage(manager, resource, partition.getPartitionName(), instanceName,
currentState, nextState, sessionIdMap.get(instanceName), stateModelDef.getId());

IdealState idealState = cache.getIdealState(resourceName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simply pass in the entire resource and createMessage can fetch required attributes from resource

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the method to take resource as argument for my updated pull request.

if (idealState != null
Expand Down Expand Up @@ -188,23 +186,30 @@ public void process(ClusterEvent event) throws Exception {
event.addAttribute(AttributeName.MESSAGES_ALL.toString(), output);
}

private Message createMessage(HelixManager manager, String resourceName, String partitionName,
private Message createMessage(HelixManager manager, Resource resource, String partitionName,
String instanceName, String currentState, String nextState, String sessionId,
String stateModelDefName, String stateModelFactoryName, int bucketSize) {
String stateModelDefName) {
String uuid = UUID.randomUUID().toString();
Message message = new Message(MessageType.STATE_TRANSITION, uuid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has too many parameters, we need to just pass in resource or have a message builder class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed,

message.setSrcName(manager.getInstanceName());
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setPartitionName(partitionName);
message.setResourceName(resourceName);
message.setResourceName(resource.getResourceName());
message.setFromState(currentState);
message.setToState(nextState);
message.setTgtSessionId(sessionId);
message.setSrcSessionId(manager.getSessionId());
message.setStateModelDef(stateModelDefName);
message.setStateModelFactoryName(stateModelFactoryName);
message.setBucketSize(bucketSize);
message.setStateModelFactoryName(resource.getStateModelFactoryname());
message.setBucketSize(resource.getBucketSize());

if (resource.getResourceGroupName() != null) {
message.setResourceGroupName(resource.getResourceGroupName());
}
if (resource.getResourceTag() != null) {
message.setResourceTag(resource.getResourceTag());
}

return message;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void process(ClusterEvent event) throws Exception {
resource.setStateModelFactoryName(idealState.getStateModelFactoryName());
resource.setBucketSize(idealState.getBucketSize());
resource.setBatchMessageMode(idealState.getBatchMessageMode());
resource.setResourceGroupName(idealState.getResourceGroupName());
resource.setResourceTag(idealState.getInstanceGroupTag());
}

for (String partition : partitionSet) {
Expand Down Expand Up @@ -102,6 +104,12 @@ public void process(ClusterEvent event) throws Exception {
resource.setStateModelFactoryName(currentState.getStateModelFactoryName());
resource.setBucketSize(currentState.getBucketSize());
resource.setBatchMessageMode(currentState.getBatchMessageMode());

IdealState idealState = idealStates.get(resourceName);
if (idealState != null) {
resource.setResourceGroupName(idealState.getResourceGroupName());
resource.setResourceTag(idealState.getInstanceGroupTag());
}
}

if (currentState.getStateModelDefRef() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ public void resetPartition(String clusterName, String instanceName, String resou
message.setToState(stateModel.getInitialState());
message.setStateModelFactoryName(idealState.getStateModelFactoryName());

if (idealState.getResourceGroupName() != null) {
message.setResourceGroupName(idealState.getResourceGroupName());
}
if (idealState.getInstanceGroupTag() != null) {
message.setResourceTag(idealState.getInstanceGroupTag());
}

resetMessages.add(message);
messageKeys.add(keyBuilder.message(instanceName, message.getId()));
}
Expand Down
36 changes: 36 additions & 0 deletions helix-core/src/main/java/org/apache/helix/model/ExternalView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
* of current states for the partitions in a resource
*/
public class ExternalView extends HelixProperty {

/**
* Properties that are persisted and are queryable for an external view
*/
public enum ExternalViewProperty {
INSTANCE_GROUP_TAG,
RESOURCE_GROUP_NAME,
GROUP_ROUTING_ENABLED
}

/**
* Instantiate an external view with the resource it corresponds to
* @param resource the name of the resource
Expand Down Expand Up @@ -95,6 +105,32 @@ public String getResourceName() {
return _record.getId();
}

/**
* Get the resource group name
*
* @return the name of the resource group this resource belongs to.
*/
public String getResourceGroupName() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who calls this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoutingTableProvider call this to determine whether it needs to cache all resource group partition/instance information.

return _record.getSimpleField(ExternalViewProperty.RESOURCE_GROUP_NAME.toString());
}

/**
* Check whether the group routing is enabled for this resource.
*
* @return true if the group routing enabled for this resource; false otherwise
*/
public boolean isGroupRoutingEnabled() {
return _record.getBooleanField(ExternalViewProperty.GROUP_ROUTING_ENABLED.name(), false);
}

/**
* Check for a group tag of this resource
* @return the group tag, or null if none is present
*/
public String getInstanceGroupTag() {
return _record.getSimpleField(ExternalViewProperty.INSTANCE_GROUP_TAG.toString());
}

@Override
public boolean isValid() {
return true;
Expand Down
45 changes: 42 additions & 3 deletions helix-core/src/main/java/org/apache/helix/model/IdealState.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public enum IdealStateProperty {
MAX_PARTITIONS_PER_INSTANCE,
INSTANCE_GROUP_TAG,
REBALANCER_CLASS_NAME,
HELIX_ENABLED
HELIX_ENABLED,
RESOURCE_GROUP_NAME,
GROUP_ROUTING_ENABLED
}

public static final String QUERY_LIST = "PREFERENCE_LIST_QUERYS";
Expand Down Expand Up @@ -113,7 +115,7 @@ public String getResourceName() {
}

/**
* Get the rebalance mode of the ideal state
* Set the rebalance mode of the ideal state
* @param mode {@link IdealStateModeProperty}
*/
@Deprecated
Expand All @@ -124,7 +126,7 @@ public void setIdealStateMode(String mode) {
}

/**
* Get the rebalance mode of the resource
* Set the rebalance mode of the resource
* @param rebalancerType
*/
public void setRebalanceMode(RebalanceMode rebalancerType) {
Expand Down Expand Up @@ -159,6 +161,43 @@ public String getRebalancerClassName() {
return _record.getSimpleField(IdealStateProperty.REBALANCER_CLASS_NAME.toString());
}

/**
* Set the resource group name
* @param resourceGroupName
*/
public void setResourceGroupName(String resourceGroupName) {
_record.setSimpleField(IdealStateProperty.RESOURCE_GROUP_NAME.toString(), resourceGroupName);
}

/**
* Get the resource group name
*
* @return
*/
public String getResourceGroupName() {
return _record.getSimpleField(IdealStateProperty.RESOURCE_GROUP_NAME.toString());
}

/**
* Get if the resource group routing feature is enabled or not
* By default, it's disabled
*
* @return true if enabled; false otherwise
*/
public boolean isResourceGroupEnabled() {
return _record.getBooleanField(IdealStateProperty.GROUP_ROUTING_ENABLED.name(), false);
}

/**
* Enable/Disable the aggregated routing on resource group.
*
* @param enabled
*/
public void enableGroupRouting(boolean enabled) {
_record.setSimpleField(IdealStateProperty.GROUP_ROUTING_ENABLED.name(),
Boolean.toString(enabled));
}

/**
* Set the maximum number of partitions of this resource that an instance can serve
* @param max the maximum number of partitions supported
Expand Down
38 changes: 38 additions & 0 deletions helix-core/src/main/java/org/apache/helix/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public enum Attributes {
MSG_STATE,
PARTITION_NAME,
RESOURCE_NAME,
RESOURCE_GROUP_NAME,
RESOURCE_TAG,
FROM_STATE,
TO_STATE,
STATE_MODEL_DEF,
Expand Down Expand Up @@ -396,6 +398,42 @@ public String getResourceName() {
return _record.getSimpleField(Attributes.RESOURCE_NAME.toString());
}

/**
* Set the resource group associated with this message
*
* @param resourceGroupName resource group name to set
*/
public void setResourceGroupName(String resourceGroupName) {
_record.setSimpleField(Attributes.RESOURCE_GROUP_NAME.toString(), resourceGroupName);
}

/**
* Get the resource group name associated with this message
*
* @return resource group name
*/
public String getResourceGroupName() {
return _record.getSimpleField(Attributes.RESOURCE_GROUP_NAME.toString());
}

/**
* Set the resource tag associated with this message
*
* @param resourceTag resource tag to set
*/
public void setResourceTag(String resourceTag) {
_record.setSimpleField(Attributes.RESOURCE_TAG.toString(), resourceTag);
}

/**
* Get the resource tag associated with this message
*
* @return resource tag
*/
public String getResourceTag() {
return _record.getSimpleField(Attributes.RESOURCE_TAG.toString());
}

/**
* Get the resource partition associated with this message
* @return partition name
Expand Down
35 changes: 35 additions & 0 deletions helix-core/src/main/java/org/apache/helix/model/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class Resource {
private String _stateModelFactoryName;
private int _bucketSize = 0;
private boolean _batchMessageMode = false;
private String _resourceGroupName;
private String _resourceTag;

/**
* Instantiate a resource by its name
Expand Down Expand Up @@ -149,6 +151,39 @@ public boolean getBatchMessageMode() {
return _batchMessageMode;
}

/**
* Get the resource tag assigned to this resource
*
* @return the name of the tag
*/
public String getResourceTag() {
return _resourceTag;
}

/**
* Set the resource tag
* @param resourceTag
*/
public void setResourceTag(String resourceTag) {
_resourceTag = resourceTag;
}

/**
* Get resource group name
* @return the resource group name
*/
public String getResourceGroupName() {
return _resourceGroupName;
}

/**
* Set resource group name
* @param resourceGroupName
*/
public void setResourceGroupName(String resourceGroupName) {
_resourceGroupName = resourceGroupName;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down