Skip to main content

Uploads

How documentation gets into the doc service: what happens to a bundle after it arrives, how far an upload gets, and what a retry does. For the endpoint itself and its parameters see API.

What happens to a bundle​

An upload is written to the database before its bundle is read, and stored on S3 afterwards:

Three rules are worth knowing, because everything else follows from them:

  • The database comes first. A recorded upload without an object is a visible state that can be retried; an object without a row would be documentation nobody knows about.
  • No transaction is open while the bundle streams. The upload is committed, then the bundle is transferred, then the result is written - a slow pipeline holds no database connection.
  • Nothing is stored until the set is accepted. What the rules ask about is the list of paths, and that is read from the archive's own table of contents without unpacking a single entry - so a refused upload leaves no object behind and no set to undo.

The state of an upload​

StateMeaning
UPLOADINGThe upload is recorded and its bundle is on its way. One attempt holds the upload id while this lasts
PENDINGThe set is current and the upload is waiting for the publication: a build was asked for, and its pages appear when that build runs
FAILEDThe set was refused, or its bundle could not be stored. Nothing of it is published, and a retry under the same upload id replaces the attempt

On its way to the object storage a bundle is spooled to a file in jeap.doc.storage.spool-directory rather than kept in memory, and the file is deleted as soon as the transfer is over.

What was stored is recorded with the upload: where the bundle lies and the SHA-256 of the bytes that went into the object storage, so what lies there can be held against what a pipeline sent. The digest is computed by the service itself; an upload does not send one, the service does not hand it to the object storage, and only the attempt whose bundle the upload names is recorded - the digest says what the upload points at, not what every attempt sent.

Every attempt writes its own object, under its own number: an attempt that was taken over as abandoned is not dead, only slow, and it will finish and write. Without a place of its own it would replace the bundle of the attempt that took the upload over, and the upload would then describe - down to its digest - other bytes than the ones lying there. The upload names the object of the attempt that won; what a straggler wrote is left behind and belongs to nothing.

The incoming documentation is stored separately from the generated documentation, under the configurable prefix of jeap.doc.storage.upload-prefix, and the identifier the doc service gives an upload is the path its bundle lies under.

Idempotency: what a retry does​

uploadId is the idempotency key of the API. One upload id is one upload: repeating the PUT under it never produces a second documentation set and never a second upload - so a pipeline may retry without asking whether its previous attempt got through. What a repetition does depends on what became of the attempt before it.

The upload idWhat the request doesAnswer
is unknownThe upload is recorded, its bundle stored201 with the result
belongs to a stored uploadNothing is written, the body is read and discarded200 with the result of the attempt that stored it
belongs to a failed uploadThe upload is claimed again and the bundle stored, under the key of the new attempt201 with the result
belongs to an upload another attempt is receivingNothing happens - the body is not even read409 UPLOAD_IN_PROGRESS, with Retry-After
belongs to an upload that has been in progress too longThe attempt is taken over as abandoned201 with the result
belongs to an upload that describes something elseNothing is written409 UPLOAD_ID_CONFLICT

A retry of an upload that is currently being received is refused, not queued. An upload belongs to one attempt at a time: it names one bundle, and two attempts filling it at once would make it a race which one it ends up naming. The second is told when to come back instead - and if the first finishes in the meantime, the retry is answered as a repetition of it.

An abandoned attempt frees itself. A service that dies while a bundle streams leaves an upload in UPLOADING with nobody to finish it. An upload that has been in progress for longer than jeap.doc.upload.in-progress-timeout counts as abandoned and is taken over by the next attempt.

Nothing may differ between the attempts of one upload. Every parameter is compared with the one recorded, from system down to build-url and generated-at; any difference is 409 UPLOAD_ID_CONFLICT. A retry re-sends the request it sent before, so nothing it could send is different - anything that is comes from somewhere else: a re-run of the workflow, an upload id that is not unique, a copied configuration. A restarted workflow is not a retry: it uses a new upload id, and that is a new upload with its own bundle.

The bundle itself is not compared. The parameters are checked, the bytes are not - the service has no digest of an upload before it has read it, and it does not ask a caller for one. A retry is therefore expected to send the same file again, not to produce it again: a ZIP built a second time differs in its entry timestamps even when the documentation in it is identical, and a workflow that regenerates its bundle before retrying is starting a new upload, which is what a new upload id is for.

