serve/mirror: Move some code tracking migration speed into serve
The rationale is that status will need this information
This commit is contained in:
16
src/mirror.c
16
src/mirror.c
@@ -447,20 +447,6 @@ int mirror_exceeds_max_bps( struct mirror * mirror )
|
||||
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
|
||||
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
|
||||
* */
|
||||
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" );
|
||||
server_forbid_new_clients( ctrl->serve );
|
||||
server_close_clients( ctrl->serve );
|
||||
|
@@ -132,5 +132,7 @@ struct mirror_super * mirror_super_create(
|
||||
);
|
||||
void * mirror_super_runner( void * serve_uncast );
|
||||
|
||||
uint64_t mirror_current_bps( struct mirror * mirror );
|
||||
|
||||
#endif
|
||||
|
||||
|
27
src/serve.c
27
src/serve.c
@@ -860,6 +860,33 @@ int server_is_mirroring( struct server * serve )
|
||||
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 );
|
||||
|
||||
|
@@ -123,6 +123,10 @@ void server_unlock_acl( struct server *serve );
|
||||
void server_lock_start_mirror( struct server *serve );
|
||||
void server_unlock_start_mirror( 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_prevent_mirror_start( struct server *serve );
|
||||
void server_allow_mirror_start( struct server *serve );
|
||||
|
Reference in New Issue
Block a user