Skip to content

[development]: Changes for polling result status and skeletons for chunk downloader - #4

Merged
gopalldb merged 5 commits into
mainfrom
development
Jul 31, 2023
Merged

gopalldb merged 5 commits into
mainfrom
development

Conversation

@gopalldb

Copy link
Copy Markdown
Collaborator

Adding changes to poll the statement execution result, and wrap the result in a DatabricksResultSet instance. Also adding changes to define skeletons for ArrowChunk result and chunk downloader class.

@gopalldb
gopalldb requested a review from yunbodeng-db July 26, 2023 18:38
@gopalldb gopalldb self-assigned this Jul 26, 2023
this.workspaceClient = new WorkspaceClient(databricksConfig);
}

@VisibleForTesting

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is already a public method, you don't need VisibleForTesting.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

handleFailedExecution(responseState, statementId);

// TODO: Add timeout
while (responseState.equals(StatementState.PENDING) || responseState.equals(StatementState.RUNNING)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should use == for enum?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

}
}
// should not reach here, add better handling
throw new RuntimeException("Unreachable code");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code structure here is confusing. Can you consider this flow?

executeStatement();
while (RUNNING || PENDING) {
Sleep();
GetResponse();
}
if (!SUCCESS) {
handleErrors(); // this will throw exception.
}
return successResults;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for suggestion. This indeed looks cleaner.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this file's changes are not pushed to the head yet?

@gopalldb gopalldb Jul 28, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is, I can see the uploaded changes. There are 4 commits in the PR now.

workspaceClient.statementExecution().closeStatement(statementId);
}

private void handleFailedExecution(StatementState statementState, String statementId) throws SQLException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Given the method's name, I almost think you should assert that the input is an error case.

@gopalldb gopalldb Jul 27, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added exception for other cases

* </ul>
* ->
*/
enum DownloadStatus {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Usually you would have a NONE or UNKNOWN as a default value in the enum.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

}

