@@ -993,6 +993,9 @@ std::pair<uint64_t, uint64_t> Writer::ingest_samples_v4(
993993 // Write and finalize anchors stored in the anchor worker.
994994 anchors_ingested += write_anchors (anchor_worker);
995995
996+ // Unset buffer sizes on the query (same ptrs, size 0). The Query
997+ // must retain the submit response for finalize; do not discard
998+ // the query or its state until submit_and_finalize() completes.
996999 worker->buffers ().clear_query_buffers (
9971000 query_.get (), dataset_->metadata ().version );
9981001 // Finalize fragment for this contig async
@@ -1104,8 +1107,8 @@ std::pair<uint64_t, uint64_t> Writer::ingest_samples_v4(
11041107 }
11051108 }
11061109
1107- // When an ingestion worker is finished, clear its query buffers
1108- // only if the query buffers are not empty .
1110+ // When an ingestion worker is finished, unset buffer sizes on the query
1111+ // (Query retains submit response for finalize). Only do so if set .
11091112 if (finished && utils::query_buffers_set (query_.get ())) {
11101113 worker->buffers ().clear_query_buffers (
11111114 query_.get (), dataset_->metadata ().version );
@@ -1389,6 +1392,12 @@ void Writer::dataset_version(int32_t* version) const {
13891392 *version = dataset_->metadata ().version ;
13901393}
13911394
1395+ // REST write protocol: Submit (WRITE) returns serialized query state in the
1396+ // response. The client must retain that exact state and send it as the
1397+ // finalize request body. If the client discards the submit response before
1398+ // calling finalize, the server cannot deserialize the query correctly. The
1399+ // TileDB Query object must hold the submit response until submit_and_finalize()
1400+ // completes, which sends the submit response.
13921401void Writer::finalize_query (std::unique_ptr<tiledb::Query> query) {
13931402 if (utils::query_buffers_set (query.get ())) {
13941403 LOG_FATAL (" Cannot submit_and_finalize query with buffers set." );
0 commit comments