Overlap durable sync for interactive document drafts
This commit is contained in:
1 parent
062a2b9f60
commit
5163fc9854
3 files changed
+101
-20
No files matched your search
@@ -207,6 +207,12 @@ SHA-256 为 `a0c3b9929508e8bfbb8f33fe177fc662c4eca0cc7d5c41ac52503a39e337ab1b`
|
|||||||
回执 `target/p4-parallel-draft-sync/interleaved-a3-3/receipt.json` 的 SHA-256
|
回执 `target/p4-parallel-draft-sync/interleaved-a3-3/receipt.json` 的 SHA-256
|
||||||
为 `cac9b9da9cf15032ff2c614093e0b01476bc139e99e3c6e3b6dc8216e99df9db`。
|
为 `cac9b9da9cf15032ff2c614093e0b01476bc139e99e3c6e3b6dc8216e99df9db`。
|
||||||
|
|
||||||
|
并行同步已与 schema25 主线及流式失败报告合并。新版定向回归通过60项,
|
||||||
|
覆盖同步失败后原 PDF、日志、辅助文件和账本保留,以及共享会话取消、失败
|
||||||
|
恢复和发布顺序。报告 `target/p4-parallel-sync-main-reconcile/directed.log` 的
|
||||||
|
SHA-256 为 `2bb2dd465e5a7f1c94f834d305b2405a03efadb2382db5c64cdfc9b151fcfdfc`。
|
||||||
|
上面的30次浏览器配对对应此前隔离构建,合并版仍需在固定条件下测量。
|
||||||
|
|
||||||
大规模错误报告按原 JSON 格式直接写入缓冲暂存文件,再完整同步并按新文件
|
大规模错误报告按原 JSON 格式直接写入缓冲暂存文件,再完整同步并按新文件
|
||||||
发布。集成测试核对 11 种失败路径,包含原序列化字节、原有报告保护、错误
|
发布。集成测试核对 11 种失败路径,包含原序列化字节、原有报告保护、错误
|
||||||
保留及暂存清理。真实 CVPR 大报告的峰值内存还需重新测量。
|
保留及暂存清理。真实 CVPR 大报告的峰值内存还需重新测量。
|
||||||
|
|||||||
+7
-1
@@ -1099,7 +1099,13 @@ impl CompileJob {
|
|||||||
let inputs = files.input_snapshot();
|
let inputs = files.input_snapshot();
|
||||||
let prepared = pdf
|
let prepared = pdf
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|bytes| PreparedOutput::write(&output, bytes))
|
.map(|bytes| {
|
||||||
|
if checkpoints.is_some() {
|
||||||
|
PreparedOutput::write_for_draft(&output, bytes)
|
||||||
|
} else {
|
||||||
|
PreparedOutput::write(&output, bytes)
|
||||||
|
}
|
||||||
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
let receipt = prepared.as_ref().map(|p| p.version(&output)).transpose()?;
|
let receipt = prepared.as_ref().map(|p| p.version(&output)).transpose()?;
|
||||||
let previous = self.compiler.latest();
|
let previous = self.compiler.latest();
|
||||||
|
|||||||
+88
-19
@@ -1132,10 +1132,7 @@ impl Files {
|
|||||||
if !draft.finished {
|
if !draft.finished {
|
||||||
return Err("native draft must finish successfully before publication".into());
|
return Err("native draft must finish successfully before publication".into());
|
||||||
}
|
}
|
||||||
if let Some(log) = self.log.take() {
|
let log = self.log.take();
|
||||||
log.sync_all()
|
|
||||||
.map_err(|e| format!("sync native draft log: {e}"))?;
|
|
||||||
}
|
|
||||||
let initial = self
|
let initial = self
|
||||||
.preparation
|
.preparation
|
||||||
.generated_initial
|
.generated_initial
|
||||||
@@ -1160,15 +1157,46 @@ impl Files {
|
|||||||
.map(|(path, version)| (path.clone(), version.clone()))
|
.map(|(path, version)| (path.clone(), version.clone()))
|
||||||
.collect::<BTreeMap<_, _>>();
|
.collect::<BTreeMap<_, _>>();
|
||||||
let mut artifacts: Vec<_> = draft.generated.into_values().collect();
|
let mut artifacts: Vec<_> = draft.generated.into_values().collect();
|
||||||
for artifact in &artifacts {
|
let sync_pdf = || -> Result<(), String> {
|
||||||
OpenOptions::new()
|
if let Some(file) = pdf.as_ref().and_then(|pdf| pdf.pending_sync.as_ref()) {
|
||||||
.write(true)
|
file.sync_all().map_err(|error| {
|
||||||
.open(&artifact.staged.path)
|
format!("sync native draft {}: {error}", draft.pdf.path.display())
|
||||||
.and_then(|file| file.sync_all())
|
|
||||||
.map_err(|e| {
|
|
||||||
format!("sync native draft {}: {e}", artifact.target.path.display())
|
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
let sync_log = || -> Result<(), String> {
|
||||||
|
if let Some(file) = &log {
|
||||||
|
file.sync_all()
|
||||||
|
.map_err(|error| format!("sync native draft log: {error}"))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
// Flush independent files concurrently, then finish collecting all
|
||||||
|
// results before the revision gate can install any artifact.
|
||||||
|
std::thread::scope(|scope| {
|
||||||
|
let pdf_worker = pdf.as_ref().and_then(|pdf| pdf.pending_sync.as_ref())
|
||||||
|
.and_then(|_| std::thread::Builder::new().spawn_scoped(scope, sync_pdf).ok());
|
||||||
|
let log_worker = log.as_ref()
|
||||||
|
.and_then(|_| std::thread::Builder::new().spawn_scoped(scope, sync_log).ok());
|
||||||
|
let generated = artifacts.iter().try_for_each(|artifact| {
|
||||||
|
OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.open(&artifact.staged.path)
|
||||||
|
.and_then(|file| file.sync_all())
|
||||||
|
.map_err(|error| {
|
||||||
|
format!("sync native draft {}: {error}", artifact.target.path.display())
|
||||||
|
})
|
||||||
|
});
|
||||||
|
let pdf_result = pdf_worker.map_or_else(sync_pdf, |worker| {
|
||||||
|
worker.join().map_err(|_| "native draft PDF sync thread panicked".to_owned())?
|
||||||
|
});
|
||||||
|
let log_result = log_worker.map_or_else(sync_log, |worker| {
|
||||||
|
worker.join().map_err(|_| "native draft log sync thread panicked".to_owned())?
|
||||||
|
});
|
||||||
|
pdf_result.and(log_result).and(generated)
|
||||||
|
})?;
|
||||||
|
drop(log);
|
||||||
artifacts.push(draft.log);
|
artifacts.push(draft.log);
|
||||||
let untouched_ledger = if let Some(DraftLedger { file, staged }) = draft.ledger {
|
let untouched_ledger = if let Some(DraftLedger { file, staged }) = draft.ledger {
|
||||||
let target = &draft.ledger_target.path;
|
let target = &draft.ledger_target.path;
|
||||||
@@ -1195,7 +1223,8 @@ impl Files {
|
|||||||
} else {
|
} else {
|
||||||
Some(draft.ledger_target)
|
Some(draft.ledger_target)
|
||||||
};
|
};
|
||||||
if let Some(staged) = pdf {
|
if let Some(mut staged) = pdf {
|
||||||
|
drop(staged.pending_sync.take());
|
||||||
artifacts.push(DraftArtifact {
|
artifacts.push(DraftArtifact {
|
||||||
target: draft.pdf,
|
target: draft.pdf,
|
||||||
staged,
|
staged,
|
||||||
@@ -1846,6 +1875,7 @@ fn restore_draft(
|
|||||||
/// Write complete bytes before publishing the output path.
|
/// Write complete bytes before publishing the output path.
|
||||||
pub struct PreparedOutput {
|
pub struct PreparedOutput {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
pending_sync: Option<File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PreparedOutput {
|
impl PreparedOutput {
|
||||||
@@ -1864,14 +1894,31 @@ impl PreparedOutput {
|
|||||||
output: &Path,
|
output: &Path,
|
||||||
write: impl FnOnce(&mut File) -> Result<(), String>,
|
write: impl FnOnce(&mut File) -> Result<(), String>,
|
||||||
) -> Result<Self, String> {
|
) -> Result<Self, String> {
|
||||||
let (prepared, mut file) = Self::create(output)?;
|
let (prepared, file) = Self::write_staged(output, write)?;
|
||||||
let written = write(&mut file)
|
let synced = file.sync_all();
|
||||||
.and_then(|()| file.sync_all().map_err(|error| error.to_string()));
|
|
||||||
drop(file);
|
drop(file);
|
||||||
written.map_err(|error| format!("stage output {}: {error}", output.display()))?;
|
synced.map_err(|error| format!("stage output {}: {error}", output.display()))?;
|
||||||
Ok(prepared)
|
Ok(prepared)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn write_for_draft(output: &Path, bytes: &[u8]) -> Result<Self, String> {
|
||||||
|
let (mut prepared, file) = Self::write_staged(output, |file| {
|
||||||
|
file.write_all(bytes).map_err(|error| error.to_string())
|
||||||
|
})?;
|
||||||
|
prepared.pending_sync = Some(file);
|
||||||
|
Ok(prepared)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_staged(
|
||||||
|
output: &Path,
|
||||||
|
write: impl FnOnce(&mut File) -> Result<(), String>,
|
||||||
|
) -> Result<(Self, File), String> {
|
||||||
|
let (prepared, mut file) = Self::create(output)?;
|
||||||
|
write(&mut file)
|
||||||
|
.map_err(|error| format!("stage output {}: {error}", output.display()))?;
|
||||||
|
Ok((prepared, file))
|
||||||
|
}
|
||||||
|
|
||||||
fn draft(output: &Path) -> Result<(Self, File), String> {
|
fn draft(output: &Path) -> Result<(Self, File), String> {
|
||||||
let existing = match fs::symlink_metadata(output) {
|
let existing = match fs::symlink_metadata(output) {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
@@ -1932,7 +1979,7 @@ impl PreparedOutput {
|
|||||||
let path = output.with_file_name(format!(".texrra-{}-{id}.tmp", std::process::id()));
|
let path = output.with_file_name(format!(".texrra-{}-{id}.tmp", std::process::id()));
|
||||||
if path != output {
|
if path != output {
|
||||||
match create(&path) {
|
match create(&path) {
|
||||||
Ok(value) => return Ok((Self { path }, value)),
|
Ok(value) => return Ok((Self { path, pending_sync: None }, value)),
|
||||||
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => continue,
|
Err(error) if error.kind() == io::ErrorKind::AlreadyExists => continue,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
return Err(format!("stage output {}: {error}", output.display()));
|
return Err(format!("stage output {}: {error}", output.display()));
|
||||||
@@ -1967,6 +2014,7 @@ impl PreparedOutput {
|
|||||||
|
|
||||||
impl Drop for PreparedOutput {
|
impl Drop for PreparedOutput {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
drop(self.pending_sync.take());
|
||||||
if !self.path.as_os_str().is_empty() {
|
if !self.path.as_os_str().is_empty() {
|
||||||
let _ = fs::remove_file(&self.path);
|
let _ = fs::remove_file(&self.path);
|
||||||
}
|
}
|
||||||
@@ -2107,7 +2155,28 @@ mod generated_file_tests {
|
|||||||
assert!(error.contains("native staged ledger changed"), "{error}");
|
assert!(error.contains("native staged ledger changed"), "{error}");
|
||||||
assert!(!staged.exists());
|
assert!(!staged.exists());
|
||||||
assert_eq!(fs::read(&ledger_path).unwrap(), original_ledger);
|
assert_eq!(fs::read(&ledger_path).unwrap(), original_ledger);
|
||||||
assert_eq!(fs::read(generated).unwrap(), b"original");
|
assert_eq!(fs::read(&generated).unwrap(), b"original");
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
let output = root.join("job.pdf");
|
||||||
|
let log = root.join("job.log");
|
||||||
|
fs::write(&output, b"already published PDF").unwrap();
|
||||||
|
let original_log = fs::read(&log).unwrap();
|
||||||
|
let mut host = draft();
|
||||||
|
write(&mut host, "actual.aux", "another draft");
|
||||||
|
host.finish().unwrap();
|
||||||
|
let mut pdf = PreparedOutput::write_for_draft(&output, b"new PDF").unwrap();
|
||||||
|
let path = pdf.path.clone();
|
||||||
|
pdf.pending_sync = Some(File::open("/dev/null").unwrap());
|
||||||
|
let error = host.seal_draft(Some(pdf)).err().unwrap();
|
||||||
|
assert!(error.contains("sync native draft") && error.contains("job.pdf"), "{error}");
|
||||||
|
assert!(!path.exists());
|
||||||
|
assert_eq!(fs::read(&output).unwrap(), b"already published PDF");
|
||||||
|
assert_eq!(fs::read(&log).unwrap(), original_log);
|
||||||
|
assert_eq!(fs::read(&generated).unwrap(), b"original");
|
||||||
|
assert_eq!(fs::read(&ledger_path).unwrap(), original_ledger);
|
||||||
|
}
|
||||||
fs::remove_dir_all(root).unwrap();
|
fs::remove_dir_all(root).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user