dataroaring commented on code in PR #53844:
URL: https://github.com/apache/doris/pull/53844#discussion_r2232784553
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java:
##########
@@ -287,94 +345,162 @@ public void
checkPartitionItemListsConflict(List<PartitionItem> list1,
}
public DataProperty getDataProperty(long partitionId) {
- return idToDataProperty.get(partitionId);
+ readLock();
+ try {
+ return idToDataProperty.get(partitionId);
+ } finally {
+ readUnlock();
+ }
}
public void setDataProperty(long partitionId, DataProperty
newDataProperty) {
- idToDataProperty.put(partitionId, newDataProperty);
+ writeLock();
+ try {
+ idToDataProperty.put(partitionId, newDataProperty);
+ } finally {
+ writeUnlock();
+ }
}
public void refreshTableStoragePolicy(String storagePolicy) {
- idToStoragePolicy.replaceAll((k, v) -> storagePolicy);
- idToDataProperty.entrySet().forEach(entry -> {
- entry.getValue().setStoragePolicy(storagePolicy);
- });
+ writeLock();
+ try {
+ idToStoragePolicy.replaceAll((k, v) -> storagePolicy);
+ idToDataProperty.entrySet().forEach(entry -> {
+ entry.getValue().setStoragePolicy(storagePolicy);
+ });
+ } finally {
+ writeUnlock();
+ }
}
public String getStoragePolicy(long partitionId) {
- return idToStoragePolicy.getOrDefault(partitionId, "");
+ readLock();
+ try {
+ return idToStoragePolicy.getOrDefault(partitionId, "");
+ } finally {
+ readUnlock();
+ }
}
public void setStoragePolicy(long partitionId, String storagePolicy) {
- idToStoragePolicy.put(partitionId, storagePolicy);
+ writeLock();
+ try {
+ idToStoragePolicy.put(partitionId, storagePolicy);
+ } finally {
+ writeUnlock();
+ }
}
- public Map<Long, ReplicaAllocation> getPartitionReplicaAllocations() {
- return idToReplicaAllocation;
+ public void modifyReplicaAlloc(ReplicaAllocation replicaAlloc) {
+ writeLock();
+ for (ReplicaAllocation alloc : idToReplicaAllocation.values()) {
+ Map<Tag, Short> allocMap = alloc.getAllocMap();
+ allocMap.clear();
+ allocMap.putAll(replicaAlloc.getAllocMap());
+ }
+ writeUnlock();
}
public ReplicaAllocation getReplicaAllocation(long partitionId) {
- if (!idToReplicaAllocation.containsKey(partitionId)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("failed to get replica allocation for partition:
{}", partitionId);
+ readLock();
+ try {
+ if (!idToReplicaAllocation.containsKey(partitionId)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("failed to get replica allocation for partition:
{}", partitionId);
+ }
+ return ReplicaAllocation.DEFAULT_ALLOCATION;
}
- return ReplicaAllocation.DEFAULT_ALLOCATION;
+ return idToReplicaAllocation.get(partitionId);
+ } finally {
+ readUnlock();
}
- return idToReplicaAllocation.get(partitionId);
}
public void setReplicaAllocation(long partitionId, ReplicaAllocation
replicaAlloc) {
+ writeLock();
this.idToReplicaAllocation.put(partitionId, replicaAlloc);
+ writeUnlock();
}
public boolean getIsInMemory(long partitionId) {
- return idToInMemory.get(partitionId);
+ readLock();
+ try {
+ return idToInMemory.get(partitionId);
+ } finally {
+ readUnlock();
+ }
}
public boolean getIsMutable(long partitionId) {
- return idToDataProperty.get(partitionId).isMutable();
+ readLock();
+ try {
+ return idToDataProperty.get(partitionId).isMutable();
+ } finally {
+ readUnlock();
+ }
}
public void setIsMutable(long partitionId, boolean isMutable) {
+ writeLock();
idToDataProperty.get(partitionId).setMutable(isMutable);
+ writeUnlock();
}
public void setIsInMemory(long partitionId, boolean isInMemory) {
+ writeLock();
idToInMemory.put(partitionId, isInMemory);
+ writeUnlock();
}
public TTabletType getTabletType(long partitionId) {
- if (!idToTabletType.containsKey(partitionId)) {
- return TTabletType.TABLET_TYPE_DISK;
+ readLock();
+ try {
+ if (!idToTabletType.containsKey(partitionId)) {
+ return TTabletType.TABLET_TYPE_DISK;
+ }
+ return idToTabletType.get(partitionId);
+ } finally {
+ readUnlock();
}
- return idToTabletType.get(partitionId);
}
public void setTabletType(long partitionId, TTabletType tabletType) {
+ writeLock();
Review Comment:
try final
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]