Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

TOML storage plugin #3292

Merged
merged 190 commits into from
Sep 3, 2020
Merged

TOML storage plugin #3292

merged 190 commits into from
Sep 3, 2020

Conversation

bauhaus93
Copy link
Contributor

@bauhaus93 bauhaus93 commented Nov 27, 2019

Basics

These points need to be fulfilled for every PR:

  • Short descriptions of your changes are in the release notes
    (added as entry in doc/news/_preparation_next_release.md which
    contains _(my name)_)
    Please always add something to the release notes.
  • Details of what you changed are in commit messages
    (first line should have module: short statement syntax)
  • References to issues, e.g. close #X, are in the commit messages.
  • The buildservers are happy.
  • The PR is rebased with current master.

If you have any troubles fulfilling these criteria, please write
about the trouble as comment in the PR. We will help you.
But we cannot accept PRs that do not fulfill the basics.

Checklist

Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.

  • I added unit tests for my code
  • I fully described what my PR does in the documentation
    (not in the PR description)
  • I fixed all affected documentation
  • I added code comments, logging, and assertions as appropriate (see Coding Guidelines)
  • I updated all meta data (e.g. README.md of plugins and METADATA.ini)
  • I mentioned every code not directly written by me in THIRD-PARTY-LICENSES

Review

Reviewers will usually check the following:

Labels

If you are already Elektra developer:

  • Add the "work in progress" label if you do not want the PR to be reviewed yet.
  • Add the "ready to merge" label if the basics are fulfilled and you also
    say that everything is ready to be merged.

Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good: please concentrate now on rebasing, fixing build errors and docu. Other features can be added later in separated PRs (simply document limitations in the README.md)

* Can't associate those info to array top key in the way like file ending comments are preserved
* Maybe add own metakey (eg. epilogue/comment/#1)?

## TODOs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODOs are enough, no duplication of TODOs in the PR description are needed.


- Don't know where/how exactly to store trailing array comments/newline info
* Can't associate those info to array top key in the way like file ending comments are preserved
* Maybe add own metakey (eg. epilogue/comment/#1)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example for the problem in an issue? Usually we collect meta-data not belonging to a specific key in the parentKey. Maybe you can simply add comment/# there? Please do not forget to document this, so that we do not get a mess with different behaviors between plugins.

## TODOs
- Document functions
- proper sorting -> arrays
- base64 for binary k/v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be simply adding the base64 plugin in infos/needs

ELEKTRA_SET_INTERNAL_ERROR (root, msg);
break;
case ERROR_MEMORY:
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (root, msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In master this takes only one argument, please rebase.

snprintf (fraction, fracSize, "%s/%s", baseName, fracDup);
elektraFree (fracDup);
keyAddName (childDup, "..");
} while (keyRel (parent, childDup) != 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyRel was removed, use keyIs(Direct)Below.


static void testWriteReadBoolean (void)
{
// can't check without active type plugin, must check how to add plugin dependency to tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TODO

@markus2330
Copy link
Contributor

@sanssecours can you give some feedback about the parsing?

Copy link
Member

@sanssecours sanssecours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanssecours can you give some feedback about the parsing?

I added some comment. However, since this PR is still pretty much a work in progress I stopped the review process for now. I do not think it makes much sense to comment on a pull request that might be updated any time. Overall the stuff I have seen looks good though 😊.

case SCALAR_STRING_BARE:
return elektraStrDup (scalar->str);
default:
ELEKTRA_ASSERT (0, "All possible scalar enums must be handeled, but got into default branch");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ELEKTRA_ASSERT (0, "All possible scalar enums must be handeled, but got into default branch");
ELEKTRA_ASSERT (0, "All possible scalar enums must be handled, but got into default branch");

src/plugins/toml/CMakeLists.txt Outdated Show resolved Hide resolved

# TODO: Documentation

## NULL keys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to use the null plugin to store these types of key values instead.

src/plugins/toml/utility.h Outdated Show resolved Hide resolved
@@ -1295,3 +1295,14 @@ status = implemented
usedby/plugins = cache
type = boolean
description = tells the cache plugin to remove all cache files during the next `kdbGet` in a safe way.

[tomltype]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if it is directly integrated in the types of Elektra (type, enum, array) and only for the tables there is some internal/toml/type or we even add the "tables" to standardtypes. I would prefer the name "section" though (similar to array as extra meta-data).

@markus2330
Copy link
Contributor

@bauhaus93 It would be great if we can finally go towards merging this. Once the build-server says it is okay, we can merge it (at least as experimental plugin).

@@ -110,6 +112,9 @@ void destroyTree (Node * node)
{
if (node != NULL)
{
if (node->type == NT_LIST_ELEMENT) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

@mpranj
Copy link
Member

mpranj commented Mar 1, 2020

@bauhaus93 how is the toml plugin progressing? Regarding the build failures it seems that some problems should vanish if you rebase, but seems like there are some memleaks.

@markus2330
Copy link
Contributor

@bauhaus93 how is the TOML plugin doing? I closed now bugs related to INI as TOML will replace it.

@bauhaus93
Copy link
Contributor Author

@markus2330 I tried to track down the remaining memory leak(s), but I couldn't figure out where exactly they reside.

The leaks do not appear with valgrind, but only with ASAN. If I compile with -DENABLE_DEBUG=ON, to find the location where the leaked memory was allocated, the leaks disappear.

It seems to me, that the leaks happen exactly once for each test case/invocation of the parser:

  • 1 direct leak of 8 byte
  • 1 indirect leak of 64 byte,
  • 1 indirect leak of 16384 byte

Even if I let the lexer drop every read char or modify the parser to not match anything, the leaks persist. They disappear only, when not calling yyparse at all.

@markus2330
Copy link
Contributor

@sanssecours can we maybe blacklist these leaks? Did you have similar experiences?

@sanssecours
Copy link
Member

Did you have similar experiences?

As far as I remember, no. However, I did not use Flex and only used the C++ interface of Bison, which makes handling of dynamic memory much easier, since you can just use RAII.

can we maybe blacklist these leaks?

We probably can, but I think it would make sense to check if these memory problems show up with a very simple parsing example that uses Flex and Bison beforehand.

@mpranj
Copy link
Member

mpranj commented May 4, 2020

@bauhaus93 can you please rebase and push again? It's weird but it seems that we are missing debug symbols for some packages. Maybe we get more output this time.

@markus2330
Copy link
Contributor

Great to see activity here 💖

@mpranj
Copy link
Member

mpranj commented May 7, 2020

@bauhaus93 thank you for rebasing. Unfortunately it seems the issue was not fixed. From the addresses of the backtrace I would guess its inside libc. I took the liberty to add the corresponding debug symbols on top of your branch. I hope we will see what's going on now.

@mpranj
Copy link
Member

mpranj commented May 8, 2020

@bauhaus93 unfortunately we were still missing the correct debug symbols. I now added a fedora 32 asan build in #3434 with bison and flex debug symbols among others. Can you please pull and rebase again.

@mpranj
Copy link
Member

mpranj commented May 8, 2020

Thank you for rebasing again. The fedora 32 GCC asan build failed as well with apparently the same problems. Debug symbols for libc, bison, flex are definitely available. Is it possible it uses another lib? If you find the correct lib please add debug symbols to the fedora 32 docker image until we find the underlying problem. Debug symbols can be added in the section below dnf debuginfo-install -y.

The plugin now fills in missing comment metakeys (start/spaces) when writing.
Previously, if a comment was created via kdb meta-set, it would miss the
start and space metakeys, resulting in the comment written without it's
starting symbol, creating invalid TOML files.

Fixed an infinte loop, which occurec when the root key was in the
keyset.

Fixed a test case, which didn't test file ending comments properly.
Added some doc for comments.
@markus2330
Copy link
Contributor

Great to see an update here! 💖

@bauhaus93
Copy link
Contributor Author

@markus2330 I've also contacted the author of the page from which I took the UTF-8 samples and he said I may use the collection. Could there be an issue with the single texts themselves? They mostly are poems/texts 100+ years old.

I've also removed the directory value plugin from the needed plugins for now, otherwise there's a problem on writing (the tomltype metakeys get moved, resulting in an incorrect file) . I will create an issue for this tomorrow for more details.

I've got a question about the build servers: Some of them (eg the FreeBSD ones) exclude the plugin from being built, because flex is missing. Where can I add this dependency? I couldn't find related Dockerfiles in the scripts/docker folder.

@markus2330
Copy link
Contributor

I've also contacted the author of the page from which I took the UTF-8 samples and he said I may use the collection. Could there be an issue with the single texts themselves? They mostly are poems/texts 100+ years old.

Thank you for asking! ❤️

If the author we took it from said it is okay, then we assume that he/she checked. If the text is old enough, the copyright expired anyway and it is public domain (okay to use for us).

I've also removed the directory value plugin from the needed plugins for now, otherwise there's a problem on writing (the tomltype metakeys get moved, resulting in an incorrect file) . I will create an issue for this tomorrow for more details.

Thank you 👍

I've got a question about the build servers: Some of them (eg the FreeBSD ones) exclude the plugin from being built, because flex is missing. Where can I add this dependency? I couldn't find related Dockerfiles in the scripts/docker folder.

It is probably .cirrus.yml for BSD or .travis.yml (both in the root directory as these CIs do not allow the files to be located anywhere else).

@markus2330 markus2330 mentioned this pull request Sep 1, 2020
Adds the path of flex to the cmake paths, when on apple and using
homebrew.
Dockerfile now installs flex and bison.
@markus2330
Copy link
Contributor

It finally passes the CI! I think we can merge it as this PR is already very long and it will be easier if new changes come in a new PR.

Copy link
Member

@mpranj mpranj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely ready to be merged if you ask me. Minor things can always be polished/fixed, and this looks great to me as-is.

Good work @bauhaus93! Ping me if you agree with the merge and remove the draft status.

scripts/docker/cirrus/fedora/Dockerfile Outdated Show resolved Hide resolved
scripts/docker/cirrus/fedora/Dockerfile Outdated Show resolved Hide resolved
bauhaus93 and others added 3 commits September 2, 2020 19:38
Fixes ElektraInitiative#3474
The problem was, that when having comments associated to
table array declarations in a TOML file, the table element root key (eg.
tablearray/#0), which normally is not emitted in the keyset, has to be added to it.
This caused trouble in the building of the file tree for writing.
Fixed the table array index loop, to handle the element root key
appropriatly.
@bauhaus93
Copy link
Contributor Author

@mpranj Yeah, I think it's ready to merge if the tests pass now. I just fixed the issue with tablearrays @markus2330 pointed out, and if this didn't cause any new problems, it should be fine.

@bauhaus93 bauhaus93 marked this pull request as ready for review September 2, 2020 18:27
@mpranj mpranj merged commit 15d8cf8 into ElektraInitiative:master Sep 3, 2020
@mpranj
Copy link
Member

mpranj commented Sep 3, 2020

@bauhaus93 thank you so much! It's great to finally have this merged so everyone can test it.

Can you open a new PR where dump is replaced by toml as the default storage plugin, to iron out the last things?

@bauhaus93
Copy link
Contributor Author

@mpranj Yeah, nice it's finally merged. Yes, I'll create a PR for that.

@bauhaus93
Copy link
Contributor Author

How would I set toml as the default storage plugin for checking?
Should I just set the proper environment variables (KDB_DEFAULT_STORAGE, KDB_DB_FILE, KDB_DB_INIT - like it's done for the mmap target) in .cirrus.yml for all kind of targets?

@markus2330
Copy link
Contributor

In scripts/cmake/ElektraCache.cmake line 137 you can change KDB_DEFAULT_STORAGE to toml.

Comment on lines +154 to +165
const Key * findMetaKey (Key * key, const char * metakeyName)
{
keyRewindMeta (key);
for (const Key * meta = keyNextMeta (key); meta != NULL; meta = keyNextMeta (key))
{
if (elektraStrCmp (keyName (meta), metakeyName) == 0)
{
return meta;
}
}
return NULL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bauhaus93 Any particular reason, why you didn't just use keyGetMeta instead of looping through all metakeys?

Just asking, because it just caused me some confusing while rebasing #3447.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there wasn't any. I just somehow missed the existence of keyGetMeta. I'll replace all findMetaKeyoccurences with keyGetMeta, which does exactly what I want. Thanks for the hint!

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

Successfully merging this pull request may close these issues.

5 participants