From 417fae51f79c7fbc9f17943f0df1ee15bc36dc6c Mon Sep 17 00:00:00 2001 From: "Andrey V. Mashenkov" Date: Tue, 25 Dec 2018 18:08:17 +0300 Subject: [PATCH] IGNITE-10558: MVCC: IgniteWalReader fixed. This closes #5583. --- .../pagemem/wal/record/LazyDataEntry.java | 18 ++++---- .../pagemem/wal/record/LazyMvccDataEntry.java | 18 ++++---- .../wal/record/MarshalledDataEntry.java | 45 +++++++++++++++++++ .../pagemem/wal/record/UnwrapDataEntry.java | 20 +++------ .../wal/record/UnwrapMvccDataEntry.java | 20 +++------ .../wal/record/UnwrappedDataEntry.java | 39 ++++++++++++++++ .../reader/StandaloneWalRecordsIterator.java | 10 ++--- .../db/wal/reader/IgniteWalReaderTest.java | 24 +++------- 8 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/MarshalledDataEntry.java create mode 100644 modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrappedDataEntry.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyDataEntry.java index 403d77889e292..ba2fabc9f0eeb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyDataEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyDataEntry.java @@ -31,7 +31,7 @@ * Represents Data Entry ({@link #key}, {@link #val value}) pair update {@link #op operation}.
* This Data entry was not converted to key, value pair during record deserialization. */ -public class LazyDataEntry extends DataEntry { +public class LazyDataEntry extends DataEntry implements MarshalledDataEntry { /** */ private GridCacheSharedContext cctx; @@ -124,23 +124,23 @@ public LazyDataEntry( return val; } - /** @return Data Entry Key type code. See {@link CacheObject} for built-in value type codes */ - public byte getKeyType() { + /** {@inheritDoc} */ + @Override public byte getKeyType() { return keyType; } - /** @return Key value bytes. */ - public byte[] getKeyBytes() { + /** {@inheritDoc} */ + @Override public byte[] getKeyBytes() { return keyBytes; } - /** @return Data Entry Value type code. See {@link CacheObject} for built-in value type codes */ - public byte getValType() { + /** {@inheritDoc} */ + @Override public byte getValType() { return valType; } - /** @return Value value bytes. */ - public byte[] getValBytes() { + /** {@inheritDoc} */ + @Override public byte[] getValBytes() { return valBytes; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyMvccDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyMvccDataEntry.java index 15b146807dc44..a7ad86f4eaf82 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyMvccDataEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/LazyMvccDataEntry.java @@ -32,7 +32,7 @@ * Represents Data Entry ({@link #key}, {@link #val value}) pair update {@link #op operation}.
* This Data entry was not converted to key, value pair during record deserialization. */ -public class LazyMvccDataEntry extends MvccDataEntry { +public class LazyMvccDataEntry extends MvccDataEntry implements MarshalledDataEntry { /** */ private GridCacheSharedContext cctx; @@ -127,23 +127,23 @@ public LazyMvccDataEntry( return val; } - /** @return Data Entry Key type code. See {@link CacheObject} for built-in value type codes */ - public byte getKeyType() { + /** {@inheritDoc} */ + @Override public byte getKeyType() { return keyType; } - /** @return Key value bytes. */ - public byte[] getKeyBytes() { + /** {@inheritDoc} */ + @Override public byte[] getKeyBytes() { return keyBytes; } - /** @return Data Entry Value type code. See {@link CacheObject} for built-in value type codes */ - public byte getValType() { + /** {@inheritDoc} */ + @Override public byte getValType() { return valType; } - /** @return Value value bytes. */ - public byte[] getValBytes() { + /** {@inheritDoc} */ + @Override public byte[] getValBytes() { return valBytes; } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/MarshalledDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/MarshalledDataEntry.java new file mode 100644 index 0000000000000..c977d527941e9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/MarshalledDataEntry.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.ignite.internal.pagemem.wal.record; + +import org.apache.ignite.internal.processors.cache.CacheObject; + +/** + * Interface for Data Entry record that was not converted to key, value pair during record deserialization. + */ +public interface MarshalledDataEntry { + /** + * @return Data Entry Key type code. See {@link CacheObject} for built-in value type codes. + */ + byte getKeyType(); + + /** + * @return Key value bytes. + */ + byte[] getKeyBytes(); + + /** + * @return Data Entry Value type code. See {@link CacheObject} for built-in value type codes. + */ + byte getValType(); + + /** + * @return Value value bytes. + */ + byte[] getValBytes(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapDataEntry.java index dbcc65176b6fa..5dd268b3b8ca8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapDataEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapDataEntry.java @@ -27,7 +27,7 @@ /** * Data Entry for automatic unwrapping key and value from Data Entry */ -public class UnwrapDataEntry extends DataEntry { +public class UnwrapDataEntry extends DataEntry implements UnwrappedDataEntry { /** Cache object value context. Context is used for unwrapping objects. */ private final CacheObjectValueContext cacheObjValCtx; @@ -64,13 +64,8 @@ public UnwrapDataEntry( this.keepBinary = keepBinary; } - /** - * Unwraps key value from cache key object into primitive boxed type or source class. If client classes were used - * in key, call of this method requires classes to be available in classpath. - * - * @return Key which was placed into cache. Or null if failed to convert. - */ - public Object unwrappedKey() { + /** {@inheritDoc} */ + @Override public Object unwrappedKey() { try { if (keepBinary && key instanceof BinaryObject) return key; @@ -93,13 +88,8 @@ public Object unwrappedKey() { } } - /** - * Unwraps value value from cache value object into primitive boxed type or source class. If client classes were - * used in key, call of this method requires classes to be available in classpath. - * - * @return Value which was placed into cache. Or null for delete operation or for failure. - */ - public Object unwrappedValue() { + /** {@inheritDoc} */ + @Override public Object unwrappedValue() { try { if (val == null) return null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapMvccDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapMvccDataEntry.java index 25d7a6e3f947b..c3c12a372e757 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapMvccDataEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapMvccDataEntry.java @@ -28,7 +28,7 @@ /** * Data Entry for automatic unwrapping key and value from Mvcc Data Entry */ -public class UnwrapMvccDataEntry extends MvccDataEntry { +public class UnwrapMvccDataEntry extends MvccDataEntry implements UnwrappedDataEntry { /** Cache object value context. Context is used for unwrapping objects. */ private final CacheObjectValueContext cacheObjValCtx; @@ -68,13 +68,8 @@ public UnwrapMvccDataEntry( this.keepBinary = keepBinary; } - /** - * Unwraps key value from cache key object into primitive boxed type or source class. If client classes were used - * in key, call of this method requires classes to be available in classpath. - * - * @return Key which was placed into cache. Or null if failed to convert. - */ - public Object unwrappedKey() { + /** {@inheritDoc} */ + @Override public Object unwrappedKey() { try { if (keepBinary && key instanceof BinaryObject) return key; @@ -97,13 +92,8 @@ public Object unwrappedKey() { } } - /** - * Unwraps value value from cache value object into primitive boxed type or source class. If client classes were - * used in key, call of this method requires classes to be available in classpath. - * - * @return Value which was placed into cache. Or null for delete operation or for failure. - */ - public Object unwrappedValue() { + /** {@inheritDoc} */ + @Override public Object unwrappedValue() { try { if (val == null) return null; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrappedDataEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrappedDataEntry.java new file mode 100644 index 0000000000000..b3a20b9ca0525 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrappedDataEntry.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.ignite.internal.pagemem.wal.record; + +/** + * Interface for Data Entry for automatic unwrapping key and value from Data Entry + */ +public interface UnwrappedDataEntry { + /** + * Unwraps key value from cache key object into primitive boxed type or source class. If client classes were used in + * key, call of this method requires classes to be available in classpath. + * + * @return Key which was placed into cache. Or null if failed to convert. + */ + Object unwrappedKey(); + + /** + * Unwraps value value from cache value object into primitive boxed type or source class. If client classes were + * used in key, call of this method requires classes to be available in classpath. + * + * @return Value which was placed into cache. Or null for delete operation or for failure. + */ + Object unwrappedValue(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneWalRecordsIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneWalRecordsIterator.java index 238f99ae7781e..d9e86075ac226 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneWalRecordsIterator.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneWalRecordsIterator.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.pagemem.wal.record.DataEntry; import org.apache.ignite.internal.pagemem.wal.record.DataRecord; import org.apache.ignite.internal.pagemem.wal.record.FilteredRecord; -import org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry; +import org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry; import org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry; import org.apache.ignite.internal.pagemem.wal.record.MvccDataRecord; import org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry; @@ -434,15 +434,15 @@ private boolean checkBounds(long idx) { final IgniteCacheObjectProcessor processor, final CacheObjectContext fakeCacheObjCtx, final DataEntry dataEntry) throws IgniteCheckedException { - if(dataEntry instanceof EncryptedDataEntry) + if (dataEntry instanceof EncryptedDataEntry) return dataEntry; final KeyCacheObject key; final CacheObject val; boolean keepBinary = this.keepBinary || !fakeCacheObjCtx.kernalContext().marshallerContext().initialized(); - if (dataEntry instanceof LazyDataEntry) { - final LazyDataEntry lazyDataEntry = (LazyDataEntry)dataEntry; + if (dataEntry instanceof MarshalledDataEntry) { + final MarshalledDataEntry lazyDataEntry = (MarshalledDataEntry)dataEntry; key = processor.toKeyCacheObject(fakeCacheObjCtx, lazyDataEntry.getKeyType(), @@ -472,7 +472,7 @@ private boolean checkBounds(long idx) { * @param keepBinary Don't convert non primitive types. * @return Unwrapped entry. */ - private @NotNull DataEntry unwrapDataEntry(CacheObjectContext coCtx, DataEntry dataEntry, + private DataEntry unwrapDataEntry(CacheObjectContext coCtx, DataEntry dataEntry, KeyCacheObject key, CacheObject val, boolean keepBinary) { if (dataEntry instanceof MvccDataEntry) return new UnwrapMvccDataEntry( diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/reader/IgniteWalReaderTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/reader/IgniteWalReaderTest.java index 0b467d1724f17..3ae92b7e27540 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/reader/IgniteWalReaderTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/reader/IgniteWalReaderTest.java @@ -61,11 +61,10 @@ import org.apache.ignite.internal.pagemem.wal.WALPointer; import org.apache.ignite.internal.pagemem.wal.record.DataEntry; import org.apache.ignite.internal.pagemem.wal.record.DataRecord; -import org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry; -import org.apache.ignite.internal.pagemem.wal.record.LazyMvccDataEntry; +import org.apache.ignite.internal.pagemem.wal.record.MarshalledDataEntry; import org.apache.ignite.internal.pagemem.wal.record.TxRecord; import org.apache.ignite.internal.pagemem.wal.record.UnwrapDataEntry; -import org.apache.ignite.internal.pagemem.wal.record.UnwrapMvccDataEntry; +import org.apache.ignite.internal.pagemem.wal.record.UnwrappedDataEntry; import org.apache.ignite.internal.pagemem.wal.record.WALRecord; import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheOperation; @@ -126,9 +125,6 @@ public class IgniteWalReaderTest extends GridCommonAbstractTest { /** Custom wal mode. */ private WALMode customWalMode; - /** Clear properties in afterTest() method. */ - private boolean clearProps; - /** Set WAL and Archive path to same value. */ private boolean setWalAndArchiveToSameVal; @@ -185,11 +181,6 @@ public class IgniteWalReaderTest extends GridCommonAbstractTest { /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - if (MvccFeatureChecker.forcedMvcc()) - fail("https://issues.apache.org/jira/browse/IGNITE-10558"); - - stopAllGrids(); - cleanPersistenceDir(); } @@ -199,8 +190,7 @@ public class IgniteWalReaderTest extends GridCommonAbstractTest { cleanPersistenceDir(); - if (clearProps) - System.clearProperty(IgniteSystemProperties.IGNITE_WAL_LOG_TX_RECORDS); + System.clearProperty(IgniteSystemProperties.IGNITE_WAL_LOG_TX_RECORDS); } /** @@ -1114,8 +1104,6 @@ public void testPutAllTxIntoTwoNodes() throws Exception { */ @Test public void testTxRecordsReadWoBinaryMeta() throws Exception { - clearProps = true; - System.setProperty(IgniteSystemProperties.IGNITE_WAL_LOG_TX_RECORDS, "true"); Ignite ignite = startGrid("node0"); @@ -1383,12 +1371,12 @@ private Map iterateAndCountDataRecord( Object unwrappedKeyObj; Object unwrappedValObj; - if (entry instanceof UnwrapDataEntry || entry instanceof UnwrapMvccDataEntry) { - UnwrapDataEntry unwrapDataEntry = (UnwrapDataEntry)entry; + if (entry instanceof UnwrappedDataEntry) { + UnwrappedDataEntry unwrapDataEntry = (UnwrappedDataEntry)entry; unwrappedKeyObj = unwrapDataEntry.unwrappedKey(); unwrappedValObj = unwrapDataEntry.unwrappedValue(); } - else if (entry instanceof LazyDataEntry || entry instanceof LazyMvccDataEntry) { + else if (entry instanceof MarshalledDataEntry) { unwrappedKeyObj = null; unwrappedValObj = null; //can't check value