-
Notifications
You must be signed in to change notification settings - Fork 103
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
IGNITE-22620 Implement ReplicaSafeTimeSyncRequest processing for zone replica #5258
Draft
JAkutenshi
wants to merge
1
commit into
apache:main
Choose a base branch
from
gridgain:ignite-22620
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
|
@@ -58,11 +58,15 @@ | |
import org.apache.ignite.internal.cluster.management.configuration.NodeAttributesConfiguration; | ||
import org.apache.ignite.internal.configuration.testframework.InjectConfiguration; | ||
import org.apache.ignite.internal.distributionzones.DistributionZonesTestUtil; | ||
import org.apache.ignite.internal.hlc.HybridTimestamp; | ||
import org.apache.ignite.internal.metastorage.MetaStorageManager; | ||
import org.apache.ignite.internal.metastorage.dsl.Operation; | ||
import org.apache.ignite.internal.partition.replicator.fixtures.Node; | ||
import org.apache.ignite.internal.partitiondistribution.Assignment; | ||
import org.apache.ignite.internal.partitiondistribution.Assignments; | ||
import org.apache.ignite.internal.partitiondistribution.PartitionDistributionUtils; | ||
import org.apache.ignite.internal.partitiondistribution.TokenizedAssignments; | ||
import org.apache.ignite.internal.partitiondistribution.TokenizedAssignmentsImpl; | ||
import org.apache.ignite.internal.replicator.Replica; | ||
import org.apache.ignite.internal.replicator.ZonePartitionId; | ||
import org.apache.ignite.internal.schema.BinaryRow; | ||
|
@@ -656,6 +660,41 @@ public void testScanCloseReplicaRequest() throws Exception { | |
assertDoesNotThrow(tx::commit); | ||
} | ||
|
||
@Test | ||
public void testReplicaSafeTimeSyncRequest() throws Exception { | ||
// Prepare a single node cluster. | ||
startCluster(2); | ||
Node node0 = getNode(0); | ||
List<Set<Assignment>> assignments = PartitionDistributionUtils.calculateAssignments( | ||
cluster.stream().map(n -> n.name).collect(toList()), 1, 1); | ||
|
||
List<TokenizedAssignments> tokenizedAssignments = assignments.stream() | ||
.map(a -> new TokenizedAssignmentsImpl(a, Integer.MIN_VALUE)) | ||
.collect(toList()); | ||
|
||
placementDriver.setPrimary(node0.clusterService.topologyService().localMember()); | ||
placementDriver.setAssignments(tokenizedAssignments); | ||
|
||
// Prepare a zone. | ||
String zoneName = "test_zone"; | ||
createZone(node0, zoneName, 1, 2); | ||
int zoneId = DistributionZonesTestUtil.getZoneId(node0.catalogManager, zoneName, node0.hybridClock.nowLong()); | ||
int partId = 0; | ||
|
||
// Create a table to work with. | ||
createTable(node0, zoneName, "test_table"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please adjust the test in a following way.
|
||
|
||
HybridTimestamp node0safeTimeBefore = node0.currentSafeTimeForZonePartition(zoneId, partId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currentSafeTimeForZonePartition may fail with
fast enough. |
||
Node node1 = getNode(1); | ||
HybridTimestamp node1safeTimeBefore = node1.currentSafeTimeForZonePartition(zoneId, partId); | ||
|
||
waitForCondition( | ||
() -> node0safeTimeBefore.compareTo(node0.currentSafeTimeForZonePartition(zoneId, partId)) < 0 | ||
&& node1safeTimeBefore.compareTo(node1.currentSafeTimeForZonePartition(zoneId, partId)) < 0, | ||
idleSafeTimePropagationDuration() * 2 | ||
); | ||
} | ||
|
||
private static RemotelyTriggeredResource getVersionedStorageCursor(Node node, FullyQualifiedResourceId cursorId) { | ||
return node.resourcesRegistry.resources().get(cursorId); | ||
} | ||
|
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
64 changes: 64 additions & 0 deletions
64
...ache/ignite/internal/partition/replicator/handlers/ReplicaSafeTimeSyncRequestHandler.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,64 @@ | ||
/* | ||
* 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.partition.replicator.handlers; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import org.apache.ignite.internal.hlc.ClockService; | ||
import org.apache.ignite.internal.partition.replicator.ReplicationRaftCommandApplicator; | ||
import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory; | ||
import org.apache.ignite.internal.replicator.message.ReplicaSafeTimeSyncRequest; | ||
|
||
/** | ||
* Handler for {@link ReplicaSafeTimeSyncRequest}. | ||
*/ | ||
public class ReplicaSafeTimeSyncRequestHandler { | ||
/** Factory for creating replica command messages. */ | ||
private static final ReplicaMessagesFactory REPLICA_MESSAGES_FACTORY = new ReplicaMessagesFactory(); | ||
|
||
/** Applicator that applies RAFT command that is created by this handler. */ | ||
private final ReplicationRaftCommandApplicator commandApplicator; | ||
|
||
/** Clock service. */ | ||
private final ClockService clockService; | ||
|
||
/** | ||
* Creates a new instance of ReplicaSafeTimeSyncRequestHandler. | ||
* | ||
* @param clockService Clock service. | ||
* @param commandApplicator Applicator that applies RAFT command that is created by this handler. | ||
*/ | ||
public ReplicaSafeTimeSyncRequestHandler( | ||
ClockService clockService, | ||
ReplicationRaftCommandApplicator commandApplicator | ||
) { | ||
this.clockService = clockService; | ||
this.commandApplicator = commandApplicator; | ||
} | ||
|
||
/** | ||
* Handles {@link ReplicaSafeTimeSyncRequest}. | ||
* | ||
* @param request Request to handle. | ||
* @return Future that will be completed when the request is handled. | ||
*/ | ||
public CompletableFuture<?> handle(ReplicaSafeTimeSyncRequest request) { | ||
return commandApplicator.applyCommandWithExceptionHandling( | ||
REPLICA_MESSAGES_FACTORY.safeTimeSyncCommand().initiatorTime(clockService.now()).build() | ||
); | ||
} | ||
} |
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
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.
It's not a single node cluster))