1- from __future__ import annotations
2-
31import contextlib
42import dataclasses
53import enum
4+ import logging
65import os
76import time
87from concurrent .futures import Future
@@ -109,12 +108,13 @@ def get_or_create(self) -> BlobLookupRoutine[schema.Blob]:
109108
110109 write_result = self .__create_missing_chunks (actual_path_to_read , snapshot , known_db_chunks )
111110
112- self .logger .debug ('Chunked file {} in {:.2f}s, compressed size {}/{}, chunk count: {} (+{}, {:.1f}%)' .format (
113- src_path_str , time .time () - process_start_time ,
114- write_result .stored_size_sum , write_result .raw_size_sum ,
115- len (write_result .offset_to_db_chunk ), len (write_result .new_db_chunks ),
116- 100.0 * len (write_result .new_db_chunks ) / max (1 , len (write_result .offset_to_db_chunk )),
117- ))
111+ if self .logger .isEnabledFor (logging .DEBUG ):
112+ self .logger .debug ('Chunked file {} in {:.2f}s, compressed size {}/{}, chunk count: {} (+{}, {:.1f}%)' .format (
113+ src_path_str , time .time () - process_start_time ,
114+ write_result .stored_size_sum , write_result .raw_size_sum ,
115+ len (write_result .offset_to_db_chunk ), len (write_result .new_db_chunks ),
116+ 100.0 * len (write_result .new_db_chunks ) / max (1 , len (write_result .offset_to_db_chunk )),
117+ ))
118118 if (
119119 len (write_result .new_db_chunks ) >= max (5000 , int (write_result .unique_chunk_count * 0.6 )) and
120120 self .ctx .file_lookup .previous_backup_has_chunked_file (self .args .src_path )
@@ -138,9 +138,10 @@ def __select_plan(self) -> _ChunkedBlobPlan:
138138 policy = _ChunkedBlobCreatePolicy .default
139139 pre_cal_result = self .ctx .file_lookup .pop_pre_calc_result (self .args .src_path )
140140 if pre_cal_result is not None and (self .args .st .st_size != pre_cal_result .size or pre_cal_result .should_be_chunked is False ):
141- self .logger .debug ('Drop pre cal result for path {} due to stat mismatched, st.st_size {}, pre_cal_result {}' .format (
142- self .args .src_path , self .args .st .st_size , pre_cal_result .simple_repr (),
143- ))
141+ if self .logger .isEnabledFor (logging .DEBUG ):
142+ self .logger .debug ('Drop pre cal result for path {} due to stat mismatched, st.st_size {}, pre_cal_result {}' .format (
143+ self .args .src_path , self .args .st .st_size , pre_cal_result .simple_repr (),
144+ ))
144145 pre_cal_result = None
145146 return _ChunkedBlobPlan (policy , pre_cal_result )
146147
@@ -163,17 +164,20 @@ def __load_or_cut_chunks(self, actual_path_to_read: Path, pre_cal_result: Option
163164 if pre_cal_result .chunks is not None :
164165 chunks = pre_cal_result .chunks
165166 blob_size = pre_cal_result .size
166- self .logger .debug ('Cut and hashed file {} with size {} into {} chunks using {} (precalc)' .format (
167- src_path_str , ByteCount (blob_size ).auto_str (), len (chunks ), self .args .chunk_method .name ,
168- ))
167+ if self .logger .isEnabledFor (logging .DEBUG ):
168+ self .logger .debug ('Cut and hashed file {} with size {} into {} chunks using {} (precalc)' .format (
169+ src_path_str , ByteCount (blob_size ).auto_str (), len (chunks ), self .args .chunk_method .name ,
170+ ))
169171 if (cache := (yield from self .query_cached_blob (pre_calc_blob_hash ))) is not None :
170- self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
172+ if self .logger .isEnabledFor (logging .DEBUG ):
173+ self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
171174 return cache
172175 return _ChunkedBlobSnapshot (chunks , pre_calc_blob_hash , blob_size )
173176
174177 if pre_calc_blob_hash is not None :
175178 if (cache := (yield from self .query_cached_blob (pre_calc_blob_hash ))) is not None :
176- self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
179+ if self .logger .isEnabledFor (logging .DEBUG ):
180+ self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
177181 return cache
178182
179183 if (
@@ -188,12 +192,14 @@ def __load_or_cut_chunks(self, actual_path_to_read: Path, pre_cal_result: Option
188192 if sah .size != self .args .st .st_size :
189193 self .log_and_raise_blob_file_changed ('Blob size mismatch, previous: {}, current: {}' .format (self .args .st .st_size , sah .size ), self .args .last_chance )
190194 pre_calc_blob_hash = sah .hash
191- self .logger .debug ('Hashed stat unchanged chunked file {} with size {} in {:.2f}s ({}/s)' .format (
192- src_path_str , ByteCount (sah .size ).auto_str (), hash_cost (),
193- ByteCount (sah .size / hash_cost () if hash_cost () > 0 else 0 ).auto_str (),
194- ))
195+ if self .logger .isEnabledFor (logging .DEBUG ):
196+ self .logger .debug ('Hashed stat unchanged chunked file {} with size {} in {:.2f}s ({}/s)' .format (
197+ src_path_str , ByteCount (sah .size ).auto_str (), hash_cost (),
198+ ByteCount (sah .size / hash_cost () if hash_cost () > 0 else 0 ).auto_str (),
199+ ))
195200 if (cache := (yield from self .query_cached_blob (pre_calc_blob_hash ))) is not None :
196- self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
201+ if self .logger .isEnabledFor (logging .DEBUG ):
202+ self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , pre_calc_blob_hash ))
197203 return cache
198204
199205 previous_chunks = self .ctx .file_lookup .get_previous_chunks (self .args .src_path ) if self .args .chunk_method .needs_previous_chunks () else None
@@ -205,12 +211,14 @@ def __load_or_cut_chunks(self, actual_path_to_read: Path, pre_cal_result: Option
205211 if pre_calc_blob_hash is not None and pre_calc_blob_hash != blob_hash :
206212 self .log_and_raise_blob_file_changed ('Blob hash mismatch, pre calc {}, chunked {}' .format (pre_calc_blob_hash , blob_hash ), self .args .last_chance )
207213
208- self .logger .debug ('Cut and hashed file {} with size {} into {} chunks using {} in {:.2f}s ({}/s)' .format (
209- src_path_str , ByteCount (blob_size ).auto_str (), len (chunks ), self .args .chunk_method .name , chunking_cost (),
210- ByteCount (blob_size / chunking_cost () if chunking_cost () > 0 else 0 ).auto_str (),
211- ))
214+ if self .logger .isEnabledFor (logging .DEBUG ):
215+ self .logger .debug ('Cut and hashed file {} with size {} into {} chunks using {} in {:.2f}s ({}/s)' .format (
216+ src_path_str , ByteCount (blob_size ).auto_str (), len (chunks ), self .args .chunk_method .name , chunking_cost (),
217+ ByteCount (blob_size / chunking_cost () if chunking_cost () > 0 else 0 ).auto_str (),
218+ ))
212219 if pre_calc_blob_hash is None and (cache := (yield from self .query_cached_blob (blob_hash ))) is not None :
213- self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , blob_hash ))
220+ if self .logger .isEnabledFor (logging .DEBUG ):
221+ self .logger .debug ('Chunked file {} (hash {}) already exists in DB' .format (src_path_str , blob_hash ))
214222 return cache
215223 return _ChunkedBlobSnapshot (chunks , blob_hash , blob_size )
216224
0 commit comments