chore(lab5): remove stale templates and refresh source comments

This commit is contained in:
Mikhail Verkovykh
2026-11-20 19:05:23 +03:00
parent fec2882c9a
commit 1ce93185af
49 changed files with 33 additions and 5324 deletions
+3 -3
View File
@@ -101,7 +101,7 @@ func (h *Handler) Upload(c fiber.Ctx) error {
// decoding anything. Chunked requests are caught by the streaming counter
// below.
//
// AGENT: the declared body is drained first, but only within the bounded
// The declared body is drained first, but only within the bounded
// HTTP envelope (upload limit plus the JSON body slack). If the server
// closed immediately, the client would often see a connection reset instead
// of the required 413 while it was still sending. Draining is bounded and
@@ -134,7 +134,7 @@ func (h *Handler) Upload(c fiber.Ctx) error {
_ = os.Remove(filePath)
}()
// AGENT: the 32 KiB copy buffer is the only request-sized allocation here.
// The 32 KiB copy buffer is the only request-sized allocation here.
// The body is never read with io.ReadAll, so ten simultaneous 10 MiB
// uploads do not require ten 10 MiB Go slices.
var reader io.Reader = requestBody(c)
@@ -230,7 +230,7 @@ func (h *Handler) Get(c fiber.Ctx) error {
return err
}
// queued/processing snapshots are part of lab5: the client polls this
// Queued/processing snapshots; the client polls this
// endpoint until status becomes ready or failed.
return c.JSON(attachment)
}
+1 -1
View File
@@ -41,7 +41,7 @@ func NewValidator(maxPixels, decodeBudgetBytes int64) *Validator {
// decodes the image under a shared memory budget. The decode is what turns a
// structurally broken or truncated file into 415 instead of a saved object.
//
// AGENT: image.DecodeConfig first reads only the header. This is the important
// The image.DecodeConfig call first reads only the header. This is the important
// ordering: a decompression bomb is rejected from width×height before the
// decoder is allowed to allocate pixel memory.
func (v *Validator) Validate(ctx context.Context, file *os.File, declared string) (ImageInfo, error) {
+2 -1
View File
@@ -152,7 +152,8 @@ func NewConsumer(url, queue string, logger *slog.Logger) *Consumer {
// Run reconnects until ctx is cancelled. concurrency bounds simultaneous
// handlers in this process; prefetch bounds unacked messages the broker may
// push. The two knobs are intentionally separate for the lab5 experiment.
// push. The two knobs are intentionally separate so throughput and in-flight
// memory can be measured independently.
func (c *Consumer) Run(ctx context.Context, concurrency, prefetch int, handler Handler) error {
for {
if ctx.Err() != nil {
@@ -5,8 +5,8 @@ ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_pipeline_version;
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_error_state;
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status;
-- Collapse asynchronous states back to lab4's single in-flight state. Ready
-- and failed rows keep their meaning; queued/processing work is abandoned.
-- Collapse asynchronous states back to the previous single in-flight state.
-- Ready and failed rows keep their meaning; queued/processing work is abandoned.
UPDATE attachments
SET status = 'pending', error_code = NULL
WHERE status IN ('queued', 'processing');
@@ -1,4 +1,4 @@
-- Lab5 turns attachment processing into a durable asynchronous job.
-- Attachment processing is a durable asynchronous job.
-- The API stages bytes in S3, then in ONE transaction writes the attachment
-- snapshot and its outbox/job row. A separate publisher moves the intent to
-- RabbitMQ, so a broker outage cannot lose an accepted upload.
@@ -6,9 +6,9 @@
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_status;
ALTER TABLE attachments DROP CONSTRAINT IF EXISTS attachments_error_state;
-- Lab4 "pending" meant "object PUT in progress". Nothing can finish it now,
-- because lab5 acceptors write "queued" plus a job. Preserve the row for the
-- operator instead of silently deleting it.
-- The previous "pending" state meant "object PUT in progress". Nothing can
-- finish it now, because acceptors write "queued" plus a job. Preserve the row
-- for the operator instead of silently deleting it.
UPDATE attachments
SET status = 'failed', error_code = 'legacy_interrupted', updated_at = now()
WHERE status = 'pending';
+1 -1
View File
@@ -51,7 +51,7 @@ func New(cfg Config) (*Client, error) {
return nil, err
}
// AGENT: a bounded retry count keeps a broken S3 dependency from turning an
// Bounded retry count keeps a broken S3 dependency from turning an
// HTTP upload into an unbounded wait. Context deadlines in the handlers set
// the overall request budget.
awsCfg.RetryMaxAttempts = 2
+4 -4
View File
@@ -78,7 +78,7 @@ func (s *Store) CreateMessage(ctx context.Context, chatID, senderID uuid.UUID, t
return model.Message{}, dbError(scanErr)
}
found++
// Lab5: a queued/processing attachment is already linked to its
// A queued/processing attachment is already linked to its
// chat and may be sent. Only a terminal failed one is refused.
if status == "failed" {
rows.Close()
@@ -159,9 +159,9 @@ func canonicalAttachmentIDs(ids []uuid.UUID) []uuid.UUID {
return result
}
// messageFingerprint keeps the lab3 hash for messages without attachments, so
// an idempotency key stored before this migration still replays correctly. For
// messages with attachments the sorted IDs are part of the canonical body.
// messageFingerprint keeps the legacy hash for messages without attachments,
// so an idempotency key stored before this migration still replays correctly.
// For messages with attachments the sorted IDs are part of the canonical body.
func messageFingerprint(text string, attachmentIDs []uuid.UUID) []byte {
if len(attachmentIDs) == 0 {
sum := sha256.Sum256([]byte(text))