File size: 8,730 Bytes
e8c001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
-- mysql_004 database initialization: create tables + load seed data
-- Executed via: mysql -u root < init_db.sql

-- Fix: MySQL root default auth_socket blocks pymysql TCP connections,
-- switch to mysql_native_password so pymysql (Python) can connect.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123';
FLUSH PRIVILEGES;

CREATE DATABASE IF NOT EXISTS internal_platform_db
  DEFAULT CHARACTER SET utf8mb4
  DEFAULT COLLATE utf8mb4_unicode_ci;

USE internal_platform_db;

-- Input table: Ceph path coldness score data
CREATE TABLE IF NOT EXISTS t_ceph_path_coldness_score_v2_mysql_004 (
    cluster_name            VARCHAR(256) COMMENT '集群名',
    path_level              INT COMMENT '路径层级: 1/2/3/4',
    path_level2             VARCHAR(256) COMMENT '路径值',
    app_group_id            VARCHAR(256) COMMENT '应用组ID(访问侧)',
    inventory_app_group_id  VARCHAR(256) COMMENT '应用组ID(存储侧)',
    total_size              BIGINT COMMENT '总容量(字节)',
    size_tb                 DOUBLE COMMENT '总容量(TB)',
    file_count              BIGINT COMMENT '文件数量',
    dir_count               BIGINT COMMENT '目录数量',
    access_count            BIGINT COMMENT '访问次数(30天累计)',
    access_bytes            BIGINT COMMENT '访问字节数(30天累计)',
    access_days             BIGINT COMMENT '有访问的天数(0-30)',
    read_count              BIGINT COMMENT '读操作次数',
    write_count             BIGINT COMMENT '写操作次数',
    days_since_last_access  INT COMMENT '距最后访问天数',
    access_density          DOUBLE COMMENT '访问密度(次/GB)',
    access_count_score      DOUBLE COMMENT '访问次数评分(0-30)',
    active_days_score       DOUBLE COMMENT '活跃天数评分(0-15)',
    access_heat_score       DOUBLE COMMENT '访问热度总分(0-45)',
    last_access_score       DOUBLE COMMENT '最后访问时间评分(0-27)',
    last_modify_score       DOUBLE COMMENT '最后修改时间评分(0-18)',
    freshness_score         DOUBLE COMMENT '数据新鲜度总分(0-45)',
    storage_efficiency_score DOUBLE COMMENT '存储效率评分(0-10)',
    coldness_score          DOUBLE COMMENT '综合冷热评分(0-100)',
    governance_level        VARCHAR(256) COMMENT '治理等级: P0/P1/P2/P3',
    treatment               VARCHAR(256) COMMENT '治理建议',
    heat_level              VARCHAR(256) COMMENT '热度分级',
    has_access_data         VARCHAR(256) COMMENT '是否有访问数据: Y/N',
    has_inventory_data      VARCHAR(256) COMMENT '是否有容量数据: Y/N',
    dt                      VARCHAR(256) COMMENT '数据日期 yyyyMMdd'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Output table: cluster-level coldness stats
CREATE TABLE IF NOT EXISTS t_ceph_coldness_cluster_stats_v2_cand_mysql_004 (
    cluster_name        VARCHAR(256) COMMENT '集群名',
    agg_method          VARCHAR(256) COMMENT '聚合方式',
    total_path_count    BIGINT COMMENT '路径总数',
    total_size_tb       DOUBLE COMMENT '总容量(TB)',
    total_access_count  BIGINT COMMENT '总访问次数',
    avg_coldness_score  DOUBLE COMMENT '平均冷热评分',
    cluster_heat_category VARCHAR(256) COMMENT '集群热度分类',
    p0_count            BIGINT COMMENT 'P0路径数',
    p0_size_tb          DOUBLE COMMENT 'P0容量TB',
    p1_count            BIGINT COMMENT 'P1路径数',
    p1_size_tb          DOUBLE COMMENT 'P1容量TB',
    p2_count            BIGINT COMMENT 'P2路径数',
    p2_size_tb          DOUBLE COMMENT 'P2容量TB',
    p3_count            BIGINT COMMENT 'P3路径数',
    p3_size_tb          DOUBLE COMMENT 'P3容量TB',
    cold_path_pct       DOUBLE COMMENT '冷路径占比',
    cold_size_pct       DOUBLE COMMENT '冷容量占比',
    dt                  VARCHAR(256) COMMENT '数据日期'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Seed data: 12 rows covering 3 clusters, path_level 1-4, governance P0-P3
-- Includes cluster_C: a single-level path with no children (boundary case for leaf_only/max_available)
INSERT INTO t_ceph_path_coldness_score_v2_mysql_004
    (cluster_name, path_level, path_level2, app_group_id, inventory_app_group_id,
     total_size, size_tb, file_count, dir_count, access_count, access_bytes, access_days,
     read_count, write_count, days_since_last_access, access_density,
     access_count_score, active_days_score, access_heat_score,
     last_access_score, last_modify_score, freshness_score,
     storage_efficiency_score, coldness_score, governance_level, treatment,
     heat_level, has_access_data, has_inventory_data, dt)
VALUES
    -- cluster_A, level1 path /data
    ('cluster_A', 1, '/data', 'ag1', 'iag1', 1099511627776, 1.0, 100, 10, 500, 1000000, 20, 300, 200, 5, 0.5, 25.0, 10.0, 35.0, 20.0, 15.0, 35.0, 8.0, 78.0, 'P3', '保持现状', '2', 'Y', 'Y', '20260507'),
    -- cluster_A, level2 path /data/logs (has child level3 -> non-leaf)
    ('cluster_A', 2, '/data/logs', 'ag1', 'iag1', 549755813888, 0.5, 50, 5, 200, 500000, 15, 150, 50, 10, 0.4, 20.0, 8.0, 28.0, 15.0, 10.0, 25.0, 6.0, 59.0, 'P2', '观察', '3', 'Y', 'Y', '20260507'),
    -- cluster_A, level3 path /data/logs/app1 (has child level4 -> non-leaf)
    ('cluster_A', 3, '/data/logs/app1', 'ag1', 'iag1', 274877906944, 0.25, 25, 2, 100, 250000, 10, 80, 20, 15, 0.4, 15.0, 6.0, 21.0, 10.0, 8.0, 18.0, 5.0, 44.0, 'P2', '观察', '4', 'Y', 'Y', '20260507'),
    -- cluster_A, level4 path /data/logs/app1/2026 (leaf)
    ('cluster_A', 4, '/data/logs/app1/2026', 'ag1', 'iag1', 109951162777, 0.1, 10, 1, 50, 100000, 5, 40, 10, 30, 0.5, 10.0, 4.0, 14.0, 5.0, 3.0, 8.0, 3.0, 25.0, 'P1', '建议归档', '5', 'Y', 'Y', '20260507'),
    -- cluster_A, level2 path /data/backup (leaf, no deeper path)
    ('cluster_A', 2, '/data/backup', 'ag2', 'iag2', 2199023255552, 2.0, 200, 20, 10, 5000, 2, 5, 5, 90, 0.005, 2.0, 1.0, 3.0, 2.0, 1.0, 3.0, 1.0, 7.0, 'P0', '强烈建议删除', '6', 'Y', 'Y', '20260507'),
    -- cluster_B, level1 path /shared
    ('cluster_B', 1, '/shared', 'ag3', 'iag3', 3298534883328, 3.0, 300, 30, 1000, 2000000, 25, 600, 400, 3, 0.33, 28.0, 12.0, 40.0, 25.0, 17.0, 42.0, 9.0, 91.0, 'P3', '保持现状', '1', 'Y', 'Y', '20260507'),
    -- cluster_B, level2 path /shared/team1 (has child -> non-leaf)
    ('cluster_B', 2, '/shared/team1', 'ag3', 'iag3', 1649267441664, 1.5, 150, 15, 800, 1500000, 22, 500, 300, 4, 0.53, 26.0, 11.0, 37.0, 23.0, 16.0, 39.0, 8.5, 84.5, 'P3', '保持现状', '2', 'Y', 'Y', '20260507'),
    -- cluster_B, level3 path /shared/team1/proj (leaf)
    ('cluster_B', 3, '/shared/team1/proj', 'ag3', 'iag3', 549755813888, 0.5, 50, 5, 300, 600000, 18, 200, 100, 7, 0.6, 22.0, 9.0, 31.0, 18.0, 12.0, 30.0, 7.0, 68.0, 'P2', '观察', '3', 'Y', 'Y', '20260507'),
    -- cluster_B, level2 path /shared/archive (leaf, P0 cold data)
    ('cluster_B', 2, '/shared/archive', 'ag4', 'iag4', 5497558138880, 5.0, 500, 50, 5, 2000, 1, 3, 2, 120, 0.001, 1.0, 0.5, 1.5, 1.0, 0.5, 1.5, 0.5, 3.5, 'P0', '强烈建议删除', '6', 'Y', 'Y', '20260507'),
    -- cluster_B, level2 path /shared/temp (leaf, P1)
    ('cluster_B', 2, '/shared/temp', 'ag4', 'iag4', 824633720832, 0.75, 75, 8, 20, 10000, 3, 15, 5, 60, 0.027, 5.0, 2.0, 7.0, 4.0, 2.0, 6.0, 2.0, 15.0, 'P1', '建议归档', '5', 'Y', 'Y', '20260507'),
    -- cluster_C, level1 path /staging (single-level, no children -> both leaf and max_available)
    ('cluster_C', 1, '/staging', 'ag5', 'iag5', 274877906944, 0.25, 25, 2, 80, 200000, 8, 50, 30, 45, 0.8, 12.0, 5.0, 17.0, 8.0, 6.0, 14.0, 4.0, 35.0, 'P2', '观察', '4', 'Y', 'Y', '20260507'),
    -- cluster_C, level2 path /staging/tmp (leaf, P1)
    ('cluster_C', 2, '/staging/tmp', 'ag5', 'iag5', 549755813888, 0.5, 50, 5, 5, 1000, 1, 3, 2, 180, 0.002, 1.0, 0.5, 1.5, 1.0, 0.5, 1.5, 0.5, 3.5, 'P0', '强烈建议删除', '6', 'Y', 'Y', '20260507'),
    -- 正例: cluster_D, single level2 path /warm (P2), coldness=50 -> avg in [40,60) -> '较热集群' (covers the >=40 heat branch). Leaf + level2 + max_available all select it.
    ('cluster_D', 2, '/warm', 'ag6', 'iag6', 1099511627776, 1.0, 100, 10, 100, 500000, 12, 60, 40, 20, 0.2, 18.0, 7.0, 25.0, 13.0, 9.0, 22.0, 3.0, 50.0, 'P2', '观察', '4', 'Y', 'Y', '20260507'),
    -- 诱饵: cluster_D stale partition dt='20260506' (P0, coldness=99). Must be removed by the dt='20260507' filter; if the filter were dropped it would leak into cluster_D and change counts/avg.
    ('cluster_D', 2, '/warm_stale', 'ag6', 'iag6', 9895604649984, 9.0, 100, 10, 9999, 500000, 30, 600, 400, 1, 9.9, 30.0, 15.0, 45.0, 27.0, 18.0, 45.0, 9.0, 99.0, 'P0', '保持现状', '1', 'Y', 'Y', '20260506');