diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-07-10 14:56:59 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-07-19 11:11:42 -0500 |
commit | 3181e058307893e86afedb3f817317e7b2f0bf1b (patch) | |
tree | 99c5a5caa0b3d82be5ebb76122ba7d77b0ad8590 | |
parent | eefdc0dacab28c375d7e5e10080cd24315963da0 (diff) | |
download | couchdb-3181e058307893e86afedb3f817317e7b2f0bf1b.tar.gz |
FIXUP: Don't send possibly large messages
User design documents can be fairly large which could end up crushing
the ddoc_cache_lru mailbox. This just converts the possibly large values
to binaries before sending them.
-rw-r--r-- | src/ddoc_cache/src/ddoc_cache_entry.erl | 5 | ||||
-rw-r--r-- | src/ddoc_cache/src/ddoc_cache_lru.erl | 3 | ||||
-rw-r--r-- | src/ddoc_cache/src/ddoc_cache_value.erl | 27 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl index 38bc9612a..f40ac40e8 100644 --- a/src/ddoc_cache/src/ddoc_cache_entry.erl +++ b/src/ddoc_cache/src/ddoc_cache_entry.erl @@ -116,7 +116,8 @@ init({Key, undefined}) -> ?EVENT(started, Key), gen_server:enter_loop(?MODULE, [], St); -init({Key, Default}) -> +init({Key, Wrapped}) -> + Default = ddoc_cache_value:unwrap(Wrapped), Updates = [ {#entry.val, Default}, {#entry.pid, self()} @@ -133,7 +134,7 @@ init({Key, Default}) -> accessed = 1 }, ?EVENT(default_started, Key), - gen_server:enter_loop(?MODULE, [], St). + gen_server:enter_loop(?MODULE, [], St, hibernate). terminate(_Reason, St) -> diff --git a/src/ddoc_cache/src/ddoc_cache_lru.erl b/src/ddoc_cache/src/ddoc_cache_lru.erl index 49aa62d53..12f5d10e8 100644 --- a/src/ddoc_cache/src/ddoc_cache_lru.erl +++ b/src/ddoc_cache/src/ddoc_cache_lru.erl @@ -72,7 +72,8 @@ open(Key) -> insert(Key, Value) -> case ets:lookup(?CACHE, Key) of [] -> - gen_server:call(?MODULE, {start, Key, Value}, infinity); + Wrapped = ddoc_cache_value:wrap(Value), + gen_server:call(?MODULE, {start, Key, Wrapped}, infinity); [#entry{}] -> ok end. diff --git a/src/ddoc_cache/src/ddoc_cache_value.erl b/src/ddoc_cache/src/ddoc_cache_value.erl new file mode 100644 index 000000000..21a5bb549 --- /dev/null +++ b/src/ddoc_cache/src/ddoc_cache_value.erl @@ -0,0 +1,27 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(ddoc_cache_value). + + +-export([ + wrap/1, + unwrap/1 +]). + + +wrap(Value) -> + {?MODULE, term_to_binary(Value)}. + + +unwrap({?MODULE, Bin}) when is_binary(Bin) -> + binary_to_term(Bin). |