Skip to content

DAOS-18625 utils: interpret key based to object's type for ddb output#17617

Open
Nasf-Fan wants to merge 4 commits intomasterfrom
Nasf-Fan/DAOS-18625
Open

DAOS-18625 utils: interpret key based to object's type for ddb output#17617
Nasf-Fan wants to merge 4 commits intomasterfrom
Nasf-Fan/DAOS-18625

Conversation

@Nasf-Fan
Copy link
Contributor

@Nasf-Fan Nasf-Fan commented Feb 27, 2026

Current ddb logic may print some integer keys' output as not-readable, for example dkey 10, 60 will be printed as following: DKEY: (/[4]/[2]/[0]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/ {8} DKEY: (/[4]/[2]/[2]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/<{8}

That is very confused. The patch defines new ddb_key_to_printable_buf() interface that will interpret key based to object's type and generate more readable ddb output.

Test-tag: recovery

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).

@github-actions
Copy link

github-actions bot commented Feb 27, 2026

Ticket title is 'Confused ddb ls ouput for integer keys'
Status is 'In Progress'
Labels: 'scrubbed_2.8'
https://daosio.atlassian.net/browse/DAOS-18625

@Nasf-Fan Nasf-Fan force-pushed the Nasf-Fan/DAOS-18625 branch 6 times, most recently from 23588dd to 847df11 Compare February 27, 2026 13:16
@daosbuild3
Copy link
Collaborator

@Nasf-Fan Nasf-Fan force-pushed the Nasf-Fan/DAOS-18625 branch from 847df11 to 2fe1617 Compare February 27, 2026 13:25
@daosbuild3
Copy link
Collaborator

@Nasf-Fan Nasf-Fan force-pushed the Nasf-Fan/DAOS-18625 branch from 2fe1617 to 7e0a598 Compare March 2, 2026 02:57
Current ddb logic may print some integer keys' output as not-readable,
for example dkey 10, 60 will be printed as following:
DKEY: (/[4]/[2]/[0]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/ {8}
DKEY: (/[4]/[2]/[2]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/<{8}

That is very confused. The patch defines new ddb_key_to_printable_buf()
interface that will interpret key based to object's type and generate
more readable ddb output.

Test-tag: recovery

Signed-off-by: Xuezhao Liu <xuezhao.liu@hpe.com>
Signed-off-by: Fan Yong <fan.yong@hpe.com>
@Nasf-Fan Nasf-Fan force-pushed the Nasf-Fan/DAOS-18625 branch from 7e0a598 to 4c0e467 Compare March 2, 2026 08:50
@daosbuild3
Copy link
Collaborator

Test stage Functional Hardware Large MD on SSD completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17617/9/execution/node/1352/log

@Nasf-Fan Nasf-Fan marked this pull request as ready for review March 3, 2026 03:28
@Nasf-Fan Nasf-Fan requested review from grom72, janekmi, knard38 and liuxuezhao and removed request for grom72 and janekmi March 3, 2026 03:29
liuxuezhao
liuxuezhao previously approved these changes Mar 3, 2026
@liuxuezhao
Copy link
Contributor

looks better to backport to 2.6 when convenient, thx

@Nasf-Fan
Copy link
Contributor Author

Nasf-Fan commented Mar 3, 2026

looks better to backport to 2.6 when convenient, thx

Yes, the patch for release/2.6 is #17618.

@Nasf-Fan Nasf-Fan requested a review from gnailzenh March 4, 2026 00:28
Copy link
Contributor

@knard38 knard38 left a comment

Choose a reason for hiding this comment

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

I am probably missing something, but do not see new tests checking print improvements of this PR.

d_iov_t *key_iov = &key_part->itp_key;
itp_print_part_key(struct ddb_ctx *ctx, struct indexed_tree_path_part *part)
{
char buf[DDB_MAX_PRITABLE_KEY];
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT

Suggested change
char buf[DDB_MAX_PRITABLE_KEY];
char buf[DDB_MAX_PRINTABLE_KEY];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, it was typo in original implementation. I will fix it.


len = ddb_key_to_printable_buf(key_iov, part->itp_otype, buf, ARRAY_SIZE(buf));
if (len > ARRAY_SIZE(buf)) {
len += 2; /* +2 for escape character if needed and null terminator. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure to fully understand this +2: I am probably missing something.
From my understanding, escape character need 2 printable characters.
Do not see why we could only have one escape character.
If I am true, then +2 should be evaluated according to the number of escape characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, +2 is for the escape character.

(!ddb_key_is_int(part->itp_otype) && ddb_can_print(key_iov))) {
/* +1 to make sure there's room for a null terminator */
char key_str[key_part->itp_key.iov_len + 1];
char key_str[key_iov->iov_len + 1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that this size will stay reasonable to allocate key_str on the stack ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally, we should dynamically allocate the buffer instead of static on stack. Current patch just reused original implementation. I will refresh it.

Copy link
Contributor

@knard38 knard38 Mar 12, 2026

Choose a reason for hiding this comment

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

Did you plan to keep this stack allocation or change it to heap allocation as indicated in your comments ?
From my side, no real issue to keep on the stack if we are sure that it will always be reasonable.

uint32_t len;

len = ddb_key_to_printable_buf(key_iov, part->itp_otype, buf, ARRAY_SIZE(buf));
if (len > ARRAY_SIZE(buf)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the following +2 should not take into account into this test ?

Suggested change
if (len > ARRAY_SIZE(buf)) {
if (len + 2 > ARRAY_SIZE(buf)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because else len = ARRAY_SIZE(buf);

Copy link
Contributor

Choose a reason for hiding this comment

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

if len == ARRAY_SIZE(but) and if we have some escape characters then buf will not have enough space from the comment at line 838 ?

@Nasf-Fan
Copy link
Contributor Author

Nasf-Fan commented Mar 5, 2026

I am probably missing something, but do not see new tests checking print improvements of this PR.

Added new test case in check src/utils/ddb/tests/ddb_path_tests.c:
assert_key_parsed_printed("{uint64:10}", "{uint64:0xa}", true);

If without the patch, the out will be something like:
DKEY: (/[4]/[2]/[0]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/ {8}

Please note the invisible output ' ' before {8}. After applying the patch, the output will be:
DKEY: (/[4]/[2]/[0]) /b2b37b1a-2894-4970-b51c-1a964526bb02/948289433254841843.256.535.2/{uint64:0xa}

Test-tag: recovery

Signed-off-by: Fan Yong <fan.yong@hpe.com>
@daosbuild3
Copy link
Collaborator

Test stage Functional Hardware Medium Verbs Provider MD on SSD completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-17617/11/execution/node/1311/log

@Nasf-Fan
Copy link
Contributor Author

Nasf-Fan commented Mar 6, 2026

CR leader switch cased CR test failure, not related with the ddb patch, to be retested.

@Nasf-Fan Nasf-Fan requested review from knard38 and liuxuezhao March 9, 2026 02:48
liuxuezhao
liuxuezhao previously approved these changes Mar 9, 2026
if (!itp_key_safe_str(buf, ARRAY_SIZE(buf))) {
if (!itp_key_safe_str(ptr, len)) {
ddb_print(ctx, "(ISSUE PRINTING KEY)");
D_FREE(key_str);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should free ptr if needed:

	if (ptr != buf)
		D_FREE(ptr);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I will fix it. Thanks!

Test-tag: recovery

Signed-off-by: Fan Yong <fan.yong@hpe.com>
uint32_t len;

len = ddb_key_to_printable_buf(key_iov, part->itp_otype, buf, ARRAY_SIZE(buf));
if (len > ARRAY_SIZE(buf)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be ?

Suggested change
if (len > ARRAY_SIZE(buf)) {
if (len >= ARRAY_SIZE(buf)) {

Copy link
Contributor Author

@Nasf-Fan Nasf-Fan Mar 11, 2026

Choose a reason for hiding this comment

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

The logic is stale. I will refresh the patch soon.

Test-tag: recovery

Signed-off-by: Fan Yong <fan.yong@hpe.com>
@Nasf-Fan Nasf-Fan requested a review from knard38 March 12, 2026 02:21

ddb_iov_to_printable_buf(key_iov, buf, ARRAY_SIZE(buf));
if (ddb_can_print(key_iov)) {
ddb_key_to_printable_buf(key_iov, part->itp_otype, buf, ARRAY_SIZE(buf));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check if the value return is greater or equal than ARRAY_SIZE(buf).
If yes, maybe we should print a truncation warning message from my understanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the buffer is not large enough to hold the key, it will be automatically truncated with '\0' terminated. The macro DDB_MAX_PRINTABLE_KEY is for case of very long key string.

We can add warning in ddb_key_to_printable_buf() for the key that is longer than DDB_MAX_PRINTABLE_KEY. Since such case (key length > 1024) is very rare and RC1 branch-time is coming soon, I prefer to do that in subsequent patch.

How do you think? @knard38

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.

4 participants