From 4b9e1dd37f6e55ba1a04fad36d8ed3c0201b1942 Mon Sep 17 00:00:00 2001
From: Fred Hebert
Date: Sat, 22 Apr 2017 17:39:08 -0400
Subject: Add persistence to history of the non-legacy shell
This patch adds a mechanism by which shell history gets stored
persistently on disk and gets loaded whenever a new shell session
begins.
The log files are added to the user's cache directory, with multiple
files in it, although the location is configurable.
All Erlang instances on a given host will share the same log file.
There are two hook points in group.erl that are used: when instantiating
the buffer, where we fetch from disk, and when adding a line to the
buffer (gets stored).
This allows all shell instances to use the same base set of lines when
loaded, but to keep their history separate after the fact. As lines are
added as you go, a new shell session (with ^G -> s -> c) will have
access to previous sessions' lines.
The implementation makes use of the disk_log library with a rotating log
in order to store data, and allow automated repairs.
By default, the feature is disabled and must be turned on through OTP
environment variable part of the kernel application. The options
include:
| Option | Accepted values | Default | Description |
| ------------------------ | ----------------- |---------- | -------------------- |
| shell_history | enabled, disabled | disabled | turn feature on/off |
| shell_history_path | any string | user cache| where to put files |
| shell_history_file_bytes | 51200..N bytes | 512kb | max data size (>50kb)|
| shell_history_drop | ["q().", ...] | [] | blacklisted lines |
A version header is added to the disk_log configuration, allowing
changes in the storage format to be enacted in the future (i.e. adding
segmentation by node name in the same file, or encoding) without
conflict.
Log rotation is used with multiple log files to ensure proper
enforcement of resizing without too much data loss. Because disk_log
does not allow to just flush bits of content on rewrite (it truncates
any full file), we instead use a wrap log and try to divide the
configured size into up to 10 log files so that every time we rotate a
log, we lose only 10% of the data. This remains true for corrupted files
that cannot fully be repaired.
This many-logs-based approach in turn forces the use of a minimal log
size for the `shell_history_file_bytes` configuration, since it has to
be divided by 10.
The shell history is not loaded for the `user` process which, despite
running the group.erl module, does not actually require history as it
mostly just forwards IO protocol information.
---
lib/kernel/doc/src/kernel_app.xml | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'lib/kernel/doc')
diff --git a/lib/kernel/doc/src/kernel_app.xml b/lib/kernel/doc/src/kernel_app.xml
index 28af155493..9fccb4c7ac 100644
--- a/lib/kernel/doc/src/kernel_app.xml
+++ b/lib/kernel/doc/src/kernel_app.xml
@@ -419,6 +419,29 @@ MaxT = TickTime + TickTime / 4
using this service.
Defaults to false.
+ shell_history = enabled | disabled
+ -
+
Specifies whether shell history should be logged to disk
+ between usages of erl.
+
+ shell_history_drop = [string()]
+ -
+
Specific log lines that should not be persisted. For
+ example ["q().", "init:stop()."] will allow to
+ ignore commands that shut the node down. Defaults to
+ [].
+
+ shell_history_file_bytes = integer()
+ -
+
how many bytes the shell should remember. By default, the
+ value is set to 512kb, and the minimal value is 50kb.
+
+ shell_history_path = string()
+ -
+
Specifies where the shell history files will be stored.
+ defaults to the user's cache directory as returned by
+ filename:basedir(user_cache, "erlang-history").
+
shutdown_func = {Mod, Func}
-
Where:
--
cgit v1.2.3