Orginize
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Live Hyperdrive / core length hints for `/proc/bare_os/replication` and
|
||||
* `metrics_live.replicationLive` (non-secret progress; not full per-peer throughput).
|
||||
*
|
||||
* @param {{ drive?: unknown, personalDrive?: unknown } | null | undefined} disk
|
||||
* @param {number} peerCount
|
||||
*/
|
||||
export function buildBareOsReplicationLiveSketch(disk, peerCount) {
|
||||
let systemCoreLength = null
|
||||
let personalCoreLength = null
|
||||
try {
|
||||
const c =
|
||||
disk &&
|
||||
disk.drive &&
|
||||
/** @type {{ core?: { length?: number } }} */ (disk.drive).core
|
||||
if (c && typeof c.length === 'number') systemCoreLength = c.length
|
||||
} catch {
|
||||
systemCoreLength = null
|
||||
}
|
||||
try {
|
||||
const c =
|
||||
disk &&
|
||||
disk.personalDrive &&
|
||||
/** @type {{ core?: { length?: number } }} */ (disk.personalDrive).core
|
||||
if (c && typeof c.length === 'number') personalCoreLength = c.length
|
||||
} catch {
|
||||
personalCoreLength = null
|
||||
}
|
||||
let auxiliaryDriveCount = 0
|
||||
try {
|
||||
if (disk && Array.isArray(disk.auxiliaryDrives))
|
||||
auxiliaryDriveCount = disk.auxiliaryDrives.length
|
||||
} catch {
|
||||
auxiliaryDriveCount = 0
|
||||
}
|
||||
const stallHint =
|
||||
peerCount === 0
|
||||
? 'no_peers'
|
||||
: systemCoreLength == null
|
||||
? 'length_unavailable'
|
||||
: 'ok'
|
||||
/** @type {{ schema: number, download?: number, upload?: number, peers?: number, source?: string } | null} */
|
||||
let monitorProgress = null
|
||||
try {
|
||||
const m = disk && disk.drive && typeof disk.drive.monitor === 'function'
|
||||
? disk.drive.monitor()
|
||||
: null
|
||||
if (m && typeof m === 'object') {
|
||||
const dl =
|
||||
typeof m.downloadedBlocks === 'number'
|
||||
? m.downloadedBlocks
|
||||
: typeof m.download === 'number'
|
||||
? m.download
|
||||
: null
|
||||
const ul =
|
||||
typeof m.uploadedBlocks === 'number'
|
||||
? m.uploadedBlocks
|
||||
: typeof m.upload === 'number'
|
||||
? m.upload
|
||||
: null
|
||||
const peers = typeof m.peers === 'number' ? m.peers : null
|
||||
if (dl != null || ul != null || peers != null) {
|
||||
monitorProgress = {
|
||||
schema: 1,
|
||||
...(dl != null ? { download: dl } : {}),
|
||||
...(ul != null ? { upload: ul } : {}),
|
||||
...(peers != null ? { peers } : {}),
|
||||
source: 'hyperdrive.monitor'
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
monitorProgress = null
|
||||
}
|
||||
return {
|
||||
schema: 4,
|
||||
systemCoreLength,
|
||||
personalCoreLength,
|
||||
auxiliaryDriveCount,
|
||||
stallHint,
|
||||
...(monitorProgress ? { monitorProgress } : {}),
|
||||
corestoreSnapshotSurface: {
|
||||
schema: 1,
|
||||
operatorWorkflow:
|
||||
'Pause or quiesce writers → replicate cores → export snapshot (corestore-snapshot style). Guest **`guestSuspendResume`** remains **ENOTSUP** unless the host registers Corestore suspend/resume hooks.',
|
||||
readOnly: true
|
||||
},
|
||||
note: 'Schema 4 keeps schema 3 fields and optionally exposes monitorProgress when Hyperdrive monitor() returns counters (download/upload/peers).'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user