Skip to content

Commit

Permalink
defrag: defrag both patricia key and variable size columns
Browse files Browse the repository at this point in the history
GitHub: groongaGH-2168

Ensure defragmentation covers both keys and variable-size columns
in Patricia trees

Previously, the defragmentation process for Patricia trees only
targeted the keys, leaving variable-size columns untouched. This
change handles both the keys and the variable-size columns.
  • Loading branch information
otegami committed Jan 12, 2025
1 parent 468bd5d commit 4debe49
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -14872,7 +14872,7 @@ grn_obj_defrag(grn_ctx *ctx, grn_obj *obj, int threshold)
case GRN_TABLE_PAT_KEY:
GRN_TABLE_LOCK_BEGIN(ctx, obj) { r = grn_pat_defrag(ctx, (grn_pat *)obj); }
GRN_TABLE_LOCK_END(ctx);
break;
/* FALLTHROUGH */
case GRN_TABLE_HASH_KEY:
case GRN_TABLE_DAT_KEY:
case GRN_TABLE_NO_KEY:
Expand Down
101 changes: 101 additions & 0 deletions test/command/suite/defrag/combined/pat_and_var_size_column.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
table_create --name Users --flags TABLE_PAT_KEY --key_type ShortText
[[0,0.0,0.0],true]
column_create Users secret COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
delete Users --filter '_id == 2'
[[0,0.0,0.0],true]
object_inspect Users
[
[
0,
0.0,
0.0
],
{
"id": 256,
"name": "Users",
"type": {
"id": 49,
"name": "table:pat_key"
},
"key": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
},
"total_size": 36,
"max_total_size": 4294967294
},
"value": {
"type": null
},
"n_records": 3,
"disk_usage": 0
}
]
defrag Users
[[0,0.0,0.0],true]
#|w| segment_infos[1] = 2097160 after defrag
object_inspect Users
[
[
0,
0.0,
0.0
],
{
"id": 256,
"name": "Users",
"type": {
"id": 49,
"name": "table:pat_key"
},
"key": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
},
"total_size": 27,
"max_total_size": 4294967294
},
"value": {
"type": null
},
"n_records": 3,
"disk_usage": 0
}
]
check Users
[
[
0,
0.0,
0.0
],
[
{
"flags": "0000C001",
"key size": 4096,
"value_size": 0,
"tokenizer": 0,
"normalizer": 0,
"n_entries": 3,
"curr_rec": 4,
"curr_key": 27,
"curr_del": 1,
"curr_del2": 0,
"curr_del3": 0,
"n_garbages": 1
}
]
]
22 changes: 22 additions & 0 deletions test/command/suite/defrag/combined/pat_and_var_size_column.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is too slow with HTTP chunked.
#@require-interface stdio

table_create --name Users --flags TABLE_PAT_KEY --key_type ShortText
column_create Users secret COLUMN_SCALAR ShortText

# The 'secret' column stores large strings over 65536B, whicha are `SEQUENTIAL`
# elements and stored in `SEQUENTIAL` segments. These segments will be
# defragmentation targets.
#@disable-logging
#@generate-series 1 4 Users '{"_key" => "user-no-#{i}", "secret" => "#{"x" * (2 ** 20)}"}'
#@enable-logging

delete Users --filter '_id == 2'

# After defragmentation, the total size of the PAT keys should decrease.
# Additionally, defragmentation logs for the variable-size column should be
# displayed.
object_inspect Users
defrag Users
object_inspect Users
check Users

0 comments on commit 4debe49

Please sign in to comment.