How an upload is cleaned up again​

An upload is not kept forever, and the two halves of it are removed by two different mechanisms - the database by the doc service, the object storage by the bucket itself:

RemovesAfterBy
The doc servicethe upload in the databasejeap.doc.upload.housekeeping.retention, 14 days by defaulta nightly job, 0 30 2 * * * by default
The bucketthe bundle in the object storage21 days, in the lifecycle rule - see Operating the bucketthe object storage

In that order, and not the other way round. The lifecycle rule has to be set longer than the retention, so an upload never points at a bundle that is already gone; between the two an orphaned bundle lies around for a few days, which nothing reads and nobody misses.

What this removes is the upload, not the documentation. The set the upload became lives under its own prefix and is not expired by anything - a component that publishes once and stays stable for a year is the normal case. See The documentation a team writes for what does remove one.

Everything older than the retention is removed whatever state it is in. An upload that is still UPLOADING after two weeks belongs to a request nobody remembers, and one that is PENDING has had its set taken over long since - the record of the request is what goes, and the documentation stays. The job is the only place uploads go. What an upload documented is kept too: the system, component or library stays in the catalogue of the documentation.

Of several instances of the doc service only one runs the job: it takes a lock in the database (shedlock) for as long as it may run, and the others find it taken.

The lifecycle rule​

Every uploaded bundle is tagged jeap-doc-content=upload when it is stored, and the rule selects on that tag rather than on the prefix - jeap.doc.storage.upload-prefix is configured per instance, so a rule written against a prefix would have to know each instance's value, while the tag is the same everywhere.

The rule is provisioned with the bucket, by whatever infrastructure code creates it:

{
"Rules": [
{
"ID": "expire-jeap-doc-uploads",
"Status": "Enabled",
"Filter": { "Tag": { "Key": "jeap-doc-content", "Value": "upload" } },
"Expiration": { "Days": 21 },
"NoncurrentVersionExpiration": { "NoncurrentDays": 1 }
}
]
}

In Terraform this is an aws_s3_bucket_lifecycle_configuration with the same filter and expiration. NoncurrentVersionExpiration matters only on a versioned bucket, where an overwritten bundle would otherwise be kept as a previous version.

The rule must not select the sets. It filters on jeap-doc-content=upload, and a set carries jeap-doc-content=current for exactly this reason: the bundle of an upload is a staging copy, the set it became is the only copy there is, and nothing under that prefix may be expired by age at any value. See Operating the bucket.

The service needs s3:PutObject, s3:PutObjectTagging - without it the upload fails with an access denied while storing - and s3:GetObject and s3:DeleteObject for reading and removing objects. CopyObject uses read access to its source and write access to its destination.

What is checked, and what is not​

An upload is checked for what it says about itself: the parameters have to describe a documentation set (see API), the bundle may not be larger than jeap.doc.upload.max-size, and it has to be as long as its Content-Length announced.

The structure of the bundle is checked on upload, and on request before it. A pipeline may ask POST /api/uploads/docs/validation before it builds the ZIP and get a finding per misfiled path; the upload endpoint applies the same rules to the same paths, and refuses a set that breaks one with 422 and the findings in the body. The rules are on What an upload is validated against.

A refused set leaves nothing behind. The bundle is read onto a file and its list of entries decides before anything is stored, so there is no object, no set, and an upload a retry can take over once the set is fixed. Reading that list costs one seek and unpacks not one entry: the structure rules ask only about a path.

Most of the Markdown itself - CommonMark, dead links, the front-matter allowlist - is the doc workflow's half of the validation, before anything is sent, and the doc service does not read it again. The one exception is a page's own placement among the items of its chapter - sidebar_position, sidebar_after and sidebar_before - which is checked once more here, because that client is one a caller can skip. Nothing else about a file's content is scanned.

What happens next​

An upload that stored its bundle asks for the part that carries its system to be published, unless that site is configured not to be (publish-on-upload). It does not wait for the build: several uploads for one system arriving while a build runs are one request, and the next run serves all of them - see Generating the documentation.

