Repository navigation
Use a general store to handle Solid behaviour - #167
Conversation
|
Just a quick question:
Why don't we simply put files on disk? |
That would also work, but I'm a bit hesitant about writing actual files during tests due to the extra overhead and potential issues it could have. But one big thing is that it is now very easy also to quickly set up a file structure for a single test such as here and also quickly see if data was written. |
Looks nice indeed! |
ad7519d to
8ceabaa
Compare
|
Added integration. Since they should have identical functionality, the integration tests of the file store could be completely reused as seen here. |
8ceabaa to
bc5b3c0
Compare
|
I added an InMemoryDataAccessor as well to show how a different DataAccessor would work (going to stop working on this branch now in case the entire idea gets scrapped 😄). Some things I did notice that would probably need issues:
|
RubenVerborgh
left a comment
There was a problem hiding this comment.
The accessor pattern itself is good (perhaps with the exception of modifyResource).
Can you comment on why the existing file store is still in there? Performance?
Overall, I found some of the longer methods difficult to read. I like code that's partitioned in blocks, preceded by one comment explaining why what is happening. I often had to reconstruct what was happening. Perhaps consider helper methods where it makes the flow more clear.
Also, a couple of private methods can just be protected for me.
| * This class is important because this way different stores don't all need to implement behaviour | ||
| * Examples: |
There was a problem hiding this comment.
| * This class is important because this way different stores don't all need to implement behaviour | |
| * Examples: | |
| * The DataAccessor interface provides elementary store operations such as read and write. | |
| * This DataAccessorBasedStore uses those elementary store operations | |
| * to implement the more high-level ResourceStore contact, abstracting all common functionality | |
| * such that new stores can be added by implementing the more simple DataAccessor contract. | |
| * DataAccessorBasedStore thereby provides behaviours for reuse across different stores, such as: |
| const result = { | ||
| binary: false, | ||
| get data(): Readable { | ||
| // This allows other modules to still add metadata before the output data is written | ||
| return streamifyArray(result.metadata.quads()); | ||
| }, | ||
| metadata, | ||
| }; | ||
| return result; |
There was a problem hiding this comment.
| const result = { | |
| binary: false, | |
| get data(): Readable { | |
| // This allows other modules to still add metadata before the output data is written | |
| return streamifyArray(result.metadata.quads()); | |
| }, | |
| metadata, | |
| }; | |
| return result; | |
| return { | |
| binary: false, | |
| get data(): Readable { | |
| // This allows other modules to still add metadata before the output data is written | |
| return streamifyArray(result.metadata.quads()); | |
| }, | |
| metadata, | |
| }; |
| return result; | ||
| } | ||
|
|
||
| return { binary: metadata.contentType !== INTERNAL_QUADS, data: await this.accessor.getData(identifier), metadata }; |
There was a problem hiding this comment.
| return { binary: metadata.contentType !== INTERNAL_QUADS, data: await this.accessor.getData(identifier), metadata }; | |
| return { | |
| binary: metadata.contentType !== INTERNAL_QUADS, | |
| data: await this.accessor.getData(identifier), metadata, | |
| }; |
| return entry; | ||
| } | ||
|
|
||
| private copyData(source: DataEntry): Readable { |
There was a problem hiding this comment.
Isn't there a better method? The highWaterMark thing was just a hack.
There was a problem hiding this comment.
True, I should drain the stream into an array.
| /** | ||
| * Abstract class that implements `getNormalizedMetadata` by calling the `getMetadata` with the incoming identifier | ||
| * and trying again by changing the trailing slash and trying again. | ||
| */ | ||
| export abstract class NormalizedDataAccessor implements DataAccessor { |
There was a problem hiding this comment.
Naming and comment can be clearer. (What is normalizing?)
There was a problem hiding this comment.
Very open to suggestions there since finding good names for things is way more difficult than actually implementing them
| /** | ||
| * Abstract class that implements `getNormalizedMetadata` by calling the `getMetadata` with the incoming identifier | ||
| * and trying again by changing the trailing slash and trying again. | ||
| */ | ||
| export abstract class NormalizedDataAccessor implements DataAccessor { |
There was a problem hiding this comment.
But I would not encode this functionality as a class. Can't FileDataAccessor (or perhaps better, DataAccessorBasedStore, possibly with a flag) have that functionality?
| * then the other URI MUST NOT correspond to another resource." | ||
| * @param identifier - Identifier that needs to be checked. | ||
| */ | ||
| getNormalizedMetadata: (identifier: ResourceIdentifier) => Promise<RepresentationMetadata>; |
There was a problem hiding this comment.
Mmm, why is that in the accessor contract? Seems like a more high-level thing to me.
There was a problem hiding this comment.
The reason for this one being in the DataAccessor is performance reasons. Specifically a SPARQL backend can do this with 1 query, but would need 2 queries if it is encoded in the DataAccessorBasedStore. So it's a trade-off. Can always move it back if you don't think the trade-off is worth it.
There was a problem hiding this comment.
Yeah, the accessor contract is there for simplicity. So would not add this. Performance can be an additional interface if needed.
| * @param identifier - Resource to modify. | ||
| * @param patch - Patch specifying how the resource should be modified. | ||
| */ | ||
| modifyResource: (identifier: ResourceIdentifier, patch: Patch) => Promise<void>; |
There was a problem hiding this comment.
Was a bit surprised to see that one here.
There was a problem hiding this comment.
This is something we discussed in a meeting before the work on this was started. The problem is that modifyResource is completely dependend on the backend storage. E.g. a file backend can't handle patches but a SPARQL backend can send the update request to the store. There is not really a way around this (except not allowing any backend to have custom patch implementations but that's not ideal), so there needs to be a way to send the patch to the backend. The function can always be renamed to something else of course.
There was a problem hiding this comment.
(except not allowing any backend to have custom patch implementations but that's not ideal)
Yeah, this was my suggestion as I was reading this. But perhaps a bit too harsh.
That seems like the kind of optimization for which you'd implement a store then instead of an accessor.
There was a problem hiding this comment.
To combine with the comment about getNormalizedMetadata. When making the SPARQL store, this would mean that we would have a SparqlDataAccessorBasedStore (or a name with less than 5 words) and a SparqlDataAccessor. The store would inherit from the DataAccessorBasedStore. The store would override 2 functions: modifyResource and getNormalizedMetadata (now being a protected function of the store). For both of these, SPARQL queries are required, so the store would have to call doSparql, which is a specific function of a SparqlDataAccessor. So that would mean this specific store only works with this specific kind of data accessor.
Not saying that's a bad thing, none of the actual store "behaviour" is duplicated, that's all still stored in the original store, and that is the main important part of this PR for me. Just want to clear up what the result of this is.
There was a problem hiding this comment.
-
Would it also work when plugging in
SparqlDataAccessorinto a normalDataAccessorBasedStore? So "work" as in functionally identical, just less optimal? -
Instead of
SparqlDataAccessorBasedStore, how aboutSparqlDataAccessoractually implements two interfaces:DataAccessorand something likeNormalizedDataAccessor? ThenDataAccessorBasedStorecan check for the optional presence of the second interface, and adjust accordingly? -
To what sense are we strongly optimizing here for SPARQL though? I.e., would the Normalized pattern also occur in other cases>
There was a problem hiding this comment.
- Yes, there would only be a few more requests.
- That would also work. Not sure yet what my opinion is on this compared to inheriting from the store. My first gut reaction is that this might make the store messier since for several functions it might need to check if they exist. Another potential option this made me think of is having the class extend both the store and implement the data accessor interface so all sparql related stuff is contained in the same class, so it would be its own data accessor (but still use most of the generic functions of the default store). But that would be even tighter coupling of course.
- That I don't know and is hard to predict. This is relevant specifically for backends where doing an "access" is expensive. In the case of the file store, it's a lot cheaper to check if a file exists on the file system than the cost of sending a query to a triple store.
But I am ok with moving the getNormalizedMetadata to the store, it makes the data accessor even cleaner. But if we ever want to optimize in the future it is something to keep in mind. The good thing is that this doesn't make optimizations impossible (or even super hard).
There was a problem hiding this comment.
Indeed, sounds good. Derivatives of SparqlDataAccessorBasedStore just seem to defeat the purpose (only a little though, I still see the reuse).
Because I first wanted to see the response to this PR before going into that discussion 😄 . But yes, I would suggest removing that one (and the InMemoryStore) after this PR since there already are some differences (mostly edge cases based on the spec). |
bc5b3c0 to
19ee0ca
Compare
|
Tried to fix all issues. Might have succeeded! |
66d1e32 to
45d51f9
Compare
|
I already rebased to the master branch. One big consequence of this is that the new resourcemapper is used. I did not fully support #146 yet since that would potentially create a few new discussions and I first want to close this one off. This does mean that this PR will not work well with the edge case of updating the content-type of a resource (since that requires changing the extension of the stored file). |
b3e3674 to
84ed680
Compare
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| public _read(): void { |
There was a problem hiding this comment.
| public _read(): void { | |
| protected _read(): void { |
There was a problem hiding this comment.
Has to be public to match the Readable interface.
The root container wasn't being created for file based tests. Containers should be POSTed as RDF bodies. Containment triples of child containers had no trailing slash.
84ed680 to
3004723
Compare
Resolves #63.
Draft PR since I also want to add integration tests. Specifically I want to run the same integration tests as are currently run on the file store (this actually works but I didn't have time to finish it cleanly today and I'm not here on Tuesday, just in case someone had time to look already tomorrow).
This is a pretty big one so I assume there will be discussions here (including the names 😄). Also grew a bit bigger than expected when working on it. We now sort of have a partial mocking framework for
fs. This way we don't need to mock the results of thefsfunctions in every call and tests don't break if you add one more call somewhere in the source code.I tried to keep as much as possible into account what might be done or required by future
DataAccessors, but I'm happy with how this turned out actualy. The Solid behaviour is now (mostly) handled by a single class, which means when we add some extra features in the future (such as redirects) only this one class will need to be updated. I might also add anInMemoryDataAccessorafter the integration part since that should be easy to implement now.