flexnbd status: Add current pass clean/dirty byte statistics

This commit is contained in:
nick
2013-07-08 13:51:15 +01:00
parent b29ef6d4de
commit f4bfc70a4b
5 changed files with 44 additions and 0 deletions

View File

@@ -166,8 +166,10 @@ int mirror_pass(struct server * serve, int is_last_pass, uint64_t *written)
uint64_t current = 0; uint64_t current = 0;
int success = 1; int success = 1;
struct bitset_mapping *map = serve->mirror->dirty_map; struct bitset_mapping *map = serve->mirror->dirty_map;
struct mirror * m = serve->mirror;
*written = 0; *written = 0;
while (current < serve->size) { while (current < serve->size) {
int run = bitset_run_count(map, current, mirror_longest_write); int run = bitset_run_count(map, current, mirror_longest_write);
@@ -205,7 +207,10 @@ int mirror_pass(struct server * serve, int is_last_pass, uint64_t *written)
} }
if (!is_last_pass) { server_unlock_io( serve ); } if (!is_last_pass) { server_unlock_io( serve ); }
m->this_pass_dirty += run;
*written += run; *written += run;
} else {
m->this_pass_clean += run;
} }
current += run; current += run;
@@ -353,6 +358,8 @@ void mirror_run( struct server *serve )
info("Starting mirror" ); info("Starting mirror" );
for (m->pass=0; m->pass < mirror_maximum_passes-1; m->pass++) { for (m->pass=0; m->pass < mirror_maximum_passes-1; m->pass++) {
m->this_pass_clean = 0;
m->this_pass_dirty = 0;
debug("mirror start pass=%d", m->pass); debug("mirror start pass=%d", m->pass);
if ( !mirror_pass( serve, 0, &written ) ){ if ( !mirror_pass( serve, 0, &written ) ){
@@ -366,6 +373,9 @@ void mirror_run( struct server *serve )
server_lock_io( serve ); server_lock_io( serve );
{ {
m->this_pass_clean = 0;
m->this_pass_dirty = 0;
if ( mirror_pass( serve, 1, &written ) && if ( mirror_pass( serve, 1, &written ) &&
mirror_should_quit( serve->mirror ) ) { mirror_should_quit( serve->mirror ) ) {
debug("exit!"); debug("exit!");

View File

@@ -82,6 +82,12 @@ struct mirror {
/* The current mirror pass. We put this here so status can query it */ /* The current mirror pass. We put this here so status can query it */
int pass; int pass;
/* The number of dirty (had to send to dest) and clean (could skip) bytes
* for this pass. Add them together and subtract from size to get remaining
* bytes. */
uint64_t this_pass_dirty;
uint64_t this_pass_clean;
}; };

View File

@@ -17,6 +17,8 @@ struct status * status_create( struct server * serve )
status->is_mirroring = NULL != serve->mirror; status->is_mirroring = NULL != serve->mirror;
if ( status->is_mirroring ) { if ( status->is_mirroring ) {
status->migration_pass = serve->mirror->pass; status->migration_pass = serve->mirror->pass;
status->pass_dirty_bytes = serve->mirror->this_pass_dirty;
status->pass_clean_bytes = serve->mirror->this_pass_clean;
} }
server_unlock_start_mirror( serve ); server_unlock_start_mirror( serve );

View File

@@ -45,7 +45,14 @@
* When migrating, we perform a number of passes over the file. This indicates * When migrating, we perform a number of passes over the file. This indicates
* the current pass. * the current pass.
* *
* pass_dirty_bytes:
* For the current pass, how many dirty bytes have we found so far? These are
* classed as bytes that we are required to send to the destination.
* *
* pass_clean_bytes:
* For the current pass, how many clean bytes? These are bytes we don't need
* to send to the destination. Once all the bytes are clean, the migration is
* done.
*/ */
@@ -60,6 +67,9 @@ struct status {
int has_control; int has_control;
int is_mirroring; int is_mirroring;
int migration_pass; int migration_pass;
uint64_t pass_dirty_bytes;
uint64_t pass_clean_bytes;
}; };
/** Create a status object for the given server. */ /** Create a status object for the given server. */

View File

@@ -119,6 +119,22 @@ START_TEST( test_gets_size )
} }
END_TEST END_TEST
START_TEST( test_gets_pass_statistics )
{
struct server * server = mock_mirroring_server();
server->mirror->this_pass_clean = 2048;
server->mirror->this_pass_dirty = 4096;
struct status * status = status_create( server );
fail_unless( 2048 == status->pass_clean_bytes, "pass_clean_bytes wasn't gathered" );
fail_unless( 4096 == status->pass_dirty_bytes, "pass_dirty_bytes wasn't gathered" );
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
START_TEST( test_renders_has_control ) START_TEST( test_renders_has_control )
{ {