Skip to content

Commit

Permalink
Block deletion with ref count & repostore refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tbekas committed Dec 13, 2023
1 parent 0c3d1dd commit bfc467e
Show file tree
Hide file tree
Showing 14 changed files with 653 additions and 482 deletions.
2 changes: 1 addition & 1 deletion codex/codex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ proc new*(
repoDs = repoData,
metaDs = SQLiteDatastore.new(config.dataDir / CodexMetaNamespace)
.expect("Should create meta data store!"),
quotaMaxBytes = config.storageQuota.uint,
quotaMaxBytes = config.storageQuota,
blockTtl = config.blockTtl)

maintenance = BlockMaintainer.new(
Expand Down
13 changes: 7 additions & 6 deletions codex/sales/reservations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import pkg/stew/byteutils
import ../stores
import ../contracts/requests
import ../utils/json
import ../units

export requests
export chronicles except toJson
Expand Down Expand Up @@ -165,10 +166,10 @@ func key*(availability: Availability): ?!Key =
func key*(reservation: Reservation): ?!Key =
return key(reservation.id, reservation.availabilityId)

func available*(self: Reservations): uint = self.repo.available
func available*(self: Reservations): uint = self.repo.available.uint

func hasAvailable*(self: Reservations, bytes: uint): bool =
self.repo.available(bytes)
self.repo.available(bytes.NBytes)

proc exists*(
self: Reservations,
Expand Down Expand Up @@ -287,14 +288,14 @@ proc createAvailability*(
)
let bytes = availability.size.truncate(uint)

if reserveErr =? (await self.repo.reserve(bytes)).errorOption:
if reserveErr =? (await self.repo.reserve(bytes.NBytes)).errorOption:
return failure(reserveErr.toErr(ReserveFailedError))

if updateErr =? (await self.update(availability)).errorOption:

# rollback the reserve
trace "rolling back reserve"
if rollbackErr =? (await self.repo.release(bytes)).errorOption:
if rollbackErr =? (await self.repo.release(bytes.NBytes)).errorOption:
rollbackErr.parent = updateErr
return failure(rollbackErr)

Expand Down Expand Up @@ -385,7 +386,7 @@ proc release*(
"size of the Reservation")
return failure(error)

if releaseErr =? (await self.repo.release(bytes)).errorOption:
if releaseErr =? (await self.repo.release(bytes.NBytes)).errorOption:
return failure(releaseErr.toErr(ReleaseFailedError))

reservation.size -= bytes.u256
Expand All @@ -395,7 +396,7 @@ proc release*(

# rollback release if an update error encountered
trace "rolling back release"
if rollbackErr =? (await self.repo.reserve(bytes)).errorOption:
if rollbackErr =? (await self.repo.reserve(bytes.NBytes)).errorOption:
rollbackErr.parent = err
return failure(rollbackErr)
return failure(err)
Expand Down
2 changes: 1 addition & 1 deletion codex/stores/maintenance.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ proc deleteExpiredBlock(self: BlockMaintainer, cid: Cid): Future[void] {.async.}
trace "Unable to delete block from repoStore"

proc processBlockExpiration(self: BlockMaintainer, be: BlockExpiration): Future[void] {.async} =
if be.expiration < self.clock.now:
if be.expiry < self.clock.now:
await self.deleteExpiredBlock(be.cid)
else:
inc self.offset
Expand Down
Loading

0 comments on commit bfc467e

Please sign in to comment.