Files
ulthon_admin/database/migrations/20260814100005_xhprof_log_position.php

32 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use think\migration\Migrator;
/**
* XHProf 性能日志 - 文件读取位置表
*
* 记录每个 runs-*.jsonl 文件的 inode/offset/最近读取时间/失败计数等增量读取状态。
* 唯一键 uniq_node_file(node_id, file_path):多节点导各自文件互不覆盖。
*/
class XhprofLogPosition extends Migrator
{
public function change()
{
$table = $this->table('xhprof_log_position', ['id' => false, 'primary_key' => ['id']])
->setComment('XHProf 日志文件读取位置(增量读取状态)')
->addColumn('id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID'])
->addColumn('node_id', 'string', ['limit' => 64, 'null' => false, 'default' => '', 'comment' => '节点ID区分不同采集节点'])
->addColumn('file_path', 'string', ['limit' => 500, 'null' => false, 'comment' => '日志文件绝对路径'])
->addColumn('inode', 'biginteger', ['default' => 0, 'comment' => '文件 inode用于检测日志轮转', 'signed' => false])
->addColumn('offset', 'biginteger', ['default' => 0, 'comment' => '上次读取到的字节偏移', 'signed' => false])
->addColumn('last_read_time', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '上次读取时间戳', 'signed' => false])
->addColumn('last_line_hash', 'string', ['limit' => 32, 'default' => '', 'comment' => '上次最后一行的 md5 哈希(容错校验)'])
->addColumn('parse_fail_count', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '解析失败累计次数', 'signed' => false])
->addColumn('parse_fail_samples', 'text', ['null' => true, 'comment' => '解析失败样本行(最多保留若干条)'])
->addColumn('create_time', 'integer', ['limit' => 11, 'comment' => '创建时间戳', 'signed' => false])
->addColumn('update_time', 'integer', ['limit' => 11, 'comment' => '更新时间戳', 'signed' => false])
->addIndex(['node_id', 'file_path'], ['unique' => true, 'name' => 'uniq_node_file'])
->create();
}
}