Skip to content

Commit

Permalink
Code revision
Browse files Browse the repository at this point in the history
  • Loading branch information
kristyelee committed Oct 12, 2024
1 parent 3431081 commit 8385009
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,9 @@ public synchronized void checkWhetherStoragePartitionsShouldBeKeptOrNot(SafeHeli
new PropertyKey.Builder(configLoader.getVeniceClusterConfig().getClusterName());
SafeHelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
IdealState idealState = helixDataAccessor.getProperty(propertyKeyBuilder.idealStates(storeName));
String listenerHostName = manager.getInstanceName();
String instanceHostName = manager.getInstanceName();

if (idealState != null) {
Set<Integer> idealStatePartitionIds = new HashSet<>();
Set<String> partitionSet = idealState.getPartitionSet();
partitionSet.stream().forEach(partitionDbName -> {
idealStatePartitionIds.add(RocksDBUtils.parsePartitionIdFromPartitionDbName(partitionDbName));
});

Map<String, Map<String, String>> mapFields = idealState.getRecord().getMapFields();
for (Map.Entry<String, Map<String, String>> entry: mapFields.entrySet()) {
boolean keepPartition = false;
Expand All @@ -406,7 +400,7 @@ public synchronized void checkWhetherStoragePartitionsShouldBeKeptOrNot(SafeHeli
continue;
}
for (String hostName: entry.getValue().keySet()) {
if (hostName.equals(listenerHostName)) {
if (hostName.equals(instanceHostName)) {
keepPartition = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,6 @@ public synchronized Set<Integer> getPartitionIds() {
return this.partitionList.values().stream().map(Partition::getPartitionId).collect(Collectors.toSet());
}

public synchronized SparseConcurrentList<Partition> getPartitionList() {
return this.partitionList;
}

public AbstractStoragePartition getPartitionOrThrow(int partitionId) {
AbstractStoragePartition partition;
ReadWriteLock readWriteLock = getRWLockForPartitionOrThrow(partitionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.helix.HelixManager;
import org.apache.helix.PropertyKey;
import org.apache.helix.model.IdealState;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
Expand Down Expand Up @@ -142,8 +141,6 @@ public void testGetStoreAndUserPartitionsMapping() {
public void testCheckWhetherStoragePartitionsShouldBeKeptOrNot() throws NoSuchFieldException, IllegalAccessException {
StorageService mockStorageService = mock(StorageService.class);
SafeHelixManager manager = mock(SafeHelixManager.class);
HelixManager helixManager = mock(HelixManager.class);
when(manager.getOriginalManager()).thenReturn(helixManager);
StorageEngineRepository mockStorageEngineRepository = mock(StorageEngineRepository.class);
AbstractStorageEngine abstractStorageEngine = mock(AbstractStorageEngine.class);
mockStorageEngineRepository.addLocalStorageEngine(abstractStorageEngine);
Expand Down Expand Up @@ -171,8 +168,6 @@ public void testCheckWhetherStoragePartitionsShouldBeKeptOrNot() throws NoSuchFi
when(manager.getHelixDataAccessor()).thenReturn(helixDataAccessor);
IdealState idealState = mock(IdealState.class);
when(helixDataAccessor.getProperty((PropertyKey) any())).thenReturn(idealState);
Set<String> helixPartitionSet = new HashSet<>(Arrays.asList("test_store_v1_0", "test_store_v1_1"));
when(idealState.getPartitionSet()).thenReturn(helixPartitionSet);
ZNRecord record = new ZNRecord("testId");
Map<String, Map<String, String>> mapFields = new HashMap<>();
Map<String, String> testPartitionZero = new HashMap<>();
Expand Down Expand Up @@ -208,9 +203,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Field configLoaderField = StorageService.class.getDeclaredField("configLoader");
configLoaderField.setAccessible(true);
configLoaderField.set(mockStorageService, mockVeniceConfigLoader);
Field partitionListField = AbstractStorageEngine.class.getDeclaredField("partitionList");
partitionListField.setAccessible(true);
partitionListField.set(abstractStorageEngine, abstractStorageEngine.getPartitionList());

doCallRealMethod().when(mockStorageService).checkWhetherStoragePartitionsShouldBeKeptOrNot(manager);
mockStorageService.checkWhetherStoragePartitionsShouldBeKeptOrNot(manager);
Expand Down

0 comments on commit 8385009

Please sign in to comment.