Skip to content

Commit 37c1800

Browse files
receive: Extract lostFoundDir constant and add rationale comment
Per reviewer feedback, replace the "lost+found" string literal with a named constant and document why the directory is skipped and why a name-based check was chosen over inode or filesystem-type inspection. Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
1 parent 0b26a9c commit 37c1800

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

pkg/receive/multitsdb.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ func (m *MultiTSDB) initTSDBIfNeeded(tenantID string, t *tenant) error {
403403

404404
const compactionDelayPercentBlockLength = 10
405405

406+
// lostFoundDir is the directory name that ext4 (and some other filesystems)
407+
// create automatically at the root of every partition. When a receiver's
408+
// --tsdb.path points directly at a mount point, the directory scan in Open()
409+
// and RemoveLockFilesIfAny() would otherwise treat it as a tenant name and
410+
// attempt to open or clean a TSDB for it, producing spurious errors on
411+
// startup. A name-based skip is the simplest cross-platform fix; checking the
412+
// inode or filesystem type would require platform-specific syscalls and adds
413+
// complexity without meaningful safety benefit, since a tenant legitimately
414+
// named "lost+found" is not a realistic concern.
415+
const lostFoundDir = "lost+found"
416+
406417
// generateCompactionDelay() generates a time.Duration of up to compactionDelayPercentBlockLength% of the block range. Used to stagger compactions & uploads.
407418
func (t *tenant) generateCompactionDelay() time.Duration {
408419
return time.Duration(rand.Int63n((t.maxBlockDuration*compactionDelayPercentBlockLength)/100)) * time.Millisecond
@@ -626,7 +637,7 @@ func (t *MultiTSDB) Open() error {
626637
if !f.IsDir() {
627638
continue
628639
}
629-
if f.Name() == "lost+found" {
640+
if f.Name() == lostFoundDir {
630641
continue
631642
}
632643

@@ -813,7 +824,7 @@ func (t *MultiTSDB) RemoveLockFilesIfAny() error {
813824
if !fi.IsDir() {
814825
continue
815826
}
816-
if fi.Name() == "lost+found" {
827+
if fi.Name() == lostFoundDir {
817828
continue
818829
}
819830
if err := os.Remove(filepath.Join(t.defaultTenantDataDir(fi.Name()), "lock")); err != nil {

0 commit comments

Comments
 (0)