Skip to content

Commit 3b993fd

Browse files
add result reporting to WAL management commands
1 parent 9f73e77 commit 3b993fd

File tree

4 files changed

+203
-19
lines changed

4 files changed

+203
-19
lines changed

modules/core/src/main/java/org/apache/ignite/internal/management/wal/WalDisableCommand.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
package org.apache.ignite.internal.management.wal;
1919

20+
import java.util.List;
21+
import java.util.function.Consumer;
2022
import org.apache.ignite.internal.management.api.ComputeCommand;
2123

2224
/** */
23-
public class WalDisableCommand implements ComputeCommand<WalDisableCommand.WalDisableCommandArg, Void> {
25+
public class WalDisableCommand implements ComputeCommand<WalDisableCommand.WalDisableCommandArg, WalSetStateTaskResult> {
2426
/** {@inheritDoc} */
2527
@Override public Class<WalSetStateTask> taskClass() {
2628
return WalSetStateTask.class;
@@ -41,6 +43,25 @@ public class WalDisableCommand implements ComputeCommand<WalDisableCommand.WalDi
4143
return "Are you sure? Any node failure without WAL can lead to the loss of all PDS data. CDC events will be lost without WAL.";
4244
}
4345

46+
/** {@inheritDoc} */
47+
@Override public void printResult(WalDisableCommandArg arg, WalSetStateTaskResult res, Consumer<String> printer) {
48+
String operation = arg instanceof WalDisableCommandArg ? "disable" : "enable";
49+
List<String> successGrps = res.successGroups();
50+
List<String> errors = res.errorMessages();
51+
52+
if (!successGrps.isEmpty()) {
53+
printer.accept("Successfully " + operation + "d WAL for groups:");
54+
for (String grp : successGrps)
55+
printer.accept(" " + grp);
56+
}
57+
58+
if (errors != null && !errors.isEmpty()) {
59+
printer.accept("Errors occurred:");
60+
for (String error : errors)
61+
printer.accept(" " + error);
62+
}
63+
}
64+
4465
/** */
4566
public static class WalDisableCommandArg extends WalStateCommandArg {
4667
/** */

modules/core/src/main/java/org/apache/ignite/internal/management/wal/WalEnableCommand.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
package org.apache.ignite.internal.management.wal;
1919

20+
import java.util.function.Consumer;
2021
import org.apache.ignite.internal.management.api.ComputeCommand;
2122
import org.apache.ignite.internal.management.wal.WalDisableCommand.WalDisableCommandArg;
2223

2324
/** */
24-
public class WalEnableCommand implements ComputeCommand<WalDisableCommandArg, Void> {
25+
public class WalEnableCommand implements ComputeCommand<WalDisableCommandArg, WalSetStateTaskResult> {
2526
/** {@inheritDoc} */
2627
@Override public Class<WalSetStateTask> taskClass() {
2728
return WalSetStateTask.class;
@@ -37,6 +38,12 @@ public class WalEnableCommand implements ComputeCommand<WalDisableCommandArg, Vo
3738
return WalEnableCommandArg.class;
3839
}
3940

41+
/** {@inheritDoc} */
42+
@Override public void printResult(WalDisableCommandArg arg, WalSetStateTaskResult res, Consumer<String> printer) {
43+
WalDisableCommand cmd = new WalDisableCommand();
44+
cmd.printResult(arg, res, printer);
45+
}
46+
4047
/** */
4148
public static class WalEnableCommandArg extends WalDisableCommandArg {
4249
/** */

modules/core/src/main/java/org/apache/ignite/internal/management/wal/WalSetStateTask.java

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.ignite.internal.management.wal;
1919

20+
import java.util.ArrayList;
2021
import java.util.Arrays;
2122
import java.util.HashSet;
2223
import java.util.List;
@@ -32,22 +33,43 @@
3233
import org.jetbrains.annotations.Nullable;
3334

3435
/** */
35-
public class WalSetStateTask extends VisorMultiNodeTask<WalDisableCommandArg, Void, Void> {
36+
public class WalSetStateTask extends VisorMultiNodeTask<WalDisableCommandArg, WalSetStateTaskResult, WalSetStateTaskResult> {
3637
/** */
3738
private static final long serialVersionUID = 0;
3839

3940
/** {@inheritDoc} */
40-
@Override protected VisorJob<WalDisableCommandArg, Void> job(WalDisableCommandArg arg) {
41-
return new WalDisableJob(arg, false);
41+
@Override protected VisorJob<WalDisableCommandArg, WalSetStateTaskResult> job(WalDisableCommandArg arg) {
42+
return new WalDisableJob(arg, debug);
4243
}
4344

4445
/** {@inheritDoc} */
45-
@Override protected @Nullable Void reduce0(List<ComputeJobResult> res) throws IgniteException {
46-
return null;
46+
@Override protected @Nullable WalSetStateTaskResult reduce0(List<ComputeJobResult> res) throws IgniteException {
47+
Set<String> successGrps = new HashSet<>();
48+
List<String> errors = new ArrayList<>();
49+
50+
for (ComputeJobResult jobRes : res) {
51+
if (jobRes.getException() != null) {
52+
Throwable e = jobRes.getException();
53+
errors.add("Node " + jobRes.getNode().consistentId() +
54+
": Task execution failed - " + e.getMessage());
55+
}
56+
else {
57+
WalSetStateTaskResult result = jobRes.getData();
58+
if (result.successGroups() != null)
59+
successGrps.addAll(result.successGroups());
60+
if (!Boolean.TRUE.equals(result.success()) && result.errorMessages() != null)
61+
errors.addAll(result.errorMessages());
62+
}
63+
}
64+
65+
if (errors.isEmpty())
66+
return new WalSetStateTaskResult(new ArrayList<>(successGrps));
67+
else
68+
return new WalSetStateTaskResult(new ArrayList<>(successGrps), errors);
4769
}
4870

4971
/** */
50-
private static class WalDisableJob extends VisorJob<WalDisableCommandArg, Void> {
72+
private static class WalDisableJob extends VisorJob<WalDisableCommandArg, WalSetStateTaskResult> {
5173
/** */
5274
private static final long serialVersionUID = 0;
5375

@@ -57,22 +79,50 @@ protected WalDisableJob(@Nullable WalDisableCommandArg arg, boolean debug) {
5779
}
5880

5981
/** {@inheritDoc} */
60-
@Override protected Void run(@Nullable WalDisableCommandArg arg) throws IgniteException {
61-
Set<String> grps = F.isEmpty(arg.groups()) ? null : new HashSet<>(Arrays.asList(arg.groups()));
82+
@Override protected WalSetStateTaskResult run(@Nullable WalDisableCommandArg arg) throws IgniteException {
83+
Set<String> requestedGrps = F.isEmpty(arg.groups()) ? null : new HashSet<>(Arrays.asList(arg.groups()));
84+
boolean isEnable = arg instanceof WalEnableCommandArg;
85+
List<String> successGrps = new ArrayList<>();
86+
List<String> errors = new ArrayList<>();
87+
88+
try {
89+
Set<String> availableGrps = new HashSet<>();
6290

63-
for (CacheGroupContext gctx : ignite.context().cache().cacheGroups()) {
64-
String grpName = gctx.cacheOrGroupName();
91+
for (CacheGroupContext gctx : ignite.context().cache().cacheGroups()) {
92+
String grpName = gctx.cacheOrGroupName();
93+
availableGrps.add(grpName);
6594

66-
if (grps != null && !grps.contains(grpName))
67-
continue;
95+
if (requestedGrps != null && !requestedGrps.contains(grpName))
96+
continue;
6897

69-
if (arg instanceof WalEnableCommandArg)
70-
ignite.cluster().enableWal(grpName);
98+
try {
99+
if (isEnable)
100+
ignite.cluster().enableWal(grpName);
101+
else
102+
ignite.cluster().disableWal(grpName);
103+
104+
successGrps.add(grpName);
105+
}
106+
catch (Exception e) {
107+
errors.add("Failed to " + (isEnable ? "enable" : "disable") +
108+
" WAL for cache group: " + grpName + " - " + e.getMessage());
109+
}
110+
}
111+
112+
for (String requestedGrp : requestedGrps) {
113+
if (!availableGrps.contains(requestedGrp))
114+
errors.add("Cache group not found: " + requestedGrp);
115+
}
116+
117+
if (errors.isEmpty())
118+
return new WalSetStateTaskResult(successGrps);
71119
else
72-
ignite.cluster().disableWal(grpName);
120+
return new WalSetStateTaskResult(successGrps, errors);
121+
}
122+
catch (Exception e) {
123+
errors.add("Failed to execute operation - " + e.getMessage());
124+
return new WalSetStateTaskResult(successGrps, errors);
73125
}
74-
75-
return null;
76126
}
77127
}
78128
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.management.wal;
19+
20+
import java.io.IOException;
21+
import java.io.ObjectInput;
22+
import java.io.ObjectOutput;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
26+
import org.apache.ignite.internal.util.typedef.internal.U;
27+
28+
/**
29+
* Result of WAL enable/disable operation.
30+
*/
31+
public class WalSetStateTaskResult extends IgniteDataTransferObject {
32+
/** */
33+
private static final long serialVersionUID = 0L;
34+
35+
/** Success flag. */
36+
private Boolean success;
37+
38+
/** Successfully processed groups. */
39+
private List<String> successGrps;
40+
41+
/** Error messages if operation failed. */
42+
private List<String> errMsgs;
43+
44+
/** Default constructor. */
45+
public WalSetStateTaskResult() {
46+
// No-op.
47+
}
48+
49+
/**
50+
* Constructor for success.
51+
*
52+
* @param successGrps Successfully processed groups.
53+
*/
54+
public WalSetStateTaskResult(List<String> successGrps) {
55+
this.success = true;
56+
this.successGrps = new ArrayList<>(successGrps);
57+
this.errMsgs = null;
58+
}
59+
60+
/**
61+
* Constructor for failure.
62+
*
63+
* @param successGrps Successfully processed groups.
64+
* @param errMsgs Error messages.
65+
*/
66+
public WalSetStateTaskResult(List<String> successGrps, List<String> errMsgs) {
67+
this.success = false;
68+
this.successGrps = new ArrayList<>(successGrps);
69+
this.errMsgs = new ArrayList<>(errMsgs);
70+
}
71+
72+
/** {@inheritDoc} */
73+
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
74+
out.writeObject(success);
75+
U.writeCollection(out, successGrps);
76+
U.writeCollection(out, errMsgs);
77+
}
78+
79+
/** {@inheritDoc} */
80+
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
81+
success = (Boolean)in.readObject();
82+
successGrps = U.readList(in);
83+
errMsgs = U.readList(in);
84+
}
85+
86+
/**
87+
* @return Success flag.
88+
*/
89+
public Boolean success() {
90+
return success;
91+
}
92+
93+
/**
94+
* @return Successfully processed groups.
95+
*/
96+
public List<String> successGroups() {
97+
return successGrps;
98+
}
99+
100+
/**
101+
* @return Error messages if operation failed.
102+
*/
103+
public List<String> errorMessages() {
104+
return errMsgs;
105+
}
106+
}

0 commit comments

Comments
 (0)