-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: return allocated bytes in store/add
receipt
#1213
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45b18cd
feat: return allocated bytes in store/add receipt
b351ab9
fix: typo
f8d24cd
chore: appease linter
07e2225
fix: tests
880f001
refactor: apply suggestions from code review
313fe50
feat: result return types for upload and store table
4423167
Merge branch 'feat/store-add-allocated-bytes' of github.com:web3-stor…
db568ce
chore: appease linter
7623f6a
fix: remove unneeded codes
089888e
fix: less churn
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ export function storeAddProvider(context) { | |
Server.DID.parse(capability.with).did() | ||
) | ||
const issuer = invocation.issuer.did() | ||
const [allocated, carIsLinkedToAccount, carExists] = await Promise.all([ | ||
const [allocated, carExists] = await Promise.all([ | ||
allocate( | ||
{ | ||
capability: { | ||
|
@@ -33,7 +33,6 @@ export function storeAddProvider(context) { | |
}, | ||
context | ||
), | ||
storeTable.exists(space, link), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, we drop a request :) |
||
carStoreBucket.has(link), | ||
]) | ||
|
||
|
@@ -42,21 +41,30 @@ export function storeAddProvider(context) { | |
return allocated | ||
} | ||
|
||
if (!carIsLinkedToAccount) { | ||
await storeTable.insert({ | ||
space, | ||
link, | ||
size, | ||
origin, | ||
issuer, | ||
invocation: invocation.cid, | ||
}) | ||
let allocatedSize = size | ||
const res = await storeTable.insert({ | ||
space, | ||
link, | ||
size, | ||
origin, | ||
issuer, | ||
invocation: invocation.cid, | ||
}) | ||
if (res.error) { | ||
// if the insert failed with conflict then this item has already been | ||
// added to the space and there is no allocation change. | ||
if (res.error.name === 'RecordKeyConflict') { | ||
allocatedSize = 0 | ||
} else { | ||
return res | ||
} | ||
} | ||
|
||
if (carExists) { | ||
return { | ||
ok: { | ||
status: 'done', | ||
allocated: allocatedSize, | ||
with: space, | ||
link, | ||
}, | ||
|
@@ -67,6 +75,7 @@ export function storeAddProvider(context) { | |
return { | ||
ok: { | ||
status: 'upload', | ||
allocated: allocatedSize, | ||
with: space, | ||
link, | ||
url: url.toString(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Failure } from '@ucanto/server' | ||
|
||
export class StoreItemNotFound extends Failure { | ||
/** | ||
* @param {import('@ucanto/interface').DID} space | ||
* @param {import('@ucanto/interface').UnknownLink} link | ||
*/ | ||
constructor(space, link) { | ||
super() | ||
this.space = space | ||
this.link = link | ||
} | ||
|
||
get name() { | ||
return 'StoreItemNotFound' | ||
} | ||
|
||
describe() { | ||
return `${this.link} not found in ${this.space}` | ||
} | ||
|
||
toJSON() { | ||
return { | ||
...super.toJSON(), | ||
space: this.space, | ||
link: { '/': this.link.toString() }, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to advertise how much we can ensure consistency of this, which I imagine might be 'not very much' unless we have transactions in our underlying db
e.g. let's say cid A is not stored in the space. Two
store/add
invocations get created with different invocations CIDs (e.g. different nonce/expirty) to add cid A to the space. Then those two invocations are submitted to us at the exact same second. iiuc it may be the case that both of those responses come back withallocated: size(A)
(because we dont have transactions, and in this scenario both invocations callscarStoreBucket.has(link)
here would have returned false.my main concern
allocated
response value in some business logic without being aware of the eventual consistency lack-of-transactionality in generating this value. i.e. this could be nonzero even if technically the a differentstore/add
invocation added the CID first (in the race condition describes above).allocated
set to the size of the referent of the CID.If we want to return this information in the result of the write operation (store/add), we probably need something like transactions to do it in a way that isn't subject to these race conditions.
But if possible it may be nice to avoid returning this value in the result of the write operation (because it almost always increases the cost of the write operation to add return values that. must also be consistent)
alternatively we ignore the above concerns but maybe it's a good idea to at least put in the jsdoc here that there a nonzero response does not necessarily indicate that the
store/add
is the authoritative addition of the CID to the space.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, in hindsight this is maybe not the right solution because we want to use it in our business logic...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, so maybe we want the insert later on to have a result of being conflict or not. Only one Put should happen in dynamo successfully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, on reflection I think we can make
allocated
in the response be authoratitive about the addition of the CID to the space. This is what we can do:TransactWriteItems
since we're not writing multiple items!PutItem
so that it fails if not a new recordDeleteItem
so that it fails if record does not exist