fix(backend-java): 收口并发资源与恢复链路
This commit is contained in:
+8
-2
@@ -119,13 +119,19 @@ public class LocalFileStorageService {
|
||||
if (!baseDir.exists()) {
|
||||
return null;
|
||||
}
|
||||
String indexedName = sourceFileIndex.get(fileKey);
|
||||
String indexedName;
|
||||
synchronized (sourceFileIndex) {
|
||||
// LinkedHashMap 使用 access-order,get 也会修改链表结构,必须纳入同一把锁。
|
||||
indexedName = sourceFileIndex.get(fileKey);
|
||||
}
|
||||
if (indexedName != null && isPlainName(indexedName)) {
|
||||
File indexed = FileUtil.file(baseDir, indexedName);
|
||||
if (indexed.isFile()) {
|
||||
return indexed;
|
||||
}
|
||||
sourceFileIndex.remove(fileKey);
|
||||
synchronized (sourceFileIndex) {
|
||||
sourceFileIndex.remove(fileKey, indexedName);
|
||||
}
|
||||
}
|
||||
File[] matchedFiles = baseDir.listFiles(pathname -> pathname.isFile()
|
||||
&& (pathname.getName().equals(fileKey) || pathname.getName().startsWith(fileKey + ".")));
|
||||
|
||||
+20
-2
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Semaphore;
|
||||
@@ -151,8 +152,25 @@ public class RustfsObjectStorageService {
|
||||
try (var stream = buildClient(deadlineNanos).getObject(GetObjectArgs.builder()
|
||||
.bucket(properties.getBucket())
|
||||
.object(objectKey)
|
||||
.build())) {
|
||||
return stream.readAllBytes();
|
||||
.build());
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream(8192)) {
|
||||
long maxBytes = properties.getMaxStoredPayloadBytes() > 0
|
||||
? properties.getMaxStoredPayloadBytes()
|
||||
: 100L * 1024 * 1024;
|
||||
byte[] buffer = new byte[8192];
|
||||
long total = 0L;
|
||||
int read;
|
||||
while ((read = stream.read(buffer)) != -1) {
|
||||
if (read == 0) {
|
||||
continue;
|
||||
}
|
||||
total += read;
|
||||
if (total > maxBytes) {
|
||||
throw new IllegalArgumentException("transient payload exceeds configured read limit: " + maxBytes);
|
||||
}
|
||||
output.write(buffer, 0, read);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user