Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Capacity Page', () => {
expect(datanodeCard).toHaveTextContent(/FREE SPACE\s*3\s*KB/i);
});

test('clamps pendingBlockSize to 0 when selected datanode reports -1 (offline/unreachable)', async () => {
test('shows error card instead of outdated data when default-selected datanode reports -1 (offline/unreachable)', async () => {
capacityServer.use(
rest.get('api/v1/pendingDeletion', (req, res, ctx) => {
const component = req.url.searchParams.get('component');
Expand Down Expand Up @@ -130,13 +130,15 @@ describe('Capacity Page', () => {
if (!datanodeCard) {
return;
}
// dn-1 is selected by default; its pendingBlockSize is -1 (offline sentinel).
// PENDING DELETION should show 0 B, not a negative value.
// dn-1 is selected by default; its pendingBlockSize is -1 (offline sentinel), so the
// datanode is unavailable and its capacity data may be outdated. Show an error card for
// USED SPACE and FREE SPACE instead of the stale storage-report values.
expect(await screen.findByTestId('dn-used-space-error')).toBeInTheDocument();
expect(await screen.findByTestId('dn-free-space-error')).toBeInTheDocument();
await waitFor(() =>
expect(datanodeCard).toHaveTextContent(/PENDING DELETION\s*0\s*B/i)
expect(datanodeCard).toHaveTextContent(/USED SPACE\s*N\/A/i)
);
// USED SPACE = used (4096) + clamped pendingBlockSize (0) = 4 KB
expect(datanodeCard).toHaveTextContent(/USED SPACE\s*4\s*KB/i);
expect(datanodeCard).toHaveTextContent(/FREE SPACE\s*N\/A/i);
});

test('shows scm-only error state when SCM pending deletion returns sentinel failure values', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ const Capacity: React.FC<object> = () => {

const autoReload = useAutoReload(loadDataIfIdle);

const selectedDNDetails: DataNodeUsage & { pendingBlockSize: number } = React.useMemo(() => {
const selectedDNDetails: DataNodeUsage & {
pendingBlockSize: number;
unavailable: boolean;
} = React.useMemo(() => {
const selected = storageDistribution.data.dataNodeUsage.find(datanode => datanode.hostName === selectedDatanode)
?? storageDistribution.data.dataNodeUsage[0];
const dnPendingEntry = dnPendingDeletes.data.pendingDeletionPerDataNode?.find(
Expand All @@ -151,7 +154,10 @@ const Capacity: React.FC<object> = () => {
reserved: 0
}),
...dnPendingEntry,
pendingBlockSize: Math.max(0, dnPendingEntry.pendingBlockSize)
pendingBlockSize: Math.max(0, dnPendingEntry.pendingBlockSize),
// -1 is the sentinel for a DN whose pending deletion query failed (offline/unreachable).
// Its capacity data from the storage report may be outdated, so surface an error instead.
unavailable: dnPendingEntry.pendingBlockSize === -1
}
}, [selectedDatanode, storageDistribution.data.dataNodeUsage, dnPendingDeletes.data.pendingDeletionPerDataNode]);

Expand Down Expand Up @@ -472,6 +478,9 @@ const Capacity: React.FC<object> = () => {
dataDetails={[{
title: 'USED SPACE',
size: (selectedDNDetails.used ?? 0) + (selectedDNDetails.pendingBlockSize ?? 0),
hasError: selectedDNDetails.unavailable,
errorMessage: 'Datanode is unavailable; capacity data may be outdated.',
errorTestId: 'dn-used-space-error',
breakdown: [{
label: 'PENDING DELETION',
value: selectedDNDetails.pendingBlockSize ?? 0,
Expand All @@ -484,6 +493,9 @@ const Capacity: React.FC<object> = () => {
}, {
title: 'FREE SPACE',
size: (selectedDNDetails.remaining ?? 0) + (selectedDNDetails.committed ?? 0),
hasError: selectedDNDetails.unavailable,
errorMessage: 'Datanode is unavailable; capacity data may be outdated.',
errorTestId: 'dn-free-space-error',
breakdown: [{
label: unusedSpaceBreakdown,
value: selectedDNDetails.remaining ?? 0,
Expand Down
Loading