Переглянути джерело

chore: dont allocate resource for simple connectiors

JianBo He 2 роки тому
батько
коміт
dbc0cdce67

+ 1 - 7
apps/emqx_bridge_cassandra/src/emqx_bridge_cassandra_connector.erl

@@ -132,7 +132,6 @@ on_start(
                 []
         end,
     State = parse_prepare_cql(Config),
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case emqx_resource_pool:start(InstId, ?MODULE, Options ++ SslOpts) of
         ok ->
             {ok, init_prepare(State#{pool_name => InstId, prepare_statement => #{}})};
@@ -149,12 +148,7 @@ on_stop(InstId, _State) ->
         msg => "stopping_cassandra_connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstId).
 
 -type request() ::
     % emqx_bridge.erl

+ 1 - 7
apps/emqx_bridge_clickhouse/src/emqx_bridge_clickhouse_connector.erl

@@ -158,7 +158,6 @@ on_start(
             templates => Templates,
             connect_timeout => ConnectTimeout
         },
-        ok = emqx_resource:allocate_resource(InstanceID, pool_name, InstanceID),
         case emqx_resource_pool:start(InstanceID, ?MODULE, Options) of
             ok ->
                 {ok, State};
@@ -280,12 +279,7 @@ on_stop(InstanceID, _State) ->
         msg => "stopping clickouse connector",
         connector => InstanceID
     }),
-    case emqx_resource:get_allocated_resources(InstanceID) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstanceID).
 
 %% -------------------------------------------------------------------
 %% on_get_status emqx_resouce callback and related functions

+ 1 - 7
apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl

@@ -104,7 +104,6 @@ on_start(
         table => Table,
         templates => Templates
     },
-    ok = emqx_resource:allocate_resource(InstanceId, pool_name, InstanceId),
     case emqx_resource_pool:start(InstanceId, ?MODULE, Options) of
         ok ->
             {ok, State};
@@ -117,12 +116,7 @@ on_stop(InstanceId, _State) ->
         msg => "stopping_dynamo_connector",
         connector => InstanceId
     }),
-    case emqx_resource:get_allocated_resources(InstanceId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstanceId).
 
 on_query(InstanceId, Query, State) ->
     do_query(InstanceId, Query, State).

+ 1 - 7
apps/emqx_bridge_opents/src/emqx_bridge_opents_connector.erl

@@ -78,7 +78,6 @@ on_start(
     State = #{pool_name => InstanceId, server => Server},
     case opentsdb_connectivity(Server) of
         ok ->
-            ok = emqx_resource:allocate_resource(InstanceId, pool_name, InstanceId),
             case emqx_resource_pool:start(InstanceId, ?MODULE, Options) of
                 ok ->
                     {ok, State};
@@ -95,12 +94,7 @@ on_stop(InstanceId, _State) ->
         msg => "stopping_opents_connector",
         connector => InstanceId
     }),
-    case emqx_resource:get_allocated_resources(InstanceId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstanceId).
 
 on_query(InstanceId, Request, State) ->
     on_batch_query(InstanceId, [Request], State).

+ 1 - 7
apps/emqx_bridge_rabbitmq/src/emqx_bridge_rabbitmq_connector.erl

@@ -242,7 +242,6 @@ on_start(
             %% Already initialized
             ok
     end,
-    ok = emqx_resource:allocate_resource(InstanceID, pool_name, InstanceID),
     case emqx_resource_pool:start(InstanceID, ?MODULE, Options) of
         ok ->
             {ok, State};
@@ -268,12 +267,7 @@ on_stop(
         msg => "stopping RabbitMQ connector",
         connector => ResourceID
     }),
-    case emqx_resource:get_allocated_resources(ResourceID) of
-        #{pool_name := PoolName} ->
-            stop_clients_and_pool(PoolName);
-        _ ->
-            ok
-    end.
+    stop_clients_and_pool(ResourceID).
 
 stop_clients_and_pool(PoolName) ->
     Workers = [Worker || {_WorkerName, Worker} <- ecpool:workers(PoolName)],

+ 1 - 7
apps/emqx_bridge_sqlserver/src/emqx_bridge_sqlserver_connector.erl

@@ -215,7 +215,6 @@ on_start(
         sql_templates => parse_sql_template(Config),
         resource_opts => ResourceOpts
     },
-    ok = emqx_resource:allocate_resource(ResourceId, pool_name, PoolName),
     case emqx_resource_pool:start(PoolName, ?MODULE, Options) of
         ok ->
             {ok, State};
@@ -232,12 +231,7 @@ on_stop(ResourceId, _State) ->
         msg => "stopping_sqlserver_connector",
         connector => ResourceId
     }),
-    case emqx_resource:get_allocated_resources(ResourceId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(ResourceId).
 
 -spec on_query(
     resource_id(),

+ 1 - 7
apps/emqx_bridge_tdengine/src/emqx_bridge_tdengine_connector.erl

@@ -108,7 +108,6 @@ on_start(
 
     Prepares = parse_prepare_sql(Config),
     State = Prepares#{pool_name => InstanceId, query_opts => query_opts(Config)},
-    ok = emqx_resource:allocate_resource(InstanceId, pool_name, InstanceId),
     case emqx_resource_pool:start(InstanceId, ?MODULE, Options) of
         ok ->
             {ok, State};
@@ -121,12 +120,7 @@ on_stop(InstanceId, _State) ->
         msg => "stopping_tdengine_connector",
         connector => InstanceId
     }),
-    case emqx_resource:get_allocated_resources(InstanceId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstanceId).
 
 on_query(InstanceId, {query, SQL}, State) ->
     do_query(InstanceId, SQL, State);

+ 1 - 7
apps/emqx_connector/src/emqx_connector_http.erl

@@ -219,7 +219,6 @@ on_start(
         base_path => BasePath,
         request => preprocess_request(maps:get(request, Config, undefined))
     },
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case ehttpc_sup:start_pool(InstId, PoolOpts) of
         {ok, _} -> {ok, State};
         {error, {already_started, _}} -> {ok, State};
@@ -231,12 +230,7 @@ on_stop(InstId, _State) ->
         msg => "stopping_http_connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            ehttpc_sup:stop_pool(PoolName);
-        _ ->
-            ok
-    end.
+    ehttpc_sup:stop_pool(InstId).
 
 on_query(InstId, {send_message, Msg}, State) ->
     case maps:get(request, State, undefined) of

+ 1 - 7
apps/emqx_connector/src/emqx_connector_ldap.erl

@@ -97,7 +97,6 @@ on_start(
         {pool_size, PoolSize},
         {auto_reconnect, ?AUTO_RECONNECT_INTERVAL}
     ],
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case emqx_resource_pool:start(InstId, ?MODULE, Opts ++ SslOpts) of
         ok -> {ok, #{pool_name => InstId}};
         {error, Reason} -> {error, Reason}
@@ -108,12 +107,7 @@ on_stop(InstId, _State) ->
         msg => "stopping_ldap_connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstId).
 
 on_query(InstId, {search, Base, Filter, Attributes}, #{pool_name := PoolName} = State) ->
     Request = {Base, Filter, Attributes},

+ 1 - 7
apps/emqx_connector/src/emqx_connector_mongo.erl

@@ -183,7 +183,6 @@ on_start(
         {worker_options, init_worker_options(maps:to_list(NConfig), SslOpts)}
     ],
     Collection = maps:get(collection, Config, <<"mqtt">>),
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case emqx_resource_pool:start(InstId, ?MODULE, Opts) of
         ok ->
             {ok, #{
@@ -200,12 +199,7 @@ on_stop(InstId, _State) ->
         msg => "stopping_mongodb_connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstId).
 
 on_query(
     InstId,

+ 1 - 7
apps/emqx_connector/src/emqx_connector_mysql.erl

@@ -124,7 +124,6 @@ on_start(
             ]
         ),
     State = parse_prepare_sql(Config),
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case emqx_resource_pool:start(InstId, ?MODULE, Options ++ SslOpts) of
         ok ->
             {ok, init_prepare(State#{pool_name => InstId})};
@@ -146,12 +145,7 @@ on_stop(InstId, _State) ->
         msg => "stopping_mysql_connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstId).
 
 on_query(InstId, {TypeOrKey, SQLOrKey}, State) ->
     on_query(InstId, {TypeOrKey, SQLOrKey, [], default_timeout}, State);

+ 1 - 7
apps/emqx_connector/src/emqx_connector_pgsql.erl

@@ -121,7 +121,6 @@ on_start(
         {pool_size, PoolSize}
     ],
     State = parse_prepare_sql(Config),
-    ok = emqx_resource:allocate_resource(InstId, pool_name, InstId),
     case emqx_resource_pool:start(InstId, ?MODULE, Options ++ SslOpts) of
         ok ->
             {ok, init_prepare(State#{pool_name => InstId, prepare_statement => #{}})};
@@ -138,12 +137,7 @@ on_stop(InstId, _State) ->
         msg => "stopping postgresql connector",
         connector => InstId
     }),
-    case emqx_resource:get_allocated_resources(InstId) of
-        #{pool_name := PoolName} ->
-            emqx_resource_pool:stop(PoolName);
-        _ ->
-            ok
-    end.
+    emqx_resource_pool:stop(InstId).
 
 on_query(InstId, {TypeOrKey, NameOrSQL}, State) ->
     on_query(InstId, {TypeOrKey, NameOrSQL, []}, State);

changes/ce/feat-10895.en.md → changes/ee/feat-10895.en.md