diff options
author | Jay Doane <jaydoane@apache.org> | 2020-04-14 11:04:56 -0700 |
---|---|---|
committer | Jay Doane <jaydoane@apache.org> | 2020-04-14 11:04:56 -0700 |
commit | 38ae90da4397eda4ccaf849b653d1e7c4be96ac4 (patch) | |
tree | e2a9fd08977f189a2652892887dea63f21cb42e7 | |
parent | e9facf7254aaa2af8f2f501c2609b94210c7f5e4 (diff) | |
download | couchdb-configurable-binary-chunk-size.tar.gz |
fixup: Calculate chunk size at time of actual chunkingconfigurable-binary-chunk-size
-rw-r--r-- | src/fabric/src/fabric2_fdb.erl | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl index 03eeae512..53102d6e9 100644 --- a/src/fabric/src/fabric2_fdb.erl +++ b/src/fabric/src/fabric2_fdb.erl @@ -235,7 +235,6 @@ create(#{} = Db0, Options) -> validate_doc_update_funs => [], before_doc_update => undefined, after_doc_read => undefined, - binary_chunk_size => binary_chunk_size(), % All other db things as we add features, db_options => Options1 @@ -279,7 +278,6 @@ open(#{} = Db0, Options) -> validate_doc_update_funs => [], before_doc_update => undefined, after_doc_read => undefined, - binary_chunk_size => binary_chunk_size(), db_options => Options2 }, @@ -998,8 +996,7 @@ write_attachment(#{} = Db, DocId, Data, Encoding) when is_binary(Data), is_atom(Encoding) -> #{ tx := Tx, - db_prefix := DbPrefix, - binary_chunk_size := BinaryChunkSize + db_prefix := DbPrefix } = ensure_current(Db), AttId = fabric2_util:uuid(), @@ -1020,7 +1017,7 @@ write_attachment(#{} = Db, DocId, Data, Encoding) InfoVal = erlfdb_tuple:pack({?CURR_ATT_STORAGE_VER, Compressed}), ok = erlfdb:set(Tx, IdKey, InfoVal), - Chunks = chunkify_binary(Data1, BinaryChunkSize), + Chunks = chunkify_binary(Data1), lists:foldl(fun(Chunk, ChunkId) -> AttKey = erlfdb_tuple:pack({?DB_ATTS, DocId, AttId, ChunkId}, DbPrefix), @@ -1491,8 +1488,7 @@ fdb_to_revinfo(Key, {1, RPath, AttHash}) -> doc_to_fdb(Db, #doc{} = Doc) -> #{ - db_prefix := DbPrefix, - binary_chunk_size := BinaryChunkSize + db_prefix := DbPrefix } = Db, #doc{ @@ -1507,7 +1503,7 @@ doc_to_fdb(Db, #doc{} = Doc) -> Opts = [{minor_version, 1}, {compressed, 6}], Value = term_to_binary({Body, DiskAtts, Deleted}, Opts), - Chunks = chunkify_binary(Value, BinaryChunkSize), + Chunks = chunkify_binary(Value), {Rows, _} = lists:mapfoldl(fun(Chunk, ChunkId) -> Key = erlfdb_tuple:pack({?DB_DOCS, Id, Start, Rev, ChunkId}, DbPrefix), @@ -1542,8 +1538,7 @@ fdb_to_doc(Db, DocId, Pos, Path, BinRows) when is_list(BinRows) -> local_doc_to_fdb(Db, #doc{} = Doc) -> #{ - db_prefix := DbPrefix, - binary_chunk_size := BinaryChunkSize + db_prefix := DbPrefix } = Db, #doc{ @@ -1563,7 +1558,7 @@ local_doc_to_fdb(Db, #doc{} = Doc) -> {Rows, _} = lists:mapfoldl(fun(Chunk, ChunkId) -> K = erlfdb_tuple:pack({?DB_LOCAL_DOC_BODIES, Id, ChunkId}, DbPrefix), {{K, Chunk}, ChunkId + 1} - end, 0, chunkify_binary(BVal, BinaryChunkSize)), + end, 0, chunkify_binary(BVal)), NewSize = fabric2_util:ldoc_size(Doc), RawValue = erlfdb_tuple:pack({?CURR_LDOC_FORMAT, StoreRev, NewSize}), @@ -1632,13 +1627,16 @@ sum_rem_rev_sizes(RevInfos) -> end, 0, RevInfos). -chunkify_binary(Data, Size) -> - couch_log:info("chunkify_binary ~p", [Size]), +chunkify_binary(Data) -> + chunkify_data(Data, binary_chunk_size()). + + +chunkify_data(Data, Size) -> case Data of <<>> -> []; <<Head:Size/binary, Rest/binary>> -> - [Head | chunkify_binary(Rest, Size)]; + [Head | chunkify_data(Rest, Size)]; <<_/binary>> when size(Data) < Size -> [Data] end. |