Skip to content
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

create_if_missing doesn't always take effect #4283

Open
nickva opened this issue Dec 1, 2022 · 0 comments
Open

create_if_missing doesn't always take effect #4283

nickva opened this issue Dec 1, 2022 · 0 comments

Comments

@nickva
Copy link
Contributor

nickva commented Dec 1, 2022

In the logs we see:

[warning] 2022-12-01T06:27:19.402535Z couchdb@couchdb-couchdb-1.couchdb-couchdb.drive-app.svc.cluster.local <0.1954.0> -------- mem3_sync shards/00000000-7fffffff/manifests-0038211.1669809395 couchdb@couchdb-couchdb-0.couchdb-couchdb.drive-app.svc.cluster.local {{rexi_EXIT,{{error,missing_target},[{mem3_util,get_or_create_db,2,[{file,[115,114,99,47,109,101,109,51,95,117,116,105,108,46,101,114,108]},{line,525}]},{mem3_rpc,load_checkpoint_rpc,4,[{file,[115,114,99,47,109,101,109,51,95,114,112,99,46,101,114,108]},{line,122}]},

load_rpc_checkpoint

erlang:put(io_priority, {internal_repl, DbName}),
case get_or_create_db(DbName, [?ADMIN_CTX]) of
{ok, Db} ->
TargetUUID = couch_db:get_uuid(Db),

calls get_or_create

try
Options1 = [{create_if_missing, true} | Options],
Options2 = add_db_config_options(DbName, Options1),
couch_db:open(DbName, Options2)
catch
error:database_does_not_exist ->
throw({error, missing_target})

And there oddly enough, even with a [{create_if_missing, true}] we still catch error:database_does_not_exist error.

It could be from trying to load validation functions, security, shard doc, design docs or something of that type which blows up.

Perhaps?

{'DOWN', Ref, _, _, {database_does_not_exist, _StackTrace}} ->
ok = couch_server:close_db_if_idle(Db#db.name),
erlang:error(database_does_not_exist);

But I don't see how'd call that from this context:

open_int(DbName, Options0) ->
Ctx = couch_util:get_value(user_ctx, Options0, #user_ctx{}),
case ets:lookup(couch_dbs(DbName), DbName) of
[#entry{db = Db0, lock = Lock} = Entry] when Lock =/= locked ->
update_lru(DbName, Entry#entry.db_options),
{ok, Db1} = couch_db:incref(Db0),
couch_db:set_user_ctx(Db1, Ctx);
_ ->
Options = maybe_add_sys_db_callbacks(DbName, Options0),
Timeout = couch_util:get_value(timeout, Options, infinity),
Create = couch_util:get_value(create_if_missing, Options, false),
case gen_server:call(couch_server(DbName), {open, DbName, Options}, Timeout) of
{ok, Db0} ->
{ok, Db1} = couch_db:incref(Db0),
couch_db:set_user_ctx(Db1, Ctx);
{not_found, no_db_file} when Create ->
couch_log:warning("creating missing database: ~s", [DbName]),
couch_server:create(DbName, Options);
Error ->
Error
end
end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant