Skip to content

refactor(dataset): Redirect multipart upload through File Service - #4136

Merged
chenlica merged 22 commits into
apache:mainfrom
carloea2:refactor/multipart_upload_through_dataset_resource
Jan 5, 2026
Merged

chenlica merged 22 commits into
apache:mainfrom
carloea2:refactor/multipart_upload_through_dataset_resource

Conversation

@carloea2

@carloea2 carloea2 commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

  • DB / schema

    • Add dataset_upload_session to track multipart upload sessions, including:

      • (uid, did, file_path) as the primary key
      • upload_id (UNIQUE), physical_address
      • num_parts_requested to enforce expected part count
    • Add dataset_upload_session_part to track per-part completion for a multipart upload:

      • (upload_id, part_number) as the primary key
      • etag (TEXT NOT NULL DEFAULT '') to persist per-part ETags for finalize
      • CHECK (part_number > 0) for sanity
      • FOREIGN KEY (upload_id) REFERENCES dataset_upload_session(upload_id) ON DELETE CASCADE
  • Backend (DatasetResource)

    • Multipart upload API (server-side streaming to S3, LakeFS manages multipart state):

      • POST /dataset/multipart-upload?type=init

        • Validates permissions and input.
        • Creates a LakeFS multipart upload session.
        • Inserts a DB session row including num_parts_requested.
        • Pre-creates placeholder rows in dataset_upload_session_part for part numbers 1..num_parts_requested with etag = '' (enables deterministic per-part locking and simple completeness checks).
        • Rejects init if a session already exists for (uid, did, file_path) (409 Conflict). Race is handled via PK/duplicate handling + best-effort LakeFS abort for the losing initializer.
      • POST /dataset/multipart-upload/part?filePath=...&partNumber=...

        • Requires dataset write access and an existing upload session.
        • Requires Content-Length for streaming uploads.
        • Enforces partNumber <= num_parts_requested.
        • Per-part locking: locks the (upload_id, part_number) row using SELECT … FOR UPDATE NOWAIT to prevent concurrent uploads of the same part.
        • Uploads the part to S3 and persists the returned ETag into dataset_upload_session_part.etag (upsert/overwrite for retries).
        • Implements idempotency for retries by returning success if the ETag is already present for that part.
      • POST /dataset/multipart-upload?type=finish

        • Locks the session row using SELECT … FOR UPDATE NOWAIT to prevent concurrent finalize/abort.

        • Validates completeness using DB state:

          • Confirms the part table has num_parts_requested rows for the upload_id.
          • Confirms all parts have non-empty ETags (no missing parts).
          • Optionally surfaces a bounded list of missing part numbers (without relying on error-message asserts in tests).
        • Fetches (part_number, etag) ordered by part_number from DB and completes multipart upload via LakeFS.

        • Deletes the DB session row; part rows are cleaned up via ON DELETE CASCADE.

        • NOWAIT lock contention is handled (mapped to “already being finalized/aborted”, 409).

      • POST /dataset/multipart-upload?type=abort

        • Locks the session row using SELECT … FOR UPDATE NOWAIT.
        • Aborts the multipart upload via LakeFS and deletes the DB session row (parts cascade-delete).
        • NOWAIT lock contention is handled similarly to finish.
    • Access control and dataset permissions remain enforced on all endpoints.

  • Frontend service (dataset.service.ts)

    • multipartUpload(...) updated to reflect the server flow and return values (ETag persistence is server-side; frontend does not need to track ETags).
  • Frontend component (dataset-detail.component.ts)

    • Uses the same init/part/finish flow.
    • Abort triggers backend type=abort to clean up the upload session.

Any related issues, documentation, discussions?

Closes #4110


How was this PR tested?

  • Unit tests added/updated (multipart upload spec):

    • Init validation (invalid numParts, invalid filePath, permission denied).
    • Upload part validation (missing/invalid Content-Length, partNumber bounds, minimum size enforcement for non-final parts).
    • Per-part lock behavior under contention (no concurrent streams for the same part; deterministic assertions).
    • Finish/abort locking behavior (NOWAIT contention returns 409).
    • Successful end-to-end path (init → upload parts → finish) with DB cleanup assertions.
    • Integrity checks: positive + negative SHA-256 tests by downloading the finalized object and verifying it matches (or does not match) the expected concatenated bytes.
  • Manual testing via the dataset detail page (single and multiple uploads), verified:

    • Progress, speed, and ETA updates.
    • Abort behavior (UI state + DB session cleanup).
    • Successful completion path (all expected parts uploaded, LakeFS object present, dataset version creation works).

