-
Notifications
You must be signed in to change notification settings - Fork 336
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
SAMZA-2688: [Elasticity] introduce configs and sub-partition concept aka SystemStreamPartitionKeyHash #1531
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* 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.samza.system; | ||
|
||
import org.apache.samza.Partition; | ||
|
||
/** | ||
* Aggregate object representing a portion of {@link SystemStreamPartition} consisting of envelopes within the | ||
* SystemStreamPartition that have envelope.key % job's elasticity factor = keyHash of this object. | ||
*/ | ||
public class SystemStreamPartitionKeyHash extends SystemStreamPartition { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add the changes (i.e., keyhash) within SystemStreamPartition class itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. theoretically this should be possible. But the problem I forsee is with the serde of job model where the backwards compatability of reading an old job model containing old SSP serde might get impacted with the new defn and serde of SSP. Let me test this and get back on this thread. |
||
protected final int keyHash; | ||
|
||
/** | ||
* Constructs a Samza stream partition KeyHash object from specified components. | ||
* @param system The name of the system of which this stream is associated with. | ||
* @param stream The name of the stream as specified in the stream configuration file. | ||
* @param partition The partition in the stream of which this object is associated with. | ||
* @param keyHash The KeyHash of the partition (aka portion of SSP) this object is associated with. | ||
*/ | ||
public SystemStreamPartitionKeyHash(String system, String stream, Partition partition, int keyHash) { | ||
super(system, stream, partition); | ||
this.keyHash = keyHash; | ||
} | ||
/** | ||
* Constructs a Samza stream partition object based upon an existing Samza stream partition and a keyHash. | ||
* @param systemStreamPartition Reference to an already existing Samza stream partition. | ||
* @param keyHash the KeyHash of the systemStreamPartition for this object. | ||
*/ | ||
public SystemStreamPartitionKeyHash(SystemStreamPartition systemStreamPartition, int keyHash) { | ||
super(systemStreamPartition); | ||
this.keyHash = keyHash; | ||
} | ||
|
||
/** | ||
* Constructs a Samza stream partition KeyHash object based upon an existing Samza stream partition keyHash. | ||
* @param other Reference to an already existing Samza stream partition KeyHash. | ||
*/ | ||
public SystemStreamPartitionKeyHash(SystemStreamPartitionKeyHash other) { | ||
this(other.getSystem(), other.getStream(), other.getPartition(), other.keyHash); | ||
} | ||
|
||
/** | ||
* Constructs a Samza stream partition object based upon another Samza stream and a specified partition. | ||
* @param other Reference to an already existing Samza stream. | ||
* @param partition Reference to an already existing Samza partition. | ||
* @param keyHash the KeyHash of the systemStreamPartition for this object. | ||
*/ | ||
public SystemStreamPartitionKeyHash(SystemStream other, Partition partition, int keyHash) { | ||
super(other, partition); | ||
this.keyHash = keyHash; | ||
} | ||
|
||
public int getKeyHash() { | ||
return this.keyHash; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hash; | ||
} | ||
|
||
private int computeHashCode() { | ||
final int prime = 31; | ||
int result = super.hashCode(); | ||
result = prime * result + keyHash; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (!super.equals(obj)) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
SystemStreamPartitionKeyHash other = (SystemStreamPartitionKeyHash) obj; | ||
if (keyHash != other.keyHash) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SystemStreamPartitionKeyHash [" + system + ", " + stream + ", " + partition.getPartitionId() + ", " + keyHash + "]"; | ||
} | ||
|
||
@Override | ||
public int compareTo(SystemStreamPartition that) { | ||
SystemStreamPartitionKeyHash other = (SystemStreamPartitionKeyHash) that; | ||
if (this.system.compareTo(other.system) < 0) { | ||
return -1; | ||
} else if (this.system.compareTo(other.system) > 0) { | ||
return 1; | ||
} | ||
|
||
if (this.stream.compareTo(other.stream) < 0) { | ||
return -1; | ||
} else if (this.stream.compareTo(other.stream) > 0) { | ||
return 1; | ||
} | ||
|
||
if (this.partition.compareTo(other.partition) < 0) { | ||
return -1; | ||
} else if (this.partition.compareTo(other.partition) > 0) { | ||
return 1; | ||
} | ||
|
||
if (this.keyHash < other.keyHash) { | ||
return -1; | ||
} else if (this.keyHash > other.keyHash) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,11 @@ public class TaskConfig extends MapConfig { | |
"task.transactional.state.retain.existing.state"; | ||
private static final boolean DEFAULT_TRANSACTIONAL_STATE_RETAIN_EXISTING_STATE = true; | ||
|
||
// Job Elasticity related configs | ||
// Take effect only when job.elasticity.factor is > 1. otherwise there is no elasticity | ||
private static final String TASK_ELASTICITY_FACTOR = "task.elasticity.factor"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this more like a task-to-partition mapping factor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am looking at this more as a split multiple. As in if the factor = 2 then split each original task into 2 virtual/elastic tasks. It can also be looked at as task-to-partition/ssp factor where factor = 2 means each ssp is read by 2 virtual/elastic tasks. would lend the same semantics. |
||
private static final int TASK_ELASTICITY_FACTOR_DEFAULT = 1; | ||
|
||
public TaskConfig(Config config) { | ||
super(config); | ||
} | ||
|
@@ -379,4 +384,8 @@ public boolean getTransactionalStateRestoreEnabled() { | |
public boolean getTransactionalStateRetainExistingState() { | ||
return getBoolean(TRANSACTIONAL_STATE_RETAIN_EXISTING_STATE, DEFAULT_TRANSACTIONAL_STATE_RETAIN_EXISTING_STATE); | ||
} | ||
|
||
public int getElasticityFactor() { | ||
return getInt(TASK_ELASTICITY_FACTOR, TASK_ELASTICITY_FACTOR_DEFAULT); | ||
} | ||
} |
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 there a benefit to caching and storing it, rather than computing and exposing it via a function?
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 consider this originally but if there are multiple calls to getSystemStreamPartitionKeyHash then it would be worth having this cached.