sashapolo commented on code in PR #2596: URL: https://github.com/apache/ignite-3/pull/2596#discussion_r1328710964
########## modules/placement-driver-api/src/main/java/org/apache/ignite/internal/placementdriver/event/PrimaryReplicaEvent.java: ########## @@ -0,0 +1,26 @@ +/* + * 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.placementdriver.event; + +import org.apache.ignite.internal.event.Event; + +/** Primary replica management events. */ +public enum PrimaryReplicaEvent implements Event { + /** This event is fired when a replica becomes primary or when the primary replica changes for a replication group. */ + REPLICA_BECOME_PRIMARY; Review Comment: Maybe we should rename it to something like `PRIMARY_REPLICA_ELECTED`? ########## modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java: ########## @@ -431,6 +435,7 @@ private TopologyAwareRaftGroupService startCluster( ) { when(msm.recoveryFinishedFuture()).thenReturn(completedFuture(0L)); when(msm.invoke(any(), any(Operation.class), any(Operation.class))).thenReturn(completedFuture(true)); + when(msm.getLocally(any(), anyLong())).then(invocation -> emptyMetastoreEntry()); Review Comment: Why do you need to mock this? ########## modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java: ########## @@ -79,47 +89,33 @@ public class LeaseTracker implements PlacementDriver { /** Listener to update a leases cache. */ private final UpdateListener updateListener = new UpdateListener(); + /** Versioned value used only at manager startup to correctly fire table creation events. */ + private final IncrementalVersionedValue<Void> startVv; + /** * Constructor. * + * @param registry Registry for versioned values. * @param msManager Meta storage manager. */ - public LeaseTracker(MetaStorageManager msManager) { + public LeaseTracker(Consumer<LongFunction<CompletableFuture<?>>> registry, MetaStorageManager msManager) { this.msManager = msManager; + + startVv = new IncrementalVersionedValue<>(registry); } /** Recoveries state from Vault and subscribers on further updates. */ public void startTrack() { Review Comment: I would propose to make `startTrack` to return a `CompletableFuture` and then move the `startVv` to the upper component (`PlacementDriverManager`). This way we will only have IgniteComponents to worry about `startVv` which will help with later transition to async start ########## modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/leases/LeaseTracker.java: ########## @@ -79,47 +89,33 @@ public class LeaseTracker implements PlacementDriver { /** Listener to update a leases cache. */ private final UpdateListener updateListener = new UpdateListener(); + /** Versioned value used only at manager startup to correctly fire table creation events. */ Review Comment: This javadoc is not correct ########## modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/PlacementDriverTest.java: ########## @@ -356,6 +404,37 @@ private void publishLease(Lease lease) { noop() ); - revisionTracker.waitFor(rev + 1).join(); + long expRev = rev + 1; + + assertThat(revisionTracker.waitFor(expRev), willCompleteSuccessfully()); + + return expRev; + } + + private CompletableFuture<PrimaryReplicaEventParameters> listenReplicaBecomePrimaryEvent() { + var eventParametersFuture = new CompletableFuture<PrimaryReplicaEventParameters>(); + + placementDriver.listen(REPLICA_BECOME_PRIMARY, (parameters, exception) -> { + eventParametersFuture.complete(parameters); Review Comment: I would also suggest to not ignore the possible exception -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