Was this PR authored or co-authored using generative AI tooling?

GPT partial use.

@github-actions github-actions Bot added ddl-change Changes to the TexeraDB DDL refactor Refactor the code frontend Changes related to the frontend GUI service common labels Dec 18, 2025
@carloea2
carloea2 marked this pull request as ready for review December 19, 2025 23:10
Comment thread sql/texera_ddl.sql Resolved

@aicam aicam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xuang7 xuang7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I have tested, main functionality is working for different scale of file sizes. There is one issue of uploading the same file; both uploads were canceled due to previous approach on the frontend. Left few comments.

@chenlica

chenlica commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

@carloea2 Please resolve those finished conversations.

@carloea2

carloea2 commented Jan 3, 2026

Copy link
Copy Markdown
Contributor Author

@carloea2 Please resolve those finished conversations.
There is no conversation that should be resolved at the moment

@carloea2

carloea2 commented Jan 3, 2026

Copy link
Copy Markdown
Contributor Author

@chenlica can we run the workflows to see if they pass?

@carloea2
carloea2 requested a review from aicam January 3, 2026 23:56

@chenlica chenlica left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left comments. Please check.

Comment thread sql/updates/17.sql Resolved

@chenlica chenlica left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments.

@chenlica chenlica left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See new comments.

@chenlica
chenlica merged commit 253409a into apache:main Jan 5, 2026
SarahAsad23 pushed a commit to madisonmlin/texera that referenced this pull request May 20, 2026
…ache#4136)

### What changes were proposed in this PR?

* **DB / schema**

* Add `dataset_upload_session` to track multipart upload sessions,
including:

    * `(uid, did, file_path)` as the primary key
    * `upload_id` (**UNIQUE**), `physical_address`
    * **`num_parts_requested`** to enforce expected part count

* Add `dataset_upload_session_part` to track per-part completion for a
multipart upload:

    * `(upload_id, part_number)` as the primary key
* `etag` (`TEXT NOT NULL DEFAULT ''`) to persist per-part ETags for
finalize
    * `CHECK (part_number > 0)` for sanity
* `FOREIGN KEY (upload_id) REFERENCES dataset_upload_session(upload_id)
ON DELETE CASCADE`

* **Backend (`DatasetResource`)**

* Multipart upload API (server-side streaming to S3, LakeFS manages
multipart state):

    * `POST /dataset/multipart-upload?type=init`

      * Validates permissions and input.
      * Creates a LakeFS multipart upload session.
      * Inserts a DB session row including `num_parts_requested`.
* **Pre-creates placeholder rows** in `dataset_upload_session_part` for
part numbers `1..num_parts_requested` with `etag = ''` (enables
deterministic per-part locking and simple completeness checks).
* **Rejects init if a session already exists** for `(uid, did,
file_path)` (409 Conflict). Race is handled via PK/duplicate handling +
best-effort LakeFS abort for the losing initializer.

    * `POST /dataset/multipart-upload/part?filePath=...&partNumber=...`

      * Requires dataset write access and an existing upload session.
      * **Requires `Content-Length`** for streaming uploads.
      * Enforces `partNumber <= num_parts_requested`.
* **Per-part locking**: locks the `(upload_id, part_number)` row using
`SELECT … FOR UPDATE NOWAIT` to prevent concurrent uploads of the same
part.
* Uploads the part to S3 and **persists the returned ETag** into
`dataset_upload_session_part.etag` (upsert/overwrite for retries).
* Implements idempotency for retries by returning success if the ETag is
already present for that part.

    * `POST /dataset/multipart-upload?type=finish`

* Locks the session row using `SELECT … FOR UPDATE NOWAIT` to prevent
concurrent finalize/abort.

      * Validates completeness using DB state:

* Confirms the part table has `num_parts_requested` rows for the
`upload_id`.
* Confirms **all parts have non-empty ETags** (no missing parts).
* Optionally surfaces a bounded list of missing part numbers (without
relying on error-message asserts in tests).

* Fetches `(part_number, etag)` ordered by `part_number` from DB and
completes multipart upload via LakeFS.

