File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 11pub mod normal;
22pub mod upgrade;
33
4+ pub struct OomError {
5+ pub layout : std:: alloc:: Layout ,
6+ }
7+
48pub unsafe fn init ( ) {
59 use pgrx:: bgworkers:: BackgroundWorkerBuilder ;
610 use pgrx:: bgworkers:: BgWorkerStartTime ;
11+ use std:: time:: Duration ;
712 BackgroundWorkerBuilder :: new ( "vectors" )
813 . set_function ( "vectors_main" )
914 . set_library ( "vectors" )
1015 . set_argument ( None )
1116 . enable_shmem_access ( None )
1217 . set_start_time ( BgWorkerStartTime :: PostmasterStart )
18+ . set_restart_time ( Some ( Duration :: from_secs ( 1 ) ) )
1319 . load ( ) ;
1420}
1521
@@ -33,6 +39,10 @@ pub fn main() {
3339 builder. init ( ) ;
3440 }
3541 std:: panic:: set_hook ( Box :: new ( |info| {
42+ if let Some ( oom) = info. payload ( ) . downcast_ref :: < OomError > ( ) {
43+ log:: error!( "Out of memory. Layout: {:?}." , oom. layout) ;
44+ return ;
45+ }
3646 let backtrace;
3747 #[ cfg( not( debug_assertions) ) ]
3848 {
@@ -44,6 +54,9 @@ pub fn main() {
4454 }
4555 log:: error!( "Panickied. Info: {:?}. Backtrace: {}." , info, backtrace) ;
4656 } ) ) ;
57+ std:: alloc:: set_alloc_error_hook ( |layout| {
58+ std:: panic:: panic_any ( OomError { layout } ) ;
59+ } ) ;
4760 use service:: worker:: Worker ;
4861 use std:: path:: Path ;
4962 let path = Path :: new ( "pg_vectors" ) ;
Original file line number Diff line number Diff line change 33//! Provides an easy-to-use extension for vector similarity search.
44#![ feature( offset_of) ]
55#![ feature( never_type) ]
6+ #![ feature( alloc_error_hook) ]
67
78mod bgworker;
89mod datatype;
You can’t perform that action at this time.
0 commit comments