Skip to content
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 txn near cache #16617

Merged
merged 2 commits into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,6 +64,16 @@ public Operation newCommitOperation() {
return new CollectionCommitOperation(partitionId, name, serviceName, operationList);
}

@Override
public void onCommitSuccess() {
// NOP
}

@Override
public void onCommitFailure() {
// NOP
}

@Override
public Operation newRollbackOperation() {
long[] itemIds = createItemIdArray();
Expand Down
Expand Up @@ -49,7 +49,7 @@ public ClusterStateTransactionLogRecord() {
}

public ClusterStateTransactionLogRecord(ClusterStateChange stateChange, Address initiator, Address target,
String txnId, long leaseTime, int partitionStateVersion, boolean isTransient) {
String txnId, long leaseTime, int partitionStateVersion, boolean isTransient) {
Preconditions.checkNotNull(stateChange);
Preconditions.checkNotNull(initiator);
Preconditions.checkNotNull(target);
Expand Down Expand Up @@ -85,6 +85,16 @@ public Operation newRollbackOperation() {
return new RollbackClusterStateOp(initiator, txnId);
}

@Override
public void onCommitSuccess() {
// NOP
}

@Override
public void onCommitFailure() {
// NOP
}

@Override
public Address getTarget() {
return target;
Expand Down
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2008-2018, 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.internal.nearcache;


import com.hazelcast.nio.serialization.Data;

/**
* Hook to be used by near cache enabled proxy objects.
*
* With this hook, you can implement needed logic
* for truly invalidate/populate local near cache.
*/
public interface NearCachingHook<K, V> {

NearCachingHook EMPTY_HOOK = new NearCachingHook() {

@Override
public void beforeRemoteCall(Object key, Data keyData,
Object value, Data valueData) {
}

@Override
public void onRemoteCallSuccess() {
}

@Override
public void onRemoteCallFailure() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, no new line as in other methods?

}
};

void beforeRemoteCall(K key, Data keyData, V value, Data valueData);

void onRemoteCallSuccess();

void onRemoteCallFailure();
}
Expand Up @@ -16,6 +16,7 @@

package com.hazelcast.map.impl.tx;

import com.hazelcast.internal.nearcache.NearCachingHook;
import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.map.impl.MapRecordKey;
import com.hazelcast.nio.ObjectDataInput;
Expand All @@ -39,10 +40,15 @@ public class MapTransactionLogRecord implements TransactionLogRecord {
private String ownerUuid;
private Operation op;

private transient NearCachingHook nearCachingHook = NearCachingHook.EMPTY_HOOK;

public MapTransactionLogRecord() {
}

public MapTransactionLogRecord(String name, Data key, int partitionId, Operation op, long version, String ownerUuid) {
public MapTransactionLogRecord(String name, Data key, int partitionId,
Operation op, String ownerUuid, NearCachingHook nearCachingHook) {
assert nearCachingHook != null;

this.name = name;
this.key = key;
if (!(op instanceof MapTxnOperation)) {
Expand All @@ -51,6 +57,7 @@ public MapTransactionLogRecord(String name, Data key, int partitionId, Operation
this.op = op;
this.ownerUuid = ownerUuid;
this.partitionId = partitionId;
this.nearCachingHook = nearCachingHook;
}

@Override
Expand All @@ -69,6 +76,20 @@ public Operation newCommitOperation() {
return op;
}

@Override
public void onCommitSuccess() {
assert nearCachingHook != null;

nearCachingHook.onRemoteCallSuccess();
}

@Override
public void onCommitFailure() {
assert nearCachingHook != null;

nearCachingHook.onRemoteCallFailure();
}

@Override
public Operation newRollbackOperation() {
TxnRollbackOperation operation = new TxnRollbackOperation(partitionId, name, key, ownerUuid);
Expand Down