Skip to content

DAOS-18304 ddb: Add unit test to ddb code#17967

Draft
knard38 wants to merge 1 commit intockochhof/fix/master/daos-18291from
ckochhof/fix/master/daos-18304-patch-001
Draft

DAOS-18304 ddb: Add unit test to ddb code#17967
knard38 wants to merge 1 commit intockochhof/fix/master/daos-18291from
ckochhof/fix/master/daos-18304-patch-001

Conversation

@knard38
Copy link
Copy Markdown
Contributor

@knard38 knard38 commented Apr 10, 2026

Overview

This PR introduces a DdbApi Go interface to decouple the DDB command
layer from the C VOS implementation, making the Go code unit-testable
with stubs that do not require a live VOS environment. Several bugs
discovered during this refactoring are also fixed.


Refactoring

Go interface and method conversion

  • Introduce the DdbApi interface so a Go test stub can be injected in
    place of the real CGo implementation.
  • Convert all ddbXxx(ctx *DdbContext, ...) free functions to
    (ctx *DdbContext) Xxx(...) methods implementing DdbApi.
  • Propagate DdbApi through addAppCommands(), createGrumbleApp()
    and parseOpts() instead of passing *DdbContext directly.

DdbContext lifecycle

  • Convert Init() to a method on a caller-allocated DdbContext so
    the object lifecycle is fully controlled by the caller (or a test
    stub), instead of being allocated inside InitDdb().

Removal of dc_pool_path and dc_db_path

  • Remove the dc_pool_path and dc_db_path fields from
    struct ddb_ctx. These were workarounds used to pass path strings
    from Go to C by storing them directly in the context struct. They are
    now passed as explicit function arguments at every call site, which
    is cleaner and removes the need for the SetCString() helper.

parseOpts improvements

  • Replace the prefixesToSkip + HasPrefix loop with a noAutoOpen
    map for exact command-name matching, avoiding accidental prefix
    collisions (e.g. a future command whose name starts with an existing
    command name).
  • Remove the os.Exit() call inside parseOpts() when printing help:
    printHelp() now returns normally and parseOpts() returns nil,
    keeping the function testable.

Bug Fixes

Invalid command error messages

  • Introduce a typed unknownCmdError struct to replace raw string
    comparison against grumbleUnknownCmdErr. This enables type-safe
    detection in exitWithError().
  • exitWithError() now prints the available command list when the
    error is an unknownCmdError, making it immediately clear to the
    user what commands are available.
  • exitWithError(): fix duplicated ERROR: prefix line that was
    previously printed when a fault resolution was available.
  • printCmdHelp(): when --help is requested for an unknown command,
    the error message and the command list are now printed together via
    exitWithError(&unknownCmdError{}), consistent with all other
    invalid-command paths.

ddb_run_feature() state corruption (C)

  • dc_poh and dc_write_mode were reset unconditionally on exit,
    corrupting pool state when the pool was already open before the
    command ran. The reset is now guarded by the close flag.
  • Add missing error message when dv_pool_open() fails.

Non-interactive mode error propagation

  • Errors from runCmdStr() and runFileCmds() were previously logged
    and discarded. They are now properly returned to the caller and
    reported via exitWithError().

Startup ordering

  • Move debug.SetTraceback("crash") from parseOpts() to main() so
    it runs unconditionally before any other code, including
    DisableCStdoutBuffering().

--version flag

  • --version now prints directly and returns instead of synthesising
    a spurious version command, which previously bypassed command
    validation.

--db_path without --vos_path

  • Passing --db_path without --vos_path was silently ignored. It
    now returns an explicit error.

Pool close cleanup

  • Consolidate pool close logic into a shared closePoolIfOpen() helper.
  • Use defer closePoolIfOpen() when auto-opening via --vos_path to
    guarantee cleanup on all exit paths.

Go wrapper memory leaks and ordering

  • Feature(): C strings for the enable and disable flag
    arguments were passed anonymously without being freed. They are now
    assigned to named variables and freed via defer.
  • DtxStat(): defer freeString(options.path) was placed after
    options.details assignment. It is now placed immediately after the
    CString allocation, consistent with all other wrappers.

rm_pool Command

  • Make --vos_path mandatory: it was previously optional, causing a
    crash when omitted.
  • Pass db_path explicitly throughout the call chain:
    RmPool()ddb_run_rm_pool()dv_pool_destroy().

feature Command

  • Pass db_path explicitly throughout the call chain:
    Feature()ddb_run_feature()dv_pool_open().
  • In interactive mode, the open command also now passes db_path
    directly as a function argument instead of storing it in the context.

VOS Path Length Restriction Removed

  • Raise DB_PATH_SIZE and VOS_PATH_SIZE from 256 to PATH_MAX,
    removing the artificial restriction on deep filesystem hierarchies.
  • Add vf_vos_file_path[VOS_PATH_SIZE] to struct vos_file_parts and
    populate it in parse_vos_file_parts() so the full original path is
    preserved for vos_pool_open() / vos_pool_destroy_ex().
  • Add length-validation tests for both vos_path and db_path in
    ddb_parse_tests.c.

dv_pool_open / dv_pool_destroy API

  • Simplify signatures from (path, path_parts, poh, flags, write_mode)
    to (path, db_path, ctx, flags), moving vos_file_parts allocation
    into a new internal create_vos_file_parts() helper in ddb_vos.c.
  • All call sites in ddb_commands.c and the test suite are updated
    accordingly.

Test Fixes (C)

  • Move DTX record insertion from dump_dtx_cmd_tests() into
    dcv_suit_setup() so all DTX tests share a consistent fixture.
  • Correct VOS tree path indices in ls, value_dump and ilog_dump
    tests to match the actual test data layout after DTX record insertion
    was moved to suite setup.
  • Update dtx_stat regex to match the new
    "DTX entries statistics of the pool:" message (removes the stale
    dc_pool_path null-pointer reference in the format string).

Steps for the author:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

@knard38 knard38 self-assigned this Apr 10, 2026
@github-actions
Copy link
Copy Markdown

Ticket title is 'Add unit test to ddb go code'
Status is 'In Progress'
https://daosio.atlassian.net/browse/DAOS-18304

@daosbuild3
Copy link
Copy Markdown
Collaborator

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-001 branch 2 times, most recently from aadfb16 to 92d3255 Compare April 10, 2026 10:24
@daosbuild3
Copy link
Copy Markdown
Collaborator

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-001 branch from 92d3255 to b2a2966 Compare April 10, 2026 15:57
@daosbuild3
Copy link
Copy Markdown
Collaborator

Refactoring DDB code to allow unit testing of the go part code:
- The GO interface DdbApi is introduced to allow the use of GO test stub.
- Refactor initialisation of the C structure from the Go Code to allow the use of GO test stub.
- The useless C attributes dc_pool_path and dc_db_path are removed.

Following issues are also fixed:
- Remove invalid restrictions on pool file path size.
- Improper cleanup of the function ddb_run_feature().
- Fix invalid return code with non-interactive mode
- Fix rm_pool command:
  - Add db_path parameter to pool destroy command.
  - Makes vos_path parameter mandatory to pool destroy command.

Features: recovery
Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-001 branch from b2a2966 to 2ff60fd Compare April 10, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants