Replies: 3 comments 7 replies
This comment has been hidden.
This comment has been hidden.
-
Regarding question 1: In short, I would definitely care about comments I have in my config files. I would assume other users will want comments to work as well (and not be discarded). Many config files consist of more comments than actual data (e.g. apache config). I think discarding the comments would be the worst solution of all. If I understand Problem 2 correctly, the main problem is where to store this data. If I would have to make a solution right now, I would store the comments as first class citizens (the same way as names and values) in the Key struct. One remaining problem with this approach would be how to handle comments without any key (e.g. a config file containing a single line which is a comment). A very quick solution could be a key flag to indicate that it is only a comment. The |
Beta Was this translation helpful? Give feedback.
-
Thank you both for thinking hard about these problems. I did not have time to read everything, but here the answers to the questions. Preserving the format in general is a complex topic (if you want a data structure useful to the user, i.e., not designed to preserve format). See also #3297 for a very similar problem in arrays. We should not aim for perfection but for good usability.
We should preserve them but not always exactly at the place where they were written.
spec:/ is a totally separate thing, that is why I constantly talk about a "meta" option to toml/ni or to use "ni" as default for spec:/. spec:/ does not have values but only metadata, so formats for spec:/ can be simplified (not storing values but only metadata in sections) and also formats of other namespaces can be simplified (not storing arbitrary metadata)
This is a huge topic on its own, see #3563. We would probably need a decision meeting for it. For now I would leave it as-is but we should decide it before we rewrite the spec plugin.
I think it is a good idea as it makes the most common form of plugins (the checker plugins) much easier to write.
"cascading mounts" and spec-mount already make sure that the correct plugins are present for all namespaces. In #3693 we can rethink what a "cascading mount" actually means.
We should say much more clearly that Elektra requires
It is something we already had: it makes the _Key too fat. We should slim _Key down and not increase the size further. |
Beta Was this translation helpful? Give feedback.
-
I looked into handling comments for the
toml
plugin and found that basically the current approach doesn't work with storing metadata. This lead me to the conclusion that we may need to rethink metadata in general.Before you comment: The first part is only there to understand my conclusion. Please ignore any errors, misunderstandings, etc. and refrain from commenting on it. I added my main questions at the end. Just comment on those, to avoid unnecessary discussion that goes in circles. Additionally, question 1 is a lot more immediately relevant than the rest, so maybe answer that one first.
Introduction
Currently we have this specification for storing comments on Keys (via
meta:/
keys):libelektra/doc/METADATA.ini
Lines 98 to 169 in f655398
I do have some notes on this, but those are irrelevant, because this system is still flawed.
Problem 1: Not all formats are line-based
The first big flaw is that it still assumes file-based storage and a line-based format. Why is this a problem?
Take JSON5 a superset of JSON that supports comments. So this would be a valid JSON5 file:
I don't see how that could be mapped cleanly onto the current
comment/#
system. Sure both comments belong tobar
, but also both are inline (in fact without comments the whole file would be one line). The first comment also has preceding and following spaces.All this could be solved, by saying:
comment/#
is for storing comments.comment/#/text
contains the text of comment number N.comment/#/_
looks like what "comment number N" means, is up to the storage plugin.comment/#/text
values in array order and print them separated by\n
you must always get the same result. Additional formatting stored in other metakeys (e.g. spaces before after comment, etc.) may be lost.However, there is a bigger problem.
Problem 2: Comments on metakeys
Currently, there is no way to store comments that associated not with a key, but with a single metakey. This is not a real problem for Elektra, since comments on metakeys don't really make sense. What exactly would be the point of putting a comment on e.g. a
type
metakey?However, unless a storage format was specifically designed for Elektra (e.g.
dump
,quickdump
, but alsoni
), there probably won't be a syntactical difference between a key and a metakey. For example take TOML (syntax from #3911):The first comment is totally fine and will be stored somewhere in the
comment/#
metadata of the keyfoo/bar
. The second comment looks, from a TOML standpoint and to almost any user, syntactically identical to the first one. However, where would that be stored?Is see only three options here:
comment:/
namespacecomment:/
that is also used in metadata KeySets.comment:/
is for the key itself, and e.g.comment:/type
would be formeta:/type
.comment:/
keys are always binary an contain struct values e.g.info
into a wrong type.Conclusion
All of this leads my to the conclusion: Maybe we need to rethink metakeys themselves.
Currently metakeys serve a few purposes:
When attached to
spec:/
keys, they define a specification.This data must obviously stored. But
spec:/
keys should not have a value, so this is much easier to deal with than real metadata. In a sense, this isn't even metadata, since there is no data. You could say that everyspec:/
key only contains a keyset (via the meta-keyset) and that this keyset is the actual data.Internal metadata only used at runtime, e.g.
error
,warnings/#
,origvalue
,internal/*/*
In contrast, this metadata should never be stored. Additionally, users should never interact with it. Essentially, here metadata is more or less abused only to keep some information attached to a
Key *
.Metadata about the underlying storage format, e.g.
order
,tomltype
This data is not internal in the same sense as above. While it should never be stored explicitly, it influences the underlying storage (file or otherwise) in a user-visible way. Therefore, some users may want to interact with it, e.g. to change the order of a key or to convert a TOML inline table to a normal one.
Metadata about the configuration data itself, e.g.
array
,type
(in a more limited fashion)This is actually the only case of true metadata we have, in the sense that this is additional data that must be kept attached to and stored with the actual data. This data must also not necessarily be stored explicitly, but it must be preserved somehow. For example, we don't need to store
type
explicitly, if the storage format has native type support.One important note here is, that if a specification is present, some of this data may be reconstructed from it. But this is not always the case. For example, theoretically a spec could mandate a
type = long
key, but atype = short
key is provided. A more real world (and implemented) example isarray
. You need to know the intended size of an array, so that default values can be generated byspec
.array
is actually the only metakey that truly falls into this category at the moment. Replacingtype=long
from a spec withtype=short
could be supported, but isn't really right now. Of course, if no specification is used, everything falls into this category, but for this I assume that everybody uses a specification.Questions
My questions now are:
spec:/
is a completely separate thing and maybe rethink how deal with it? I more and more think that specification as metakeys was a big mistake.internal:/
spec
plugin really a good idea? Should we copy specification from thespec:/
namespace onto other keys? Wouldn't it better, if plugins iterated thespec:/
instead?check/range=7-10
inspec:/foo/bar
, but only mount therange
plugin onsystem:/foo
, butuser:/foo
? Shouldn't we enforce mounted plugins to be the same for one mountpoint path (key w/o namespace) regardless of namespace?spec
really (try to) generate all keys in advance? I know this is an attempt to makeksLookup
perform close to O(1), but generating all keys in advance barely works (for#
) or doesn't work at all (_
) and uses very complicated, kinda slow code. Wouldn't it be better to letksLookup
generate default keys from#
and_
specs? Even if this means recursively breaking apart the lookup key to find potential#
and_
spec keys.In know these are all very big questions and most of them put the very basis of Elektra into question. However, I'm beginning to feel that without addressing these issues, we may reach 1.0 only to realise that 1.0 doesn't actually work well and we need to start working on 2.0 immediately.
Nonetheless, the only question that actually needs an answer right now is question 1 (concerning metakey comments).
Beta Was this translation helpful? Give feedback.
All reactions