-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix WAN events fired after split-brain merges where values don't change [HZ-2620] #24928
Merged
JamesHazelcast
merged 14 commits into
hazelcast:master
from
JamesHazelcast:fix/5.4/hz-2620
Aug 10, 2023
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4579732
Fix WAN events fired after split-brain merges where values don't change
JamesHazelcast 20632fd
Checkstyle fixes
JamesHazelcast 9dcb220
Prevent WAN replication of backups when we don't replicate the primary
JamesHazelcast c75aab4
Checkstyle fixes
JamesHazelcast 5dd9c43
Element count fix in PutAllBackupOperation
JamesHazelcast fbd1801
Checkstyle fix for magic number
JamesHazelcast 339a132
Element count fix in PutAllBackupOperation
JamesHazelcast 1978c43
Improve per-key WAN replication management
JamesHazelcast a5ee2d4
Checkstyle fix
JamesHazelcast 12f0031
Use Version checks in backup operations
JamesHazelcast eccd294
Rework Cache backup value storage to use List like IMap mechanics
JamesHazelcast 264b079
Fix missing parameter in CacheMergeOperation backup creation
JamesHazelcast 0ca5ccb
Extract condition into final variable in MergeOperation
JamesHazelcast d67c8ce
WAN replicate events if expiry metadata changes
JamesHazelcast File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
hazelcast/src/main/java/com/hazelcast/cache/impl/CacheMergeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.hazelcast.cache.impl; | ||
|
||
import com.hazelcast.cache.impl.record.CacheRecord; | ||
import com.hazelcast.spi.merge.SplitBrainMergePolicy; | ||
import com.hazelcast.spi.merge.SplitBrainMergeTypes; | ||
import com.hazelcast.wan.impl.CallerProvenance; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Special response class used to provide verbose results for {@link com.hazelcast.cache.ICache} | ||
* merge operations, specifically from {@link ICacheRecordStore#merge(SplitBrainMergeTypes.CacheMergeTypes, | ||
* SplitBrainMergePolicy, CallerProvenance)} | ||
*/ | ||
public class CacheMergeResponse { | ||
@Nullable | ||
private final CacheRecord record; | ||
@Nonnull | ||
private final MergeResult result; | ||
|
||
public CacheMergeResponse(@Nullable CacheRecord record, @Nonnull MergeResult result) { | ||
this.record = record; | ||
this.result = result; | ||
} | ||
|
||
@Nullable | ||
public CacheRecord getRecord() { | ||
return record; | ||
} | ||
|
||
@Nonnull | ||
public MergeResult getResult() { | ||
return result; | ||
} | ||
|
||
public enum MergeResult { | ||
NO_MERGE_APPLIED(false), | ||
VALUES_ARE_EQUAL(true), | ||
RECORD_CREATED(true), | ||
RECORD_UPDATED(true), | ||
; | ||
|
||
private final boolean mergeApplied; | ||
|
||
MergeResult(boolean mergeApplied) { | ||
this.mergeApplied = mergeApplied; | ||
} | ||
|
||
public boolean isMergeApplied() { | ||
return mergeApplied; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
hazelcast/src/main/java/com/hazelcast/cache/impl/record/WanWrappedCacheRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.hazelcast.cache.impl.record; | ||
|
||
/** | ||
* Simple {@link CacheRecord} wrapper that includes information about whether this record should | ||
* be WAN replicated; namely used for {@link com.hazelcast.cache.impl.operation.CachePutAllBackupOperation} | ||
* as we have scenarios where individual keys have different WAN replication needs | ||
*/ | ||
public class WanWrappedCacheRecord { | ||
private CacheRecord record; | ||
private boolean wanReplicated; | ||
|
||
public WanWrappedCacheRecord(CacheRecord record, boolean wanReplicated) { | ||
this.record = record; | ||
this.wanReplicated = wanReplicated; | ||
} | ||
|
||
public CacheRecord getRecord() { | ||
return record; | ||
} | ||
|
||
public boolean isWanReplicated() { | ||
return wanReplicated; | ||
} | ||
|
||
public void setWanReplicated(boolean wanReplicated) { | ||
this.wanReplicated = wanReplicated; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about declaring
cacheRecords
asMap<Data, ? extends CacheRecord>
?This way we wouldn't impose record-wrapping to all operations (eg loadAll etc) and their serialized form. The disadvantage is there will be an additional complexity (
instanceof
check, conditionally run/serialize theisWanReplicated
logic), so maybe it's not a great trade-off. wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually like to do what I originally thought about doing - converting the Cache backup operations to use a list of pairs, like Map operations do; that way I don't need to have any wrapper at all, and everything can be dealt with in the same manner as Map operations are.
For PoC purposes and as it wasn't difficult to do, I made the changes in this commit: eccd294