-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Introduce new load manager API #303
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
Changes from all commits
1c46f5b
bbdf123
1f85e00
713ff38
5e343c9
4f97664
b7ec533
81b4725
edf6f4e
925ffca
8ae61c1
9b5358b
653a853
2203768
db12618
0d4e74d
aa2d580
358d1ff
1ea109e
31d60cb
1410008
92028f9
ba9c032
348aba3
bf79da2
1efe869
dbca10a
96c0d86
67b1fe5
9e39cc7
9b2e59c
403ee01
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,67 @@ | ||
| /** | ||
| * Copyright 2016 Yahoo Inc. | ||
| * | ||
| * Licensed 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 com.yahoo.pulsar.broker; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Data class containing three components comprising all the data available for the leader broker about other brokers: - | ||
| * The local broker data which is written to ZooKeeper by each individual broker (LocalBrokerData). - The time average | ||
| * bundle data which is written to ZooKeeper by the leader broker (TimeAverageBrokerData). - The preallocated bundles | ||
| * which are not written to ZooKeeper but are maintained by the leader broker (Map<String, BundleData>). | ||
| */ | ||
| public class BrokerData { | ||
| private LocalBrokerData localData; | ||
|
Contributor
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 think
Contributor
Author
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. While that is true, I think pushing the new fields into
Contributor
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. ok |
||
| private TimeAverageBrokerData timeAverageData; | ||
| private Map<String, BundleData> preallocatedBundleData; | ||
|
|
||
| /** | ||
| * Initialize this BrokerData using the most recent local data. | ||
| * | ||
| * @param localData | ||
| * The data local for the broker. | ||
| */ | ||
| public BrokerData(final LocalBrokerData localData) { | ||
| this.localData = localData; | ||
| timeAverageData = new TimeAverageBrokerData(); | ||
| preallocatedBundleData = new ConcurrentHashMap<>(); | ||
| } | ||
|
|
||
| public LocalBrokerData getLocalData() { | ||
| return localData; | ||
| } | ||
|
|
||
| public void setLocalData(LocalBrokerData localData) { | ||
| this.localData = localData; | ||
| } | ||
|
|
||
| public TimeAverageBrokerData getTimeAverageData() { | ||
| return timeAverageData; | ||
| } | ||
|
|
||
| public void setTimeAverageData(TimeAverageBrokerData timeAverageData) { | ||
| this.timeAverageData = timeAverageData; | ||
| } | ||
|
|
||
| public Map<String, BundleData> getPreallocatedBundleData() { | ||
| return preallocatedBundleData; | ||
| } | ||
|
|
||
| public void setPreallocatedBundleData(Map<String, BundleData> preallocatedBundleData) { | ||
| this.preallocatedBundleData = preallocatedBundleData; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /** | ||
| * Copyright 2016 Yahoo Inc. | ||
| * | ||
| * Licensed 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 com.yahoo.pulsar.broker; | ||
|
|
||
| import com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats; | ||
|
|
||
| /** | ||
| * Data class comprising the short term and long term historical data for this bundle. | ||
| */ | ||
| public class BundleData extends JSONWritable { | ||
| // Short term data for this bundle. The time frame of this data is | ||
| // determined by the number of short term samples | ||
| // and the bundle update period. | ||
| private TimeAverageMessageData shortTermData; | ||
|
|
||
| // Long term data for this bundle. The time frame of this data is determined | ||
| // by the number of long term samples | ||
| // and the bundle update period. | ||
| private TimeAverageMessageData longTermData; | ||
|
Contributor
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. Since BundleData is only maintained in memory by the leader, we will loose that info when leader restarts. Isn't it useful to have bundle specific historic data preserved across restart?
Contributor
Author
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. It is maintained on ZooKeeper also in |
||
|
|
||
| // For JSON only. | ||
| public BundleData() { | ||
| } | ||
|
|
||
| /** | ||
| * Initialize the bundle data. | ||
| * | ||
| * @param numShortSamples | ||
| * Number of short term samples to use. | ||
| * @param numLongSamples | ||
| * Number of long term samples to use. | ||
| */ | ||
| public BundleData(final int numShortSamples, final int numLongSamples) { | ||
| shortTermData = new TimeAverageMessageData(numShortSamples); | ||
| longTermData = new TimeAverageMessageData(numLongSamples); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize this bundle data and have its histories default to the given stats before the first sample is | ||
| * received. | ||
| * | ||
| * @param numShortSamples | ||
| * Number of short term samples to use. | ||
| * @param numLongSamples | ||
| * Number of long term samples to use. | ||
| * @param defaultStats | ||
| * The stats to default to before the first sample is received. | ||
| */ | ||
| public BundleData(final int numShortSamples, final int numLongSamples, final NamespaceBundleStats defaultStats) { | ||
| shortTermData = new TimeAverageMessageData(numShortSamples, defaultStats); | ||
| longTermData = new TimeAverageMessageData(numLongSamples, defaultStats); | ||
| } | ||
|
|
||
| /** | ||
| * Update the historical data for this bundle. | ||
| * | ||
| * @param newSample | ||
| * The bundle stats to update this data with. | ||
| */ | ||
| public void update(final NamespaceBundleStats newSample) { | ||
| shortTermData.update(newSample); | ||
| longTermData.update(newSample); | ||
| } | ||
|
|
||
| public TimeAverageMessageData getShortTermData() { | ||
| return shortTermData; | ||
| } | ||
|
|
||
| public void setShortTermData(TimeAverageMessageData shortTermData) { | ||
| this.shortTermData = shortTermData; | ||
| } | ||
|
|
||
| public TimeAverageMessageData getLongTermData() { | ||
| return longTermData; | ||
| } | ||
|
|
||
| public void setLongTermData(TimeAverageMessageData longTermData) { | ||
| this.longTermData = longTermData; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Copyright 2016 Yahoo Inc. | ||
| * | ||
| * Licensed 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 com.yahoo.pulsar.broker; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.yahoo.pulsar.common.util.ObjectMapperFactory; | ||
|
|
||
| /** | ||
| * Helper class used to conveniently convert a data class to a JSON. | ||
| */ | ||
| public class JSONWritable { | ||
|
|
||
| /** | ||
| * Get the JSON of this object as a byte[]. | ||
| * | ||
| * @return A byte[] of this object's JSON. | ||
| * @throws JsonProcessingException | ||
| */ | ||
| @JsonIgnore | ||
| public byte[] getJsonBytes() throws JsonProcessingException { | ||
| return ObjectMapperFactory.getThreadLocal().writeValueAsBytes(this); | ||
| } | ||
|
|
||
| /** | ||
| * Get the JSON of this object as a String. | ||
| * | ||
| * @return A String of this object's JSON. | ||
| * @throws JsonProcessingException | ||
| */ | ||
| @JsonIgnore | ||
| public String getJsonString() throws JsonProcessingException { | ||
| return ObjectMapperFactory.getThreadLocal().writeValueAsString(this); | ||
| } | ||
| } |
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.
it will require to have copy-right License here.
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 not sure why this diff is not outdated: the copy-right is present if you look at Files Changed.
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, we can see now.