pub struct QuotaCharge { /* private fields */ }Expand description
One write’s claim on a DiskQuota, from its first byte until it commits or
is abandoned.
A write that replaces a file within one host call, where no program code can
touch that file before it commits, may draw on the file’s size first and
reserve only the growth beyond it: its allowance. Only a file no handle holds
gives an allowance, since a held file’s bytes stay on disk after its name
goes. A write the program can interleave with replaces nothing up front, so
every byte it writes counts until it commits, and re-reads what it replaces
with cover just before committing. commit
then frees the replaced file. A write that truncates and rewrites a file itself
(in_place) draws on the old contents even while readers
hold the file, since they are gone either way; a writer’s own file is left for
the writer to settle. Dropping an uncommitted charge gives back
everything it reserved, for a write whose output is gone.
Implementations§
Source§impl QuotaCharge
impl QuotaCharge
Sourcepub fn new(
quota: Option<Arc<DiskQuota>>,
replaced: Option<(FileIdentity, u64)>,
) -> Self
pub fn new( quota: Option<Arc<DiskQuota>>, replaced: Option<(FileIdentity, u64)>, ) -> Self
A charge that may draw on replaced, the regular file the write replaces.
Sourcepub fn in_place(
quota: Option<Arc<DiskQuota>>,
rewritten: Option<(FileIdentity, u64)>,
) -> Self
pub fn in_place( quota: Option<Arc<DiskQuota>>, rewritten: Option<(FileIdentity, u64)>, ) -> Self
A charge for rewriting rewritten, a regular file and its size, in place:
the same file takes the new contents, so the old ones are freed at once even
while readers hold it. A writer’s own file is the writer’s to settle, so
rewriting it frees nothing and every new byte counts.
Sourcepub fn reserve(&mut self, bytes: u64) -> Result<(), QuotaExceeded>
pub fn reserve(&mut self, bytes: u64) -> Result<(), QuotaExceeded>
Claim bytes about to be written: from the allowance first, the rest from
the quota.
Sourcepub fn unreserve(&mut self, bytes: u64)
pub fn unreserve(&mut self, bytes: u64)
Give back bytes claimed by the last reserve that were
never written, as after a short write.
Sourcepub fn cover(
&mut self,
replaced: Option<(FileIdentity, u64)>,
) -> Result<(), QuotaExceeded>
pub fn cover( &mut self, replaced: Option<(FileIdentity, u64)>, ) -> Result<(), QuotaExceeded>
Settle against the file the write is about to replace, as it stands now: whatever the write drew from its allowance beyond that file’s size must be reserved after all, or the write refused.
Sourcepub fn commit(self)
pub fn commit(self)
The write landed: free what it replaced beyond the allowance it drew on. A replaced file goes once no handle holds it; old contents rewritten in place go at once.
Sourcepub fn settle_at(self, left: u64)
pub fn settle_at(self, left: u64)
The write failed partway, leaving its file at left bytes: count the file
at that size. A file rewritten in place had its old contents counted too;
otherwise no more than was reserved can be the write’s own.
Sourcepub fn keep(self)
pub fn keep(self)
The write failed but its bytes may still be on disk, under a name the program gave them: keep them counted rather than giving them back.
Sourcepub fn release_when_closed(self, written: FileIdentity)
pub fn release_when_closed(self, written: FileIdentity)
The write failed and its file, written, has no name left: its bytes go
once every handle on it closes.