Hi Everybody,
Today I wanted to talk a bit about our technical demo. We patched a version of Samba to use our
elektra-merge script in order to handle it s configuration file
smb.conf. Using the steps from
my previous tutorial, we patched Samba to use this new technique of config merging. This patched version of Samba mounts it s configuration to system/samba/smb in the Elektra Key Database. Then, during package upgrades, it uses the new
--threeway-merge-command command with
elektra-merge as the specified command. The result is automatic handling of
smb.conf that is conffile-like (thanks ucf!) and the ability to have a powerful, automatic, three-way merge solution on package upgrades.
The main thing I would like to discuss is how this project is an improvement upon the current implementation of three-way merges in ucf. Before this project, ucf could attempt three-way merges on files it controlled using the
diff3 tool. The main limitation of tools like
diff3 are that they are line based and don t inherently understand the files they are dealing with. Elektra on the other hand allows for a powerful system of backends which use plug-ins to understand configuration files. Elektra doesn t store configuration data on a line-by-line basis, but in a more abstract way that is tailored to each configuration file using backends.
smb.conf is a great example of this because it uses the syntax of an ini file so Elektra can mount it in a way that is intuitive to an ini file. Since data is stored in a format of
key=data within ini files, Elektra stores this data in a similar way. For each key in
smb.conf store a Key in Elektra with the value of that key store in a string. Then, during a merge, we can compare Keys in each version of
smb.conf and easily see which ones changed and how they need to be merged into the result. On the other hand,
diff3 has no concept of ini files or keys, it just compares the different versions line by line which results in many more conflicts than using
elektra-merge. Moreover, a traditional weakness of
diff is moving lines or data around. While
diff3 does a very good job at handling this, it s not perfect. In Elektra, Keys are named in an intelligent way based on their backend, so for
smb.conf the line
workgroup = HOME would always be saved under system/samba/smb/workgroup. It doesn t matter if the lines are changed between versions because Elektra just has to check for the Key and its value.
My favorite example is a shortcoming in the
diff3 algorithm (at least in my opinion). If something is changed to the same value in ours and theirs, but they differ from base,
diff3 reports a conflict. On the other hand
elektra-merge can easily handle this problem. A simple example of this would be changing the
max log size value in Samba. Here is that line in each version of
smb.conf:
Base:
max log size = 1000
Ours:
max log size = 2000
Theirs:
max log size = 2000
Obviously, in the merged version, result, one would expect this line to be:
max log size = 2000
Let s check the result from
elektra-merge:
max log size = 2000
Great! How about
diff3:
<<<<<<< smb.conf.base
max log size = 1000
=======
max log size = 2000
>>>>>>> smb.conf.theirs
Whoops! As I mentioned the
diff3 algorithm can t handle this type of change, it just results in a conflict. Note that
smb.conf.base is just representative of the file used as base and that
smb.conf.theirs is representative of the file used as theirs. The file names were changed for the sake of clarity.
There are many other examples of the benefits to storing configuration data in a database of Keys that can better conform to actual data as opposed to storing configuration parameters in files where they can only be compared on a line to line basis. With the help of storage plug-ins, Elektra can understand the configurations stored in it s Key Database. Since we store the data in a way that makes sense for configuration data, we can easily merge actual configuration data as opposed to just lines in a file. A good example of this is in-line comments. Many of our storage plug-ins understand the difference between comments and actual configuration data. So if a configuration file has an inline comment like so:
max log size = 10000 ; Controls the size of the log file (in KiB)
we can compare the actual Keys, value pairs between versions
max log size = 10000 and deal with the comments separately.
As a result, if we have a base:
max log size = 1000 ; Size in KiB
Ours:
max log size = 10000 ; Size in KiB
Theirs:
max log size = 1000 ; Controls the size of the log file (in KiB)
The result using
elektra-merge would be:
max log size = 10000 ; Controls the size of the log file (in KiB)
Obviously, this line would cause a conflict on any line-based merge algorithm such as diff3 or git. It is worth noting that the ability of
elektra-merge is directly related to the quality of the storage plug-ins that Elektra relies on.
elektra-merge only looks at the name, value, and any metadata affiliated with each key. As a result, using the
line plug-in would result in a merge only as powerful as any other line-based merge. Yet by using the
ini plug-in on an ini file we get a much more advanced merge like the one described above.
As you can tell, this new method offers clear advantages to the traditional method of using diff3 to handle configuration merges. Also, I hope this demo shows how easy it is to implement these great features into your Debian packages. The community can only benefit if maintainers take advantage of these great features. I am glad to say that my Google Summer of Code Project has been a success, even if we had to do a little change of plans. The ucf integration ended up working great and is really easy for maintainers to implement. Hope you enjoyed this demo and better understand the power of using Elektra.
Sincerely,
Ian S. Donnelly