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

[BUG] Fix em sort error #4915

Merged
merged 2 commits into from
Sep 25, 2023
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
Expand Up @@ -53,10 +53,10 @@ private Comparator<Node> sortByResource() {
RMNode nodeBRm = (RMNode) nodeB;
if (nodeARm.getNodeResource() == null
|| nodeARm.getNodeResource().getLeftResource() == null) {
return -1;
return 1;
} else if (nodeBRm.getNodeResource() == null
|| nodeBRm.getNodeResource().getLeftResource() == null) {
return 1;
return -1;
} else {
if (nodeARm
.getNodeResource()
Expand All @@ -69,7 +69,11 @@ private Comparator<Node> sortByResource() {
.moreThan(nodeBRm.getNodeResource().getLeftResource())) {
return -1;
} else {
return 1;
// 从大到小排序 (Sort from large to small)
return -(nodeARm
.getNodeResource()
.getLeftResource()
.compare(nodeBRm.getNodeResource().getLeftResource()));
}
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource r) {
CPUResource cpuResource = toCPUResource(r);
return Integer.compare(this.getCores(), cpuResource.getCores());
}

@Override
public String toJson() {
return String.format(" \"cpu\":%s ", cores);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,42 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource resource) {
DriverAndKubernetesResource r = new DriverAndKubernetesResource(resource);
if (isModuleOperate(r)) {
return loadInstanceResource.compare(r.loadInstanceResource);
} else {
if (loadInstanceResource.getMemory() > r.loadInstanceResource.getMemory()) {
return 1;
} else if (loadInstanceResource.getMemory() < r.loadInstanceResource.getMemory()) {
return -1;
} else {
// If memory is equal, compare cores
if (loadInstanceResource.getCores() > r.loadInstanceResource.getCores()) {
return 1;
} else if (loadInstanceResource.getCores() < r.loadInstanceResource.getCores()) {
return -1;
} else {
// If cores are equal, compare instances
if (loadInstanceResource.getInstances() > r.loadInstanceResource.getInstances()) {
return 1;
} else if (loadInstanceResource.getInstances() < r.loadInstanceResource.getInstances()) {
return -1;
} else {
if (kubernetesResource.getMemory() > r.kubernetesResource.getMemory()) {
return 1;
} else if (kubernetesResource.getMemory() < r.kubernetesResource.getMemory()) {
return -1;
} else {
return Long.compare(kubernetesResource.getCores(), r.kubernetesResource.getCores());
}
}
}
}
}
}

public String toJson() {
String load = "null";
String kubernetes = "null";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,43 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource resource) {
DriverAndYarnResource r = new DriverAndYarnResource(resource);

if (isModuleOperate(r)) {
return loadInstanceResource.compare(r.loadInstanceResource);
} else {
if (loadInstanceResource.getMemory() > r.loadInstanceResource.getMemory()) {
return 1;
} else if (loadInstanceResource.getMemory() < r.loadInstanceResource.getMemory()) {
return -1;
} else {
// If memory is equal, compare cores
if (loadInstanceResource.getCores() > r.loadInstanceResource.getCores()) {
return 1;
} else if (loadInstanceResource.getCores() < r.loadInstanceResource.getCores()) {
return -1;
} else {
// If cores are equal, compare instances
if (loadInstanceResource.getInstances() > r.loadInstanceResource.getInstances()) {
return 1;
} else if (loadInstanceResource.getInstances() < r.loadInstanceResource.getInstances()) {
return -1;
} else {
if (yarnResource.getQueueMemory() > r.yarnResource.getQueueMemory()) {
return 1;
} else if (yarnResource.getQueueMemory() < r.yarnResource.getQueueMemory()) {
return -1;
} else {
return Integer.compare(yarnResource.getQueueCores(), r.yarnResource.getQueueCores());
}
}
}
}
}
}

public String toJson() {
String load = "null";
String yarn = "null";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource r) {
KubernetesResource temp = new KubernetesResource(r);
if (this.getMemory() > temp.getMemory()) {
return 1;
} else if (this.getMemory() < temp.getMemory()) {
return -1;
} else {
// If memory is equal, compare cores
return Long.compare(this.getCores(), temp.getCores());
}
}

@Override
public String toJson() {
return String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource r) {
LoadInstanceResource temp = new LoadInstanceResource(r);

if (this.getMemory() > temp.getMemory()) {
return 1;
} else if (this.getMemory() < temp.getMemory()) {
return -1;
} else {
// If memory is equal, compare cores
if (this.getCores() > temp.getCores()) {
return 1;
} else if (this.getCores() < temp.getCores()) {
return -1;
} else {
// If cores are equal, compare instances
return Integer.compare(this.getInstances(), temp.getInstances());
}
}
}

@Override
public String toJson() {
return String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource r) {
LoadResource temp = new LoadResource(r);

if (this.getMemory() > temp.getMemory()) {
return 1;
} else if (this.getMemory() < temp.getMemory()) {
return -1;
} else {
// If memory is equal, compare cores
return Integer.compare(this.getCores(), temp.getCores());
}
}

@Override
public String toJson() {
return String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource resource) {
MemoryResource r = toMemoryResource(resource);
return Long.compare(this.getMemory(), r.getMemory());
}

@Override
public boolean caseMore(Resource r) {
return moreThan(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public static Resource getZeroResource(Resource resource) {

public abstract boolean less(Resource r);

public abstract int compare(Resource r);

public Resource add(Resource r, float rate) {
return this.add(r.multiplied(rate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource r) {
if (this.moreThan(r)) {
return 1;
} else if (this.less(r)) {
return -1;
} else {
return 0;
}
}

@Override
public String toJson() {
return String.format("Special:%s", resources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ public boolean less(Resource r) {
return !notLess(r);
}

@Override
public int compare(Resource resource) {
YarnResource r = toYarnResource(resource);
if (this.getQueueMemory() > r.getQueueMemory()) {
return 1;
} else if (this.getQueueMemory() < r.getQueueMemory()) {
return -1;
} else {
return Integer.compare(this.getQueueCores(), r.getQueueCores());
}
}

@Override
public String toJson() {
return String.format(
Expand Down