From 4c6355483d3e97971a97a9a3935263ecf47f7ca8 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Mon, 8 Nov 2010 19:22:01 +0000 Subject: =?UTF-8?q?Preserve=20attachment=20identity=20length=20when=20doin?= =?UTF-8?q?g=20local=20to=20local=20replications.=20Closes=20COUCHDB-930.?= =?UTF-8?q?=20Patch=20by=20Juuso=20V=C3=A4=C3=A4n=C3=A4nen.=20Thanks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1032673 13f79535-47bb-0310-9956-ffa450edef68 --- THANKS | 1 + src/couchdb/couch_db.erl | 5 ++-- test/etap/113-replication-attachment-comp.t | 46 ++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/THANKS b/THANKS index 3322fddf..3ed1534c 100644 --- a/THANKS +++ b/THANKS @@ -70,5 +70,6 @@ suggesting improvements or submitting changes. Some of these people are: * David Davis * Klaus Trainer * Dale Harvey + * Juuso Väänänen For a list of authors see the `AUTHORS` file. diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl index 36b61a7e..7d8d195f 100644 --- a/src/couchdb/couch_db.erl +++ b/src/couchdb/couch_db.erl @@ -803,11 +803,12 @@ flush_att(Fd, #att{data={Fd0, _}}=Att) when Fd0 == Fd -> % already written to our file, nothing to write Att; -flush_att(Fd, #att{data={OtherFd,StreamPointer}, md5=InMd5}=Att) -> +flush_att(Fd, #att{data={OtherFd,StreamPointer}, md5=InMd5, + disk_len=InDiskLen} = Att) -> {NewStreamData, Len, _IdentityLen, Md5, IdentityMd5} = couch_stream:copy_to_new_stream(OtherFd, StreamPointer, Fd), check_md5(IdentityMd5, InMd5), - Att#att{data={Fd, NewStreamData}, md5=Md5, att_len=Len, disk_len=Len}; + Att#att{data={Fd, NewStreamData}, md5=Md5, att_len=Len, disk_len=InDiskLen}; flush_att(Fd, #att{data=Data}=Att) when is_binary(Data) -> with_stream(Fd, Att, fun(OutputStream) -> diff --git a/test/etap/113-replication-attachment-comp.t b/test/etap/113-replication-attachment-comp.t index 30f602ef..19c48fc6 100755 --- a/test/etap/113-replication-attachment-comp.t +++ b/test/etap/113-replication-attachment-comp.t @@ -30,7 +30,7 @@ test_db_b_name() -> main(_) -> test_util:init_code_path(), - etap:plan(30), + etap:plan(45), case (catch test()) of ok -> etap:end_tests(); @@ -102,6 +102,33 @@ test() -> check_server_can_decompress_att(test_db_b_name()), check_att_stubs(test_db_a_name(), test_db_b_name()), + % + % test local replication + % + + delete_db(test_db_a_name()), + delete_db(test_db_b_name()), + create_db(test_db_a_name()), + create_db(test_db_b_name()), + + % enable compression + couch_config:set("attachments", "compression_level", "8"), + couch_config:set("attachments", "compressible_types", "text/*"), + + % store doc with text attachment in DB A + put_text_att(test_db_a_name()), + + % disable attachment compression + couch_config:set("attachments", "compression_level", "0"), + + % do local-local replication + do_local_replication(test_db_a_name(), test_db_b_name()), + + % verify that DB B has the attachment stored in compressed form + check_att_is_compressed(test_db_b_name()), + check_server_can_decompress_att(test_db_b_name()), + check_att_stubs(test_db_a_name(), test_db_b_name()), + timer:sleep(3000), % to avoid mochiweb socket closed exceptions delete_db(test_db_a_name()), delete_db(test_db_b_name()), @@ -152,6 +179,23 @@ do_push_replication(SourceDbName, TargetDbName) -> etap:is(RepOk, true, "Push replication completed with success"), ok. +do_local_replication(SourceDbName, TargetDbName) -> + RepObj = {[ + {<<"source">>, SourceDbName}, + {<<"target">>, TargetDbName} + ]}, + {ok, {{_, Code, _}, _Headers, Body}} = http:request( + post, + {rep_url(), [], + "application/json", list_to_binary(couch_util:json_encode(RepObj))}, + [], + [{sync, true}]), + etap:is(Code, 200, "Local replication successfully triggered"), + Json = couch_util:json_decode(Body), + RepOk = couch_util:get_nested_json_value(Json, [<<"ok">>]), + etap:is(RepOk, true, "Local replication completed with success"), + ok. + check_att_is_compressed(DbName) -> {ok, {{_, Code, _}, Headers, Body}} = http:request( get, -- cgit v1.2.3