Reliably determine whether note.add will succeed?

Hi,

it seems like there’s a short period at the start of syncing (after initial connection), when adding notes fail (due to an internal lock). Is there a way to know this in advance? I send large notes, so I think trial and error causes unnecessary stress in an already stressful situation for the notecard.

Waiting until the entire sync is done is a bit too limiting for me, and I risk loosing data.

– gaute

Hi @gauteh,

When Notes are saved to Notecard flash, they persist until a sync is successful, so you should never lose any data.

Are you seeing the error after a note.add request or when attempting a sync? If you could let me know what the explicit error message is that would help too.

If the error is on a note.add, it might be worth trying to use hub.sync.status to gate “large” syncs. If the response’s requested > completed, a sync is outstanding but not yet reported done. When requested == completed and status includes completed, the window has closed. This is a pretty conservative measure and could get around a potential conflict of active communication and saving a large Note (but I also can’t say I’ve seen that happen before!).

Thanks,
Rob

Hi,

the error happens when doing a large note.add (binary) during the initial phase of a sync. The notecard responds after the complete note.add request with a error response containing something like “failed bulk sync/block”. The only way to guard is to block completely on any requested or syncing status, but that takes too long and the internal MCU buffer fills up. This is only a problem during the initial phase of the sync anyway, maybe when preparing which notes to send?

– gaute

Hi @gauteh,

I want to be clear that these types of I/O errors should definitely NOT be happening with any regularity, so this is something we need to dive into. You’re using your Rust SDK, correct? If at all possible I’d love to take that out of the equation and have you try to replicate with note-c.

Thanks,
Rob

I won’t be able to convert this to note-c unfortunately, here is the error I am getting from the notecard:

2 days ago: Fatal error in main loop: drain_queue: Err(ErrorAddingNote('error adding note: failed to acquire bulk add/sync lock: timeout waiting for bulk add/sync lock')), check_and_sync: Ok(()). Tries left: 15

This appears to be after “modem-on”, but not during “updating note” part of the sync. I’ll paste a more detailed log next time it happens. It is pretty regular with my current firmware.

Hi @gauteh,

Thanks for sending the exact error message, this is very helpful. Basically a note.add to any templated Notefile will fail with this error if the sync task is currently uploading any templated outbound Notefile to Notehub AND that upload is taking longer than 10 seconds. This behavior is actually by design to avoid Notefile discrepancies between device/cloud, but we are looking into options for improvements for this use case.

In the meantime, I would recommend using the hub.sync.status API as a rough measurement of sync status and sync accordingly (or add a retry based on the failure).

Rob