gpt4 book ai didi

Erlang:创建光盘模式

转载 作者:行者123 更新时间:2023-12-02 06:04:58 24 4
gpt4 key购买 nike

如果 Erlang 应用程序 myapp 需要 mnesia 才能运行,则应将 mnesia 包含在其应用程序资源文件中的 applications 键下,以便启动 myapp ,mnesia 会自动启动 - 默认情况下它的节点类型是 opt_disc (OTP 18)。

如果我想要一个disc节点怎么办?我知道我可以在命令行设置 -mnesia schema_location disk ,但这仅在架构已存在的情况下才有效,这意味着我应该在启动 myapp 之前执行一些初始化,是否有“OTP-ful”方式,而不从 applications 中删除 mnesia 来避免这种初始化?主要目标是将“init-then-start”变成“start”。

最佳答案

您的帖子中的内容不正确:

... mnesia should be included in its application resource file, under key applications, so that if myapp is started, mnesia would get started automatically.

您编写的值为 applications 的应用程序输入.app文件不会自动启动,但它表明它们必须在您的应用程序启动之前启动。

<小时/>

假设我们要创建 foo依赖于 mnesia 的应用程序进行一些定制。一种方法是在 foo_app.erl 中启动它文件:

-module(foo_app).
-behaviour(application).

-export([start/2, stop/1]).

start(_Type, _Args) ->
mnesia:start().
mnesia:change_table_copy_type(schema, node(), disc_copies),

%% configure mnesia
%% create your tables
%% ...

foo_sup:start_link().

stop(_State) ->
ok.

这样它就创建了disc模式,无论它是否是之前创建的。

<小时/>

注意:在此解决方案中,如果您编写 mnesia作为 applications 下的依赖项输入您的密码foo.app.src文件(在编译时会创建 foo.app ),当启动 foo 时您获得的应用程序 {error, {not_started, mnesia}} 。所以你一定不要这样做,让你的应用程序在它的foo_app:start/2中启动它。功能。

关于Erlang:创建光盘模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com