mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
修复
This commit is contained in:
@@ -49,19 +49,23 @@ public class IdAllocator {
|
|||||||
* 处理所有待分配的自动ID请求
|
* 处理所有待分配的自动ID请求
|
||||||
*/
|
*/
|
||||||
public void processPendingAllocations() {
|
public void processPendingAllocations() {
|
||||||
|
for (Map.Entry<String, Integer> entry : this.cachedIdMap.entrySet()) {
|
||||||
|
CompletableFuture<Integer> future = this.pendingAllocations.get(entry.getKey());
|
||||||
|
if (future != null) {
|
||||||
|
int id = entry.getValue();
|
||||||
|
if (!isIdAvailable(id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allocateId(id, future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, CompletableFuture<Integer>> entry : this.pendingAllocations.entrySet()) {
|
for (Map.Entry<String, CompletableFuture<Integer>> entry : this.pendingAllocations.entrySet()) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
CompletableFuture<Integer> future = entry.getValue();
|
CompletableFuture<Integer> future = entry.getValue();
|
||||||
|
|
||||||
if (future.isDone()) {
|
if (future.isDone()) {
|
||||||
continue; // 不应该发生的情况
|
continue; // 已经在前面分配过了
|
||||||
}
|
|
||||||
|
|
||||||
// 优先尝试使用缓存的ID
|
|
||||||
Integer cachedId = this.cachedIdMap.get(name);
|
|
||||||
if (isIdAvailable(cachedId)) {
|
|
||||||
allocateId(name, cachedId, future);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分配新的自动ID
|
// 分配新的自动ID
|
||||||
@@ -71,7 +75,7 @@ public class IdAllocator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocateId(name, newId, future);
|
allocateId(newId, future);
|
||||||
this.cachedIdMap.put(name, newId);
|
this.cachedIdMap.put(name, newId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +87,7 @@ public class IdAllocator {
|
|||||||
&& !this.occupiedIdSet.get(id);
|
&& !this.occupiedIdSet.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void allocateId(String name, int id, CompletableFuture<Integer> future) {
|
private void allocateId(int id, CompletableFuture<Integer> future) {
|
||||||
this.occupiedIdSet.set(id);
|
this.occupiedIdSet.set(id);
|
||||||
future.complete(id);
|
future.complete(id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user