33// TODO: reduce API surface and add documentation
44#![ allow( missing_docs) ]
55
6- use std:: {
7- collections:: { BTreeMap , BTreeSet } ,
8- fmt:: Debug ,
9- ops:: DerefMut ,
10- sync:: { Arc , OnceLock } ,
11- } ;
6+ use std:: { collections:: BTreeSet , fmt:: Debug , ops:: DerefMut , sync:: Arc } ;
127
138use anyhow:: { anyhow, bail, Result } ;
149use futures_lite:: future:: Boxed as BoxedFuture ;
@@ -31,7 +26,7 @@ use crate::{
3126 progress:: { AsyncChannelProgressSender , ProgressSender } ,
3227 SetTagOption ,
3328 } ,
34- HashAndFormat , TempTag ,
29+ HashAndFormat ,
3530} ;
3631
3732/// A callback that blobs can ask about a set of hashes that should not be garbage collected.
@@ -58,32 +53,33 @@ pub struct Blobs<S> {
5853 pub ( crate ) store : S ,
5954 events : EventSender ,
6055 downloader : Downloader ,
56+ #[ cfg( feature = "rpc" ) ]
6157 batches : tokio:: sync:: Mutex < BlobBatches > ,
6258 endpoint : Endpoint ,
6359 gc_state : Arc < std:: sync:: Mutex < GcState > > ,
6460 #[ cfg( feature = "rpc" ) ]
65- pub ( crate ) rpc_handler : Arc < OnceLock < crate :: rpc:: RpcHandler > > ,
61+ pub ( crate ) rpc_handler : Arc < std :: sync :: OnceLock < crate :: rpc:: RpcHandler > > ,
6662}
6763
68- /// Name used for logging when new node addresses are added from gossip.
69- const BLOB_DOWNLOAD_SOURCE_NAME : & str = "blob_download" ;
70-
7164/// Keeps track of all the currently active batch operations of the blobs api.
65+ #[ cfg( feature = "rpc" ) ]
7266#[ derive( Debug , Default ) ]
7367pub ( crate ) struct BlobBatches {
7468 /// Currently active batches
75- batches : BTreeMap < BatchId , BlobBatch > ,
69+ batches : std :: collections :: BTreeMap < BatchId , BlobBatch > ,
7670 /// Used to generate new batch ids.
7771 max : u64 ,
7872}
7973
8074/// A single batch of blob operations
75+ #[ cfg( feature = "rpc" ) ]
8176#[ derive( Debug , Default ) ]
8277struct BlobBatch {
8378 /// The tags in this batch.
84- tags : BTreeMap < HashAndFormat , Vec < TempTag > > ,
79+ tags : std :: collections :: BTreeMap < HashAndFormat , Vec < crate :: TempTag > > ,
8580}
8681
82+ #[ cfg( feature = "rpc" ) ]
8783impl BlobBatches {
8884 /// Create a new unique batch id.
8985 pub fn create ( & mut self ) -> BatchId {
@@ -93,7 +89,7 @@ impl BlobBatches {
9389 }
9490
9591 /// Store a temp tag in a batch identified by a batch id.
96- pub fn store ( & mut self , batch : BatchId , tt : TempTag ) {
92+ pub fn store ( & mut self , batch : BatchId , tt : crate :: TempTag ) {
9793 let entry = self . batches . entry ( batch) . or_default ( ) ;
9894 entry. tags . entry ( tt. hash_and_format ( ) ) . or_default ( ) . push ( tt) ;
9995 }
@@ -187,10 +183,11 @@ impl<S: crate::store::Store> Blobs<S> {
187183 events,
188184 downloader,
189185 endpoint,
186+ #[ cfg( feature = "rpc" ) ]
190187 batches : Default :: default ( ) ,
191188 gc_state : Default :: default ( ) ,
192189 #[ cfg( feature = "rpc" ) ]
193- rpc_handler : Arc :: new ( OnceLock :: new ( ) ) ,
190+ rpc_handler : Default :: default ( ) ,
194191 }
195192 }
196193
@@ -252,6 +249,7 @@ impl<S: crate::store::Store> Blobs<S> {
252249 Ok ( ( ) )
253250 }
254251
252+ #[ cfg( feature = "rpc" ) ]
255253 pub ( crate ) async fn batches ( & self ) -> tokio:: sync:: MutexGuard < ' _ , BlobBatches > {
256254 self . batches . lock ( ) . await
257255 }
@@ -303,6 +301,9 @@ impl<S: crate::store::Store> Blobs<S> {
303301 nodes : Vec < NodeAddr > ,
304302 progress : AsyncChannelProgressSender < DownloadProgress > ,
305303 ) -> Result < Stats > {
304+ /// Name used for logging when new node addresses are added from gossip.
305+ const BLOB_DOWNLOAD_SOURCE_NAME : & str = "blob_download" ;
306+
306307 let mut node_ids = Vec :: with_capacity ( nodes. len ( ) ) ;
307308 let mut any_added = false ;
308309 for node in nodes {
0 commit comments