merge: PR #25을 합친 검사 브랜치에 넣는다

This commit is contained in:
DongHyeonka
2026-11-13 07:21:13 +09:00
80 changed files with 1555 additions and 284 deletions
@@ -17,10 +17,10 @@ import dev.caskeleton.shared.error.Category;
* servlet transport, the reactive transport and the Nginx delegation path cannot answer the same
* failure three different ways.
*
* <p>{@code UNAUTHENTICATED}, {@code PRECONDITION_FAILED} and {@code UNSUPPORTED_MEDIA_TYPE} share
* their name with an {@code OperationalError}; they are kept here so the failure context stays one
* enum, and {@code FileserverExceptionTest} pins that each means exactly what the operational code
* means on the wire (category, status, retryability).
* <p>{@code UNAUTHENTICATED}, {@code PRECONDITION_FAILED}, {@code UNSUPPORTED_MEDIA_TYPE} and
* {@code SERVER_BUSY} share their name with an {@code OperationalError}; they are kept here so the
* failure context stays one enum, and {@code FileserverExceptionTest} pins that each means exactly
* what the operational code means on the wire (category, status, retryability).
*/
public enum FileserverErrorCode implements ApiErrorCode {
BAD_REQUEST(400, Category.VALIDATION, false),
@@ -42,6 +42,7 @@ public enum FileserverErrorCode implements ApiErrorCode {
MALWARE_DETECTED(422, Category.DATA_INTEGRITY, false),
INVALID_PATH(422, Category.VALIDATION, false),
PATH_OUTSIDE_NAMESPACE(422, Category.VALIDATION, false),
// The caller's own transfers fill its scope's permits: the caller's rate, so 429.
TRANSFER_ADMISSION_REJECTED(429, Category.RATE_LIMIT, true),
// tus checksum extension status: one request's bytes did not match the checksum the client sent
// for them. The chunk is rolled back before its offset commits, so the upload stays resumable.
@@ -52,6 +53,9 @@ public enum FileserverErrorCode implements ApiErrorCode {
AMBIGUOUS_COMPLETION(500, Category.DATA_INTEGRITY, false),
ATOMIC_PUBLISH_UNSUPPORTED(503, Category.PERMANENT_DEPENDENCY, false),
STORAGE_UNAVAILABLE(503, Category.TRANSIENT_DEPENDENCY, true),
// The instance's permits or its transfer pool are full: server saturation, the shared code every
// transport answers it with (decisions 2.3, 2026-11-12).
SERVER_BUSY(503, Category.TRANSIENT_DEPENDENCY, true),
TRANSFER_TIMEOUT(504, Category.TRANSIENT_DEPENDENCY, true),
STORAGE_FULL(507, Category.TRANSIENT_DEPENDENCY, false);
@@ -15,9 +15,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
* In-process admission control backed by bounded semaphores.
*
* <p>The failure vocabulary is deliberately distinct so a client can tell a permanent policy denial
* from a transient one: an exhausted pool is {@code STORAGE_FULL}, and running out of concurrency
* permits — for the caller's scope or for the whole instance — is a retryable admission rejection.
* Stored bytes over a quota ({@code QUOTA_EXCEEDED}) are decided by the quota service, not here.
* from a transient one: an exhausted pool is {@code STORAGE_FULL}; running out of the caller's own
* scope permits is a retryable {@code TRANSFER_ADMISSION_REJECTED} (429, the caller's rate);
* running out of the whole instance's permits is the shared server-saturation {@code SERVER_BUSY}
* (503). Stored bytes over a quota ({@code QUOTA_EXCEEDED}) are decided by the quota service, not
* here.
*/
public final class TransferAdmissionController {
@@ -74,7 +76,7 @@ public final class TransferAdmissionController {
scopePermits.release();
throw new FileserverException(
"instance upload permits are exhausted",
FileserverFailureContext.of(FileserverErrorCode.TRANSFER_ADMISSION_REJECTED, true));
FileserverFailureContext.of(FileserverErrorCode.SERVER_BUSY, true));
}
return new SemaphorePermit(scopePermits, instanceUploads);
}
@@ -83,7 +85,7 @@ public final class TransferAdmissionController {
if (!directDownloads.tryAcquire()) {
throw new FileserverException(
"instance direct download permits are exhausted",
FileserverFailureContext.of(FileserverErrorCode.TRANSFER_ADMISSION_REJECTED, true));
FileserverFailureContext.of(FileserverErrorCode.SERVER_BUSY, true));
}
return new SemaphorePermit(directDownloads);
}
@@ -9,7 +9,9 @@ import java.util.OptionalLong;
* Client intent when starting an upload.
*
* <p>{@code originalFilename} and {@code claimedMediaType} are untrusted: they are sanitized and
* stored as display metadata, never used to build a physical key or to decide safety.
* stored as display metadata, never used to build a physical key or to decide safety. A transport
* that received no name passes an empty string; the display name of an unnamed upload is {@code
* OriginalFilenamePolicy}'s to choose, not each transport's.
*
* <p>The request carries only what the client decides. The namespace and the session lifetime are
* {@link UploadPolicy}'s, so no transport can pick its own.
@@ -119,7 +119,12 @@ class TransferAdmissionControllerTest {
assertThatThrownBy(() -> narrow.acquireUpload(scope("tenant-b"), 10))
.isInstanceOf(FileserverException.class)
.satisfies(
failure -> assertThat(((FileserverException) failure).context().retryable()).isTrue());
failure -> {
assertThat(((FileserverException) failure).context().retryable()).isTrue();
assertThat(((FileserverException) failure).context().code())
.as("the whole instance is full: server saturation, not the caller's rate")
.isEqualTo(FileserverErrorCode.SERVER_BUSY);
});
held.close();
TransferPermit afterRelease = narrow.acquireUpload(scope("tenant-b"), 10);
@@ -197,7 +202,9 @@ class TransferAdmissionControllerTest {
TransferPermit download = narrow.acquireDirectDownload(scope("tenant-a"));
assertThatThrownBy(() -> narrow.acquireDirectDownload(scope("tenant-a")))
.isInstanceOf(FileserverException.class);
.isInstanceOf(FileserverException.class)
.extracting(failure -> ((FileserverException) failure).context().code())
.isEqualTo(FileserverErrorCode.SERVER_BUSY);
assertThat(narrow.acquireUpload(scope("tenant-a"), 10).isHeld()).isTrue();
download.close();