* Deletes the DB session row; part rows are cleaned up via `ON DELETE
CASCADE`.

* **NOWAIT lock contention is handled** (mapped to “already being
finalized/aborted”, 409).

    * `POST /dataset/multipart-upload?type=abort`

      * Locks the session row using `SELECT … FOR UPDATE NOWAIT`.
* Aborts the multipart upload via LakeFS and deletes the DB session row
(parts cascade-delete).
      * **NOWAIT lock contention is handled** similarly to `finish`.

* Access control and dataset permissions remain enforced on all
endpoints.

* **Frontend service (`dataset.service.ts`)**

* `multipartUpload(...)` updated to reflect the server flow and return
values (ETag persistence is server-side; frontend does not need to track
ETags).

* **Frontend component (`dataset-detail.component.ts`)**

  * Uses the same init/part/finish flow.
  * Abort triggers backend `type=abort` to clean up the upload session.

---

### Any related issues, documentation, discussions?

Closes apache#4110

---

### How was this PR tested?

* **Unit tests added/updated** (multipart upload spec):

* Init validation (invalid numParts, invalid filePath, permission
denied).
* Upload part validation (missing/invalid Content-Length, partNumber
bounds, minimum size enforcement for non-final parts).
* **Per-part lock behavior** under contention (no concurrent streams for
the same part; deterministic assertions).
  * Finish/abort locking behavior (NOWAIT contention returns 409).
* Successful end-to-end path (init → upload parts → finish) with DB
cleanup assertions.
* **Integrity checks**: positive + negative SHA-256 tests by downloading
the finalized object and verifying it matches (or does not match) the
expected concatenated bytes.

* Manual testing via the dataset detail page (single and multiple
uploads), verified:

  * Progress, speed, and ETA updates.
  * Abort behavior (UI state + DB session cleanup).
* Successful completion path (all expected parts uploaded, LakeFS object
present, dataset version creation works).

---

### Was this PR authored or co-authored using generative AI tooling?

GPT partial use.

---------

Co-authored-by: Chen Li <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…ache#4136)

### What changes were proposed in this PR?

* **DB / schema**

* Add `dataset_upload_session` to track multipart upload sessions,
including:

    * `(uid, did, file_path)` as the primary key
    * `upload_id` (**UNIQUE**), `physical_address`
    * **`num_parts_requested`** to enforce expected part count

* Add `dataset_upload_session_part` to track per-part completion for a
multipart upload:

    * `(upload_id, part_number)` as the primary key
* `etag` (`TEXT NOT NULL DEFAULT ''`) to persist per-part ETags for
finalize
    * `CHECK (part_number > 0)` for sanity
* `FOREIGN KEY (upload_id) REFERENCES dataset_upload_session(upload_id)
ON DELETE CASCADE`

* **Backend (`DatasetResource`)**

* Multipart upload API (server-side streaming to S3, LakeFS manages
multipart state):

    * `POST /dataset/multipart-upload?type=init`

      * Validates permissions and input.
      * Creates a LakeFS multipart upload session.
      * Inserts a DB session row including `num_parts_requested`.
* **Pre-creates placeholder rows** in `dataset_upload_session_part` for
part numbers `1..num_parts_requested` with `etag = ''` (enables
deterministic per-part locking and simple completeness checks).
* **Rejects init if a session already exists** for `(uid, did,
file_path)` (409 Conflict). Race is handled via PK/duplicate handling +
best-effort LakeFS abort for the losing initializer.

    * `POST /dataset/multipart-upload/part?filePath=...&partNumber=...`

      * Requires dataset write access and an existing upload session.
      * **Requires `Content-Length`** for streaming uploads.
      * Enforces `partNumber <= num_parts_requested`.
* **Per-part locking**: locks the `(upload_id, part_number)` row using
`SELECT … FOR UPDATE NOWAIT` to prevent concurrent uploads of the same
part.
* Uploads the part to S3 and **persists the returned ETag** into
`dataset_upload_session_part.etag` (upsert/overwrite for retries).
* Implements idempotency for retries by returning success if the ETag is
already present for that part.

    * `POST /dataset/multipart-upload?type=finish`

* Locks the session row using `SELECT … FOR UPDATE NOWAIT` to prevent
concurrent finalize/abort.

      * Validates completeness using DB state:

