-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep track of connections, introduce per-vhost limits #891
Merged
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
9adb6cd
Keep track of connections, introduce per-vhost limits
michaelklishin d4aaae9
Use ?PER_VHOST_COUNTER_TABLE here
michaelklishin 995c430
Correct a type spec
michaelklishin 747b41a
Switch to a single table per node for connection tracking
michaelklishin ed4fe7e
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin 295c7b2
Remove a duplicate comment
michaelklishin 87c2d6f
Inline
michaelklishin 95b6e8f
Remove a debug message
michaelklishin da08e95
Drop the _test prefixes, remove some dead code
michaelklishin 0457b58
Simplify
michaelklishin a9fbb98
Use rabbit_misc:pget/2 here
michaelklishin e447910
Refactor
michaelklishin 363d0a1
One more test case
michaelklishin 0199aa9
Use negative values to disable per-vhost limits, 0 to refuse all conn…
michaelklishin d36d1d4
More test cases
michaelklishin cb4835b
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin f012c49
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin efc0f99
We can use record_info/2 here; log errors in table creation
michaelklishin ede361d
Emit a node_deleted event when a node is removed from the cluster
michaelklishin 0363bac
Delete connection tracking tables for nodes removed from the cluster
michaelklishin 93682bd
Rename function
michaelklishin e25e906
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin 9febe15
Combine map/2 and foldl/3
michaelklishin 0db9986
Reformat with emacs
michaelklishin 769472f
Use lists:foldl/3 only
michaelklishin bbe671d
record_info/2 is appropriate here
michaelklishin dad8511
Squash warnings
michaelklishin 754feab
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin 922a43c
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin 2994c42
Merge branch 'master' into rabbitmq-server-500-squashed
michaelklishin 2527a85
rabbit_mnesia:forget_cluster_node/2: Skip event if node if offline
dumbbell f43f6cd
rabbit_mnesia_rename: Backup local tables only
dumbbell d431320
per_vhost_connection_limit_SUITE: Sleep 500ms after connection open/c…
dumbbell 99f7562
cluster_rename_SUITE: Lower the testsuite timeout
dumbbell a5cdde1
Remove dead code left from a previous incarnation of the patch
dumbbell a660b70
per_vhost_connection_limit_SUITE: Add a test around cluster rename
dumbbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
%% The contents of this file are subject to the Mozilla Public License | ||
%% Version 1.1 (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.mozilla.org/MPL/ | ||
%% | ||
%% Software distributed under the License is distributed on an "AS IS" | ||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
%% the License for the specific language governing rights and | ||
%% limitations under the License. | ||
%% | ||
%% The Original Code is RabbitMQ. | ||
%% | ||
%% The Initial Developer of the Original Code is GoPivotal, Inc. | ||
%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
%% | ||
|
||
-module(rabbit_connection_tracker). | ||
|
||
%% Abstracts away how tracked connection records are stored | ||
%% and queried. | ||
%% | ||
%% See also: | ||
%% | ||
%% * rabbit_connection_tracking_handler | ||
%% * rabbit_reader | ||
%% * rabbit_event | ||
|
||
-behaviour(gen_server2). | ||
|
||
%% API | ||
-export([boot/0, start_link/0, reregister/1]). | ||
|
||
%% gen_fsm callbacks | ||
-export([init/1, | ||
handle_call/3, | ||
handle_cast/2, | ||
handle_info/2, | ||
terminate/2, | ||
code_change/3]). | ||
|
||
-define(SERVER, ?MODULE). | ||
|
||
|
||
%%%=================================================================== | ||
%%% API | ||
%%%=================================================================== | ||
|
||
boot() -> | ||
{ok, _} = start_link(), | ||
ok. | ||
|
||
start_link() -> | ||
gen_server2:start_link({local, ?SERVER}, ?MODULE, [], []). | ||
|
||
reregister(Node) -> | ||
rabbit_log:info("Telling node ~p to re-register tracked connections", [Node]), | ||
gen_server2:cast({?SERVER, Node}, reregister). | ||
|
||
%%%=================================================================== | ||
%%% gen_server callbacks | ||
%%%=================================================================== | ||
|
||
init([]) -> | ||
{ok, {}}. | ||
|
||
handle_call(_Req, _From, State) -> | ||
{noreply, State}. | ||
|
||
handle_cast(reregister, State) -> | ||
Cs = rabbit_networking:connections_local(), | ||
rabbit_log:info("Connection tracker: asked to re-register ~p client connections", [length(Cs)]), | ||
case Cs of | ||
[] -> ok; | ||
Cs -> | ||
[reregister_connection(C) || C <- Cs], | ||
ok | ||
end, | ||
rabbit_log:info("Done re-registering client connections"), | ||
{noreply, State}. | ||
|
||
handle_info(_Req, State) -> | ||
{noreply, State}. | ||
|
||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
code_change(_OldVsn, State, _Extra) -> | ||
{ok, State}. | ||
|
||
%%%=================================================================== | ||
%%% Internal functions | ||
%%%=================================================================== | ||
|
||
reregister_connection(Conn) -> | ||
try | ||
Conn ! reregister | ||
catch _:Error -> | ||
rabbit_log:error("Failed to re-register connection ~p after a network split: ~p", [Conn, Error]) | ||
end. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelklishin message sending to a Pid never fails, so that error will never occur. You're probably better off validating with
is_process_alive(Conn)
instead, prior to attempting to reregister, if you want to log any error here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.