Permalink
Browse files

remove couch_btree dependency on config

  • Loading branch information...
1 parent d8fc410 commit 03cc264941fa6cf65441c647e39513b465c8dd2d Robert Dionne committed Nov 13, 2010
View
9 apps/couch/src/couch_btree.erl
@@ -19,6 +19,7 @@
-record(btree,
{fd,
root,
+ chunk_size = 1279,
extract_kv,
assemble_kv,
less,
@@ -48,6 +49,8 @@ set_options(Bt, []) ->
Bt;
set_options(Bt, [{split, Extract}|Rest]) ->
set_options(Bt#btree{extract_kv=Extract}, Rest);
+set_options(Bt, [{chunk_size, Size}|Rest]) ->
+ set_options(Bt#btree{chunk_size=Size}, Rest);
set_options(Bt, [{join, Assemble}|Rest]) ->
set_options(Bt#btree{assemble_kv=Assemble}, Rest);
set_options(Bt, [{less, Less}|Rest]) ->
@@ -278,9 +281,7 @@ complete_root(Bt, KPs) ->
% written. Plus with the "case byte_size(term_to_binary(InList)) of" code
% it's probably really inefficient.
-chunkify(InList) ->
- BaseChunkSize = list_to_integer(couch_config:get("couchdb",
- "btree_chunk_size", "1279")),
+chunkify(InList, BaseChunkSize) ->
case byte_size(term_to_binary(InList)) of
Size when Size > BaseChunkSize ->
NumberOfChunksLikely = ((Size div BaseChunkSize) + 1),
@@ -342,7 +343,7 @@ get_node(#btree{fd = Fd}, NodePos) ->
write_node(Bt, NodeType, NodeList) ->
% split up nodes into smaller sizes
- NodeListList = chunkify(NodeList),
+ NodeListList = chunkify(NodeList, Bt#btree.chunk_size),
% now write out each chunk and return the KeyPointer pairs for those nodes
ResultList = [
begin
View
12 apps/couch/src/couch_db_updater.erl
@@ -407,16 +407,22 @@ init_db(DbName, Filepath, Fd, Header0) ->
true -> ok = couch_file:sync(Filepath);
_ -> ok
end,
+
+ BTreeChunkSize = list_to_integer(couch_config:get("couchdb",
+ "btree_chunk_size", "1279")),
{ok, IdBtree} = couch_btree:open(Header#db_header.id_tree_state, Fd,
[{split, fun ?MODULE:btree_by_id_split/1},
{join, fun ?MODULE:btree_by_id_join/2},
- {reduce, fun ?MODULE:btree_by_id_reduce/2}]),
+ {reduce, fun ?MODULE:btree_by_id_reduce/2},
+ {chunk_size, BTreeChunkSize}]),
{ok, SeqBtree} = couch_btree:open(Header#db_header.seq_tree_state, Fd,
[{split, fun ?MODULE:btree_by_seq_split/1},
{join, fun ?MODULE:btree_by_seq_join/2},
- {reduce, fun ?MODULE:btree_by_seq_reduce/2}]),
- {ok, LocalDocsBtree} = couch_btree:open(Header#db_header.local_tree_state, Fd),
+ {reduce, fun ?MODULE:btree_by_seq_reduce/2},
+ {chunk_size, BTreeChunkSize}]),
+ {ok, LocalDocsBtree} = couch_btree:open(Header#db_header.local_tree_state, Fd,
+ [{chunk_size, BTreeChunkSize}]),
case Header#db_header.security_ptr of
nil ->
Security = [],
View
7 apps/couch/src/couch_view_group.erl
@@ -577,8 +577,13 @@ init_group(Fd, #group{def_lang=Lang,views=Views}=Group, IndexHeader) ->
<<"raw">> ->
Less = fun(A,B) -> A < B end
end,
+
+ BTreeChunkSize = list_to_integer(couch_config:get("couchdb",
+ "btree_chunk_size", "1279")),
+
{ok, Btree} = couch_btree:open(BtreeState, Fd, [{less, Less},
- {reduce, ReduceFun}]),
+ {reduce, ReduceFun},
+ {chunk_size, BTreeChunkSize}]),
View#view{btree=Btree}
end,
ViewStates, Views),
View
3 apps/couch/test/etap/020-btree-basics.t
@@ -17,11 +17,10 @@
filename() -> test_util:build_file("test/etap/temp.020").
rows() -> 250.
--record(btree, {fd, root, extract_kv, assemble_kv, less, reduce}).
+-record(btree, {fd, root, chunk_size, extract_kv, assemble_kv, less, reduce}).
main(_) ->
test_util:init_code_path(),
- couch_config:start_link([]),
etap:plan(51),
case (catch test()) of
ok ->
View
1 apps/couch/test/etap/021-btree-reductions.t
@@ -19,7 +19,6 @@ rows() -> 1000.
main(_) ->
test_util:init_code_path(),
- couch_config:start_link([]),
etap:plan(8),
case (catch test()) of
ok ->

0 comments on commit 03cc264

Please sign in to comment.