From 84acedbc69dab6c33a2652c489e0ac141cd88264 Mon Sep 17 00:00:00 2001 From: Gil Vernik Date: Wed, 14 Oct 2015 13:49:05 +0300 Subject: [PATCH 1/2] COUCHDB-769: Store attachments in external storage. This is initial implementation, supports OpenStack Swift and SoftLayer Object store --- src/couch_att.erl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/couch_att.erl b/src/couch_att.erl index 9d38cfae..47d1ffd6 100644 --- a/src/couch_att.erl +++ b/src/couch_att.erl @@ -438,17 +438,28 @@ digest_from_json(Props) -> to_json(Att, OutputData, DataToFollow, ShowEncoding) -> - [Name, Data, DiskLen, AttLen, Enc, Type, RevPos, Md5] = fetch( + [AttExternal,AttExternalSize, AttExternalMD5] = couch_att:fetch([att_external,att_external_size,att_external_md5],Att), + [Name, Data, DiskLenTmp, AttLen, Enc, Type, RevPos, Md5] = fetch( [name, data, disk_len, att_len, encoding, type, revpos, md5], Att ), + case AttExternal of + "external" -> + DiskLen = AttExternalSize, + DigestProp = case AttExternalMD5 of + <<>> -> []; + Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}] + end; + _ -> + DiskLen = DiskLenTmp, + DigestProp = case base64:encode(Md5) of + <<>> -> []; + Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}] + end + end, Props = [ {<<"content_type">>, Type}, {<<"revpos">>, RevPos} ], - DigestProp = case base64:encode(Md5) of - <<>> -> []; - Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}] - end, DataProps = if not OutputData orelse Data == stub -> [{<<"length">>, DiskLen}, {<<"stub">>, true}]; From a1b9a6f8c7e662fe38a186236169f8728c0fac64 Mon Sep 17 00:00:00 2001 From: Gil Vernik Date: Mon, 4 Jan 2016 10:18:22 +0200 Subject: [PATCH 2/2] improved code. based on the previous review --- src/couch_att.erl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/couch_att.erl b/src/couch_att.erl index 47d1ffd6..d811133f 100644 --- a/src/couch_att.erl +++ b/src/couch_att.erl @@ -438,20 +438,22 @@ digest_from_json(Props) -> to_json(Att, OutputData, DataToFollow, ShowEncoding) -> - [AttExternal,AttExternalSize, AttExternalMD5] = couch_att:fetch([att_external,att_external_size,att_external_md5],Att), + [ExtStoreID,AttExternalSize, AttExternalMD5] = couch_att:fetch([att_extstore_id, + att_extstore_size, + att_extstore_md5], Att), [Name, Data, DiskLenTmp, AttLen, Enc, Type, RevPos, Md5] = fetch( [name, data, disk_len, att_len, encoding, type, revpos, md5], Att ), - case AttExternal of - "external" -> - DiskLen = AttExternalSize, - DigestProp = case AttExternalMD5 of + case ExtStoreID of + undefined -> + DiskLen = DiskLenTmp, + DigestProp = case base64:encode(Md5) of <<>> -> []; Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}] end; _ -> - DiskLen = DiskLenTmp, - DigestProp = case base64:encode(Md5) of + DiskLen = AttExternalSize, + DigestProp = case AttExternalMD5 of <<>> -> []; Digest -> [{<<"digest">>, <<"md5-", Digest/binary>>}] end