-
Notifications
You must be signed in to change notification settings - Fork 15
fix(Storage): fix disks view for degraded group #1930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ import React from 'react'; | |
import {Flex, useLayoutContext} from '@gravity-ui/uikit'; | ||
|
||
import {VDisk} from '../../../components/VDisk/VDisk'; | ||
import {valueIsDefined} from '../../../utils'; | ||
import type {Erasure} from '../../../types/api/storage'; | ||
import {cn} from '../../../utils/cn'; | ||
import type {PreparedVDisk} from '../../../utils/disks/types'; | ||
import {isNumeric} from '../../../utils/utils'; | ||
import {PDisk} from '../PDisk'; | ||
import type {StorageViewContext} from '../types'; | ||
import {isVdiskActive, useVDisksWithDCMargins} from '../utils'; | ||
|
@@ -19,12 +20,13 @@ const VDISKS_CONTAINER_WIDTH = 300; | |
interface DisksProps { | ||
vDisks?: PreparedVDisk[]; | ||
viewContext?: StorageViewContext; | ||
erasure?: Erasure; | ||
} | ||
|
||
export function Disks({vDisks = [], viewContext}: DisksProps) { | ||
export function Disks({vDisks = [], viewContext, erasure}: DisksProps) { | ||
const [highlightedVDisk, setHighlightedVDisk] = React.useState<string | undefined>(); | ||
|
||
const vDisksWithDCMargins = useVDisksWithDCMargins(vDisks); | ||
const vDisksWithDCMargins = useVDisksWithDCMargins(vDisks, erasure); | ||
|
||
const { | ||
theme: {spaceBaseSize}, | ||
|
@@ -40,9 +42,9 @@ export function Disks({vDisks = [], viewContext}: DisksProps) { | |
return ( | ||
<div className={b(null)}> | ||
<Flex direction={'row'} gap={1} grow style={{width: VDISKS_CONTAINER_WIDTH}}> | ||
{vDisks?.map((vDisk) => ( | ||
{vDisks?.map((vDisk, index) => ( | ||
<VDiskItem | ||
key={vDisk.StringifiedId} | ||
key={vDisk.StringifiedId || index} | ||
vDisk={vDisk} | ||
inactive={!isVdiskActive(vDisk, viewContext)} | ||
highlightedVDisk={highlightedVDisk} | ||
|
@@ -55,7 +57,7 @@ export function Disks({vDisks = [], viewContext}: DisksProps) { | |
<div className={b('pdisks-wrapper')}> | ||
{vDisks?.map((vDisk, index) => ( | ||
<PDiskItem | ||
key={vDisk?.PDisk?.StringifiedId} | ||
key={vDisk?.PDisk?.StringifiedId || index} | ||
vDisk={vDisk} | ||
highlightedVDisk={highlightedVDisk} | ||
setHighlightedVDisk={setHighlightedVDisk} | ||
|
@@ -89,7 +91,7 @@ function VDiskItem({ | |
const vDiskId = vDisk.StringifiedId; | ||
|
||
// show vdisks without AllocatedSize as having average width (#1433) | ||
const minWidth = valueIsDefined(vDiskToShow.AllocatedSize) ? undefined : unavailableVDiskWidth; | ||
const minWidth = isNumeric(vDiskToShow.AllocatedSize) ? undefined : unavailableVDiskWidth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AllocatedSize could be numeric or |
||
const flexGrow = Number(vDiskToShow.AllocatedSize) || 1; | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React from 'react'; | |
|
||
import {selectNodesMap} from '../../../store/reducers/nodesList'; | ||
import type {PreparedStorageGroup} from '../../../store/reducers/storage/types'; | ||
import type {Erasure} from '../../../types/api/storage'; | ||
import {valueIsDefined} from '../../../utils'; | ||
import type {PreparedVDisk} from '../../../utils/disks/types'; | ||
import {generateEvaluator} from '../../../utils/generateEvaluator'; | ||
|
@@ -84,12 +85,22 @@ export function getStorageGroupsInitialEntitiesCount( | |
return DEFAULT_ENTITIES_COUNT; | ||
} | ||
|
||
export function useVDisksWithDCMargins(vDisks: PreparedVDisk[] = []) { | ||
function isErasureWithDifferentDC(erasure?: Erasure) { | ||
// These erasure types suppose the data distributed across 3 different DC | ||
return erasure === 'mirror-3-dc' || erasure === 'mirror-3of4'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do these magic constant strings mean? comment would be nice (and may be move to actual constants) |
||
} | ||
|
||
export function useVDisksWithDCMargins(vDisks: PreparedVDisk[] = [], erasure?: Erasure) { | ||
const nodesMap = useTypedSelector(selectNodesMap); | ||
|
||
return React.useMemo(() => { | ||
const disksWithMargins: number[] = []; | ||
|
||
// If single-dc erasure, all disks are in the same DC | ||
if (!isErasureWithDifferentDC(erasure)) { | ||
return disksWithMargins; | ||
} | ||
|
||
// Backend returns disks sorted by DC, so we don't need to apply any additional sorting | ||
vDisks.forEach((disk, index) => { | ||
const dc1 = nodesMap?.get(Number(disk?.NodeId))?.DC; | ||
|
@@ -101,5 +112,5 @@ export function useVDisksWithDCMargins(vDisks: PreparedVDisk[] = []) { | |
}); | ||
|
||
return disksWithMargins; | ||
}, [vDisks, nodesMap]); | ||
}, [erasure, vDisks, nodesMap]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,7 @@ export function prepareGroupsVDisk(data: TStorageVDisk = {}): PreparedVDisk { | |
VDiskId: whiteboardVDisk.VDiskId, | ||
}; | ||
|
||
const preparedPDisk = PDisk | ||
? prepareGroupsPDisk({...PDisk, NodeId: mergedVDiskData.NodeId}) | ||
: undefined; | ||
const preparedPDisk = prepareGroupsPDisk({...PDisk, NodeId: mergedVDiskData.NodeId}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add empty PDisk object even if there is no PDisk field |
||
|
||
const PDiskId = preparedPDisk?.PDiskId ?? whiteboardVDisk?.PDiskId; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ export type TStorageGroupInfo = TBSGroupStateInfo & | |
|
||
interface TBSGroupStateInfo { | ||
GroupID?: number; | ||
ErasureSpecies?: string; | ||
ErasureSpecies?: Erasure; | ||
VDisks?: TVDiskStateInfo[]; | ||
/** uint64 */ | ||
ChangeTime?: string; | ||
|
@@ -137,7 +137,7 @@ export interface TGroupsStorageGroupInfo { | |
DiskSpace?: EFlag; | ||
Kind?: string; | ||
MediaType?: string; | ||
ErasureSpecies?: string; | ||
ErasureSpecies?: Erasure; | ||
/** uint64 */ | ||
AllocationUnits?: string; | ||
/** | ||
|
@@ -228,6 +228,11 @@ export interface TStoragePDisk { | |
Whiteboard?: TPDiskStateInfo; | ||
} | ||
|
||
/** | ||
* https://ydb.tech/docs/en/concepts/topology#cluster-config | ||
*/ | ||
export type Erasure = 'none' | 'block-4-2' | 'mirror-3-dc' | 'mirror-3of4'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe enum and use it in isErasureWithDifferentDC ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like enums, you have to import them everywhere to satisfy TS, while for union string types every option will be suggested by autocomplete |
||
|
||
// ==== Request types ==== | ||
|
||
export type EVersion = 'v1' | 'v2'; // only v2 versions works with sorting | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be no proper id, use
index
in such case. Array index will be always different from pdisk and vdisk ids, since ids include several numbers joined by dash (e.g. "1-1001")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in which cases there may be no StringifiedId and why cant we always use index
I dont mean to rework anything - I just dont understand (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.