Skip to content

Commit

Permalink
IGNITE-21636 MVCC code cleanup and abbreviation fixes (#11259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladsz83 authored Mar 18, 2024
1 parent f324805 commit 4fbe4d4
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import org.apache.ignite.binary.BinaryType;
import org.apache.ignite.cdc.TypeMapping;
import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.Dump;
import org.apache.ignite.lang.IgniteExperimental;

/**
* Consumer of {@link Dump}.
* Consumer of a cache dump.
* This consumer will receive all {@link DumpEntry} stored in cache dump during {@code IgniteDumpReader} application invocation.
* The lifecycle of the consumer is the following:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class DumpReaderConfiguration {
private final boolean keepBinary;

/** Cache group names. */
private String[] cacheGroupNames;
private final String[] cacheGrpNames;

/** Skip copies. */
private final boolean skipCopies;
Expand All @@ -80,7 +80,7 @@ public DumpReaderConfiguration(File dir, DumpConsumer cnsmr) {
* @param timeout Timeout of dump reader invocation.
* @param failFast Stop processing partitions if consumer fail to process one.
* @param keepBinary If {@code true} then don't deserialize {@link KeyCacheObject} and {@link CacheObject}.
* @param cacheGroupNames Cache group names.
* @param cacheGrpNames Cache group names.
* @param skipCopies Skip copies.
* @param encSpi Encryption SPI.
*/
Expand All @@ -91,7 +91,7 @@ public DumpReaderConfiguration(
Duration timeout,
boolean failFast,
boolean keepBinary,
String[] cacheGroupNames,
String[] cacheGrpNames,
boolean skipCopies,
EncryptionSpi encSpi
) {
Expand All @@ -101,7 +101,7 @@ public DumpReaderConfiguration(
this.timeout = timeout;
this.failFast = failFast;
this.keepBinary = keepBinary;
this.cacheGroupNames = cacheGroupNames;
this.cacheGrpNames = cacheGrpNames;
this.skipCopies = skipCopies;
this.encSpi = encSpi;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public boolean keepBinary() {

/** @return Cache group names. */
public String[] cacheGroupNames() {
return cacheGroupNames;
return cacheGrpNames;
}

/** @return Skip copies. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class UnwrapDataEntry extends DataEntry implements UnwrappedDataEntry {
/** Cache object value context. Context is used for unwrapping objects. */
private final CacheObjectValueContext cacheObjValCtx;

/** Keep binary. This flag disables converting of non primitive types (BinaryObjects). */
private boolean keepBinary;
/** Keep binary. This flag disables converting of non-primitive types (BinaryObjects). */
private final boolean keepBinary;

/**
* @param cacheId Cache ID.
Expand Down Expand Up @@ -103,6 +103,7 @@ public static Object unwrapKey(KeyCacheObject key, boolean keepBinary, CacheObje
if (unwrapped instanceof BinaryObject) {
if (keepBinary)
return unwrapped;

unwrapped = ((BinaryObject)unwrapped).deserialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ private static void checkMemoryConfiguration(ClusterNode rmt, GridKernalContext
) {
if (!node.isClient()) {
for (DynamicCacheDescriptor desc : map.values()) {
CacheConfiguration cfg = desc.cacheConfiguration();
CacheConfiguration<?, ?> cfg = desc.cacheConfiguration();

if (cfg.getAffinity() instanceof RendezvousAffinityFunction) {
RendezvousAffinityFunction aff = (RendezvousAffinityFunction)cfg.getAffinity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import static org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext.startAllComponents;

/**
* This class provides ability to work with saved cache dump.
* This class provides the ability to work with saved cache dump.
*/
public class Dump implements AutoCloseable {
/** Snapshot meta. */
Expand Down Expand Up @@ -200,7 +200,7 @@ public List<String> nodesDirectories() {

/** @return List of snapshot metadata saved in {@link #dumpDir}. */
public List<SnapshotMetadata> metadata() throws IOException, IgniteCheckedException {
return metadata;
return Collections.unmodifiableList(metadata);
}

/** @return List of snapshot metadata saved in {@link #dumpDir}. */
Expand Down Expand Up @@ -228,13 +228,13 @@ private static List<SnapshotMetadata> metadata(File dumpDir, @Nullable String co

/**
* @param node Node directory name.
* @param group Group id.
* @param grp Group id.
* @return List of cache configs saved in dump for group.
*/
public List<StoredCacheData> configs(String node, int group) {
public List<StoredCacheData> configs(String node, int grp) {
JdkMarshaller marsh = MarshallerUtils.jdkMarshaller(cctx.igniteInstanceName());

return Arrays.stream(FilePageStoreManager.cacheDataFiles(dumpGroupDirectory(node, group))).map(f -> {
return Arrays.stream(FilePageStoreManager.cacheDataFiles(dumpGroupDirectory(node, grp))).map(f -> {
try {
return readCacheData(f, marsh, cctx.config());
}
Expand All @@ -246,13 +246,13 @@ public List<StoredCacheData> configs(String node, int group) {

/**
* @param node Node directory name.
* @param group Group id.
* @param grp Group id.
* @return Dump iterator.
*/
public List<Integer> partitions(String node, int group) {
public List<Integer> partitions(String node, int grp) {
String suffix = comprParts ? DUMP_FILE_EXT + ZIP_SUFFIX : DUMP_FILE_EXT;

File[] parts = dumpGroupDirectory(node, group)
File[] parts = dumpGroupDirectory(node, grp)
.listFiles(f -> f.getName().startsWith(PART_FILE_PREFIX) && f.getName().endsWith(suffix));

if (parts == null)
Expand All @@ -265,18 +265,18 @@ public List<Integer> partitions(String node, int group) {

/**
* @param node Node directory name.
* @param group Group id.
* @param grp Group id.
* @return Dump iterator.
*/
public DumpedPartitionIterator iterator(String node, int group, int part) {
public DumpedPartitionIterator iterator(String node, int grp, int part) {
FileIOFactory ioFactory = comprParts
? (file, modes) -> new ReadOnlyUnzipFileIO(file)
: (file, modes) -> new ReadOnlyBufferedFileIO(file);

FileIO dumpFile;

try {
dumpFile = ioFactory.create(new File(dumpGroupDirectory(node, group), dumpPartFileName(part, comprParts)));
dumpFile = ioFactory.create(new File(dumpGroupDirectory(node, grp), dumpPartFileName(part, comprParts)));
}
catch (IOException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -333,7 +333,7 @@ private void advance() {
return;

try {
next = serializer.read(dumpFile, group, part);
next = serializer.read(dumpFile, grp, part);
}
catch (IOException | IgniteCheckedException e) {
throw new IgniteException(e);
Expand Down Expand Up @@ -362,7 +362,7 @@ public File dumpDirectory() {
}

/** */
private File dumpGroupDirectory(String node, int groupId) {
private File dumpGroupDirectory(String node, int grpId) {
File nodeDir = Paths.get(dumpDir.getAbsolutePath(), DFLT_STORE_DIR, node).toFile();

assert nodeDir.exists() && nodeDir.isDirectory();
Expand All @@ -377,7 +377,7 @@ private File dumpGroupDirectory(String node, int groupId) {
? f.getName().replaceFirst(CACHE_DIR_PREFIX, "")
: f.getName().replaceFirst(CACHE_GRP_DIR_PREFIX, "");

return groupId == CU.cacheId(grpName);
return grpId == CU.cacheId(grpName);
});

if (grpDirs.length != 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public abstract class PageIO {
public static final short MAX_PAYLOAD_SIZE = 2048;

/** */
private static List<IOVersions<? extends BPlusInnerIO<?>>> h2ExtraInnerIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);
private static final List<IOVersions<? extends BPlusInnerIO<?>>> h2ExtraInnerIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);

/** */
private static List<IOVersions<? extends BPlusLeafIO<?>>> h2ExtraLeafIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);
private static final List<IOVersions<? extends BPlusLeafIO<?>>> h2ExtraLeafIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);

/** */
private static List<IOVersions<? extends BPlusInnerIO<?>>> h2ExtraMvccInnerIOs = new ArrayList<>(MAX_PAYLOAD_SIZE);
Expand Down Expand Up @@ -632,12 +632,8 @@ public static boolean isIndexPage(int pageType) {
)
return true;

if ((T_H2_EX_REF_INNER_START <= pageType && pageType <= T_H2_EX_REF_INNER_END) ||
(T_H2_EX_REF_MVCC_INNER_START <= pageType && pageType <= T_H2_EX_REF_MVCC_INNER_END)
)
return true;

return false;
return (T_H2_EX_REF_INNER_START <= pageType && pageType <= T_H2_EX_REF_INNER_END) ||
(T_H2_EX_REF_MVCC_INNER_START <= pageType && pageType <= T_H2_EX_REF_MVCC_INNER_END);
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -841,7 +837,7 @@ public static <Q extends BPlusIO<?>> Q getBPlusIO(int type, int ver) throws Igni
* @return Index page type.
*/
public static IndexPageType deriveIndexPageType(long pageAddr) {
int pageIoType = PageIO.getType(pageAddr);
int pageIoType = getType(pageAddr);
switch (pageIoType) {
case T_DATA_REF_INNER:
case T_DATA_REF_MVCC_INNER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ void checkDump(IgniteEx ign, String name, boolean expectedComprParts) throws Exc
void checkDump(
IgniteEx ign,
String name,
String[] cacheGroupNames,
String[] cacheGrpNames,
Set<String> expectedFoundCaches,
int expectedDfltDumpSz,
int expectedGrpDumpSz,
int expectedCount,
int expectedCnt,
boolean skipCopies,
boolean expectedComprParts
) throws Exception {
Expand Down Expand Up @@ -417,7 +417,7 @@ else if (!cacheName.equals(DEFAULT_CACHE_NAME))
assertEquals(expectedDfltDumpSz, dfltDumpSz);
assertEquals(expectedGrpDumpSz, grpDumpSz);

IntStream.range(0, expectedCount).forEach(key -> assertTrue(keys.contains(key)));
IntStream.range(0, expectedCnt).forEach(key -> assertTrue(keys.contains(key)));
}
};

Expand All @@ -428,7 +428,7 @@ else if (!cacheName.equals(DEFAULT_CACHE_NAME))
DFLT_THREAD_CNT, DFLT_TIMEOUT,
true,
false,
cacheGroupNames,
cacheGrpNames,
skipCopies,
null
),
Expand Down Expand Up @@ -556,14 +556,14 @@ public static String invokeCheckCommand(IgniteEx ign, String name, String snpPat
}

/** */
void createDump(IgniteEx ign, String name, @Nullable Collection<String> cacheGroupNames) {
createDump(ign, name, cacheGroupNames, false);
void createDump(IgniteEx ign, String name, @Nullable Collection<String> cacheGrpNames) {
createDump(ign, name, cacheGrpNames, false);
}

/** */
void createDump(IgniteEx ign, String name, @Nullable Collection<String> cacheGroupNames, boolean comprParts) {
void createDump(IgniteEx ign, String name, @Nullable Collection<String> cacheGrpNames, boolean comprParts) {
ign.context().cache().context().snapshotMgr()
.createSnapshot(name, null, cacheGroupNames, false, onlyPrimary, true, comprParts, encrypted).get();
.createSnapshot(name, null, cacheGrpNames, false, onlyPrimary, true, comprParts, encrypted).get();
}

/** */
Expand All @@ -588,15 +588,15 @@ public abstract static class TestDumpConsumer implements DumpConsumer {
private boolean typesCb;

/** */
private boolean mappingcCb;
private boolean mappingCb;

/** */
private boolean cacheCfgCb;

/** {@inheritDoc} */
@Override public void start() {
assertFalse(started);
assertFalse(mappingcCb);
assertFalse(mappingCb);
assertFalse(typesCb);
assertFalse(cacheCfgCb);
assertFalse(stopped);
Expand All @@ -607,18 +607,18 @@ public abstract static class TestDumpConsumer implements DumpConsumer {
/** {@inheritDoc} */
@Override public void onMappings(Iterator<TypeMapping> mappings) {
assertTrue(started);
assertFalse(mappingcCb);
assertFalse(mappingCb);
assertFalse(typesCb);
assertFalse(cacheCfgCb);
assertFalse(stopped);

mappingcCb = true;
mappingCb = true;
}

/** {@inheritDoc} */
@Override public void onTypes(Iterator<BinaryType> types) {
assertTrue(started);
assertTrue(mappingcCb);
assertTrue(mappingCb);
assertFalse(typesCb);
assertFalse(cacheCfgCb);
assertFalse(stopped);
Expand All @@ -629,7 +629,7 @@ public abstract static class TestDumpConsumer implements DumpConsumer {
/** {@inheritDoc} */
@Override public void onCacheConfigs(Iterator<StoredCacheData> caches) {
assertTrue(started);
assertTrue(mappingcCb);
assertTrue(mappingCb);
assertTrue(typesCb);
assertFalse(cacheCfgCb);
assertFalse(stopped);
Expand All @@ -641,7 +641,7 @@ public abstract static class TestDumpConsumer implements DumpConsumer {
@Override public void stop() {
assertTrue(started);
assertTrue(typesCb);
assertTrue(mappingcCb);
assertTrue(mappingCb);
assertTrue(cacheCfgCb);
assertFalse(stopped);

Expand All @@ -652,7 +652,7 @@ public abstract static class TestDumpConsumer implements DumpConsumer {
public void check() {
assertTrue(started);
assertTrue(typesCb);
assertTrue(mappingcCb);
assertTrue(mappingCb);
assertTrue(cacheCfgCb);
assertTrue(stopped);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ protected Set<String> getNotRegisteredMbeans(Ignite ignite, String... namesToChe
* @return {@code Set} of metrics methods that have forbidden return types.
* @throws Exception If failed to obtain metrics.
*/
protected Set<String> getInvalidMbeansMethods(Ignite ignite) throws Exception {
protected Set<String> getInvalidMbeansMethods(Ignite ignite) {
Set<String> sysMetricsPackages = new HashSet<>();
sysMetricsPackages.add("sun.management");
sysMetricsPackages.add("javax.management");
Expand All @@ -2571,7 +2571,7 @@ protected Set<String> getInvalidMbeansMethods(Ignite ignite) throws Exception {
if (sysMetricsPackages.stream().anyMatch(clsName::startsWith))
continue;

Class c;
Class<?> c;

try {
c = Class.forName(clsName);
Expand All @@ -2582,7 +2582,7 @@ protected Set<String> getInvalidMbeansMethods(Ignite ignite) throws Exception {
continue;
}

for (Class interf : c.getInterfaces()) {
for (Class<?> interf : c.getInterfaces()) {
for (Method m : interf.getMethods()) {
if (!m.isAnnotationPresent(MXBeanDescription.class))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public class IgniteLoggingSelfTestSuite {
public static void setUpClass() {
JUnitTeamcityReporter.suite = IgniteLoggingSelfTestSuite.class.getName();
}

}
Loading

0 comments on commit 4fbe4d4

Please sign in to comment.