Skip to content

Commit 85b0567

Browse files
committed
Improve logging
1 parent fa5264a commit 85b0567

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/fs_store.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl FsStore {
164164
Ok(result.into_iter().collect())
165165
}
166166

167+
#[tracing::instrument(skip(self, changes))]
167168
pub fn append(&self, id: &DocumentId, changes: &[u8]) -> Result<(), Error> {
169+
tracing::debug!("writing incremental change");
168170
let paths = DocIdPaths::from(id);
169171
std::fs::create_dir_all(paths.level2_path(&self.root)).map_err(|e| {
170172
Error(ErrorKind::CreateLevel2Path(
@@ -179,7 +181,9 @@ impl FsStore {
179181
Ok(())
180182
}
181183

184+
#[tracing::instrument(skip(self, full_doc))]
182185
pub fn compact(&self, id: &DocumentId, full_doc: &[u8]) -> Result<(), Error> {
186+
tracing::debug!("compacting document");
183187
let paths = DocIdPaths::from(id);
184188

185189
// Load all the data we have into a doc
@@ -211,11 +215,8 @@ impl FsStore {
211215
let path = paths.chunk_path(&self.root, snapshot);
212216

213217
if path == just_wrote {
214-
tracing::error!(
215-
?path,
216-
"Somehow trying to delete the same path we just wrote to. Not today \
217-
Satan"
218-
);
218+
// This can happen if for some reason `compact` is called when the only thing
219+
// on disk is a snapshot containing the changes we are being asked to compact
219220
continue;
220221
}
221222

@@ -415,7 +416,7 @@ impl Chunks {
415416
fn load(root: &Path, doc_id: &DocumentId) -> Result<Option<Self>, Error> {
416417
let doc_id_hash = DocIdPaths::from(doc_id);
417418
let level2_path = doc_id_hash.level2_path(root);
418-
tracing::debug!(
419+
tracing::trace!(
419420
root=%root.display(),
420421
doc_id=?doc_id,
421422
doc_path=%level2_path.display(),
@@ -459,7 +460,7 @@ impl Chunks {
459460
tracing::warn!(bad_file=%path.display(), "unexpected non-chunk file in level2 path");
460461
continue;
461462
};
462-
tracing::debug!(chunk_path=%path.display(), "reading chunk file");
463+
tracing::trace!(chunk_path=%path.display(), "reading chunk file");
463464
let contents = match std::fs::read(&path) {
464465
Ok(c) => c,
465466
Err(e) => {

src/repo.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ impl DocState {
532532
let pinned = Pin::new(&mut storage_fut);
533533
match pinned.poll(&mut Context::from_waker(&waker)) {
534534
Poll::Ready(Ok(_)) => None,
535-
Poll::Ready(Err(_)) => {
535+
Poll::Ready(Err(e)) => {
536+
tracing::error!(err=?e, "error in save operation");
536537
// TODO: propagate error to doc handle.
537538
// `with_doc_mut` could return a future for this.
538539
None
@@ -555,7 +556,8 @@ impl DocState {
555556
let pinned = Pin::new(&mut storage_fut);
556557
let res = match pinned.poll(&mut Context::from_waker(&waker)) {
557558
Poll::Ready(Ok(_)) => None,
558-
Poll::Ready(Err(_)) => {
559+
Poll::Ready(Err(e)) => {
560+
tracing::error!(err=?e, "error in storage operation");
559561
// TODO: propagate error to doc handle.
560562
// `with_doc_mut` could return a future for this.
561563
None
@@ -880,6 +882,9 @@ impl DocumentInfo {
880882
changes.len()
881883
};
882884
let has_patches = count > 0;
885+
if has_patches {
886+
tracing::debug!("doc has changed");
887+
}
883888
self.changes_since_last_compact = self.changes_since_last_compact.saturating_add(count);
884889
has_patches
885890
}
@@ -902,13 +907,15 @@ impl DocumentInfo {
902907
let should_compact =
903908
self.changes_since_last_compact > self.allowable_changes_until_compaction;
904909
let (storage_fut, new_heads) = if should_compact {
910+
tracing::trace!(%document_id, "compacting document");
905911
let (to_save, new_heads) = {
906912
let doc = self.document.read();
907913
(doc.automerge.save(), doc.automerge.get_heads())
908914
};
909915
self.changes_since_last_compact = 0;
910916
(storage.compact(document_id.clone(), to_save), new_heads)
911917
} else {
918+
tracing::trace!(%document_id, "writing incremental chunk");
912919
let (to_save, new_heads) = {
913920
let doc = self.document.read();
914921
(

0 commit comments

Comments
 (0)