mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Add attachments (protocol 4), their edge-case tests, and handoff docs
- One optional attachment per message, any size up to the server's MaxAttachmentSize (default 1G), sent and stored in 1 MB parts, checked with its SHA-256. Uploaded before its message (UploadStart, UploadChunk), then attached by the PushMessage in the same transaction; uploads never pushed expire after UploadTimeout. Read back a part at a time (GetAttachment). - Replicated separately, after the messages: the message carries the size and SHA-256, then each check-in lists what the peer is missing (MissingAttachments) and sends the parts from where it stopped. Over the receiver's limit, the attachment is marked not kept. - Deleted with its message by the retention, parts cleaned up in the background. Schema v7 (attachments, blobs, blob_chunks), replacing the unused attachements table. - DLL: PushMessageWithFile/WithData, SaveAttachment, LoadAttachment, GetMessageAttachmentSize, IsMessageAttachmentReady. Python: push(..., attachment=), get_attachment(), save_attachment(). Tools: PushMessage -a, GetAttachment. The release smoke test round-trips one. - Tests/Attachments-Test.ps1 (39 checks) and Tests/AttachmentEdges-Test.ps1 (51 checks, with a raw protocol client): wrong SHA-256, bad parts, others' uploads, expiry, replication resuming after a kill, a corrupted stored copy. Found: a corrupted copy is re-sent to peers forever, noted as open item 3 in Notes.md with a proposed fix. - CLAUDE.md: how to build, test, the traps and working rules, for the next session. Notes.md and the Design docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVPXGLs3KK1MAQn3ouP
This commit is contained in:
@@ -13,7 +13,12 @@
|
||||
; - deletes its messages pushed (pushed_at) before now minus that age,
|
||||
; #BakaShrot_Retention_BatchSize at a time through the writer
|
||||
; (DeleteStorageMessagesBefore(), Writer.pbi), so pushes go on between
|
||||
; the batches.
|
||||
; the batches;
|
||||
; - then the attachments' leftovers (CleanUpStorageBlobs(),
|
||||
; Attachments.pbi): those of the deleted messages, and uploads not
|
||||
; pushed with a message within [BakaShrot.Server] UploadTimeout,
|
||||
; #BakaShrot_Retention_ChunkBatchSize parts at a time.
|
||||
; It runs without any [BakaShrot.Retention] too, for the leftovers.
|
||||
;
|
||||
; Messages "may be" deleted past their max age: up to RetentionInterval
|
||||
; later. Those a peer replicates here already past it aren't stored at all
|
||||
@@ -33,6 +38,9 @@
|
||||
; Most messages deleted in one statement, under the write mutex: a few ms.
|
||||
#BakaShrot_Retention_BatchSize = 5000
|
||||
|
||||
; Most attachment parts (1 MB each) deleted in one statement.
|
||||
#BakaShrot_Retention_ChunkBatchSize = 32
|
||||
|
||||
|
||||
Structure BakaShrot_RetentionTopic
|
||||
TopicId.i
|
||||
@@ -43,6 +51,7 @@ Structure BakaShrot_RetentionState
|
||||
ThreadId.i
|
||||
StopRequested.i
|
||||
IntervalMs.i
|
||||
UploadTimeoutMs.q
|
||||
DatabasePath.s
|
||||
List Rules.BakaShrot_RetentionRule()
|
||||
EndStructure
|
||||
@@ -56,6 +65,25 @@ Procedure.s BakaShrot_Retention_FormatUtc(Ms.q)
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Deletes the attachments' leftovers, a few parts at a time.
|
||||
Procedure BakaShrot_Retention_CleanUp()
|
||||
Protected Deleted.i, Total.q, Error.String
|
||||
|
||||
Repeat
|
||||
Deleted = CleanUpStorageBlobs(BakaShrot_NowUtcMs() - BakaShrot_Retention\UploadTimeoutMs, #BakaShrot_Retention_ChunkBatchSize, @Error)
|
||||
If Deleted < 0
|
||||
PrintN("[Storage] Retention: failed to delete the attachments' leftovers: " + Error\s)
|
||||
Break
|
||||
EndIf
|
||||
Total + Deleted
|
||||
Until Deleted < #BakaShrot_Retention_ChunkBatchSize Or BakaShrot_Retention\StopRequested
|
||||
|
||||
If Total > 0
|
||||
PrintN("[Storage] Retention: deleted " + Str(Total) + " attachment parts (of deleted messages, or uploads never pushed)")
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Deletes what's past its max age in every topic. DbId is the thread's own
|
||||
; connection, only read from (the deletes go through the writer).
|
||||
; Returns how many messages were deleted.
|
||||
@@ -105,6 +133,7 @@ Procedure.q BakaShrot_Retention_Pass(DbId.i)
|
||||
EndIf
|
||||
Next
|
||||
|
||||
BakaShrot_Retention_CleanUp()
|
||||
ProcedureReturn Total
|
||||
EndProcedure
|
||||
|
||||
@@ -132,27 +161,22 @@ Procedure BakaShrot_Retention_Thread(Unused.i)
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Starts deleting what's past *Config's [BakaShrot.Retention] max ages, once
|
||||
; the writer is open. Nothing to do (no thread) if every topic is kept
|
||||
; forever. Returns #False if the thread can't start.
|
||||
; Starts deleting what's past *Config's [BakaShrot.Retention] max ages, and
|
||||
; the attachments' leftovers, once the writer is open.
|
||||
; Returns #False if the thread can't start.
|
||||
Procedure.i StartStorageRetention(*Config.BakaShrot_CoreConfig)
|
||||
Protected Deletes.i
|
||||
|
||||
With BakaShrot_Retention
|
||||
ClearList(\Rules())
|
||||
CopyList(*Config\Retention(), \Rules())
|
||||
ForEach \Rules()
|
||||
If \Rules()\MaxAgeMs > 0
|
||||
Deletes = #True
|
||||
PrintN("[Storage] Retention: " + \Rules()\Ref + " = " + \Rules()\AgeText + ", checked every " + Str(*Config\Server\RetentionInterval) + " s")
|
||||
EndIf
|
||||
Next
|
||||
If Not Deletes
|
||||
ProcedureReturn #True
|
||||
EndIf
|
||||
|
||||
\DatabasePath = *Config\Server\DatabasePath
|
||||
\IntervalMs = *Config\Server\RetentionInterval * 1000
|
||||
\DatabasePath = *Config\Server\DatabasePath
|
||||
\IntervalMs = *Config\Server\RetentionInterval * 1000
|
||||
\UploadTimeoutMs = *Config\Server\UploadTimeout * 1000
|
||||
\StopRequested = #False
|
||||
\ThreadId = CreateThread(@BakaShrot_Retention_Thread(), 0)
|
||||
ProcedureReturn Bool(\ThreadId)
|
||||
|
||||
Reference in New Issue
Block a user