Skip to content

Commit 9f73e77

Browse files
support cache groups in change WAL methods
1 parent dd502d4 commit 9f73e77

File tree

7 files changed

+42
-126
lines changed

7 files changed

+42
-126
lines changed

modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerWalTest.java

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

1818
package org.apache.ignite.util;
1919

20-
import java.util.Arrays;
2120
import java.util.Objects;
2221
import java.util.regex.Pattern;
2322
import org.apache.ignite.cluster.ClusterState;
@@ -192,24 +191,15 @@ public void testWalChangeForMultiCacheGroup() throws Exception {
192191
assertEquals(EXIT_CODE_OK, execute("--wal", "state", "--groups", "testGroup"));
193192
outputContains(".*testGroup.*true.*true.*true.*true.*false");
194193

195-
// disableWal fails, but EXIT_CODE_OK
196194
assertEquals(EXIT_CODE_OK, execute("--wal", "disable", "--groups", "testGroup"));
197195

198-
// WAL is still enabled
199-
assertEquals(EXIT_CODE_OK, execute("--wal", "state", "--groups", "testGroup"));
200-
outputContains(".*testGroup.*true.*true.*true.*true.*false");
201-
202-
srv.cluster().disableWal(Arrays.asList("cache1", "cache2"));
203-
204196
assertEquals(EXIT_CODE_OK, execute("--wal", "state", "--groups", "testGroup"));
205197
outputContains(".*testGroup.*true.*false.*true.*true.*false");
206198

207-
// enableWal fails
208-
assertEquals(EXIT_CODE_OK, execute("--wal", "disable", "--groups", "testGroup"));
199+
assertEquals(EXIT_CODE_OK, execute("--wal", "enable", "--groups", "testGroup"));
209200

210-
// WAL is still disabled
211201
assertEquals(EXIT_CODE_OK, execute("--wal", "state", "--groups", "testGroup"));
212-
outputContains(".*testGroup.*true.*false.*true.*true.*false");
202+
outputContains(".*testGroup.*true.*true.*true.*true.*false");
213203
}
214204

215205
/** */