* Confirms the part table has `num_parts_requested` rows for the
`upload_id`.
* Confirms **all parts have non-empty ETags** (no missing parts).
* Optionally surfaces a bounded list of missing part numbers (without
relying on error-message asserts in tests).

* Fetches `(part_number, etag)` ordered by `part_number` from DB and
completes multipart upload via LakeFS.

* Deletes the DB session row; part rows are cleaned up via `ON DELETE
CASCADE`.

* **NOWAIT lock contention is handled** (mapped to “already being
finalized/aborted”, 409).

    * `POST /dataset/multipart-upload?type=abort`

      * Locks the session row using `SELECT … FOR UPDATE NOWAIT`.
* Aborts the multipart upload via LakeFS and deletes the DB session row
(parts cascade-delete).
      * **NOWAIT lock contention is handled** similarly to `finish`.

* Access control and dataset permissions remain enforced on all
endpoints.

* **Frontend service (`dataset.service.ts`)**

* `multipartUpload(...)` updated to reflect the server flow and return
values (ETag persistence is server-side; frontend does not need to track
ETags).

* **Frontend component (`dataset-detail.component.ts`)**

  * Uses the same init/part/finish flow.
  * Abort triggers backend `type=abort` to clean up the upload session.

---

### Any related issues, documentation, discussions?

Closes apache#4110

---

### How was this PR tested?

* **Unit tests added/updated** (multipart upload spec):

* Init validation (invalid numParts, invalid filePath, permission
denied).
* Upload part validation (missing/invalid Content-Length, partNumber
bounds, minimum size enforcement for non-final parts).
* **Per-part lock behavior** under contention (no concurrent streams for
the same part; deterministic assertions).
  * Finish/abort locking behavior (NOWAIT contention returns 409).
* Successful end-to-end path (init → upload parts → finish) with DB
cleanup assertions.
* **Integrity checks**: positive + negative SHA-256 tests by downloading
the finalized object and verifying it matches (or does not match) the
expected concatenated bytes.

* Manual testing via the dataset detail page (single and multiple
uploads), verified:

  * Progress, speed, and ETA updates.
  * Abort behavior (UI state + DB session cleanup).
* Successful completion path (all expected parts uploaded, LakeFS object
present, dataset version creation works).

---

### Was this PR authored or co-authored using generative AI tooling?

GPT partial use.

---------

Co-authored-by: Chen Li <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 26, 2026
### What changes were proposed in this PR?

Remove redundant code from the frontend, the licensing scripts, two
Scala sources and the agent service (**+26/−41 lines**). There is no
behavior change.

- **Dataset and model detail pages:** each `route.params` emission was
switched to `this.route.data`, and the empty `.subscribe()` threw away
what that emitted. The pages now `tap` the params, so the same fetches
run in the same order without the extra subscription. The dataset page's
`THROTTLE_TIME_MS` also becomes file-local: `workspace.component.ts` and
the hub spec import the copy in `hub-workflow-detail.component.ts`,
never this one.
- **Version uploader:** the abort handler's 404 branch called `done()`
and returned, which is what the handler already does for every error it
does not retry. Its three constants become file-local: nothing imported
`FINISHED_TASK_HIDE_DELAY_MS`, and only the spec imported the other two.
The spec now states the retry policy it expects.
- **Computing-unit actions:** `confirmAndTerminate` reads
`unit.computingUnit.uri` and `unit.computingUnit.name` before
`unit?.computingUnit.type`, so the `?.` goes.
- **Loop blocks:** `LOOP_END_OP_TYPE` becomes file-local. Only its spec
imported it, and the spec now checks the backend's `"LoopEnd"` name
directly.
- **Agent interaction:** two imports from `agent.service` become one.
- **Licensing scripts:** `audit_jar_licenses.py` stored each group's
notice hash in a field that nothing reads, and the NOTICE test helper
`make_jar` had an `extra` parameter that no caller passes.
- **`PveResource`:** drops `import javax.ws.rs.DELETE` and `import
javax.ws.rs.PathParam`, which `import javax.ws.rs._` already covers.
- **`SQLSourceOpExec` and `AsterixDBSourceOpExec`:** five fallback arms
list `BOOLEAN`, `STRING` and `ANY` before a trailing `_`, as in `case
AttributeType.BOOLEAN | AttributeType.STRING | AttributeType.ANY | _`.
The `_` matches those types as well, so each becomes `case _`.
- **`agent-service/.dockerignore`:** Docker reads the ignore file at the
root of the build context. CI's image matrix
(`build-and-push-images.yml`) and `bin/build-images.sh` both use the
repository root as the context, and the agent Dockerfile copies
`agent-service/...` paths from there, so the root `.dockerignore`
applies and this file is never read.

