Ejemplo n.º 1
0
def CheckCanVacuum( db_path, stop_time = None ):
    
    db = sqlite3.connect( db_path, isolation_level = None, detect_types = sqlite3.PARSE_DECLTYPES )
    
    c = db.cursor()
    
    ( page_size, ) = c.execute( 'PRAGMA page_size;' ).fetchone()
    ( page_count, ) = c.execute( 'PRAGMA page_count;' ).fetchone()
    ( freelist_count, ) = c.execute( 'PRAGMA freelist_count;' ).fetchone()
    
    db_size = ( page_count - freelist_count ) * page_size
    
    if stop_time is not None:
        
        approx_vacuum_speed_mb_per_s = 1048576 * 1
        
        approx_vacuum_duration = db_size // approx_vacuum_speed_mb_per_s
        
        time_i_will_have_to_start = stop_time - approx_vacuum_duration
        
        if HydrusData.TimeHasPassed( time_i_will_have_to_start ):
            
            raise Exception( 'I believe you need about ' + HydrusData.TimeDeltaToPrettyTimeDelta( approx_vacuum_duration ) + ' to vacuum, but there is not enough time allotted.' )
            
        
    
    ( db_dir, db_filename ) = os.path.split( db_path )
    
    HydrusPaths.CheckHasSpaceForDBTransaction( db_dir, db_size )
Ejemplo n.º 2
0
def CheckCanVacuumCursor(db_path, c, stop_time=None):

    (page_size, ) = c.execute('PRAGMA page_size;').fetchone()
    (page_count, ) = c.execute('PRAGMA page_count;').fetchone()
    (freelist_count, ) = c.execute('PRAGMA freelist_count;').fetchone()

    db_size = (page_count - freelist_count) * page_size

    vacuum_estimate = int(db_size * 1.2)

    if stop_time is not None:

        approx_vacuum_speed_mb_per_s = 1048576 * 1

        approx_vacuum_duration = vacuum_estimate // approx_vacuum_speed_mb_per_s

        time_i_will_have_to_start = stop_time - approx_vacuum_duration

        if HydrusData.TimeHasPassed(time_i_will_have_to_start):

            raise Exception(
                'I believe you need about ' +
                HydrusData.TimeDeltaToPrettyTimeDelta(approx_vacuum_duration) +
                ' to vacuum, but there is not enough time allotted.')

    db_dir = os.path.dirname(db_path)

    HydrusPaths.CheckHasSpaceForDBTransaction(db_dir, vacuum_estimate)