3636// // specific exception handler
3737// error_message.Append("error message: %s", error_message.Message());
3838// }
39- // CBDB_CATCH_COMM();
4039// CBDB_CATCH_DEFAULT();
4140// CBDB_END_TRY();
4241//
4342// CBDB_CATCH_MATCH() is optional and can have several match pattern.
4443
44+ cbdb::CException global_exception (cbdb::CException::kExTypeInvalid );
45+
4546// being of a try block w/o explicit handler
46- #define CBDB_TRY () \
47- do { \
48- bool internal_cbdb_try_throw_error_ = false ; \
49- cbdb::ErrorMessage error_message; \
47+ #define CBDB_TRY () \
48+ do { \
49+ bool internal_cbdb_try_throw_error_ = false ; \
50+ bool internal_cbdb_try_throw_error_with_stack_ = false ; \
51+ cbdb::ErrorMessage error_message; \
5052 try {
5153// begin of a catch block
5254#define CBDB_CATCH_MATCH (exception_decl ) \
5355 } \
5456 catch (exception_decl) { \
5557 internal_cbdb_try_throw_error_ = true ;
5658
57- #define CBDB_CATCH_COMM () \
58- } \
59- catch (cbdb::CException & e) { \
60- internal_cbdb_try_throw_error_ = true ; \
61- elog (LOG, " \n pax stack trace: \n %s" , e.Stack ()); \
62- ereport (ERROR, errmsg (" %s" , e.What ().c_str ()));
63-
6459// catch c++ exception and rethrow ERROR to C code
6560// only used by the outer c++ code called by C
66- #define CBDB_CATCH_DEFAULT () \
67- } \
68- catch (...) { \
69- internal_cbdb_try_throw_error_ = true ;
61+ #define CBDB_CATCH_DEFAULT () \
62+ } \
63+ catch (cbdb::CException & e) { \
64+ internal_cbdb_try_throw_error_ = true ; \
65+ internal_cbdb_try_throw_error_with_stack_ = true ; \
66+ elog (LOG, " \n pax stack trace: \n %s" , e.Stack ()); \
67+ global_exception = e; \
68+ } \
69+ catch (...) { \
70+ internal_cbdb_try_throw_error_ = true ; \
71+ internal_cbdb_try_throw_error_with_stack_ = false ;
7072
7173// like PG_FINALLY
7274#define CBDB_FINALLY (...) \
7779 } while (0 );
7880
7981// end of a try-catch block
80- #define CBDB_END_TRY () \
81- } \
82- if (internal_cbdb_try_throw_error_) { \
83- if (error_message.Length () == 0 ) \
84- error_message.Append (" ERROR: %s" , __func__); \
85- ereport (ERROR, errmsg (" %s" , error_message.Message ())); \
86- } \
87- } \
82+ #define CBDB_END_TRY () \
83+ } \
84+ if (internal_cbdb_try_throw_error_) { \
85+ if (internal_cbdb_try_throw_error_with_stack_) { \
86+ elog (LOG, " \n pax stack trace: \n %s" , global_exception.Stack ()); \
87+ ereport (ERROR, errmsg (" %s" , global_exception.What ().c_str ())); \
88+ } \
89+ if (error_message.Length () == 0 ) \
90+ error_message.Append (" ERROR: %s" , __func__); \
91+ ereport (ERROR, errmsg (" %s" , error_message.Message ())); \
92+ } \
93+ } \
8894 while (0 )
8995
9096bool AMOidIsPax (Oid am_oid) {
@@ -124,7 +130,6 @@ TableScanDesc CCPaxAccessMethod::ScanBegin(Relation relation, Snapshot snapshot,
124130 return PaxScanDesc::BeginScan (relation, snapshot, nkeys, key, pscan, flags,
125131 nullptr );
126132 }
127- CBDB_CATCH_COMM ();
128133 CBDB_CATCH_DEFAULT ();
129134 CBDB_END_TRY ();
130135
@@ -134,7 +139,6 @@ TableScanDesc CCPaxAccessMethod::ScanBegin(Relation relation, Snapshot snapshot,
134139void CCPaxAccessMethod::ScanEnd (TableScanDesc scan) {
135140 CBDB_TRY ();
136141 { PaxScanDesc::EndScan (scan); }
137- CBDB_CATCH_COMM ();
138142 CBDB_CATCH_DEFAULT ();
139143 CBDB_FINALLY ({
140144 // FIXME: destroy PaxScanDesc?
@@ -212,9 +216,7 @@ void CCPaxAccessMethod::RelationCopyForCluster(
212216 Assert (RELATION_IS_PAX (old_heap));
213217 Assert (RELATION_IS_PAX (new_heap));
214218 CBDB_TRY ();
215- {
216- pax::CCPaxAuxTable::PaxAuxRelationCopyDataForCluster (old_heap, new_heap);
217- }
219+ { pax::CCPaxAuxTable::PaxAuxRelationCopyDataForCluster (old_heap, new_heap); }
218220 CBDB_CATCH_DEFAULT ();
219221 CBDB_FINALLY ({});
220222 CBDB_END_TRY ();
@@ -237,7 +239,6 @@ void CCPaxAccessMethod::ScanRescan(TableScanDesc scan, ScanKey /*key*/,
237239 bool /* allow_pagemode*/ ) {
238240 CBDB_TRY ();
239241 { pax::PaxScanDesc::ReScan (scan); }
240- CBDB_CATCH_COMM ();
241242 CBDB_CATCH_DEFAULT ();
242243 CBDB_FINALLY ({});
243244 CBDB_END_TRY ();
@@ -248,7 +249,6 @@ bool CCPaxAccessMethod::ScanGetNextSlot(TableScanDesc scan,
248249 TupleTableSlot *slot) {
249250 CBDB_TRY ();
250251 { return PaxScanDesc::ScanGetNextSlot (scan, slot); }
251- CBDB_CATCH_COMM ();
252252 CBDB_CATCH_DEFAULT ();
253253 CBDB_FINALLY ({
254254 // FIXME: destroy PaxScanDesc?
@@ -270,7 +270,6 @@ void CCPaxAccessMethod::TupleInsert(Relation relation, TupleTableSlot *slot,
270270 CPaxInserter::TupleInsert (relation, slot, cid, options, bistate);
271271 MemoryContextSwitchTo (old_ctx);
272272 }
273- CBDB_CATCH_COMM ();
274273 CBDB_CATCH_DEFAULT ();
275274 CBDB_FINALLY ({
276275 // FIXME: destroy CPaxInserter?
@@ -285,7 +284,6 @@ TM_Result CCPaxAccessMethod::TupleDelete(Relation relation, ItemPointer tid,
285284 bool /* changing_part*/ ) {
286285 CBDB_TRY ();
287286 { return CPaxDeleter::DeleteTuple (relation, tid, cid, snapshot, tmfd); }
288-
289287 CBDB_CATCH_DEFAULT ();
290288 CBDB_FINALLY ({});
291289 CBDB_END_TRY ();
@@ -386,7 +384,6 @@ void CCPaxAccessMethod::MultiInsert(Relation relation, TupleTableSlot **slots,
386384 CPaxInserter::MultiInsert (relation, slots, ntuples, cid, options, bistate);
387385 MemoryContextSwitchTo (old_ctx);
388386 }
389- CBDB_CATCH_COMM ();
390387 CBDB_CATCH_DEFAULT ();
391388 CBDB_FINALLY ({
392389 // FIXME: destroy CPaxInserter?
@@ -404,7 +401,6 @@ void CCPaxAccessMethod::FinishBulkInsert(Relation relation, int options) {
404401 // cause it just call dml finish
405402 pax::CPaxInserter::FinishBulkInsert (relation, options);
406403 }
407- CBDB_CATCH_COMM ();
408404 CBDB_CATCH_DEFAULT ();
409405 CBDB_FINALLY ({
410406 // FIXME: destroy CPaxInserter?
@@ -413,15 +409,27 @@ void CCPaxAccessMethod::FinishBulkInsert(Relation relation, int options) {
413409}
414410
415411void CCPaxAccessMethod::ExtDmlInit (Relation rel, CmdType operation) {
416- if (RELATION_IS_PAX (rel)) {
417- pax::CPaxDmlStateLocal::Instance ()-> InitDmlState (rel, operation) ;
412+ if (! RELATION_IS_PAX (rel)) {
413+ return ;
418414 }
415+
416+ CBDB_TRY ();
417+ { pax::CPaxDmlStateLocal::Instance ()->InitDmlState (rel, operation); }
418+ CBDB_CATCH_DEFAULT ();
419+ CBDB_FINALLY ({});
420+ CBDB_END_TRY ();
419421}
420422
421423void CCPaxAccessMethod::ExtDmlFini (Relation rel, CmdType operation) {
422- if (RELATION_IS_PAX (rel)) {
423- pax::CPaxDmlStateLocal::Instance ()-> FinishDmlState (rel, operation) ;
424+ if (! RELATION_IS_PAX (rel)) {
425+ return ;
424426 }
427+
428+ CBDB_TRY ();
429+ { pax::CPaxDmlStateLocal::Instance ()->FinishDmlState (rel, operation); }
430+ CBDB_CATCH_DEFAULT ();
431+ CBDB_FINALLY ({});
432+ CBDB_END_TRY ();
425433}
426434
427435} // namespace pax
0 commit comments