The set is taken over into the current documentation before the upload is answered. Its bundle is copied to a key of its own - a server-side copy, so the bytes never come back through the service - and the files it holds are recorded. From then on the set is what a build reads; the uploaded bundle is a staging copy that the bucket expires.

The copy omits the tagging directive because some S3-compatible stores reject REPLACE. It initially inherits the upload tag. A separate PutObjectTagging request replaces that tag with jeap-doc-content=current before any database row references the copy. If copying or tagging fails, the upload fails and the previous set remains unchanged. A copy left behind is unreferenced and may be expired or swept. A retry uses a new attempt key. Neither operation transfers the bundle through the service again.

The upload itself stays PENDING, and the word still fits: what is pending is the publication. The set is current, and the build that was asked for is what puts it on the site. See The documentation a team writes.

A static site's tree​

A site whose content is static-site is a tree of Markdown uploaded for the site itself - a handbook, a set of guides - and published as it is: its folders are the navigation, and nothing is generated into it. Its upload names no system, component, library or template:

PUT /api/uploads/docs/{uploadId}?site=handbook&type=site-docs&source-format=markdown&source-repository=...
  • A tree replaces the site's previous tree whole. A file the new tree does not carry is gone from the site with the next build.
  • The same checks apply: the size, the extensions a page and its assets are written in, no .mdx, raw HTML shown as text, and the dry run of POST /api/uploads/docs/validation?type=site-docs&site=handbook. What does not apply is what belongs to a template: there are no chapters, so a file may lie at the root and in any folder, at any depth. A page's front matter keeps what any uploaded page may say about itself - its title, description, sidebar label, tags, keywords and its own sidebar_position. The validation rules list the names a tree may not use.
  • Only a static site takes it, and a static site takes nothing else. A site-level upload to a site with other content, and a system's upload to a static site, are refused - by the dry run as by the upload, where the dry run names its site.
  • Its role is the site's: <system-name>_%<site>_@site-uploads_#write - see Security.
  • Its root page is an index.md or README.md at the root, in any case. Without one the site gets a generated root page; a numbered 00-index.md is a page of its own, at /index/.
  • A tree can be removed again with DELETE /api/docs/custom/sites?site=<id>, by the same role or by an administrator of the sites, and with nothing else: the removal of a set or a subject refuses type=site-docs, as it is authorized by a system's role - see the API.

The navigation of a static site​

The sidebar is the tree: every folder is a category, every page an entry in it. Nothing has to be configured for that - a tree of plain folders and pages is a complete site. What decides how it looks:

  • The order is the numbers, or a page's own sidebar_position. A leading number on a page or folder, 01-why.md or 02-working-agreements/, orders it among its siblings and is not part of its URL or its label. Without a number, an entry comes after the numbered ones, in the order of its name - unless its front matter carries sidebar_position, which is kept as it was written and passed through to Docusaurus verbatim: a static site has no chapter-generated siblings to place a page around, so it orders its pages natively, by that number. sidebar_after and sidebar_before are refused on a static site's page - see the validation rules.
  • A folder's own page is an index.md, a README.md or a page named like its folder - guides/guides.md, compared as written, so 01-guides/guides.md is not one. Clicking the folder opens it, and its sidebar_label, or else its title, labels the folder.
  • A folder's label is, in this order: the label of its _category_.json, the label of its own page, or its name without the number - 02-working-agreements/ shows as working-agreements, written as it is.

_category_.json is optional. A folder carries one only where its name is not the label it should have, or to fold it:

intro/
_category_.json # {"label": "Introduction", "position": 1}
01-why.md
02-how-we-work.md
working-agreements/
index.md # the folder's own page: its title labels the folder
reviews.md
glossary.md
KeyTypeWhat it does
labelstringThe folder's label in the sidebar
positionnumberWhere the folder goes among its siblings, ahead of any number on the folder or its own page
collapsedbooleanWhether the folder starts closed
collapsiblebooleanWhether the folder can be closed at all
classNamestringA CSS class on the folder's sidebar entry

Only these keys are published. Everything else - above all a link, whose target Docusaurus resolves and fails the whole build over when it does not exist - is dropped, and a file that is no JSON object is left out with a warning in the log: the folder is then labelled as one without the file is. A _category_.json is the one name beginning with an underscore a static tree may carry.