nickva opened a new pull request, #5133:
URL: https://github.com/apache/couchdb/pull/5133
As we've seen in issue #5130, and demonstrated experimentally on a test
node, a node in distributed mode can return `nonode@nohost` for the `node()`
call. Our code, especially in `upgrade_epochs/1`, expect that `node()` will
always return the configured distributed node name when in distributed mode.
This commit implements the `node_name/0` function that works like `node()`
but will always return the distributed node from when the system first starts
up. The node value is saved in a persistent term and then it can accessed
throughout the life of the node, even during the shutdown phase, when the dist
controller may have exited already.
Persistent term usage should avoid this being a bottleneck. It turns out
it's even a bit faster than calling the native `node()` function:
```
> timer:tc(fun() -> [config:node_name() || _ <- lists:seq(1, 1000000)], ok
end).
{628895,ok}
% dummy tc call to check for overhead
> timer:tc(fun() -> [ok || _ <- lists:seq(1, 1000000)], ok end).
{325742,ok}
% overhead over a dummy tc call
> 628895-325742.
303153
% 0.3 microseconds
> 303153/1000000.
0.303153
% compare to `node()`
> timer:tc(fun() -> [node() || _ <- lists:seq(1, 1000000)], ok end).
{480578,ok}
```
In addition to a persistent node name, add a few a assertions in the
earliest startup code in config:init/1 to check that the configured node name
and the result of `node()` match; for instance, stop the node if user specified
a name but we still ended up standalone mode.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]