Commit 0945d28
[fix,refactor] Complete columnar metadata refactor for manager→controller path
Co-authored-by: 看我72遍<m.pb@msn.com>
# message auto-generated for no-merge-commit merge:
!29 merge refactor/columnar-field-schema into main
[fix,refactor] Complete columnar metadata refactor for manager→controller path
Created-by: mpb159753
Commit-by: 看我72遍
Merged-by: ascend-robot
Description: # Columnar FieldSchema + Unified Controller Metadata
## 1. Context & Motivation
Follows: [Ascend#28 — Columnar BatchMeta + Zero-Copy Default](https://gitcode.com/Ascend/TransferQueue/pull/28)
PR Ascend#39 converted `BatchMeta` from row-oriented to columnar layout, but two O(B×F) bottlenecks remained on the **Manager → Controller** path:
1. **`notify_data_update` payload**: The Manager expanded columnar `field_schema` back into per-sample dicts (`dtypes: {global_index: {field: dtype}}`, `shapes: {global_index: {field: shape}}`), transmitting O(B×F) data over ZMQ for information that is inherently O(F).
2. **Controller metadata storage**: `DataPartitionStatus` maintained three separate stores (`field_dtypes`, `field_shapes`, `field_schema_cache`) with redundant per-sample indexing, requiring multi-pass reconciliation logic to detect nested tensors.
This PR completes the columnar refactoring by:
- Transmitting `field_schema` directly as O(F) columnar data (no per-sample expansion)
- Introducing `FieldColumnMeta` as the **single source of truth** for per-field metadata in the Controller
- Adding `RoutingGroup` to carry batch positions alongside global indexes, eliminating intermediate mapping
- Extracting `_pack_field_values` as a reusable static method with defensive checks
## 2. Key Changes
### 2.1 Columnar `notify_data_update` Protocol (`base.py`, `simple_backend_manager.py`)
**Before** (O(B×F) expansion in Manager):
```python
dtypes_for_notify = {
global_index: {field_name: field_meta.get("dtype") for field_name, field_meta in field_schema.items()}
for global_index in metadata.global_indexes
}
shapes_for_notify = { ... } # same pattern
await self.notify_data_update(partition_id, field_names, global_indexes, dtypes_for_notify, shapes_for_notify)
```
**After** (O(F) — pass through as-is):
```python
await self.notify_data_update(partition_id, global_indexes, field_schema)
```
- Removed `fields`, `dtypes`, `shapes` parameters
- `field_schema` is already columnar from `metadata.py` — no expansion needed
- KV path (`base.py`) similarly simplified, removing 25-line per-sample expansion loop
### 2.2 `FieldColumnMeta` Dataclass (`controller.py`)
Replaces three separate stores (`field_dtypes`, `field_shapes`, `field_schema_cache`) with a single `@dataclass`:
```python
@DataClass
class FieldColumnMeta:
dtype: Any = None
shape: Optional[tuple] = None
is_nested: bool = False
is_non_tensor: bool = False
per_sample_shapes: dict[int, tuple] = field(default_factory=dict)
```
- Field-level attributes are O(1) — shared across all samples
- Sample-level shapes only stored for nested tensors — O(B_nested) not O(B)
- `to_batch_schema()` generates `BatchMeta`-compatible dicts on demand
- `remove_samples()` cleans up released indexes
### 2.3 `RoutingGroup` NamedTuple (`simple_backend_manager.py`)
```python
class RoutingGroup(NamedTuple):
global_indexes: list[int]
batch_positions: list[int]
```
- `_group_by_hash` now returns `dict[str, RoutingGroup]` instead of `dict[str, list[int]]`
- Carries both global indexes and batch positions, eliminating the intermediate `global_idx → position` mapping in `get_data`
- GET merge logic simplified: scatter results directly to batch positions without building per-sample dicts
### 2.4 `_pack_field_values` Extraction (`simple_backend_manager.py`)
Extracted inline packing logic into a reusable `@staticmethod` with explicit error handling:
- Validates non-empty input and absence of `None` values
- Handles regular tensors (`torch.stack`), nested tensors (`torch.nested.as_nested_tensor`), and non-tensors (`NonTensorStack`)
### 2.5 Simplified Controller API
- `update_production_status`: Removed `field_names` and `dtypes`/`shapes` parameters; `field_names` derived from `field_schema.keys()`
- `get_field_schema`: Delegates to `FieldColumnMeta.to_batch_schema()` instead of building from cache
- Removed `get_field_dtype` and `get_field_shape` helper methods (no longer needed)
### 2.6 Test Suite
- All test files updated to match new `notify_data_update` and `update_production_status` signatures
- `test_controller_data_partitions.py`: Tests adapted for `FieldColumnMeta`-based schema storage
## 3. Benchmark Results
Tests conducted in Docker (single-node Ray) across 7 payload sizes (0.05 MB → 25.4 GB). Three configurations compared:
- **pre-refactor**: Baseline (row-oriented, before PR Ascend#39)
- **columnar-batch-meta**: After PR Ascend#39 (columnar BatchMeta + zero-copy)
- **columnar-field-schema**: This PR (columnar notify + FieldColumnMeta + RoutingGroup)
### Speedup (relative to pre-refactor baseline)


| Data Scale | PUT Speedup (vs baseline) | PUT Speedup (vs PR Ascend#39) | GET Speedup (vs baseline) | GET Speedup (vs PR Ascend#39) |
|------------|:------------------------:|:-----------------------:|:------------------------:|:-----------------------:|
| debug (0.05 MB) | **1.4×** | +12% | **1.5×** | +16% |
| tiny (1.5 MB) | **1.8×** | +19% | **2.1×** | +13% |
| small (0.15 GB) | **5.1×** | +20% | **3.4×** | ≈0% |
| medium (1.5 GB) | **5.8×** | +7% | **2.2×** | −1% |
| large (6.3 GB) | **5.6×** | +8% | **2.0×** | −4% |
| xlarge (12.7 GB) | **5.5×** | +8% | **2.2×** | +1% |
| huge (25.4 GB) | **5.4×** | +6% | **2.2×** | +1% |
### Absolute Bandwidth


| Data Scale | Pre-Refactor | Columnar BatchMeta (PR Ascend#39) | Columnar FieldSchema (This PR) |
|------------|:-----------:|:---------------------------:|:------------------------------:|
| **PUT** medium | 3.95 Gbps | 21.29 Gbps | **22.84 Gbps** |
| **PUT** large | 5.04 Gbps | 26.14 Gbps | **28.18 Gbps** |
| **PUT** huge | 5.09 Gbps | 26.05 Gbps | **27.49 Gbps** |
| **GET** medium | 4.24 Gbps | 9.50 Gbps | **9.39 Gbps** |
| **GET** large | 4.98 Gbps | 10.51 Gbps | **10.14 Gbps** |
| **GET** huge | 4.86 Gbps | 10.46 Gbps | **10.53 Gbps** |
### Summary
- **PUT path** benefits most: +6% to +20% over PR Ascend#39 across all scales, consistent 5×+ improvement over pre-refactor baseline at medium+ scales
- **GET path** maintains parity with PR Ascend#39 — improvements are within noise margin; the GET bottleneck is in ZMQ transport, not metadata
- Small payloads see the largest relative improvement, confirming the metadata overhead reduction
### Resource Usage
Memory usage is comparable or slightly reduced (eliminated per-sample `field_dtypes`/`field_shapes` dicts in Controller).
## 4. API Breaking Changes
- `notify_data_update()`: Removed `fields`, `dtypes`, `shapes` parameters; replaced with single `field_schema` dict
- `update_production_status()`: Removed `field_names`, `dtypes`, `shapes` parameters; replaced with single `field_schema` dict; `field_names` derived from `field_schema.keys()`
- `get_field_dtype()` / `get_field_shape()`: Removed (replaced by `FieldColumnMeta`)
- `_group_by_hash()`: Now returns `dict[str, RoutingGroup]` instead of `dict[str, list[int]]`
## 5. Files Changed
```
7 files changed, 451 insertions(+), 440 deletions(-)
```
| File | Description |
|------|-------------|
| `controller.py` | `FieldColumnMeta` dataclass; simplified `update_production_status` / `get_field_schema`; removed `get_field_dtype`/`get_field_shape` |
| `simple_backend_manager.py` | `RoutingGroup`; `_pack_field_values`; position-based GET merge; columnar `notify_data_update` |
| `base.py` | Columnar `notify_data_update` protocol; simplified KV path |
| `test_controller.py` | Adapted to new API signatures |
| `test_controller_data_partitions.py` | Adapted to `FieldColumnMeta`-based schema |
| `test_async_simple_storage_manager.py` | Adapted to `RoutingGroup` and new notify protocol |
| `test_kv_storage_manager.py` | Minor signature update |
## 6. Conclusion
This PR completes the second phase of columnar refactoring by eliminating the remaining O(B×F) metadata expansion in the Manager→Controller path and unifying metadata storage in the Controller:
- **PUT throughput**: Up to 5.8× over pre-refactor baseline, +6–20% over PR Ascend#39
- **GET throughput**: Up to 3.4× over pre-refactor baseline, parity with PR Ascend#39
- **Code clarity**: Three separate metadata stores → one `FieldColumnMeta` dataclass; per-sample expansion loops eliminated
- **Net change**: +451 / −440 lines across 7 files
> **Note on GET path**: The GET path performance improvement from metadata-level refactoring has reached diminishing returns — the minor fluctuations (±1–4%) observed in benchmarks are within normal measurement noise. Further GET throughput gains would likely require a deeper architectural change: fully columnarizing the GET data flow itself (e.g., columnar storage layout in StorageUnit, field-level parallel retrieval), rather than continuing to optimize the metadata layer.
See merge request: Ascend/TransferQueue!291 parent 6ad4d07 commit 0945d28
9 files changed
Lines changed: 688 additions & 497 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| 117 | + | |
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
| |||
127 | 130 | | |
128 | 131 | | |
129 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
130 | 136 | | |
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
136 | 142 | | |
| 143 | + | |
137 | 144 | | |
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
| 150 | + | |
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
| |||
300 | 308 | | |
301 | 309 | | |
302 | 310 | | |
| 311 | + | |
303 | 312 | | |
304 | 313 | | |
305 | 314 | | |
| |||
318 | 327 | | |
319 | 328 | | |
320 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
321 | 340 | | |
322 | 341 | | |
323 | 342 | | |
| |||
430 | 449 | | |
431 | 450 | | |
432 | 451 | | |
433 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
434 | 458 | | |
435 | 459 | | |
436 | 460 | | |
| |||
702 | 726 | | |
703 | 727 | | |
704 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
705 | 827 | | |
706 | 828 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | | - | |
| 383 | + | |
| 384 | + | |
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
393 | | - | |
| 392 | + | |
| 393 | + | |
394 | 394 | | |
395 | | - | |
396 | | - | |
| 395 | + | |
| 396 | + | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
403 | 409 | | |
404 | 410 | | |
405 | 411 | | |
| |||
439 | 445 | | |
440 | 446 | | |
441 | 447 | | |
442 | | - | |
443 | | - | |
| 448 | + | |
| 449 | + | |
444 | 450 | | |
445 | 451 | | |
446 | 452 | | |
447 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
0 commit comments