forked from mtusi2026/mtusi2026lab4
feat(storage): add RustFS attachments and presigned uploads
Add two API replicas, safe object reconciliation, upload validation, regression tests and documented load experiments.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { Prisma } from '../generated/prisma/client';
|
||||
|
||||
export const OBJECT_TRANSACTION = { maxWait: 5000, timeout: 20000 };
|
||||
|
||||
/** All writers and cleaners use the same transaction-scoped lock for an immutable key. */
|
||||
export async function tryAttachmentObjectLock(
|
||||
tx: Prisma.TransactionClient,
|
||||
objectKey: string,
|
||||
): Promise<boolean> {
|
||||
// A suspended/crashed writer must not keep an idle transaction open indefinitely.
|
||||
await tx.$executeRaw`SET LOCAL idle_in_transaction_session_timeout = '15s'`;
|
||||
const [result] = await tx.$queryRaw<{ locked: boolean }[]>(Prisma.sql`
|
||||
SELECT pg_try_advisory_xact_lock(hashtextextended(${`attachment:${objectKey}`}, 0)) AS locked
|
||||
`);
|
||||
return result.locked;
|
||||
}
|
||||
Reference in New Issue
Block a user