Skip to content

Commit 6afd65f

Browse files
gammazerolidel
andauthored
Update flatfs.go
Co-authored-by: Marcin Rataj <[email protected]>
1 parent 0cdcbc0 commit 6afd65f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

flatfs.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,27 @@ type BatchReader interface {
11011101
// TODO: move this to be with other consts above
11021102
const maxConcurrentPuts = 16
11031103

1104+
// flatfsBatch implements atomic batch operations using a temporary directory.
1105+
//
1106+
// Design principles:
1107+
// - All Put operations write to a temp directory (no sharding)
1108+
// - Writes are done asynchronously in goroutines for performance
1109+
// - Commit atomically renames all files to their sharded destinations
1110+
// - On crash/discard, temp directory is cleaned (no partial writes)
1111+
//
1112+
// Concurrency: Safe for concurrent calls to Put/Delete/Get/Has/GetSize/Query.
1113+
// Not safe to call Commit or Discard concurrently with other operations.
1114+
//
1115+
// Transaction semantics: Read operations (Get/Has/GetSize/Query) see
1116+
// uncommitted writes from the same batch, following standard database
1117+
// transaction isolation.
1118+
//
1119+
// Performance characteristics:
1120+
// - Put: O(1) with async I/O, returns immediately
1121+
// - Get/Has/GetSize: O(n) where n = number of Put operations in batch
1122+
// - Commit: O(n) file renames
1123+
//
1124+
// IMPORTANT: Batch instances should not be reused after Commit or Discard.
11041125
type flatfsBatch struct {
11051126
mu sync.Mutex
11061127
puts []datastore.Key

0 commit comments

Comments
 (0)