| Event | PR / Commit |
| --- | --- |
| Introduced by | Dataset and model detail: apache#2413 (2024-02-26), apache#3269
(2025-02-19), apache#8072 (2026-08-28); version uploader: apache#4136 (2026-01-05),
moved by apache#8078 (2026-08-31); computing-unit actions: apache#4331 (2026-04-09);
loop blocks: apache#8640 (2026-10-24); agent interaction: apache#6009 (2026-11-13);
licensing scripts: apache#4387 (2026-04-29), apache#5417 (2026-06-10);
`PveResource`: apache#5035 (2026-05-13); `SQLSourceOpExec`: apache#1013
(2021-02-11); `AsterixDBSourceOpExec`: apache#1044 (2021-02-25);
`agent-service/.dockerignore`: apache#4495 (2026-04-28) |
| Usage removed by | `agent-service/.dockerignore`: apache#4544 (2026-05-01)
added the agent image's Dockerfile with paths from the repository root,
so no build has read the file. Everything else: unused or redundant
since introduction. |

As of 2026-11-25:
- The SQL sources' fallback arms have listed redundant types for over 5
years.
- The dataset page's discarded subscription is almost 3 years old.
- The version uploader's 404 branch has been redundant for over 10
months.
- `agent-service/.dockerignore` has gone unread for almost 7 months.
- The duplicate agent import is 12 days old.

### Any related issues, documentation, discussions?

Closes apache#9691.

### How was this PR tested?

Ran on this branch and on `main` at `afc2b3db7a` (Windows 11; Node 24
with Yarn 4.14.1; Python 3.12 with pytest 9.0.3 and CI's pinned `ruff`
0.14.7; JDK 17):

```bash
cd frontend
npx ng test --watch=false --include='**/dataset-detail.component.spec.ts' --include='**/model-detail.component.spec.ts' --include='**/version-uploader.component.spec.ts' --include='**/computing-unit-actions.service.spec.ts' --include='**/loop-block.util.spec.ts' --include='**/agent-interaction.component.spec.ts'
npx tsc --noEmit -p src/tsconfig.app.json
npx tsc --noEmit -p src/tsconfig.spec.json
yarn prettier-eslint --list-different $(git diff --name-only --relative origin/main -- src)
yarn eslint $(git diff --name-only --relative origin/main -- src)
cd ..
pytest bin/licensing
ruff check bin/licensing/audit_jar_licenses.py bin/licensing/test_generate_notice_binary.py
python bin/licensing/audit_jar_licenses.py <directory of 60 jars>
sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.source.sql.*" "WorkflowExecutionService/testOnly org.apache.texera.web.resource.pythonvirtualenvironment.*" WorkflowOperator/scalafmtCheckAll WorkflowExecutionService/scalafmtCheckAll "WorkflowOperator/scalafixAll --check" "WorkflowExecutionService/scalafixAll --check"
```

- **Frontend:** the six specs run 379 tests, all passing on both sides.
Both typechecks, prettier-eslint and ESLint pass.
- **Python:** the licensing tests run 53 tests and 5 subtests, all
passing on both sides, and Ruff passes. `audit_jar_licenses.py` prints
the same report on both sides for 60 jars from the local Coursier cache.
- **Scala:**
  - The 11 `source.sql` suites run 204 tests, all passing on both sides.
- The two PVE resource suites run 75 tests on both sides: 74 pass and 1
is canceled. The canceled test needs a file that is not executable,
which this Windows filesystem cannot represent.
  - scalafmt and scalafix pass on both modules.
- **`agent-service/.dockerignore`:** no image was built. The build
context comes from `context="."` for every
`bin/dockerfiles/*.dockerfile` in `build-and-push-images.yml`, and from
the `..` that `bin/build-images.sh` passes from `bin/`.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common ddl-change Changes to the TexeraDB DDL frontend Changes related to the frontend GUI refactor Refactor the code service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task(dataset): Redirect multipart upload through File Service

4 participants