feat(smartdb): add operation log APIs, point-in-time revert support, and a web-based debug dashboard

This commit is contained in:
2026-04-02 17:02:03 +00:00
parent 943302f789
commit d34b8673e1
27 changed files with 3536 additions and 64 deletions

View File

@@ -3,6 +3,7 @@ use std::collections::HashSet;
use bson::{doc, oid::ObjectId, Bson, Document};
use rustdb_index::IndexEngine;
use rustdb_query::{QueryMatcher, UpdateEngine, sort_documents, apply_projection};
use rustdb_storage::OpType;
use tracing::debug;
use crate::context::CommandContext;
@@ -151,7 +152,17 @@ async fn handle_update(
// Insert the new document.
match ctx.storage.insert_one(db, coll, updated.clone()).await {
Ok(_) => {
Ok(id_str) => {
// Record upsert in oplog as an insert.
ctx.oplog.append(
OpType::Insert,
db,
coll,
&id_str,
Some(updated.clone()),
None,
);
// Update index.
let mut engine = ctx
.indexes
@@ -212,6 +223,16 @@ async fn handle_update(
.await
{
Ok(()) => {
// Record in oplog.
ctx.oplog.append(
OpType::Update,
db,
coll,
&id_str,
Some(updated_doc.clone()),
Some(matched_doc.clone()),
);
// Update index.
if let Some(mut engine) = ctx.indexes.get_mut(&ns_key) {
let _ = engine.on_update(matched_doc, &updated_doc);
@@ -362,6 +383,16 @@ async fn handle_find_and_modify(
let id_str = extract_id_string(doc);
ctx.storage.delete_by_id(db, coll, &id_str).await?;
// Record in oplog.
ctx.oplog.append(
OpType::Delete,
db,
coll,
&id_str,
None,
Some(doc.clone()),
);
// Update index.
if let Some(mut engine) = ctx.indexes.get_mut(&ns_key) {
engine.on_delete(doc);
@@ -418,6 +449,16 @@ async fn handle_find_and_modify(
.update_by_id(db, coll, &id_str, updated_doc.clone())
.await?;
// Record in oplog.
ctx.oplog.append(
OpType::Update,
db,
coll,
&id_str,
Some(updated_doc.clone()),
Some(original_doc.clone()),
);
// Update index.
if let Some(mut engine) = ctx.indexes.get_mut(&ns_key) {
let _ = engine.on_update(&original_doc, &updated_doc);
@@ -464,10 +505,20 @@ async fn handle_find_and_modify(
updated_doc.get("_id").unwrap().clone()
};
ctx.storage
let inserted_id_str = ctx.storage
.insert_one(db, coll, updated_doc.clone())
.await?;
// Record upsert in oplog as an insert.
ctx.oplog.append(
OpType::Insert,
db,
coll,
&inserted_id_str,
Some(updated_doc.clone()),
None,
);
// Update index.
{
let mut engine = ctx