Skip to content

Commit 49b8358

Browse files
dpavlovagoncharuk
authored andcommitted
IGNITE-6553 Standalone WAL iterator fails to handle WAL delete data records - Fixes apache#2797.
1 parent 474479c commit 49b8358

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/DataEntry.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
2424
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
2525
import org.apache.ignite.internal.util.typedef.internal.S;
26+
import org.jetbrains.annotations.Nullable;
2627

2728
/**
2829
* Represents Data Entry ({@link #key}, {@link #val value}) pair update {@link #op operation} in WAL log.
@@ -32,13 +33,13 @@ public class DataEntry {
3233
@GridToStringInclude
3334
protected int cacheId;
3435

35-
/** Cache object key */
36+
/** Cache object key. */
3637
protected KeyCacheObject key;
3738

38-
/** Cache object value */
39-
protected CacheObject val;
39+
/** Cache object value. May be {@code} null for {@link GridCacheOperation#DELETE} */
40+
@Nullable protected CacheObject val;
4041

41-
/** Entry operation performed */
42+
/** Entry operation performed. */
4243
@GridToStringInclude
4344
protected GridCacheOperation op;
4445

@@ -67,7 +68,7 @@ private DataEntry() {
6768
/**
6869
* @param cacheId Cache ID.
6970
* @param key Key.
70-
* @param val Value.
71+
* @param val Value or null for delete operation.
7172
* @param op Operation.
7273
* @param nearXidVer Near transaction version.
7374
* @param writeVer Write version.
@@ -78,7 +79,7 @@ private DataEntry() {
7879
public DataEntry(
7980
int cacheId,
8081
KeyCacheObject key,
81-
CacheObject val,
82+
@Nullable CacheObject val,
8283
GridCacheOperation op,
8384
GridCacheVersion nearXidVer,
8485
GridCacheVersion writeVer,

modules/core/src/main/java/org/apache/ignite/internal/pagemem/wal/record/UnwrapDataEntry.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ public class UnwrapDataEntry extends DataEntry {
3131
/** Cache object value context. Context is used for unwrapping objects. */
3232
private final CacheObjectValueContext cacheObjValCtx;
3333

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

3737
/**
3838
* @param cacheId Cache ID.
3939
* @param key Key.
40-
* @param val Value.
40+
* @param val Value or null for delete operation.
4141
* @param op Operation.
4242
* @param nearXidVer Near transaction version.
4343
* @param writeVer Write version.
4444
* @param expireTime Expire time.
4545
* @param partId Partition ID.
4646
* @param partCnt Partition counter.
4747
* @param cacheObjValCtx cache object value context for unwrapping objects.
48-
* @param keepBinary disable unwrapping for non primitive objects, Binary Objects would be returned instead
48+
* @param keepBinary disable unwrapping for non primitive objects, Binary Objects would be returned instead.
4949
*/
5050
public UnwrapDataEntry(
5151
final int cacheId,
@@ -66,39 +66,47 @@ public UnwrapDataEntry(
6666

6767
/**
6868
* Unwraps key value from cache key object into primitive boxed type or source class. If client classes were used
69-
* in key, call of this method requires classes to be available in classpath
69+
* in key, call of this method requires classes to be available in classpath.
7070
*
71-
* @return Key which was placed into cache. Or null if failed
71+
* @return Key which was placed into cache. Or null if failed to convert.
7272
*/
7373
public Object unwrappedKey() {
7474
try {
7575
if (keepBinary && key instanceof BinaryObject)
7676
return key;
77+
7778
Object unwrapped = key.value(cacheObjValCtx, false);
79+
7880
if (unwrapped instanceof BinaryObject) {
7981
if (keepBinary)
8082
return unwrapped;
8183
unwrapped = ((BinaryObject)unwrapped).deserialize();
8284
}
85+
8386
return unwrapped;
8487
}
8588
catch (Exception e) {
8689
cacheObjValCtx.kernalContext().log(UnwrapDataEntry.class)
8790
.error("Unable to convert key [" + key + "]", e);
91+
8892
return null;
8993
}
9094
}
9195

9296
/**
9397
* Unwraps value value from cache value object into primitive boxed type or source class. If client classes were
94-
* used in key, call of this method requires classes to be available in classpath
98+
* used in key, call of this method requires classes to be available in classpath.
9599
*
96-
* @return Value which was placed into cache. Or null if failed
100+
* @return Value which was placed into cache. Or null for delete operation or for failure.
97101
*/
98102
public Object unwrappedValue() {
99103
try {
104+
if (val == null)
105+
return null;
106+
100107
if (keepBinary && val instanceof BinaryObject)
101108
return val;
109+
102110
return val.value(cacheObjValCtx, false);
103111
}
104112
catch (Exception e) {

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneWalRecordsIterator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,17 @@ private DataEntry postProcessDataEntry(
335335

336336
if (dataEntry instanceof LazyDataEntry) {
337337
final LazyDataEntry lazyDataEntry = (LazyDataEntry)dataEntry;
338+
338339
key = processor.toKeyCacheObject(fakeCacheObjCtx,
339340
lazyDataEntry.getKeyType(),
340341
lazyDataEntry.getKeyBytes());
341-
val = processor.toCacheObject(fakeCacheObjCtx,
342-
lazyDataEntry.getValType(),
343-
lazyDataEntry.getValBytes());
342+
343+
final byte type = lazyDataEntry.getValType();
344+
345+
val = type == 0 ? null :
346+
processor.toCacheObject(fakeCacheObjCtx,
347+
type,
348+
lazyDataEntry.getValBytes());
344349
}
345350
else {
346351
key = dataEntry.key();

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/wal/reader/IgniteWalReaderTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private void putAllDummyRecords(Ignite ignite, int recordsToWrite) {
356356

357357
cache0.putAll(values);
358358
}
359+
359360
/**
360361
* Puts provided number of records to fill WAL under transactions
361362
*
@@ -912,8 +913,16 @@ private void runRemoveOperationTest(CacheAtomicityMode mode) throws Exception {
912913
deletesFound != null && deletesFound > 0);
913914
}
914915

915-
@NotNull private IgniteWalIteratorFactory createWalIteratorFactory(String subfolderName,
916-
String workDir) throws IgniteCheckedException {
916+
/**
917+
* @param subfolderName Subfolder name.
918+
* @param workDir Work directory.
919+
* @return WAL iterator factory.
920+
* @throws IgniteCheckedException If failed.
921+
*/
922+
@NotNull private IgniteWalIteratorFactory createWalIteratorFactory(
923+
String subfolderName,
924+
String workDir
925+
) throws IgniteCheckedException {
917926
final File binaryMeta = U.resolveWorkDirectory(workDir, "binary_meta", false);
918927
final File binaryMetaWithConsId = new File(binaryMeta, subfolderName);
919928
final File marshallerMapping = U.resolveWorkDirectory(workDir, "marshaller", false);
@@ -924,7 +933,6 @@ private void runRemoveOperationTest(CacheAtomicityMode mode) throws Exception {
924933
marshallerMapping);
925934
}
926935

927-
928936
/**
929937
* @param values collection with numbers
930938
* @return sum of numbers

0 commit comments

Comments
 (0)