release: v0.2.3 AriaEngine 引擎加固 — RB-Tree fixDelete/LSM SSTable缓存预热/LZ4格式修复
This commit is contained in:
Vendored
+100
-3
@@ -1305,9 +1305,97 @@ class RedBlackTree {
|
||||
if (this.root)
|
||||
this.root.color = Color.BLACK;
|
||||
}
|
||||
fixDelete(_x, _parent) {
|
||||
// 简化:在实际生产环境中需要完整的删除修复
|
||||
// 这里使用简化版,仅处理常见情况
|
||||
fixDelete(x, parent) {
|
||||
// 标准 RB-Tree 删除修复(修复"双黑"问题)
|
||||
let node = x;
|
||||
let nodeParent = parent;
|
||||
while ((!node || node.color === Color.BLACK) && node !== this.root) {
|
||||
if (!nodeParent)
|
||||
break;
|
||||
if (node === nodeParent.left) {
|
||||
let sibling = nodeParent.right;
|
||||
if (!sibling)
|
||||
break;
|
||||
// Case 1: 兄弟是红色
|
||||
if (sibling.color === Color.RED) {
|
||||
sibling.color = Color.BLACK;
|
||||
nodeParent.color = Color.RED;
|
||||
this.rotateLeft(nodeParent);
|
||||
sibling = nodeParent.right;
|
||||
if (!sibling)
|
||||
break;
|
||||
}
|
||||
// Case 2: 兄弟的两个子节点都是黑色
|
||||
const sibLeft = sibling.left;
|
||||
const sibRight = sibling.right;
|
||||
if ((!sibLeft || sibLeft.color === Color.BLACK) &&
|
||||
(!sibRight || sibRight.color === Color.BLACK)) {
|
||||
sibling.color = Color.RED;
|
||||
node = nodeParent;
|
||||
nodeParent = node.parent;
|
||||
}
|
||||
else {
|
||||
// Case 3: 兄弟右子黑色(左子红色)
|
||||
if (!sibRight || sibRight.color === Color.BLACK) {
|
||||
if (sibLeft)
|
||||
sibLeft.color = Color.BLACK;
|
||||
sibling.color = Color.RED;
|
||||
this.rotateRight(sibling);
|
||||
sibling = nodeParent.right;
|
||||
if (!sibling)
|
||||
break;
|
||||
}
|
||||
// Case 4: 兄弟右子红色
|
||||
sibling.color = nodeParent.color;
|
||||
nodeParent.color = Color.BLACK;
|
||||
if (sibling.right)
|
||||
sibling.right.color = Color.BLACK;
|
||||
this.rotateLeft(nodeParent);
|
||||
node = this.root;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 镜像:node 是父节点的右子
|
||||
let sibling = nodeParent.left;
|
||||
if (!sibling)
|
||||
break;
|
||||
if (sibling.color === Color.RED) {
|
||||
sibling.color = Color.BLACK;
|
||||
nodeParent.color = Color.RED;
|
||||
this.rotateRight(nodeParent);
|
||||
sibling = nodeParent.left;
|
||||
if (!sibling)
|
||||
break;
|
||||
}
|
||||
const sibLeft = sibling.left;
|
||||
const sibRight = sibling.right;
|
||||
if ((!sibLeft || sibLeft.color === Color.BLACK) &&
|
||||
(!sibRight || sibRight.color === Color.BLACK)) {
|
||||
sibling.color = Color.RED;
|
||||
node = nodeParent;
|
||||
nodeParent = node.parent;
|
||||
}
|
||||
else {
|
||||
if (!sibLeft || sibLeft.color === Color.BLACK) {
|
||||
if (sibRight)
|
||||
sibRight.color = Color.BLACK;
|
||||
sibling.color = Color.RED;
|
||||
this.rotateLeft(sibling);
|
||||
sibling = nodeParent.left;
|
||||
if (!sibling)
|
||||
break;
|
||||
}
|
||||
sibling.color = nodeParent.color;
|
||||
nodeParent.color = Color.BLACK;
|
||||
if (sibling.left)
|
||||
sibling.left.color = Color.BLACK;
|
||||
this.rotateRight(nodeParent);
|
||||
node = this.root;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node)
|
||||
node.color = Color.BLACK;
|
||||
}
|
||||
rotateLeft(x) {
|
||||
const y = x.right;
|
||||
@@ -2115,6 +2203,15 @@ class LSM {
|
||||
if (metas.length > 0) {
|
||||
this.nextSSTableId = Math.max(...metas.map((m) => m.id)) + 1;
|
||||
}
|
||||
// 预加载所有 SSTable 数据到缓存(避免后续 cache miss 返回 null)
|
||||
for (const meta of metas) {
|
||||
try {
|
||||
await this.preloadSSTable(meta.id);
|
||||
}
|
||||
catch {
|
||||
// 单个文件加载失败不影响整体启动
|
||||
}
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
// =======================================================================
|
||||
|
||||
Reference in New Issue
Block a user