You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerryshao (via GitHub)" <gi...@apache.org> on 2026/08/18 13:13:16 UTC

[PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

jerryshao opened a new pull request, #12497:
URL: https://github.com/apache/gravitino/pull/12497

   ### What changes were proposed in this pull request?
   
   Expose the job's finished-execution time (already tracked internally by `JobEntity`/`JobPO`/storage) through the public surface:
   
   - `JobHandle.finishedAt()` (Java `default` method) / `finished_at()` (Python) — non-abstract, raising `UnsupportedOperationException`/`NotImplementedError` by default so existing external implementers don't break.
   - `JobDTO.finishedAt` (Java `Instant`, Python `datetime`), matching the existing `Audit.createTime` convention.
   - `finishedAt` added to the `Job` schema in `docs/open-api/jobs.yaml`.
   - `JobEntity.finishedAtAsInstant()` — single conversion point from the storage layer's raw epoch-millis + "not finished" sentinel to `Instant`, used by `JobOperations.toDTO` and `JobInfo.fromJobEntity`.
   - `GenericJobHandle` (Java + Python) delegate to the DTO.
   - `JobManager.pullAndUpdateJobStatus` now stamps `finishedAt` at the moment a job transitions to a terminal state (`SUCCEEDED`/`FAILED`/`CANCELLED`).
   - `JobEntity.FINISHED_AT` is now a required field, enforced at build time, so every construction site must decide the value explicitly; `equals()`/`hashCode()` now include it.
   
   ### Why are the changes needed?
   
   Callers could observe a job's status but had no way to know *when* it actually finished, failed, or was cancelled — only the storage layer tracked this internally.
   
   Fix: #12495
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes:
   - New `finishedAt` field on the `Job` REST API response / OpenAPI schema.
   - New `JobHandle.finishedAt()` (Java) / `finished_at()` (Python) client API, returning `null`/`None` if the job hasn't finished yet.
   - `JobHandle` implementers outside this repo will get a default that raises `UnsupportedOperationException`/`NotImplementedError` unless they override it.
   
   ### How was this patch tested?
   
   Unit tests across `common`, `core`, `server`, `clients/client-java`, and `clients/client-python` (DTO ser/de, `JobEntity` builder/equality, `JobManager` status-polling, `JobOperations`/`JobPO` conversion), plus Java and Python integration tests (`JobIT`, `tests/integration/test_supports_jobs.py`) running real jobs to completion/failure/cancellation and asserting `finishedAt`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#discussion_r3809285980


##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {
+    throw new UnsupportedOperationException("finishedAt is not implemented");

Review Comment:
   Done, the default exception message now includes the implementing class name and instructs overriding the method, in 4f85fd94d.



##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -588,6 +592,11 @@ void pullAndUpdateJobStatus() {
             }
 
             if (newStatus != job.status()) {
+              boolean isFinished =
+                  newStatus == JobHandle.Status.SUCCEEDED
+                      || newStatus == JobHandle.Status.FAILED
+                      || newStatus == JobHandle.Status.CANCELLED;

Review Comment:
   This scenario isn't actually reachable today: `activeJobs` (filtered a few lines above) only includes jobs whose status is QUEUED/STARTED/CANCELLING, and every JobEntity construction site in this class carries forward or explicitly sets finishedAt=0 for non-terminal statuses. So by the time a job reaches this branch with newStatus terminal, its prior finishedAt is guaranteed to be 0 — there's no terminal-with-a-real-timestamp job that can re-enter this code path. Adding a `job.finishedAt() > 0 ? ... : Instant.now()` guard would be dead code today rather than a real safeguard, so leaving as-is per this repo's guidance against validating unreachable states. Thanks for flagging the coupling though — it's a fair point that this correctness depends on the activeJobs filter staying as-is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#discussion_r3804773562


##########
docs/open-api/jobs.yaml:
##########
@@ -514,6 +514,10 @@ components:
             - "canceled"
         audit:
           $ref: "./openapi.yaml#/components/schemas/Audit"
+        finishedAt:
+          type: string
+          format: date-time
+          description: The time when the job finished execution, or absent if the job has not finished execution yet

Review Comment:
   The schema declares `finishedAt` as a non-null `string`, but server/client tests added in this PR assert that unfinished jobs round-trip `finishedAt` as `null` over the wire. If the API can return `\"finishedAt\": null`, the OpenAPI schema should explicitly allow it (e.g., `nullable: true` or a `oneOf` including `null`). Alternatively, ensure serialization omits the field entirely when unfinished and align the description/examples accordingly.



##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {
+    throw new UnsupportedOperationException("finishedAt is not implemented");

Review Comment:
   The default exception message is fairly generic for external implementers. Consider making it more actionable (e.g., explicitly instructing implementers to override `finishedAt()` or indicating the interface/class name) to reduce debugging time when third-party implementations hit this at runtime.



##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -602,6 +611,7 @@ void pullAndUpdateJobStatus() {
                               .withLastModifier(PrincipalUtils.getCurrentPrincipal().getName())
                               .withLastModifiedTime(Instant.now())
                               .build())
