File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
pub mod normal;
2
2
pub mod upgrade;
3
3
4
+ pub struct OomError {
5
+ pub layout : std:: alloc:: Layout ,
6
+ }
7
+
4
8
pub unsafe fn init ( ) {
5
9
use pgrx:: bgworkers:: BackgroundWorkerBuilder ;
6
10
use pgrx:: bgworkers:: BgWorkerStartTime ;
11
+ use std:: time:: Duration ;
7
12
BackgroundWorkerBuilder :: new ( "vectors" )
8
13
. set_function ( "vectors_main" )
9
14
. set_library ( "vectors" )
10
15
. set_argument ( None )
11
16
. enable_shmem_access ( None )
12
17
. set_start_time ( BgWorkerStartTime :: PostmasterStart )
18
+ . set_restart_time ( Some ( Duration :: from_secs ( 1 ) ) )
13
19
. load ( ) ;
14
20
}
15
21
@@ -33,6 +39,10 @@ pub fn main() {
33
39
builder. init ( ) ;
34
40
}
35
41
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
+ }
36
46
let backtrace;
37
47
#[ cfg( not( debug_assertions) ) ]
38
48
{
@@ -44,6 +54,9 @@ pub fn main() {
44
54
}
45
55
log:: error!( "Panickied. Info: {:?}. Backtrace: {}." , info, backtrace) ;
46
56
} ) ) ;
57
+ std:: alloc:: set_alloc_error_hook ( |layout| {
58
+ std:: panic:: panic_any ( OomError { layout } ) ;
59
+ } ) ;
47
60
use service:: worker:: Worker ;
48
61
use std:: path:: Path ;
49
62
let path = Path :: new ( "pg_vectors" ) ;
Original file line number Diff line number Diff line change 3
3
//! Provides an easy-to-use extension for vector similarity search.
4
4
#![ feature( offset_of) ]
5
5
#![ feature( never_type) ]
6
+ #![ feature( alloc_error_hook) ]
6
7
7
8
mod bgworker;
8
9
mod datatype;
You can’t perform that action at this time.
0 commit comments