Repository navigation
Description
This is a discovery ticket that would end in multiple ADRs in this repo. The goal is to determine the basic data structures and relationships needed to store content data for the LMS with the following goals:
- Handle all existing course use cases.
- Handle v2 content libraries, and library resources shared across multiple courses, with different policies/overrides.
- Handle potentially non-XBlock content.
- Allow for fast publishing.
- Allow for atomic publishing.
- Allow for easy export.
- Allow third party applications to build their own advanced data structures on top of it.
- Allow for efficient querying.
- Minimize the amount of wasted space caused by nearly identical versions caused by minor edits.
There will likely be some prototyping involved in this, as well as a lot of discussion.
These ADRs would include:
- Determine high level approach to splitting reusable content and learning context specific policy.
- Determine high level approach to versioning and incremental publishing.
- Determine leaf XBlock-level modeling.
- Determine unit-level modeling.
- Determine sequence-level modeling.
Open edX's ModuleStore has explicit versioning capabilities (though they're not really used from LMS most of the time). Blockstore has versioning deeply baked into the design, but we've generally avoided encoding multi-version support into the post-publish data stores we build during course publish (e.g. CourseOverview, Block Transformers/Course Blocks API, etc.)
I think we've come to a point where we really do need to cross that divide and start introducing content versioning concepts to the LMS more generally. Some motivating reasons:
- It's difficult to preview changes before publishing if the LMS can only display the published version.
- The design of content libraries assumes that multiple versions are available simutaneously.
- Building all these separate stores of published data takes time, and parts may fail. When this happens, our course is in an inconsistent half-published state. For example, the rendered course content may be updated but the course outline generation may have failed so that nobody can see the new content. Ideally, we'd want to give these systems time to build up the data that they need, and then change everything atomically at once.
- Other systems like scoring and state storage would benefit from being able to store the actual version it was created against.
Storage Scaling Issues
SplitMongo ModuleStore wasted a lot of space with old version data, eventually leading us to create a separate cleanup script for it. There were a number of reasons why disk usage got so bad with this system:
- Structural data was stored inefficiently.
- New versions were being published for tiny changes.
- There was no cleanup.
- Historical course data had very little use.
Every time there was even a small change (e.g. the title of a Unit), we ended up writing a document with all settings-scoped data for the course. This happened all the time in Studio, so that for every one version that is of interest to us for viewing or preview purposes, there would be dozens of almost-identical intermediate versions. We ended up in a place where the majority of course storage was wasted in this way.
There are a few ways we can make this much better:
- Isolate changes better
Most content doesn't change very much from one version to the next, so we should break up the course into more granular pieces and track their changes individually. - Support simple cleanup policies
There will be intermediate versions that can be almost immediately discarded (like the last state of the Studio draft). We should have obvious cleanup facilities for getting rid of those as soon as they are not needed. - Support a simplified data model for clients.
Thinking about versions is hard, and unintuitive. We should have a set of primitives that help people model version-awareness into their content without having to overly complicate their data models.
Modeling Versioning in a way that scales (i.e. both features and users)
The following is a disorganized set of thoughts:
Entities (the names are bad, I'm just trying to get down the ideas)
- LearningObject
- LearningObjectVersion (with sub-types made with joined tables that represent things like Units, Blocks).
- Bundles (?) of LearningObjectVersions. I wanted to resist adding a separate layer here, but I realized that without this, we'd have to echo out all the (LearningObjectVersion/LearningContextVersion) entries with each new version, even if the libraries that a course is using isn't changing at all. Which would be really bad for encouraging library use. I really don't like the reuse of a Blockstore term and concept though.
- LearningContextVersion can contain multiple Bundles (e.g. a Course consists of versioned bundles for its "own" resources, as well as the Bundles of various other things like Libraries).
- LearningContextBranch enforces that at any given point, there is one live version per branch (e.g. "draft", "live")
- Some sort of registry where any app that has data related to a version has a chance to put the status of it (i.e. is it ready?) (How to handle the case where a process dies?)
I'm fiddling with some of these ideas in the learning_publishing app's models.py file at the moment.
Concern: How is it different than Blockstore? A: It's going to be much more relational data model that you hang other relational models (e.g. XBlock content, scheduling information) off of. Also, it's going to have zero intelligence about cycle detection or dependencies. It's also going to have explicit measures for cleanup of unused versions, which is not a thing in Blockstore.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
ormsbee commentedon Feb 7, 2022
Okay, I think I'm overloading LearningContext with concepts of content ownership and student state association, and I'm not sure how to reconcile that cleanly. I feel like there's something missing that I don't have the right vocabulary for.
Some rambling thoughts:
So it's almost like there's a PublishingContext (each library, the course, some part of a course, some part of a pathway, etc.), which is a group of content that can be versioned and published together. And then there's a LearningContextVersion, which has one or more PublishingContextVersions batched together.
So maybe Learning Contexts have:
That could match up to a Course Run in the LMS. But is that over-complicating things to introduce a distinction between a publishing context and a learning one? If we want to shift how courses are authored to something more granular, it might be worthwhile.
ormsbee commentedon Feb 7, 2022
FYI @kdmccormick, @feanil, @Carlos-Muniz, @arbrandes, @bradenmacdonald, @doctoryes, @saksham115, @jristau1984: Some thoughts I've been having lately about data modeling content in the LMS, with possible implications for content libraries v2 and unit composition in the LMS. It's not very well organized, and no action is required–there's a lot to unpack here that's beyond the current scope of BD-14. I just wanted to be transparent about where my head was at.
ormsbee commentedon Feb 7, 2022
Thinking on this a bit more, this might be a viable way to model something like CCX, where the LearningContext becomes the CCX course key, and it has the PublishingContext for the base course. Policy things like dates would joins between LearningContexts and PublishingContexts.
This would also allow for how we model default behavior in libraries. The default values becomes the policy tables that join the library's LearningContext and the library's PublishingContext. The overrides that are specific to courses using the library become joins between the course's LearningContext and the library's PublishingContext.
ormsbee commentedon Feb 7, 2022
That's actually pretty exciting to me, because it gives us a place to more cleanly apply policy-level separation in a way that decouples content authoring and administration–and does so in a way that unifies CCX and libraries override handling.
arbrandes commentedon Feb 8, 2022
I'm not going to pretend I have the time to dive into this in the near future, but I certainly like it that you're giving it serious thought, Dave. :)
Nevertheless, here's a use case I want to bring up for consideration.
This is because Studio never offered a wiki-like history (including grouping changes, who made them, etc) that a course team could navigate. I'm positive authors would love this: I know because I went as far as versioning OLX on git just so I could have all this stuff. I've seen this pop up in the forum on occasion, and if memory serves, MIT used to do this a lot.
I realize what you're discussing here is at a deeper level than exposing diffs on a frontend. But, again, it might be a use case worth considering as you model the data.
ormsbee commentedon Feb 8, 2022
@arbrandes: Right. I guess it's more accurate to say that historical course data had very little use in the LMS. The main use there would be for fast rollback. Studio could benefit from it, though we didn't manage to prioritize any of that work at edX.
ormsbee commentedon Feb 8, 2022
In this view of the world, we'd conceptually have:
LearningObject
PublishingContext
LearningContext
Relationship between LearningContexts and PublishingContexts
Next question: How is policy (e.g. defaults, scheduling, partitioning) stored against these data models?
kdmccormick commentedon Feb 9, 2022
@ormsbee I found your latest comment (the directly above the one I'm typing) to be illuminating. Your distinction between LearningContext and PublishingContext is something that I've wondered about but hadn't been able to crystalize.
I agree with the overall direction you are taking in this app. I haven't taken a deep look a the other two apps yet but will soon.
Yeah :/ I was really hoping we could hold onto "LMS doesn't do versions" but I admit I don't have any robust solutions for the pitfalls you listed.
Now some more in-the-weeds reactions/ramblings:
Hm, this sounds complicated. I had always thought that student state would remain isolated between LearningContexts, and by consequence, Content Libraries would carry no student state other than maybe author-preview state in Studio.
I guess I view Content Libraries as a more generalized type of LearningContext, one that should hold policy but not state. Would that function as a helpful or even sensical simplifying assumption? Would it lock Content Libraries out of an interesting use case?
Going another direction, what if policy itself were a LearningObject within the PublishingContext? At that point, could we say that a Content Library is a PublishingContext but not a LearningContext in the eyes of the LMS?
I know you said the names aren't final. I'm still going to poke at them because it helps me think about the architecture, and also I can't help myself :)
So, maybe:
keeping in mind that these are models are all namespaced under
openedx_learning.publishing.ormsbee commentedon Feb 9, 2022
@kdmccormick: I'm going to chew on the first half of your reactions for a while, but w.r.t. the naming suggestions:
FWIW, in case it wasn't clear, my naming attempt was a desperate cry for help. 😛 Thank you for suggesting new ones.
I had originally dabbled with the idea of intentionally using LO since some of them will be LOs in the general industry sense, but I like your framing of ContentObject better. I would still prefer ContentObjectVersion over VersionedContentObject because to me "VersionedContentObject" implies that there is a separate model with versions–i.e. I should be able to call
versioned_content_obj.versionsand get back a list of other models with version information. I think that ContentObjectVersion more clearly conveys that this is the data for a single version.I also like ContentPackage as a way to not use the word "context" so much, and I do think it's simpler and clearer.
I'm in the middle of writing a model for encoding Units, and I'll try to do so in a way that incorporates some of this new language and addresses your other questions/suggestions above. Thank you for looking at this!
ormsbee commentedon Feb 10, 2022
Implementing Unit Composition
Let's imagine what Unit Composition would look like it if was built on top of a data model like this. In this framing, all the ContentObject and ContentPackage stuff mentioned above would be part of the
learning_publishingapp, and most of this would be a layer above that as thelearning_compositionapp. Given the data model I'm suggesting, even the LearningContext model might move up to this level.Idea: ContentPackages represent raw pools of ContentObjects, and composition of those COs only exists within a LearningContext.
This sounds a bit weird, since moving a Block from one Unit to another should surely count as a change in content. But a few thoughts I had around this:
These entities live at the LearningContext level.
Model that joins LearningContextVersion and ContentObjectVersion: "Block"?
Unit
UnitBlocks
There's a weird sort of language flip with these names in that we're taking things that are versioned but talking about them
Edge Case: Nested blocks in Units
Units are flat lists. There are two scenarios I know of in which we have nesting within units right now:
These include the LibraryContentBlock, SplitTestBlock, and ConditionalBlock. I think we can add these inline as part of the list, along with their content group settings, so that we can efficiently select the subset that our student cares about.
We might be able to just collapse this into a single Block as far as this layer of abstraction is concerned, and let the XBlock runtime deal with the nesting.
Right now, when you make a SplitTestBlock, with two things in it, you’re actually ending up with a hierarchy in ModuleStore that looks like this:
So the hierarchy looks like: Course -> Section -> Sequence -> Vertical -> SplitTest -> Vertical -> ProblemBlock. We've had a number of bugs along the lines of “nobody actually thinks this kind of structure is a thing on our platform", because they don't realize that extra level of hierarchy is allowed to exist.
But this kind of nesting for SplitTest only exists to generate what is a conceptually flat list–what we’re really trying to do is render Problem 1a+2a for one group and Problem 1b+2b for another group. The nesting is just because that’s how XBlocks work, and implementing them as children lets the SplitTestBlock control which one to show when rendering. But the mechanism SplitTestBlock uses underneath is user partitioning.
So Studio can keep this view of the world, but there’s no reason we need to encode it like that for the LMS.
The LMS can have a version of the data that just looks like:
ormsbee commentedon Feb 11, 2022
Okay, I've rambled a lot here, but I'm going to actually try to code this up in models and see how it holds together.
ormsbee commentedon Feb 11, 2022
Side note: Explicit branches (draft vs. published) vs. having entirely different LearningContexts to encode drafts for previewing (or even sending explicit versions during preview)?
ormsbee commentedon Feb 14, 2022
Latest wrinkle issue is: How important is it to be able to change the identifier for a piece of content over time? So in other words, can I change the UsageKey for something and still keep student state/history associated with it?
The data model implication if we wanted that kind of capability would be:
It's a bit wasteful of space, since the identifiers are getting repeated with every revision, though it's not that big a deal–we'd use 8 bytes for the foreign key anyway, and identifiers would compress well if we use the right row type.
The bigger thing is how intuitive it is, and how awkward it would be to work with. Certain queries get potentially much more expensive, like "did this identifier ever exist in this course?". There's also potential for more confusion between when you're working with this abstract, version-less Block, and a concrete, version-of-a-Block.
ormsbee commentedon Feb 14, 2022
Another weird wrinkle with having an abstract, versionless Block in this scenario is that it makes it harder to enforce uniqueness of UsageKey-style identifier within a LearningContextVersion (since the identifiers would be in the versioned-block table and the f-key to LearningContextVersion would be in the versionless-block table).
ormsbee commentedon Feb 18, 2022
Additional wrinkle: Does it make sense to allow for multiple identifiers for a piece of content? This might be too obscure a use case, but we've had requests in the past for something like this. The scenario was that a university had their own content library, and that content was converted into capa problems (among other formats). Those problems had UsageKeys, but they also wanted to associate it with their original content IDs when they analyzed the usage data later. This could be done with some sort of namespaced identifier scheme, e.g.
('xblock', <usage_key>), ('uni-lib', <uni-identifier>)46 remaining items
feanil commentedon May 6, 2022
Assumption check: While trying to work through how this would work with videos, I realized that probably the blob in the content atom is actually going to need to use something like the FileField(backed by whatever storage mechanism you want) so that we don't have to store large amounts of data in the database.
In which case, making the ContentAtom be akin to a file makes sense to me. We want to have the files be immutable but then have the metadata related to files(in the case of video, title, language, etc) be easy to change even if you're not modifying the video.
Going down this line of reasoning a bit further, is the reason that you're thinking we might want multiple types of content atoms(e.g. VideoContentAtom) that we may want to extract some of the data in the atom for ease of querying? I'm imagining things like the length of a video which is going to be part of the video data but that we might want to be able to quickly access without re-analyzing the whole video.
ormsbee commentedon May 6, 2022
Agreed. Unfortunately. Video's always the edge case that breaks everything by being 1000X the size of everything else. 😞
Originally, yes. I thought that it made sense to have a model for metadata that was intrinsic to the data of the raw bytes themselves, separate from other metadata about said bytes (like the author name, or a short description). But after our conversation yesterday, I came around to the idea that small levels of duplication of metadata is fine, and that it's preferable to do that than to confuse developers by giving them two places to hang this kind of data off of (which is I think was one of the points you and @kdmccormick were making?).
In the case of a video, that might mean that a VideoContentObject would hold both the length (intrinsic to the file itself) + a short description (layered metadata).
I think that extension at the ContentAtom layer then makes sense primarily when data requires significant transformation. This may be on a small scale, like stripping out all the policy/due date information, or removing deprecated fields. Or it may be on a large scale, if we're converting formats entirely–like QTI to Capa, or OLX into some more optimized representation. In that case, the original content-as-imported might stay in the ContentAtom, but a new derived ProblemBlockAtom might store the transformed version.
Granted, a lot of this conversion can (and probably should) be done before it gets published into the LMS at all. But having this side-loadable Atom gives other apps the opportunity to process and make derived content as necessary, which I think will be useful for querying, experimentation, and data migration. ContentAtoms aren't "owned" by any app, really. Any app can create a ContentObject that points to one, and any app can make a MySpecialAtom that derives its data from a ContentAtom.
ormsbee commentedon May 7, 2022
Random testing thought: In addition to having standard abstract models to inherit from for certain needs (e.g. something with the right way to subclass and query ContentObject), it would be good to have some standard test classes that apps could use, that would run common scenarios like, "Hey, what happens when the LearningContext gets deleted?"
ormsbee commentedon May 9, 2022
Okay, I've done some prototype hacking, and I think this is feasible. I'll make a new ADR PR for data model and post the link here shortly. It'll cover the basic high level concepts/models for block and unit level content types, and the extensibility story.
Follow-on ADRs would cover error handling and potentially a more efficient versioning representation. That last one is tricky because I can think of a model that would do it, but it would make it more difficult to have the database enforce certain correctness constraints.
ormsbee commentedon May 23, 2022
As I was writing up the ADR for the data modeling basics, I came to the conclusion that the ContentPackage/LearningContext distinction was more trouble than it's worth, especially as more and more things were moved up to LearingContext anyway (e.g. Unit/Sequence composition). I think that what we really got from the split of those concepts were a couple of ideas:
But having the ContentPackage/LearningContext split was giving some painful duplication, and I ran into particular issues in figuring out how to model Segments in a way that tied it to the ContentPackage.
So with Content/Learning prefixes gone, I think the models simplify out to something like this:
I've also renamed the primitive, verisonless content-package layer classes from ContentObject/ContentAtom to ItemInfo/ItemRaw, which brings it more into line with Item/ItemVersion terminology used elsewhere.
ormsbee commentedon May 23, 2022
Side Note on Re-Use: To facilitate easier querying in the future, some of the models should have nullable fields that can point to the original thing they're copying from. So if my ItemVersion was a copy of a Library's ItemVersion, it should have a fkey to that Library's ItemVersion.
At the same time, if we want to be resilient to content deletion, we can't rely on the fkey to always exist.
ormsbee commentedon May 27, 2022
I'm going to close this for now, but may re-open if there is further discussion.
ormsbee commentedon Jul 9, 2022
Okay, one adjustment that I'm making to this is to allow the association of multiple ItemRaw objects with a given ItemVersion. I think that will give some flexibility around associating multiple assets (e.g. for Video data + transcripts, problems with graders, etc.) without adding too much complexity.
ormsbee commentedon Jul 18, 2022
Two more tweaks:
ItemRaw is now Content
This makes the hierarchy look like:
graph TD; CI[Item]-->CIV[ItemVersion] CIV[ItemVersion]-->CC1[Content]It also gives the M:M through-model between
ItemVersionandContentthe clearer sounding name ofItemVersionContent.Mapping Data to ItemVersion
I was creating models for serving static assets, and in particular I was thinking about images vs. other downloadable assets like zip files or PDFs. There are certain commonalities, like download permissions. But there is a lot of variation as well–images get alt text, resolutions, possibly multiple files for different sizing, etc.
One option is to make the relationship hierarchical by having a StaticAssetVersion model and then hanging yet more models off of that one. But one of the frustrating things about that arrangement is that we'd be repeating ourselves a lot. Say something that is image-specific gets changed–all the static asset-generic metadata gets re-generated each time (new ItemVersion so a new OneToOne StaticAssetVersion + the ImageAssetVersion that actually changed. Extrapolated across anything that might ever want to attach any kind of metadata, and that could be a mess.
Instead, I'm now thinking about treating these different aspects of the data (Downloadable, Image, etc.) as separate data models that are mapped to ItemVersions via a 1:M table that is locked 1:1 on the
item_version_id. So:graph LR subgraph itemstore ItemVersion end subgraph staticassets direction TB Image DownloadableAsset subgraph "(autogenerated)" direction TB ItemVersionImage ItemVersionDownloadableAsset end end subgraph staticassets ItemVersionImage --"M:1"--> Image ItemVersionImage --"1:1"--> ItemVersion ItemVersionDownloadableAsset--"M:1"--> DownloadableAsset ItemVersionDownloadableAsset --"1:1"--> ItemVersion endThings I think are promising about this approach: