GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dbengine: load only exactly named datafiles by stelfrag · Pull Request #24436 · netdata/netdata

Conversation

@stelfrag

@stelfrag stelfrag commented Oct 26, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

scan_data_files() took any name for which sscanf("datafile-%1u-%10u.ndf") converted both numbers. sscanf() does not check the .ndf literal or trailing text, so:

  • a copy such as datafile-1-0000000001.ndf.bak loaded the real datafile and journal a second time (two structs for one file, disk space charged twice, one struct orphaned with its open file);
  • a stray datafile-2-<n>.ndf aborted startup on fatal_assert(tier == 1);
  • the startup probe that tells ram-mode agents whether dbengine data exists counted the same names.

datafile_name_parse() accepts only the exact name generate_datafilepath() writes (tier 1, 10-digit file number, .ndf); both places use it. Other names now get the existing "Unknown file detected" warning. A unit check covers the accepted and rejected names.

Validation on test agents:

  • pair + .ndf.bak: master "loading 2 data/journal files", this PR "loading 1" and the .bak reported as unknown
  • datafile-2-*.ndf: master "Assertion `tier == 1' failed", this PR starts normally
  • ram-mode agent with only a .ndf.bak: dbengine_datafiles_present true on master, false here (a real datafile still sets it)
  • full -W unittest passes

Fixes F5 of #23896.

Summary by CodeRabbit

  • Bug Fixes
    • Datafile discovery now recognizes only correctly formatted tier-1 datafile names. Unrelated files, backup copies, and names with invalid prefixes, extensions, or file numbers are excluded, helping ensure the database engine loads the intended persisted datafiles.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stelfrag
dbengine: load only exactly named datafiles
4abdfa2
sscanf() accepted any name that starts like a datafile: a copy such as
datafile-1-0000000001.ndf.bak loaded the real datafile and journal a
second time, and a datafile-2-* name aborted startup. Both the scan and
the startup presence probe now require the exact name dbengine writes.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40cae51f-80e7-4320-b914-ad2ee510eb06
Commits

Reviewing files that changed from the base of the PR and between 8965ee4 and 4abdfa2.

Files selected for processing: 4
  • src/daemon/config/netdata-conf-db.c
  • src/database/engine/datafile.c
  • src/database/engine/datafile.h
  • src/database/engine/dbengine-unittest.c

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

Datafile scans now use a parser that accepts canonical tier-1 datafile names and extracts the file number. Unit tests cover valid names and reject suffixes, incorrect prefixes or extensions, missing extensions, and short file numbers.

Changes: Datafile name validation

Layer / File(s) Summary
Canonical filename parser
src/database/engine/datafile.h, src/database/engine/datafile.c, src/database/engine/dbengine-unittest.c
A public parser accepts canonical tier-1 datafile names and returns the file number. Unit tests cover accepted and rejected names, and the dbengine test runner includes the new tests.
Datafile scan integration
src/daemon/config/netdata-conf-db.c, src/database/engine/datafile.c
Both scans use the parser to recognize persisted datafiles. The datafile scan assigns accepted files to tier 1.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: thiagoftsm

Merge Risk: Minimal · up to 4abdf

No actionable risk introduced by this change is established. It is ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: dbengine now loads only datafiles with the exact expected names.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added area/daemon area/database labels Oct 26, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 26, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stelfrag
stelfrag marked this pull request as ready for review October 26, 2026 08:15
@stelfrag
stelfrag requested review from thiagoftsm and vkalintiris as code owners October 26, 2026 08:15
thiagoftsm
thiagoftsm approved these changes Oct 26, 2026
View reviewed changes

@thiagoftsm thiagoftsm left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR was tested on Microsoft Windows and load files and rotation happened as expected. LGTM!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stelfrag
stelfrag merged commit e55d5ff into netdata:master Oct 26, 2026
161 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@stelfrag
stelfrag deleted the fix-datafile-scan-suffix branch October 26, 2026 14:02
stelfrag added a commit to stelfrag/netdata that referenced this pull request Oct 26, 2026
@stelfrag
dbengine: load only exactly named datafiles (netdata#24436)
2311275
sscanf() accepted any name that starts like a datafile: a copy such as
datafile-1-0000000001.ndf.bak loaded the real datafile and journal a
second time, and a datafile-2-* name aborted startup. Both the scan and
the startup presence probe now require the exact name dbengine writes.

(cherry picked from commit e55d5ff)
@stelfrag stelfrag mentioned this pull request Oct 26, 2026
Patch release 2.12.3 #24442
Merged
Ferroin pushed a commit that referenced this pull request Nov 4, 2026
@stelfrag @Ferroin
dbengine: load only exactly named datafiles (#24436)
99425ab
sscanf() accepted any name that starts like a datafile: a copy such as
datafile-1-0000000001.ndf.bak loaded the real datafile and journal a
second time, and a datafile-2-* name aborted startup. Both the scan and
the startup presence probe now require the exact name dbengine writes.

(cherry picked from commit e55d5ff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@thiagoftsm thiagoftsm thiagoftsm approved these changes
@vkalintiris vkalintiris Awaiting requested review from vkalintiris vkalintiris is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/daemon area/database

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@stelfrag @thiagoftsm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.