MisterRaindrop commented on code in PR #124:
URL: https://github.com/apache/cloudberry-pxf/pull/124#discussion_r3860017015
##########
server/pxf-service/src/main/java/org/apache/cloudberry/pxf/service/controller/ReadServiceImpl.java:
##########
@@ -84,6 +87,13 @@ private OperationResult writeStream(RequestContext context,
OutputStream outputS
try {
List<Fragment> fragments =
fragmenterService.getFragmentsForSegment(context);
for (int i = 0; i < fragments.size(); i++) {
+ // stop before starting the next fragment if the request was
+ // cancelled via pxf_cancel_backend
+ if (isCancelled()) {
+ log.info("Read of resource {} cancelled after {} of {}
fragments",
+ context.getDataSource(), i, fragments.size());
+ break;
Review Comment:
I notice that it returns directly after the cancel operation here. Are there
any other operations that need to be performed?
##########
external-table/pxf--2.1--2.2.sql:
##########
@@ -0,0 +1,88 @@
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied. See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+
+/* external_table/pxf--2.1--2.2.sql */
+
+------------------------------------------------------------------
+-- PXF Activity Monitoring
+------------------------------------------------------------------
+
+-- Raw per-segment accessor: each segment asks its local PXF instance for the
+-- activity that originates from its own segment id and returns the JSON body
+-- verbatim as a single row. Dispatched to every segment; the typed columns are
+-- produced by the pxf_stat_activity view below. The function is set-returning
+-- (one row per segment) because EXECUTE ON ALL SEGMENTS is only permitted for
+-- set-returning functions.
+CREATE FUNCTION pxf_stat_activity_raw() RETURNS SETOF text
+AS 'MODULE_PATHNAME', 'pxf_stat_activity_raw'
+LANGUAGE C VOLATILE EXECUTE ON ALL SEGMENTS;
+
+-- pg_stat_activity-like view of the queries currently running inside PXF,
+-- aggregated across all segment hosts. DISTINCT is a safety net; PXF already
+-- de-duplicates by filtering each response to the requesting segment id.
+CREATE VIEW pxf_stat_activity AS
+SELECT DISTINCT
+ (a->>'segmentId')::int AS segment_id,
+ (a->>'gpSessionId')::int AS session_id,
+ (a->>'gpCommandCount')::int AS command_count,
+ a->>'transactionId' AS xid,
+ a->>'requestType' AS operation,
+ a->>'user' AS usename,
+ a->>'serverName' AS server,
+ a->>'profile' AS profile,
+ a->>'schemaName' AS schema_name,
+ a->>'tableName' AS table_name,
+ a->>'dataSource' AS data_source,
+ to_timestamp((a->>'startTimeMs')::bigint / 1000.0) AS query_start,
+ a->>'host' AS pxf_host
+FROM (
+ SELECT json_array_elements(raw::json -> 'activities') AS a
+ FROM pxf_stat_activity_raw() AS raw
+) s;
+
+-- Per-segment cancellation primitives backing pxf_cancel_backend /
+-- pxf_interrupt_backend. Each segment asks its local PXF instance to terminate
+-- the in-flight requests of the given Cloudberry session that originate from
its
+-- own segment id, returning the JSON body verbatim as a single row (e.g.
+-- {"cancelled":N} / {"interrupted":N}). Dispatched to every segment; the
counts
+-- are summed by the SQL wrappers below. Set-returning because EXECUTE ON ALL
+-- SEGMENTS is only permitted for set-returning functions.
+CREATE FUNCTION pxf_cancel_backend_raw(session_id int) RETURNS SETOF text
+AS 'MODULE_PATHNAME', 'pxf_cancel_backend_raw'
+LANGUAGE C VOLATILE STRICT EXECUTE ON ALL SEGMENTS;
Review Comment:
This is a public method, allowing other users to cancel other PXF requests.
I'm not sure whether this design is reasonable.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]