Add the --unlink option to mirror

This deletes the local file before tearing down the mirror connection,
allowing us to avoid an ambiguous recovery situation.
This commit is contained in:
Alex Young
2012-07-23 13:39:27 +01:00
parent fd935ce4c9
commit 33f95e1986
9 changed files with 140 additions and 44 deletions

View File

@@ -73,6 +73,10 @@ class Environment
@nbd1.mirror_unchecked( @nbd2.ip, @nbd2.port, nil, nil, 10 )
end
def mirror12_unlink
@nbd1.mirror_unlink( @nbd2.ip, @nbd2.port, 2 )
end
def writefile1(data)
@file1 = FileWriter.new(@filename1, @blocksize).write(data)

View File

@@ -195,7 +195,7 @@ class FlexNBD
end
end
def initialize(bin, ip, port)
def initialize( bin, ip, port )
@bin = bin
@do_debug = ENV['DEBUG']
@debug = build_debug_opt
@@ -259,12 +259,29 @@ class FlexNBD
end
def mirror_cmd(dest_ip, dest_port)
"#{@bin} mirror "\
"--addr #{dest_ip} "\
def base_mirror_opts( dest_ip, dest_port )
"--addr #{dest_ip} "\
"--port #{dest_port} "\
"--sock #{ctrl} "\
"#{@debug} "
end
def unlink_mirror_opts( dest_ip, dest_port )
"#{base_mirror_opts( dest_ip, dest_port )} "\
"--unlink "
end
def base_mirror_cmd( opts )
"#{@bin} mirror "\
"#{opts} "\
"#{@debug}"
end
def mirror_cmd(dest_ip, dest_port)
base_mirror_cmd( base_mirror_opts( dest_ip, dest_port ) )
end
def mirror_unlink_cmd( dest_ip, dest_port )
base_mirror_cmd( unlink_mirror_opts( dest_ip, dest_port ) )
end
def break_cmd
@@ -389,6 +406,14 @@ class FlexNBD
end
def mirror_unlink( dest_ip, dest_port, timeout=nil )
cmd = mirror_unlink_cmd( dest_ip, dest_port )
debug( cmd )
maybe_timeout( cmd, timeout )
end
def maybe_timeout(cmd, timeout=nil )
stdout, stderr = "",""
run = Proc.new do
@@ -417,6 +442,7 @@ class FlexNBD
end
def break(timeout=nil)
cmd = break_cmd
debug( cmd )

View File

@@ -64,12 +64,17 @@ class TestHappyPath < Test::Unit::TestCase
end
def test_mirror
def setup_to_mirror
@env.writefile1( "f"*4 )
@env.serve1
@env.writefile2( "0"*4 )
@env.listen2
end
def test_mirror
setup_to_mirror()
@env.nbd1.can_die
@env.nbd2.can_die(0)
@@ -78,11 +83,30 @@ class TestHappyPath < Test::Unit::TestCase
@env.nbd1.join
@env.nbd2.join
assert( File.file?( @env.filename1 ),
"The source file was incorrectly deleted")
assert_equal(@env.file1.read_original( 0, @env.blocksize ),
@env.file2.read( 0, @env.blocksize ) )
end
def test_mirror_unlink
setup_to_mirror()
assert File.file?( @env.filename1 )
stdout, stderr = @env.mirror12_unlink
assert_no_match( /unrecognized/, stderr )
@env.nbd1.can_die(0)
@env.nbd2.can_die(0)
Timeout.timeout(2) do @env.nbd1.join end
assert !File.file?( @env.filename1 )
end
def test_write_to_high_block
# Create a large file, then try to write to somewhere after the 2G boundary
@env.truncate1 "4G"