| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <script setup lang="ts">
- import { computed, shallowRef } from 'vue';
- import service from '/@/utils/request';
- type ApiInteger = number | string;
- interface CapacityResult {
- sample: {
- estimate: {
- sourceRows: ApiInteger | null;
- sourceRowsBasis: 'sample' | 'catalog' | 'sample-floor' | 'unknown';
- sampleRows: number;
- sampleBatches: number;
- sampleRawBytes: ApiInteger;
- rawBytesPerRow: number | null;
- fullRawBytes: ApiInteger | null;
- fullSecondsLow: number | null;
- fullSecondsHigh: number | null;
- };
- isolatedRows: number;
- setupMs: number;
- sourceMs: number;
- rawMs: number;
- cleanMs: number;
- handoffMs: number;
- reconcileMs: number;
- };
- history: {
- increments: { recordedDays: number; dailyIncrementRows: number | null };
- full: { sourceRows: ApiInteger; pageCount: number; completedUtc: string; elapsedMs: number } | null;
- rawBytes?: ApiInteger | null;
- rawToCleanMs?: number | null;
- } | null;
- }
- const props = defineProps<{ endpoint: string; factoryId: string; active: boolean }>();
- const busy = shallowRef(false);
- const result = shallowRef<CapacityResult>();
- const retentionDays = shallowRef<number | undefined>(30);
- const dailyOverride = shallowRef<number>();
- const historicalDaily = computed(() => {
- const increments = result.value?.history?.increments;
- return increments && increments.recordedDays >= 2 ? increments.dailyIncrementRows : null;
- });
- const forecast = computed(() => {
- const estimate = result.value?.sample.estimate;
- const dailyRows = dailyOverride.value ?? historicalDaily.value;
- const days = retentionDays.value;
- if (!estimate?.sampleRows || dailyRows == null || !days) return null;
- const perRow = Number(estimate.sampleRawBytes) / estimate.sampleRows;
- const daily = Math.ceil(perRow * dailyRows);
- const incremental = Math.ceil(perRow * dailyRows * days);
- const total = estimate.fullRawBytes == null ? null : Number(estimate.fullRawBytes) + incremental;
- return { daily, incremental, total };
- });
- const number = new Intl.NumberFormat('zh-CN', { maximumFractionDigits: 3 });
- const amount = (value: ApiInteger | null | undefined) => value == null ? '待估算' : number.format(Number(value));
- const bytes = (value: ApiInteger | null | undefined) => {
- if (value == null) return '待估算';
- const units = ['字节', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
- let size = Number(value);
- let index = 0;
- while (size >= 1024 && index < units.length - 1) {
- size /= 1024;
- index++;
- }
- return `${number.format(size)} ${units[index]}`;
- };
- const elapsed = (value: number | null | undefined) => value == null ? '未记录' : `${number.format(value)} 毫秒`;
- const rowCountBasis = {
- sample: '本次已读到来源末尾,采用本次读取行数',
- catalog: '行数采用源目录统计',
- 'sample-floor': '源目录低于已读行数,当前以样本行数为估算下限',
- unknown: '源目录没有行数统计',
- };
- const forecastTime = computed(() => {
- const estimate = result.value?.sample.estimate;
- const low = estimate?.fullSecondsLow;
- const high = estimate?.fullSecondsHigh;
- if (low == null || high == null) return '待估算';
- return low === high ? `约 ${amount(low)} 秒` : `${amount(low)}–${amount(high)} 秒`;
- });
- async function measure() {
- if (!props.active || busy.value) return;
- busy.value = true;
- try {
- const response = await service.post<CapacityResult>(props.endpoint, {}, {
- params: { factoryId: props.factoryId },
- timeout: 40000,
- });
- result.value = response.data;
- } finally {
- busy.value = false;
- }
- }
- </script>
- <template>
- <section class="relational-capacity">
- <h4>同步耗时和保留容量</h4>
- <el-button :loading="busy" :disabled="!active" @click="measure">运行隔离测算</el-button>
- <p v-if="!active">启用已审批的来源版本后可以运行测算。</p>
- <div v-if="result" role="status">
- <p>样本 {{ result.sample.estimate.sampleRows }} 行 · {{ result.sample.estimate.sampleBatches }} 批 · Raw {{ bytes(result.sample.estimate.sampleRawBytes) }} · 隔离 {{ result.sample.isolatedRows }} 行</p>
- <p v-if="!result.sample.estimate.sampleRows">来源没有可用样本,耗时及每行容量待估算。</p>
- <p v-else-if="result.sample.estimate.sourceRows == null">源目录没有行数统计,首次全量待估算。</p>
- <p v-if="result.sample.isolatedRows">样本出现隔离。请复核来源字段和映射,再用于投产评估。</p>
- <template v-if="result.sample.estimate.sampleRows">
- <p>沙箱准备 {{ elapsed(result.sample.setupMs) }} · 源库读取 {{ elapsed(result.sample.sourceMs) }} · Raw 入库 {{ elapsed(result.sample.rawMs) }}</p>
- <p>清洗 {{ elapsed(result.sample.cleanMs) }} · 贴源及标准层 {{ elapsed(result.sample.handoffMs) }} · 对账 {{ elapsed(result.sample.reconcileMs) }}</p>
- </template>
- <p>首次全量预计 {{ amount(result.sample.estimate.sourceRows) }} 行 · {{ forecastTime }} · Raw {{ bytes(result.sample.estimate.fullRawBytes) }}</p>
- <p v-if="result.sample.estimate.sampleRows">{{ rowCountBasis[result.sample.estimate.sourceRowsBasis] }}。每行 Raw {{ bytes(result.sample.estimate.rawBytesPerRow) }},耗时按样本批次速度推算。队列等待见实际运行。</p>
- <div class="capacity-inputs">
- <label>保留天数 <el-input-number v-model="retentionDays" :min="1" :max="3650" :precision="0" aria-label="保留天数" /></label>
- <label>日均增量假设 <el-input-number v-model="dailyOverride" :min="0" :max="1000000000" :precision="0" placeholder="沿用历史" aria-label="日均增量假设" /></label>
- </div>
- <p v-if="dailyOverride != null">使用手填假设,每日 {{ amount(dailyOverride) }} 行。</p>
- <p v-else-if="historicalDaily != null">取近 14 天内 {{ result.history?.increments.recordedDays }} 个有对账记录的完整 UTC 日,日均 {{ amount(historicalDaily) }} 行,含增量窗口的重叠数据。</p>
- <p v-else>日均增量待估算。历史记录不足时可填写假设值。</p>
- <p>每日 Raw {{ bytes(forecast?.daily) }} · 保留期增量 Raw {{ bytes(forecast?.incremental) }} · 含首次全量 {{ bytes(forecast?.total) }}</p>
- <p>容量按 Raw 原文计算,索引及贴源、标准层各自占用空间。</p>
- <template v-if="result.history?.full">
- <p>最近一次已对账全量 {{ result.history.full.sourceRows }} 行 · {{ result.history.full.pageCount }} 批 · Raw {{ bytes(result.history.rawBytes) }}</p>
- <p>实际全程 {{ elapsed(result.history.full.elapsedMs) }},含排队和对账等待。每批 Raw 入库至清洗完成平均 {{ elapsed(result.history.rawToCleanMs) }},含 Worker 排队。</p>
- </template>
- <p v-else>当前配置暂无已对账全量可供比较。</p>
- </div>
- </section>
- </template>
- <style scoped>
- .relational-capacity { margin: 14px 0; }
- .capacity-inputs { display: flex; flex-wrap: wrap; gap: 12px 20px; }
- .capacity-inputs label { display: inline-flex; align-items: center; gap: 8px; }
- </style>
|