@@ -13,8 +13,9 @@ use smallvec::SmallVec;
13
13
use std:: ffi:: c_char;
14
14
use std:: time:: Duration ;
15
15
16
+ use crate :: data_type:: unpack_target_entry;
16
17
use crate :: error:: FusionError ;
17
- use crate :: ipc:: { my_slot, Bus , SlotStream } ;
18
+ use crate :: ipc:: { my_slot, worker_id , Bus , SlotStream , INVALID_PROC_NUMBER } ;
18
19
use crate :: protocol:: {
19
20
consume_header, read_error, request_explain, send_metadata, send_params, send_query, Direction ,
20
21
NeedSchema , Packet ,
@@ -88,6 +89,9 @@ unsafe extern "C" fn create_df_scan_state(cscan: *mut CustomScan) -> *mut Node {
88
89
}
89
90
let mut skip_wait = true ;
90
91
loop {
92
+ if worker_id ( ) == INVALID_PROC_NUMBER {
93
+ error ! ( "Worker ID is invalid" ) ;
94
+ }
91
95
if !skip_wait {
92
96
wait_latch ( Some ( BACKEND_WAIT_TIMEOUT ) ) ;
93
97
skip_wait = false ;
@@ -96,7 +100,11 @@ unsafe extern "C" fn create_df_scan_state(cscan: *mut CustomScan) -> *mut Node {
96
100
continue ;
97
101
} ;
98
102
let mut stream = SlotStream :: from ( slot) ;
99
- let header = consume_header ( & mut stream) . expect ( "Failed to consume header" ) ;
103
+ let header = match consume_header ( & mut stream) {
104
+ Ok ( header) => header,
105
+ // TODO: before panic we should send a Failure message to the worker.
106
+ Err ( err) => error ! ( "Failed to consume header: {}" , err) ,
107
+ } ;
100
108
if header. direction != Direction :: ToBackend {
101
109
continue ;
102
110
}
@@ -105,37 +113,44 @@ unsafe extern "C" fn create_df_scan_state(cscan: *mut CustomScan) -> *mut Node {
105
113
// No data, just continue waiting.
106
114
continue ;
107
115
}
108
- Packet :: Failure => {
109
- let msg = read_error ( & mut stream ) . expect ( "Failed to read the error message" ) ;
110
- error ! ( "Failed to compile the query : {}" , msg ) ;
111
- }
116
+ Packet :: Failure => match read_error ( & mut stream ) {
117
+ Ok ( msg) => error ! ( "Failed to compile the query: {}" , msg ) ,
118
+ Err ( err ) => error ! ( "Double error : {}" , err ) ,
119
+ } ,
112
120
Packet :: Metadata => {
113
- let oids = table_oids ( & mut stream) . expect ( "Failed to read table OIDs" ) ;
121
+ let oids = match table_oids ( & mut stream) {
122
+ Ok ( oids) => oids,
123
+ Err ( err) => error ! ( "Failed to read the table OIDs: {}" , err) ,
124
+ } ;
114
125
if let Err ( err) = send_metadata ( my_slot ( ) , stream, & oids) {
115
126
error ! ( "Failed to send the table metadata: {}" , err) ;
116
127
}
128
+ }
129
+ Packet :: Bind => {
130
+ let mut params: & [ ParamExternData ] = & [ ] ;
131
+ let param_list = ( * list_nth ( list, 1 ) ) . ptr_value as ParamListInfo ;
132
+ if !param_list. is_null ( ) {
133
+ let num_params = unsafe { ( * param_list) . numParams } as usize ;
134
+ params = unsafe { ( * param_list) . params . as_slice ( num_params) } ;
135
+ }
136
+ if let Err ( err) = send_params ( my_slot ( ) , stream, params) {
137
+ error ! ( "Failed to send the parameter list: {}" , err) ;
138
+ }
139
+ }
140
+ Packet :: Columns => {
141
+ if let Err ( err) = unpack_target_entry ( & mut stream, ( * cscan) . custom_scan_tlist ) {
142
+ error ! ( "Failed to unpack target entry: {}" , err) ;
143
+ }
117
144
break ;
118
145
}
119
- Packet :: Bind | Packet :: Parse | Packet :: Explain => {
146
+ Packet :: Parse | Packet :: Explain => {
120
147
error ! (
121
- "Unexpected packet for create custom plan: {:?}" ,
148
+ "Unexpected packet while creating a custom plan: {:?}" ,
122
149
header. packet
123
150
)
124
151
}
125
152
}
126
153
}
127
- let mut params: & [ ParamExternData ] = & [ ] ;
128
- let param_list = ( * list_nth ( list, 1 ) ) . ptr_value as ParamListInfo ;
129
- if !param_list. is_null ( ) {
130
- let num_params = unsafe { ( * param_list) . numParams } as usize ;
131
- params = unsafe { ( * param_list) . params . as_slice ( num_params) } ;
132
- }
133
- let stream = wait_stream ( ) ;
134
- if let Err ( err) = send_params ( my_slot ( ) , stream, params) {
135
- error ! ( "Failed to send the parameter list: {}" , err) ;
136
- }
137
- // TODO: request plan fields from the worker to build custom_scan_tlist
138
- // with repack_output().
139
154
let css = CustomScanState {
140
155
methods : exec_methods ( ) ,
141
156
..Default :: default ( )
@@ -200,7 +215,7 @@ unsafe extern "C" fn explain_df_scan(
200
215
let msg = read_error ( & mut stream) . expect ( "Failed to read the error message" ) ;
201
216
error ! ( "Failed to compile the query: {}" , msg) ;
202
217
}
203
- Packet :: Metadata | Packet :: Bind | Packet :: Parse => {
218
+ Packet :: Columns | Packet :: Metadata | Packet :: Bind | Packet :: Parse => {
204
219
error ! ( "Unexpected packet for explain: {:?}" , header. packet)
205
220
}
206
221
Packet :: Explain => {
0 commit comments