This is an automated email from the ASF dual-hosted git repository.

apolovtsev pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new db17a85d6b IGNITE-23771 Remove intermediate conversion to string in 
AssignmentsTracker (#4804)
db17a85d6b is described below

commit db17a85d6bc4587594a39ea57a6482f5174160e3
Author: Alexander Polovtcev <[email protected]>
AuthorDate: Fri Nov 29 14:24:04 2024 +0200

    IGNITE-23771 Remove intermediate conversion to string in AssignmentsTracker 
(#4804)
---
 modules/placement-driver/build.gradle              |  1 +
 .../placementdriver/AssignmentsTracker.java        |  9 ++---
 .../internal/placementdriver/ActiveActorTest.java  | 13 ++-----
 .../internal/placementdriver/LeaseUpdaterTest.java | 43 +++++++++-------------
 4 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/modules/placement-driver/build.gradle 
b/modules/placement-driver/build.gradle
index 8e313213b9..e0de984099 100644
--- a/modules/placement-driver/build.gradle
+++ b/modules/placement-driver/build.gradle
@@ -78,6 +78,7 @@ dependencies {
     testImplementation(testFixtures(project(':ignite-metastorage')))
     testImplementation(testFixtures(project(':ignite-vault')))
     testImplementation(testFixtures(project(':ignite-configuration')))
+    testImplementation(testFixtures(project(':ignite-replicator')))
     testImplementation(testFixtures(project(':ignite-runner')))
     testImplementation libs.hamcrest.core
     testImplementation libs.mockito.core
diff --git 
a/modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java
 
b/modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java
index 635987258b..da0695cdef 100644
--- 
a/modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java
+++ 
b/modules/placement-driver/src/main/java/org/apache/ignite/internal/placementdriver/AssignmentsTracker.java
@@ -17,13 +17,11 @@
 
 package org.apache.ignite.internal.placementdriver;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
 import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.PENDING_ASSIGNMENTS_PREFIX_BYTES;
 import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX_BYTES;
 import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.extractTablePartitionId;
 import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
 import static org.apache.ignite.internal.util.IgniteUtils.inBusyLock;
-import static org.apache.ignite.internal.util.StringUtils.incrementLastChar;
 
 import java.util.List;
 import java.util.Map;
@@ -219,12 +217,11 @@ public class AssignmentsTracker implements 
AssignmentsPlacementDriver {
             byte[] assignmentsMetastoreKeyPrefix,
             Map<ReplicationGroupId, TokenizedAssignments> 
groupIdToAssignmentsMap
     ) {
-        var startKey = new ByteArray(assignmentsMetastoreKeyPrefix);
-        // FIXME: Remove intermediate string conversion, see 
https://issues.apache.org/jira/browse/IGNITE-23771
-        ByteArray endKey = ByteArray.fromString(incrementLastChar(new 
String(assignmentsMetastoreKeyPrefix, UTF_8)));
+        var prefix = new ByteArray(assignmentsMetastoreKeyPrefix);
+
         long revision = recoveryRevisions.revision();
 
-        try (Cursor<Entry> cursor = msManager.getLocally(startKey, endKey, 
revision)) {
+        try (Cursor<Entry> cursor = msManager.prefixLocally(prefix, revision)) 
{
             for (Entry entry : cursor) {
                 if (entry.tombstone()) {
                     continue;
diff --git 
a/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
 
b/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
similarity index 94%
rename from 
modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
rename to 
modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
index 67adde0cca..c73a3241cd 100644
--- 
a/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
+++ 
b/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/ActiveActorTest.java
@@ -22,6 +22,7 @@ import static java.util.stream.Collectors.toSet;
 import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
 import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
 import static 
org.apache.ignite.internal.util.CompletableFutures.trueCompletedFuture;
+import static org.apache.ignite.internal.util.CursorUtils.emptyCursor;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -31,7 +32,6 @@ import static org.mockito.Mockito.when;
 
 import java.nio.file.Path;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import 
org.apache.ignite.internal.cluster.management.topology.api.LogicalTopologyService;
@@ -51,21 +51,17 @@ import org.apache.ignite.internal.raft.PeersAndLearners;
 import 
org.apache.ignite.internal.raft.client.AbstractTopologyAwareGroupServiceTest;
 import 
org.apache.ignite.internal.raft.client.TopologyAwareRaftGroupServiceFactory;
 import 
org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
-import org.apache.ignite.internal.util.Cursor;
 import org.apache.ignite.raft.jraft.rpc.impl.RaftGroupEventsClientListener;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
 
 /**
  * Placement driver active actor test.
  */
 @ExtendWith(MockitoExtension.class)
-@MockitoSettings(strictness = Strictness.LENIENT)
 public class ActiveActorTest extends AbstractTopologyAwareGroupServiceTest {
     private final Map<String, PlacementDriverManager> placementDriverManagers 
= new HashMap<>();
 
@@ -80,20 +76,17 @@ public class ActiveActorTest extends 
AbstractTopologyAwareGroupServiceTest {
         when(msm.recoveryFinishedFuture()).thenReturn(completedFuture(new 
Revisions(0, -1)));
         when(msm.invoke(any(), any(Operation.class), 
any(Operation.class))).thenReturn(trueCompletedFuture());
         when(msm.getLocally(any(), anyLong())).then(invocation -> 
emptyMetastoreEntry());
-        when(msm.getLocally(any(), any(), anyLong())).then(invocation -> 
Cursor.fromIterable(List.of()));
+        when(msm.prefixLocally(any(), anyLong())).then(invocation -> 
emptyCursor());
     }
 
     @AfterEach
-    @Override
-    public void tearDown() throws Exception {
+    public void stopPlacementDriverManagers() {
         for (PlacementDriverManager pdMgr : placementDriverManagers.values()) {
             pdMgr.beforeNodeStop();
             assertThat(pdMgr.stopAsync(new ComponentContext()), 
willCompleteSuccessfully());
         }
 
         placementDriverManagers.clear();
-
-        super.tearDown();
     }
 
     @Override
diff --git 
a/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java
 
b/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java
index cff4264450..d75c893111 100644
--- 
a/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java
+++ 
b/modules/placement-driver/src/test/java/org/apache/ignite/internal/placementdriver/LeaseUpdaterTest.java
@@ -21,8 +21,8 @@ import static java.util.Collections.emptyMap;
 import static java.util.UUID.randomUUID;
 import static java.util.concurrent.CompletableFuture.completedFuture;
 import static java.util.stream.Collectors.toSet;
-import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.PENDING_ASSIGNMENTS_PREFIX;
-import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.PENDING_ASSIGNMENTS_PREFIX_BYTES;
+import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX_BYTES;
 import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.pendingPartAssignmentsKey;
 import static 
org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
 import static org.apache.ignite.internal.util.ArrayUtils.BYTE_EMPTY_ARRAY;
@@ -37,7 +37,6 @@ import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.nio.ByteOrder;
@@ -103,21 +102,9 @@ public class LeaseUpdaterTest extends 
BaseIgniteAbstractTest {
     /** Cluster nodes. */
     private final LogicalNode stableNode = new LogicalNode(randomUUID(), 
"test-node-stable", NetworkAddress.from("127.0.0.1:10000"));
     private final LogicalNode pendingNode = new LogicalNode(randomUUID(), 
"test-node-pending", NetworkAddress.from("127.0.0.1:10001"));
-    @Mock
-    private ClusterService clusterService;
-    @Mock
-    private MetaStorageManager metaStorageManager;
+
     @Mock
     private LogicalTopologyService topologyService;
-    @Mock
-    private LeaseTracker leaseTracker;
-    @Mock
-    private Cursor<Entry> msStableAssignmentsEntriesCursor;
-    @Mock
-    private Cursor<Entry> msPendingAssignmentsEntriesCursor;
-
-    @InjectConfiguration
-    private ReplicationConfiguration replicationConfiguration;
 
     /** Lease updater for tests. */
     private LeaseUpdater leaseUpdater;
@@ -128,7 +115,13 @@ public class LeaseUpdaterTest extends 
BaseIgniteAbstractTest {
     private volatile Consumer<Lease> renewLeaseConsumer = null;
 
     @BeforeEach
-    void setUp() {
+    void setUp(
+            @Mock ClusterService clusterService,
+            @Mock LeaseTracker leaseTracker,
+            @Mock MetaStorageManager metaStorageManager,
+            @Mock MessagingService messagingService,
+            @InjectConfiguration ReplicationConfiguration 
replicationConfiguration
+    ) {
         HybridClockImpl clock = new HybridClockImpl();
 
         Entry stableEntry = new EntryImpl(
@@ -145,20 +138,20 @@ public class LeaseUpdaterTest extends 
BaseIgniteAbstractTest {
                 clock.now()
         );
 
-        MessagingService messagingService = mock(MessagingService.class);
         when(messagingService.invoke(anyString(), any(), anyLong()))
                 .then(i -> 
completedFuture(PLACEMENT_DRIVER_MESSAGES_FACTORY.leaseGrantedMessageResponse().accepted(true).build()));
 
-        
when(msStableAssignmentsEntriesCursor.iterator()).thenReturn(List.of(stableEntry).iterator());
-        
when(msPendingAssignmentsEntriesCursor.iterator()).thenReturn(List.of(pendingEntry).iterator());
         when(clusterService.messagingService()).thenReturn(messagingService);
+
         lenient().when(leaseTracker.leasesCurrent()).thenReturn(leases);
         
lenient().when(leaseTracker.getLease(any(ReplicationGroupId.class))).then(i -> 
Lease.emptyLease(i.getArgument(0)));
+
         
when(metaStorageManager.recoveryFinishedFuture()).thenReturn(completedFuture(new
 Revisions(1, -1)));
-        
when(metaStorageManager.getLocally(eq(ByteArray.fromString(STABLE_ASSIGNMENTS_PREFIX)),
 any(ByteArray.class), anyLong()))
-                .thenReturn(msStableAssignmentsEntriesCursor);
-        
when(metaStorageManager.getLocally(eq(ByteArray.fromString(PENDING_ASSIGNMENTS_PREFIX)),
 any(ByteArray.class), anyLong()))
-                .thenReturn(msPendingAssignmentsEntriesCursor);
+        when(metaStorageManager.prefixLocally(eq(new 
ByteArray(STABLE_ASSIGNMENTS_PREFIX_BYTES)), anyLong()))
+                .thenReturn(Cursor.fromIterable(List.of(stableEntry)));
+        when(metaStorageManager.prefixLocally(eq(new 
ByteArray(PENDING_ASSIGNMENTS_PREFIX_BYTES)), anyLong()))
+                .thenReturn(Cursor.fromIterable(List.of(pendingEntry)));
+
         
when(topologyService.logicalTopologyOnLeader()).thenReturn(completedFuture(new 
LogicalTopologySnapshot(1, List.of(stableNode))));
 
         lenient().when(metaStorageManager.invoke(any(Condition.class), 
any(Operation.class), any(Operation.class)))
@@ -374,7 +367,7 @@ public class LeaseUpdaterTest extends 
BaseIgniteAbstractTest {
      *
      * @return The lease updater thread.
      */
-    private Thread getUpdaterThread() {
+    private static @Nullable Thread getUpdaterThread() {
         Set<Thread> threads = Thread.getAllStackTraces().keySet().stream()
                 .filter(t -> 
t.getName().contains("lease-updater")).collect(toSet());
 

Reply via email to