+                      .withFinishedAt(isFinished ? Instant.now().toEpochMilli() : job.finishedAt())

Review Comment:
   `finishedAt` is overwritten with `Instant.now()` on *any* transition where `newStatus` is terminal, even if the job already had a positive `finishedAt` (e.g., a terminal→terminal transition due to executor/status correction). This can corrupt the original completion time. Prefer only setting `finishedAt` when the job becomes terminal *and* the existing `finishedAt` is not already set (<= 0), otherwise preserve the existing value.



##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -588,6 +592,11 @@ void pullAndUpdateJobStatus() {
             }
 
             if (newStatus != job.status()) {
+              boolean isFinished =
+                  newStatus == JobHandle.Status.SUCCEEDED
+                      || newStatus == JobHandle.Status.FAILED
+                      || newStatus == JobHandle.Status.CANCELLED;

Review Comment:
   `finishedAt` is overwritten with `Instant.now()` on *any* transition where `newStatus` is terminal, even if the job already had a positive `finishedAt` (e.g., a terminal→terminal transition due to executor/status correction). This can corrupt the original completion time. Prefer only setting `finishedAt` when the job becomes terminal *and* the existing `finishedAt` is not already set (<= 0), otherwise preserve the existing value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#issuecomment-5336882396

   @jerryshao Should this one be cherry-picked to branch-1.3?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#discussion_r3809286699


##########
core/src/main/java/org/apache/gravitino/job/JobManager.java:
##########
@@ -602,6 +611,7 @@ void pullAndUpdateJobStatus() {
                               .withLastModifier(PrincipalUtils.getCurrentPrincipal().getName())
                               .withLastModifiedTime(Instant.now())
                               .build())
+                      .withFinishedAt(isFinished ? Instant.now().toEpochMilli() : job.finishedAt())

Review Comment:
   Same spot as the other comment on line 598 - see reply there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #12497:
URL: https://github.com/apache/gravitino/pull/12497


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#discussion_r3804618391


##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {

Review Comment:
   Better to add `@Nullable`.



##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {

Review Comment:
   JobInfo.finishedAt()、JobEntity.finishedAtAsInstant() also share the same issue.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#discussion_r3809285063


##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {

Review Comment:
   Good catch, added `@Nullable` in 4f85fd94d.



##########
api/src/main/java/org/apache/gravitino/job/JobHandle.java:
##########
@@ -69,4 +71,13 @@ enum Status {
    * @return the status of the job
    */
   Status jobStatus();
+
+  /**
+   * Get the time when the job finished execution.
+   *
+   * @return the finished time of the job, or null if the job has not finished execution yet
+   */
+  default Instant finishedAt() {

Review Comment:
   Added `@Nullable` to both `JobInfo.finishedAt()` and `JobEntity.finishedAtAsInstant()` as well, in 4f85fd94d.



##########
docs/open-api/jobs.yaml:
##########
@@ -514,6 +514,10 @@ components:
             - "canceled"
         audit:
           $ref: "./openapi.yaml#/components/schemas/Audit"
+        finishedAt:
+          type: string
+          format: date-time
+          description: The time when the job finished execution, or absent if the job has not finished execution yet

Review Comment:
   Good catch, added `nullable: true` and updated the description to match the actual wire behavior, in 4f85fd94d.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#issuecomment-5330728416

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|68.84% **`+0.17%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|86.71%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|49.3% **`-0.09%`**|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|42.04%|:green_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|9.92%|:red_circle:|
   |catalog-fileset|79.77%|:green_circle:|
   |catalog-glue|68.95%|:green_circle:|
   |catalog-hive|82.96%|:green_circle:|
   |catalog-jdbc-common|45.7%|:green_circle:|
   |catalog-jdbc-doris|81.8%|:green_circle:|
   |catalog-jdbc-mysql|79.33%|:green_circle:|
   |catalog-jdbc-postgresql|83.39%|:green_circle:|
   |catalog-jdbc-starrocks|79.16%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|59.18%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.93%|:green_circle:|
   |catalog-lakehouse-paimon|84.23%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.48%|:green_circle:|
   |client-java|78.57% **`+0.04%`**|:green_circle:|
   |common|53.19% **`+0.27%`**|:green_circle:|
   |core|83.65% **`+0.07%`**|:green_circle:|
   |filesystem-hadoop3|77.28%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|48.68%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-auth|68.0%|:green_circle:|
   |hadoop-common|12.7%|:red_circle:|
   |hive-metastore-common|53.4%|:green_circle:|
   |iceberg-aliyun-bundle|0.0%|:red_circle:|
   |iceberg-common|64.75%|:green_circle:|
   |iceberg-rest-server|75.0%|:green_circle:|
   |idp-basic|86.02%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|62.92%|:green_circle:|
   |lance-common|31.63%|:red_circle:|
   |lance-rest-server|63.47%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|83.24%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|87.38% **`+0.27%`**|:green_circle:|
   |server-common|79.57%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|45.89%|:green_circle:|
   |tencent|69.84%|:green_circle:|
   |trino-connector|41.56%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |api|[JobHandle.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/api/src/main/java/org/apache/gravitino/job/JobHandle.java)|0.0%|:red_circle:|
   |client-java|[GenericJobHandle.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/clients/client-java/src/main/java/org/apache/gravitino/client/GenericJobHandle.java)|100.0%|:green_circle:|
   |common|[JobDTO.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/common/src/main/java/org/apache/gravitino/dto/job/JobDTO.java)|88.24%|:green_circle:|
   ||[CallerContext.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/common/src/main/java/org/apache/gravitino/audit/CallerContext.java)|78.26%|:green_circle:|
   |core|[JobEntity.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/core/src/main/java/org/apache/gravitino/meta/JobEntity.java)|96.88%|:green_circle:|
   ||[JobInfo.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/core/src/main/java/org/apache/gravitino/listener/api/info/JobInfo.java)|94.44%|:green_circle:|
   ||[JobManager.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/core/src/main/java/org/apache/gravitino/job/JobManager.java)|86.09%|:green_circle:|
   ||[JobPO.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/core/src/main/java/org/apache/gravitino/storage/relational/po/JobPO.java)|76.56%|:green_circle:|
   |server|[JobOperations.java](https://github.com/jerryshao/gravitino/blob/d9f0d67466372318f52140918c8ed944a5b120b5/server/src/main/java/org/apache/gravitino/server/web/rest/JobOperations.java)|92.45%|:green_circle:|
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#issuecomment-5336887413

   > @jerryshao Should this one be cherry-picked to branch-1.3?
   
   No, we don't.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#12495] feat(job): Expose job finishedAt across the public surface [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #12497:
URL: https://github.com/apache/gravitino/pull/12497#issuecomment-5336333592

   I have no further comments.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org