serve/mirror: Move some code tracking migration speed into serve

The rationale is that status will need this information
This commit is contained in:
nick
2013-09-23 13:49:01 +01:00
parent 0f2225becf
commit 0ae249009c
4 changed files with 34 additions and 15 deletions

View File

@@ -447,20 +447,6 @@ int mirror_exceeds_max_bps( struct mirror * mirror )
return 0; return 0;
} }
/* Given historic bps measurements and number of bytes left to transfer, give
* an estimate of how many seconds are remaining before the migration is
* complete, assuming no new bytes are written.
*/
uint64_t mirror_estimate_time( struct server * serve )
{
uint64_t bytes_to_xfer =
bitset_stream_size( serve->allocation_map ) +
( serve->size - serve->mirror->offset );
debug("Bytes left to transfer: %"PRIu64, bytes_to_xfer );
return bytes_to_xfer / ( mirror_current_bps( serve->mirror ) + 1 );
}
// ONLY CALL THIS AFTER CLOSING CLIENTS // ONLY CALL THIS AFTER CLOSING CLIENTS
void mirror_complete( struct server *serve ) void mirror_complete( struct server *serve )
{ {
@@ -622,7 +608,7 @@ static void mirror_read_cb( struct ev_loop *loop, ev_io *w, int revents )
/* Regardless of time estimates, if there's no waiting transfer, we can /* Regardless of time estimates, if there's no waiting transfer, we can
* */ * */
if ( !ctrl->clients_closed && ( !next_xfer || mirror_estimate_time( ctrl->serve ) < 60 ) ) { if ( !ctrl->clients_closed && ( !next_xfer || server_mirror_eta( ctrl->serve ) < 60 ) ) {
info( "Closing clients to allow mirroring to converge" ); info( "Closing clients to allow mirroring to converge" );
server_forbid_new_clients( ctrl->serve ); server_forbid_new_clients( ctrl->serve );
server_close_clients( ctrl->serve ); server_close_clients( ctrl->serve );

View File

@@ -132,5 +132,7 @@ struct mirror_super * mirror_super_create(
); );
void * mirror_super_runner( void * serve_uncast ); void * mirror_super_runner( void * serve_uncast );
uint64_t mirror_current_bps( struct mirror * mirror );
#endif #endif

View File

@@ -860,6 +860,33 @@ int server_is_mirroring( struct server * serve )
return !!serve->mirror_super; return !!serve->mirror_super;
} }
uint64_t server_mirror_bytes_remaining( struct server * serve )
{
if ( server_is_mirroring( serve ) ) {
uint64_t bytes_to_xfer =
bitset_stream_size( serve->allocation_map ) +
( serve->size - serve->mirror->offset );
return bytes_to_xfer;
}
return 0;
}
/* Given historic bps measurements and number of bytes left to transfer, give
* an estimate of how many seconds are remaining before the migration is
* complete, assuming no new bytes are written.
*/
uint64_t server_mirror_eta( struct server * serve )
{
if ( server_is_mirroring( serve ) ) {
uint64_t bytes_to_xfer = server_mirror_bytes_remaining( serve );
return bytes_to_xfer / ( mirror_current_bps( serve->mirror ) + 1 );
}
return 0;
}
void mirror_super_destroy( struct mirror_super * super ); void mirror_super_destroy( struct mirror_super * super );

View File

@@ -123,6 +123,10 @@ void server_unlock_acl( struct server *serve );
void server_lock_start_mirror( struct server *serve ); void server_lock_start_mirror( struct server *serve );
void server_unlock_start_mirror( struct server *serve ); void server_unlock_start_mirror( struct server *serve );
int server_is_mirroring( struct server * serve ); int server_is_mirroring( struct server * serve );
uint64_t server_mirror_bytes_remaining( struct server * serve );
uint64_t server_mirror_eta( struct server * serve );
void server_abandon_mirror( struct server * serve ); void server_abandon_mirror( struct server * serve );
void server_prevent_mirror_start( struct server *serve ); void server_prevent_mirror_start( struct server *serve );
void server_allow_mirror_start( struct server *serve ); void server_allow_mirror_start( struct server *serve );