File tree Expand file tree Collapse file tree 6 files changed +74
-3
lines changed Expand file tree Collapse file tree 6 files changed +74
-3
lines changed Original file line number Diff line number Diff line change @@ -62,13 +62,24 @@ pub struct IndexOptions {
62
62
pub indexing : IndexingOptions ,
63
63
}
64
64
65
+ #[ derive( Debug , Serialize , Deserialize ) ]
66
+ #[ serde( deny_unknown_fields) ]
67
+ pub struct SegmentSizeInfo {
68
+ pub id : Uuid ,
69
+ #[ serde( rename = "type" ) ]
70
+ pub typ : String ,
71
+ pub length : usize ,
72
+ pub size : u64 ,
73
+ }
74
+
65
75
#[ derive( Debug , Serialize , Deserialize ) ]
66
76
pub struct IndexStat {
67
77
pub indexing : bool ,
68
78
pub sealed : Vec < u32 > ,
69
79
pub growing : Vec < u32 > ,
70
80
pub write : u32 ,
71
81
pub options : IndexOptions ,
82
+ pub sizes : Vec < SegmentSizeInfo > ,
72
83
}
73
84
74
85
pub struct Index < S : G > {
@@ -239,6 +250,12 @@ impl<S: G> Index<S> {
239
250
growing : view. growing . values ( ) . map ( |x| x. len ( ) ) . collect ( ) ,
240
251
write : view. write . as_ref ( ) . map ( |( _, x) | x. len ( ) ) . unwrap_or ( 0 ) ,
241
252
options : self . options ( ) . clone ( ) ,
253
+ sizes : view
254
+ . sealed
255
+ . values ( )
256
+ . map ( |x| x. size ( ) )
257
+ . chain ( view. growing . values ( ) . map ( |x| x. size ( ) ) )
258
+ . collect ( ) ,
242
259
}
243
260
}
244
261
}
Original file line number Diff line number Diff line change 3
3
use super :: SegmentTracker ;
4
4
use crate :: index:: IndexOptions ;
5
5
use crate :: index:: IndexTracker ;
6
+ use crate :: index:: SegmentSizeInfo ;
6
7
use crate :: prelude:: * ;
7
8
use crate :: utils:: dir_ops:: sync_dir;
8
9
use crate :: utils:: file_wal:: FileWal ;
@@ -140,6 +141,14 @@ impl<S: G> GrowingSegment<S> {
140
141
pub fn len ( & self ) -> u32 {
141
142
self . len . load ( Ordering :: Acquire ) as u32
142
143
}
144
+ pub fn size ( & self ) -> SegmentSizeInfo {
145
+ SegmentSizeInfo {
146
+ id : self . uuid ,
147
+ typ : "growing" . to_string ( ) ,
148
+ length : self . len ( ) as usize ,
149
+ size : ( self . len ( ) as u64 ) * ( std:: mem:: size_of :: < Log < S > > ( ) as u64 ) ,
150
+ }
151
+ }
143
152
pub fn vector ( & self , i : u32 ) -> & [ S :: Scalar ] {
144
153
let i = i as usize ;
145
154
if i >= self . len . load ( Ordering :: Acquire ) {
Original file line number Diff line number Diff line change 1
1
use super :: growing:: GrowingSegment ;
2
2
use super :: SegmentTracker ;
3
3
use crate :: index:: indexing:: { DynamicIndexIter , DynamicIndexing } ;
4
- use crate :: index:: { IndexOptions , IndexTracker } ;
4
+ use crate :: index:: { IndexOptions , IndexTracker , SegmentSizeInfo } ;
5
5
use crate :: prelude:: * ;
6
- use crate :: utils:: dir_ops:: sync_dir;
6
+ use crate :: utils:: dir_ops:: { dir_size , sync_dir} ;
7
7
use serde:: { Deserialize , Serialize } ;
8
8
use std:: path:: PathBuf ;
9
9
use std:: sync:: Arc ;
@@ -58,6 +58,22 @@ impl<S: G> SealedSegment<S> {
58
58
pub fn len ( & self ) -> u32 {
59
59
self . indexing . len ( )
60
60
}
61
+ pub fn size ( & self ) -> SegmentSizeInfo {
62
+ let mut info = SegmentSizeInfo {
63
+ id : self . uuid ,
64
+ typ : "sealed" . to_string ( ) ,
65
+ length : self . len ( ) as usize ,
66
+ size : 0 ,
67
+ } ;
68
+ let path = self . _tracker . path . join ( "indexing" ) ;
69
+ match dir_size ( & path) {
70
+ Ok ( size) => info. size = size as u64 ,
71
+ Err ( e) => {
72
+ panic ! ( "Failed to get size of {:?}: {}" , path, e) ;
73
+ }
74
+ }
75
+ info
76
+ }
61
77
pub fn vector ( & self , i : u32 ) -> & [ S :: Scalar ] {
62
78
self . indexing . vector ( i)
63
79
}
Original file line number Diff line number Diff line change 1
- use std:: fs:: File ;
1
+ use std:: fs:: { read_dir, File } ;
2
+ use std:: io;
2
3
use std:: path:: Path ;
3
4
4
5
pub fn sync_dir ( path : impl AsRef < Path > ) {
5
6
let file = File :: open ( path) . expect ( "Failed to sync dir." ) ;
6
7
file. sync_all ( ) . expect ( "Failed to sync dir." ) ;
7
8
}
9
+
10
+ pub fn dir_size ( dir : & Path ) -> io:: Result < usize > {
11
+ let mut size = 0 ;
12
+ if dir. is_dir ( ) {
13
+ for entry in read_dir ( dir) ? {
14
+ let entry = entry?;
15
+ let path = entry. path ( ) ;
16
+ let name = path. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
17
+ if name. starts_with ( '.' ) {
18
+ // ignore hidden files
19
+ continue ;
20
+ }
21
+ if path. is_dir ( ) {
22
+ size += dir_size ( & path) ?;
23
+ } else {
24
+ size += entry. metadata ( ) ?. len ( ) as usize ;
25
+ }
26
+ }
27
+ }
28
+ Ok ( size)
29
+ }
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ We also provide a view `pg_vector_index_info` to monitor the progress of indexin
119
119
| idx_sealed | int8[ ] | The number of tuples in each sealed segment. |
120
120
| idx_growing | int8[ ] | The number of tuples in each growing segment. |
121
121
| idx_write | int8 | The number of tuples in write buffer. |
122
+ | idx_size | int8 | The byte size for all the segments. |
122
123
| idx_config | text | The configuration of the index. |
123
124
124
125
## Examples
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ CREATE TYPE VectorIndexStat AS (
9
9
idx_sealed BIGINT[],
10
10
idx_growing BIGINT[],
11
11
idx_write BIGINT,
12
+ idx_size BIGINT,
12
13
idx_options TEXT
13
14
);" ,
14
15
name = "create_composites" ,
@@ -40,6 +41,11 @@ fn vector_stat(oid: pgrx::pg_sys::Oid) -> pgrx::composite_type!("VectorIndexStat
40
41
} )
41
42
. unwrap ( ) ;
42
43
res. set_by_name ( "idx_write" , stat. write as i64 ) . unwrap ( ) ;
44
+ res. set_by_name (
45
+ "idx_size" ,
46
+ stat. sizes . iter ( ) . map ( |x| x. size as i64 ) . sum :: < i64 > ( ) ,
47
+ )
48
+ . unwrap ( ) ;
43
49
res. set_by_name ( "idx_options" , serde_json:: to_string ( & stat. options ) )
44
50
. unwrap ( ) ;
45
51
res
You can’t perform that action at this time.
0 commit comments