modules/core/src/main/java/org/apache/ignite/IgniteCluster.java

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -536,38 +536,13 @@ public IgniteFuture<Collection<ClusterStartNodeResult>> startNodesAsync(Collecti
536536
* Cache may be stuck in inconsistent state due to violation of these conditions. It is advised to destroy
537537
* such cache.
538538
*
539-
* @param cacheName Cache name.
539+
* @param cacheOrGrpName Cache or cache group name.
540540
* @return Whether WAL disabled by this call.
541541
* @throws IgniteException If error occurs.
542542
* @see #enableWal(String)
543543
* @see #isWalEnabled(String)
544544
*/
545-
public boolean disableWal(String cacheName) throws IgniteException;
546-
547-
/**
548-
* Disables write-ahead logging for specified caches. When WAL is disabled, changes are not logged to disk.
549-
* This significantly improves cache update speed. The drawback is absence of local crash-recovery guarantees.
550-
* If node is crashed, local content of WAL-disabled cache will be cleared on restart to avoid data corruption.
551-
* <p>
552-
* Internally this method will wait for all current cache operations to finish and prevent new cache operations
553-
* from being executed. Then checkpoint is initiated to flush all data to disk. Control is returned to the callee
554-
* when all dirty pages are prepared for checkpoint, but not necessarily flushed to disk.
555-
* <p>
556-
* WAL state can be changed only for persistent caches.
557-
* <p>
558-
* <b>NOTE:</b>
559-
* Currently, this method should only be called on a stable topology when no nodes are leaving or joining cluster,
560-
* and all baseline nodes are present.
561-
* Cache may be stuck in inconsistent state due to violation of these conditions. It is advised to destroy
562-
* such cache.
563-
*
564-
* @param cacheNames Collection of cache names, all caches must be in the same cache group.
565-
* @return Whether WAL disabled by this call.
566-
* @throws IgniteException If error occurs.
567-
* @see #enableWal(Collection)
568-
* @see #isWalEnabled(String)
569-
*/
570-
public boolean disableWal(Collection<String> cacheNames) throws IgniteException;
545+
public boolean disableWal(String cacheOrGrpName) throws IgniteException;
571546

572547
/**
573548
* Enables write-ahead logging for specified cache. Restoring crash-recovery guarantees of a previous call to
@@ -585,37 +560,13 @@ public IgniteFuture<Collection<ClusterStartNodeResult>> startNodesAsync(Collecti
585560
* Cache may be stuck in inconsistent state due to violation of these conditions. It is advised to destroy
586561
* such cache.
587562
*
588-
* @param cacheName Cache name.
563+
* @param cacheOrGrpName Cache or cache group name.
589564
* @return Whether WAL enabled by this call.
590565
* @throws IgniteException If error occurs.
591566
* @see #disableWal(String)
592567
* @see #isWalEnabled(String)
593568
*/
594-
public boolean enableWal(String cacheName) throws IgniteException;
595-
596-
/**
597-
* Enables write-ahead logging for specified caches. Restoring crash-recovery guarantees of a previous call to
598-
* {@link #disableWal(Collection)}.
599-
* <p>
600-
* Internally this method will wait for all current cache operations to finish and prevent new cache operations
601-
* from being executed. Then checkpoint is initiated to flush all data to disk. Control is returned to the callee
602-
* when all data is persisted to disk.
603-
* <p>
604-
* WAL state can be changed only for persistent caches.
605-
* <p>
606-
* <b>NOTE:</b>
607-
* Currently, this method should only be called on a stable topology when no nodes are leaving or joining cluster,
608-
* and all baseline nodes are present.
609-
* Cache may be stuck in inconsistent state due to violation of these conditions. It is advised to destroy
610-
* such cache.
611-
*
612-
* @param cacheNames Collection of cache names, all caches must be in the same cache group.
613-
* @return Whether WAL state enabled by this call.
614-
* @throws IgniteException If error occurs.
615-
* @see #disableWal(Collection)
616-
* @see #isWalEnabled(String)
617-
*/
618-
public boolean enableWal(Collection<String> cacheNames) throws IgniteException;
569+
public boolean enableWal(String cacheOrGrpName) throws IgniteException;
619570

620571
/**
621572
* Checks if write-ahead logging is enabled for specified cache.

modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,23 +345,13 @@ public IgniteClusterAsyncImpl(IgniteClusterImpl cluster) {
345345
}
346346

347347
/** {@inheritDoc} */
348-
@Override public boolean enableWal(String cacheName) throws IgniteException {
349-
return cluster.enableWal(cacheName);
348+
@Override public boolean enableWal(String cacheOrGrpName) throws IgniteException {
349+
return cluster.enableWal(cacheOrGrpName);
350350
}
351351

352352
/** {@inheritDoc} */
353-
@Override public boolean enableWal(Collection<String> cacheNames) throws IgniteException {
354-
return cluster.enableWal(cacheNames);
355-
}
356-
357-
/** {@inheritDoc} */
358-
@Override public boolean disableWal(String cacheName) throws IgniteException {
359-
return cluster.disableWal(cacheName);
360-
}
361-
362-
/** {@inheritDoc} */
363-
@Override public boolean disableWal(Collection<String> cacheNames) throws IgniteException {
364-
return cluster.disableWal(cacheNames);
353+
@Override public boolean disableWal(String cacheOrGrpName) throws IgniteException {
354+
return cluster.disableWal(cacheOrGrpName);
365355
}
366356

367357
/** {@inheritDoc} */

modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterImpl.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.ignite.internal.GridKernalContext;
5353
import org.apache.ignite.internal.IgniteComponentType;
5454
import org.apache.ignite.internal.IgniteInternalFuture;
55+
import org.apache.ignite.internal.processors.cache.CacheGroupDescriptor;
5556
import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor;
5657
import org.apache.ignite.internal.processors.cluster.BaselineTopology;
5758
import org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus;
@@ -631,40 +632,41 @@ private void setBaselineTopology(long topVer, boolean isBaselineAutoAdjust) {
631632
}
632633

633634
/** {@inheritDoc} */
634-
@Override public boolean enableWal(String cacheName) throws IgniteException {
635-
return changeWalMode(Collections.singleton(cacheName), true);
635+
@Override public boolean enableWal(String cacheOrGrpName) throws IgniteException {
636+
return changeWalMode(cacheOrGrpName, true);
636637
}
637638

638639
/** {@inheritDoc} */
639-
@Override public boolean enableWal(Collection<String> cacheNames) throws IgniteException {
640-
return changeWalMode(cacheNames, true);
641-
}
642-
643-
/** {@inheritDoc} */
644-
@Override public boolean disableWal(String cacheName) throws IgniteException {
645-
return changeWalMode(Collections.singleton(cacheName), false);
646-
}
647-
648-
/** {@inheritDoc} */
649-
@Override public boolean disableWal(Collection<String> cacheNames) throws IgniteException {
650-
return changeWalMode(cacheNames, false);
640+
@Override public boolean disableWal(String cacheOrGrpName) throws IgniteException {
641+
return changeWalMode(cacheOrGrpName, false);
651642
}
652643

653644
/**
654645
* Change WAL mode.
655646
*
656-
* @param cacheNames Cache names.
647+
* @param cacheOrGrpName Cache or cache group name.
657648
* @param enabled Enabled flag.
658649
* @return {@code True} if WAL mode was changed as a result of this call.
659650
*/
660-
private boolean changeWalMode(Collection<String> cacheNames, boolean enabled) {
661-
A.notNull(cacheNames, "cacheNames");
662-
663-
if (cacheNames.isEmpty())
664-
return false;
651+
private boolean changeWalMode(String cacheOrGrpName, boolean enabled) {
652+
A.notNull(cacheOrGrpName, "cacheOrGrpName");
665653

666654
guard();
667655

656+
List<String> cacheNames = new ArrayList<>();
657+
658+
int cacheOrGrpId = CU.cacheId(cacheOrGrpName);
659+
CacheGroupDescriptor grpDesc = ctx.cache().cacheGroupDescriptor(cacheOrGrpId);
660+
661+
if (grpDesc != null) {
662+
for (DynamicCacheDescriptor cacheDesc : ctx.cache().cacheDescriptors().values()) {
663+
if (cacheDesc.groupId() == cacheOrGrpId)
664+
cacheNames.add(cacheDesc.cacheName());
665+
}
666+
}
667+
else
668+
cacheNames.add(cacheOrGrpName);
669+
668670
try {
669671
return ctx.cache().context().walState().changeWalMode(cacheNames, enabled).get();
670672
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.ignite.internal.management.wal.WalDisableCommand.WalDisableCommandArg;
2727
import org.apache.ignite.internal.management.wal.WalEnableCommand.WalEnableCommandArg;
2828
import org.apache.ignite.internal.processors.cache.CacheGroupContext;
29-
import org.apache.ignite.internal.processors.cache.GridCacheContext;
3029
import org.apache.ignite.internal.util.typedef.F;
3130
import org.apache.ignite.internal.visor.VisorJob;
3231
import org.apache.ignite.internal.visor.VisorMultiNodeTask;
@@ -67,15 +66,10 @@ protected WalDisableJob(@Nullable WalDisableCommandArg arg, boolean debug) {
6766
if (grps != null && !grps.contains(grpName))
6867
continue;
6968

70-
GridCacheContext<?, ?> cctx = F.first(gctx.caches());
71-
72-
if (cctx == null)
73-
continue;
74-
7569
if (arg instanceof WalEnableCommandArg)
76-
ignite.cluster().enableWal(cctx.name());
70+
ignite.cluster().enableWal(grpName);
7771
else
78-
ignite.cluster().disableWal(cctx.name());
72+
ignite.cluster().disableWal(grpName);
7973
}
8074

8175
return null;

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/WalModeChangeAdvancedSelfTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
import java.io.File;
2121
import java.util.ArrayList;
22-
import java.util.Arrays;
2322
import java.util.Collection;
24-
import java.util.Collections;
2523
import java.util.concurrent.CountDownLatch;
2624
import java.util.concurrent.ThreadLocalRandom;
2725
import java.util.concurrent.atomic.AtomicBoolean;
@@ -569,7 +567,8 @@ public void testCacheDestroy() throws Exception {
569567
String msg = e.getMessage();
570568

571569
assert msg.startsWith("Cache doesn't exist") ||
572-
msg.startsWith("Failed to change WAL mode because some caches no longer exist") :
570+
msg.startsWith("Failed to change WAL mode because some caches no longer exist") ||
571+
msg.startsWith("Cache names cannot be empty.") :
573572
e.getMessage();
574573
}
575574
finally {
@@ -737,7 +736,7 @@ public void testWalModeChangeRequiresAllGroupCaches() throws Exception {
737736

738737
assertThrows(
739738
() -> {
740-
srv.cluster().disableWal(Collections.singleton(CACHE_NAME_2));
739+
srv.cluster().disableWal(CACHE_NAME_2);
741740
return null;
742741
},
743742
IgniteException.class,
@@ -749,14 +748,14 @@ public void testWalModeChangeRequiresAllGroupCaches() throws Exception {
749748

750749
assertThrows(
751750
() -> {
752-
srv.cluster().enableWal(Collections.singleton(CACHE_NAME));
751+
srv.cluster().enableWal(CACHE_NAME);
753752
return null;
754753
},
755754
IgniteException.class,
756755
"Cannot change WAL mode because not all cache names belonging to the group are provided"
757756
);
758757

759-
srv.cluster().disableWal(Arrays.asList(CACHE_NAME, CACHE_NAME_2));
758+
srv.cluster().disableWal("testGroup");
760759

761760
assertForAllNodes(CACHE_NAME, false);
762761
assertForAllNodes(CACHE_NAME_2, false);
@@ -770,7 +769,7 @@ public void testWalModeChangeRequiresAllGroupCaches() throws Exception {
770769
"Cannot change WAL mode because not all cache names belonging to the group are provided"
771770
);
772771

773-
srv.cluster().enableWal(Arrays.asList(CACHE_NAME, CACHE_NAME_2));
772+
srv.cluster().enableWal("testGroup");
774773

775774
assertForAllNodes(CACHE_NAME, true);
776775
assertForAllNodes(CACHE_NAME_2, true);

modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteClusterProcessProxy.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,12 @@ public IgniteClusterProcessProxy(IgniteProcessProxy proxy) {
168168
}
169169

170170
/** {@inheritDoc} */
171-
@Override public boolean enableWal(String cacheName) throws IgniteException {
171+
@Override public boolean enableWal(String cacheOrGrpName) throws IgniteException {
172172
throw new UnsupportedOperationException("Operation is not supported yet.");
173173
}
174174

175175
/** {@inheritDoc} */
176-
@Override public boolean enableWal(Collection<String> cacheNames) throws IgniteException {
177-
throw new UnsupportedOperationException("Operation is not supported yet.");
178-
}
179-
180-
/** {@inheritDoc} */
181-
@Override public boolean disableWal(String cacheName) throws IgniteException {
182-
throw new UnsupportedOperationException("Operation is not supported yet.");
183-
}
184-
185-
/** {@inheritDoc} */
186-
@Override public boolean disableWal(Collection<String> cacheNames) throws IgniteException {
176+
@Override public boolean disableWal(String cacheOrGrpName) throws IgniteException {
187177
throw new UnsupportedOperationException("Operation is not supported yet.");
188178
}
189179

0 commit comments

Comments
 (0)