void setChunkUrl(String chunkUrl) {
this.chunkUrl = chunkUrl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is the relationship between the new URL (chunk) and chunkIndex, numberRows, rowOffset etc? Do you need to reset all or part of the state?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I may understand setter on status but I do not understand why chunkUrl can be set.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So, few things I will get from resultManifest: chunk index, rowOffset, numberOfRows and bytes. But next index, url, expiry would be fetched from GetResultData API which would take next-chunk-index and statement-Id as parameters.

The first chunk url will be part of statement response, for others we need to fetch each one by one, and then set the chunk Url. The chunk downloader will then download chunks in parallel based on number of threads, buffer memory size and if chunk url is available.

I will add these changes in separate PR.


private final long totalRows;
private final long totalChunks;
private final ImmutableMap<Long, ChunkInfo> rowOffsetToChunkMap;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Chunk info is self contained. Why do you need a Map? When you have a map, do you have to deal with the exposure such as duplicate chunks or missing chunks? I do not see the use or validation logic around the chunk indice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Basically, this map is in ArrowStreamResult class, which is main handler for ArrowStream based results. Now based on current row index, it can return exact chunk-index, which can be used for reading current row data. Chunk downloader also has a map, which maps to chunk index to arrow result (including data). So, using together both of these maps, I can reach to exact chunk, and then read exact row from that chunk.

In this map, the data is populated from manifest, and not actual result data, thus there won't be missing chunks, since these are metadata.

I will send more changes in separate PR.

* @param chunkIndex index of chunk
* @return the chunk at given index
*/
public ArrowResultChunk getChunk(int chunkIndex) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you need to keep track of the chunks or you can rely on the server?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will have multiple chunks pre-downloaded based on buffer size, and once a chunk is consumed, I will free that from memory, and download the next one. So, we will keep track of chunks which are already downloaded (or freed or yet to be downloaded).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Did we chat about this today that you just need a simple throughput controller by size of the thread pool?
The chunk sizes are predictable by the server. It's how it decides how many chunks you would end up getting.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we will control it by allowed number of chunks to be downloaded which will eventually be controlled by number of worker threads. Chunk size will be ignored for now.

StatementStatus responseStatus = response.getStatus();
ResultManifest resultManifest =
responseStatus.getState() == StatementState.SUCCEEDED ? response.getManifest() : null;
ResultData resultData = responseStatus.getState() == StatementState.SUCCEEDED ? response.getResult() : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I now realize you could get results from ExecuteStatementResponse or GetStatementResponse which do not share the same interface. If you convert ExecuteStatementResponse to GetStatementResponse, your code would be more compact.

GetStatementResponse getStatementResponse = ... // response.getManifest() + response.getResult()
... remove line 73-75
... reuse getStatementResponse in the loop too.
... remove line 89-92
return new DatabricksResultSet(responseStatus, statementId, getStatementResponse.getResult(),
getStatementResponse.getManifest())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FYI.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, converted getResponse as ExecuteResponse, and removed extra code.

@gopalldb
gopalldb merged commit 2e04900 into main Jul 31, 2023
gopalldb added a commit that referenced this pull request May 11, 2026
Major fixes:
- #1: Use 2-thread pool instead of single-thread to prevent one blocked
  heartbeat RPC from starving others on the same connection
- #3: Fix getStoppedFlag() leak — use get() + ALREADY_STOPPED sentinel
  instead of computeIfAbsent() which re-created a false flag after
  stopHeartbeat() removed it, causing RPCs after stop

Minor fixes:
- #2: Increase awaitTermination from 5s to 10s with explanatory comment
- #4: Add comment about client capture retaining session reference
- #5: Document reactive vs proactive heartbeat stop limitation
- #6, #7, #9, #10, #11: Acknowledged as correct/acceptable per reviewer

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
vikrantpuppala added a commit that referenced this pull request May 20, 2026
Removes the OWASP step, NVD database cache, and OWASP findings parsing
from securityScan.yml. OSV-Scanner now drives the gate alone.

Motivation:

  - OSV's database is a strict superset of NVD's (federates GHSA, NVD,
    PyPA, RustSec, Go vuln DB). We've already seen two real CVEs OSV
    catches that OWASP misses entirely -- CVE-2025-66566 in lz4 and
    CVE-2026-5598 in bouncycastle, both GHSA-only with no NVD CPE.

  - The release pipeline at databricks/secure-public-registry-releases-eng
    already skips OWASP (every Maven step has -Ddependency-check.skip=true)
    and runs its own artifact-level scan via databricks/gh-action-scan.
    So removing OWASP from this repo's CI does not disturb release gating.

  - OWASP's NVD database (~150-700 MB), the NVD_API_KEY secret, and the
    cache machinery added minutes per run for coverage we don't actually
    use any more.

The OWASP plugin block stays in jdbc-core/pom.xml and owasp-suppressions.xml
stays in the repo, because the disabled-anyway in-repo release.yml /
release-thin.yml workflows still reference them. Cleaning those up is a
separate change.

Also addresses these from the PR review:

  #1 (SBOM existence guard): the OSV step now explicitly checks
      target/bom.json exists before scanning, and that osv-scanner
      produced a non-empty output. Build failures now surface with a
      clear ::error:: instead of a downstream jq error.

  #3 (set -uo pipefail without -e): added a comment explaining that -e
      is dropped intentionally because osv-scanner exits 1 on any
      finding regardless of severity; the severity >= 7 filter below is
      the real gate.

  #4 (severity filter silently treats malformed scores as 0): the
      Collect findings step now logs total_findings alongside
      high_count, so a mismatch (e.g. "10 total / 0 high") would be
      visible in the step summary and warn ops about OSV format drift.

  #5 (suppressions are CVE-id global, not package-scoped): OSV-Scanner
      v2.3.8 does not actually support per-package CVE-id ignores
      (verified against internal/config/config.go -- PackageOverrides
      has no per-CVE field). Documented the trade-off explicitly in
      osv-scanner.toml's header so future readers understand the
      scoping model and the acceptable-risk reasoning.

  #7 (fork PR maven config): added a comment in the workflow explaining
      that fork PRs work even with JFrog OIDC skipped, because all of
      the driver's direct dependencies are published to public Maven
      Central. JFrog is just a mirror, not a source.

Verified locally: OSV reports the same 2 unsuppressed CVSS>=7 findings
(bouncycastle CVE-2026-5598 + libthrift cluster) as before, with no
schema errors against the corrected osv-scanner.toml.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <[email protected]>
vikrantpuppala added a commit that referenced this pull request May 21, 2026
Removes the OWASP step, NVD database cache, and OWASP findings parsing
from securityScan.yml. OSV-Scanner now drives the gate alone.

Motivation:

  - OSV's database is a strict superset of NVD's (federates GHSA, NVD,
    PyPA, RustSec, Go vuln DB). We've already seen two real CVEs OSV
    catches that OWASP misses entirely -- CVE-2025-66566 in lz4 and
    CVE-2026-5598 in bouncycastle, both GHSA-only with no NVD CPE.

  - The release pipeline at databricks/secure-public-registry-releases-eng
    already skips OWASP (every Maven step has -Ddependency-check.skip=true)
    and runs its own artifact-level scan via databricks/gh-action-scan.
    So removing OWASP from this repo's CI does not disturb release gating.

  - OWASP's NVD database (~150-700 MB), the NVD_API_KEY secret, and the
    cache machinery added minutes per run for coverage we don't actually
    use any more.

The OWASP plugin block stays in jdbc-core/pom.xml and owasp-suppressions.xml
stays in the repo, because the disabled-anyway in-repo release.yml /
release-thin.yml workflows still reference them. Cleaning those up is a
separate change.

Also addresses these from the PR review:

  #1 (SBOM existence guard): the OSV step now explicitly checks
      target/bom.json exists before scanning, and that osv-scanner
      produced a non-empty output. Build failures now surface with a
      clear ::error:: instead of a downstream jq error.

  #3 (set -uo pipefail without -e): added a comment explaining that -e
      is dropped intentionally because osv-scanner exits 1 on any
      finding regardless of severity; the severity >= 7 filter below is
      the real gate.

  #4 (severity filter silently treats malformed scores as 0): the
      Collect findings step now logs total_findings alongside
      high_count, so a mismatch (e.g. "10 total / 0 high") would be
      visible in the step summary and warn ops about OSV format drift.

  #5 (suppressions are CVE-id global, not package-scoped): OSV-Scanner
      v2.3.8 does not actually support per-package CVE-id ignores
      (verified against internal/config/config.go -- PackageOverrides
      has no per-CVE field). Documented the trade-off explicitly in
      osv-scanner.toml's header so future readers understand the
      scoping model and the acceptable-risk reasoning.

  #7 (fork PR maven config): added a comment in the workflow explaining
      that fork PRs work even with JFrog OIDC skipped, because all of
      the driver's direct dependencies are published to public Maven
      Central. JFrog is just a mirror, not a source.

Verified locally: OSV reports the same 2 unsuppressed CVSS>=7 findings
(bouncycastle CVE-2026-5598 + libthrift cluster) as before, with no
schema errors against the corrected osv-scanner.toml.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants