UnfinishedWrite
Defined in: src/unfinished-write.ts:12
A create, update or remove of an object whose lock is still held: its writer is still working, or died. The library can’t tell which. Got from StorageRoot.unfinishedWrites or StorageRoot.unfinishedWrite, it is the write as its lock recorded it then.
Properties
Section titled “Properties”
readonlyid:string
Defined in: src/unfinished-write.ts:14
The id of the object being created, updated or removed.
lockedAt
Section titled “lockedAt”
readonlylockedAt:Date
Defined in: src/unfinished-write.ts:16
When its writer took the object’s lock, by that writer’s clock.
removing
Section titled “removing”
readonlyremoving:boolean
Defined in: src/unfinished-write.ts:18
Whether its writer had begun deleting the object. Recovering it then deletes the rest of the object.
Methods
Section titled “Methods”recover()
Section titled “recover()”recover():
Promise<void>
Defined in: src/unfinished-write.ts:52
Clears what the write left behind and releases the object’s lock. Does nothing if the lock has been released since.
Only call this when its writer is no longer alive: a live writer’s update is destroyed, and the library can’t tell
a live writer from a dead one. lockedAt says when the lock was taken.
Recover a write from one process at a time. Two recoveries of the same write at once, on any hosts or in one process, aren’t kept apart: if a new writer takes the lock between them, the later one destroys that writer’s update.
A remove that had begun deleting the object is finished. An update that wasn’t committed is discarded: its unfinished version in the workspace, the directory of the version after the head in the object, and staged inventory files are removed. A create that wasn’t committed is discarded: the declaration and first version of an object that never got an inventory, and its directory if the create made it. An update that was committed is completed by writing the root inventory’s sidecar. A version is never made the head, and no other version directory is removed, except the first version of an object that has lost its root inventory, which is taken for a dead create. If the write’s directory holds another id’s object, or is inside another object, its writer was refused before it wrote anything there: only the lock and what is left in the workspace are removed.
After RECOVERY_NEEDED, recover the write and then open the object again before retrying: the head shows whether the update was committed.
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”OcflError UPDATE_IN_PROGRESS if another writer has taken the object’s lock since; lockedAt says when. Nothing is changed.
Throws
Section titled “Throws”OcflError INVALID_OBJECT if the object’s inventory is corrupt or inconsistent, or it has a declaration and no inventory and a version other than the first, which a dead create never leaves. Nothing is changed.
Throws
Section titled “Throws”The file system error that stopped it; the object stays locked, and the write can be recovered again.
Example
Section titled “Example”try { object = await object.update(details, change);} catch (error) { if ((error as OcflError).code !== 'RECOVERY_NEEDED') throw error; // This process is the only writer, so none is alive await (await root.unfinishedWrite(object.id))?.recover(); object = await root.open(object.id);}