On Tue, Oct 21, 2014 at 8:27 PM, 'Terry Brown' via leo-editor
> I don't understand the above - I don't see how there's more
> than one invocation involved. I certainly thought of the possibility
> of Leo needing to allocate gnxs before all the @auto nodes were loaded,
> if I didn't mention it, and figured that something like the solution
> you mention would work - so I'm not seeing why it doesn't?
Good question. I'll discuss it below. To avoid tl;dr (too long;
didn't read) I'll state my conclusions first...
===== Executive summary
1. The post-pass must go.
2. Aside from Bob's automated test cases, the probability of real
problems arising from clashing gnx's is negligible.
3. A new unique_timestamps plugin will repackage Bob's timestamp code.
Bob will have to enable this plugin when running his unit tests.
4. Your comments are essential. I won't do anything until I've heard from you.
===== The answer to Terry's question
Delayed allocation of gnx's would work as I described, but it's only a
partial fix.
The fundamental problem is that two different invocations of Leo can
clash, which can lead to two *different* vnodes (different purposes)
getting assigned the same gnx. Like this:
Invocation 1 opens two files, f1.leo and f2.leo and allocates v1 in
f1.leo and v2 in f2.leo.
Invocation 2 clashes with invocation 1: the timestamps of both
invocations are the same. Invocation 2 opens f1.leo only and
allocates v3 with a gnx that clashes with v2 (because the scan doesn't
include f2.leo).
The clash between v3 in f1.leo and v2 in f2.leo could cause problems
if a later invocation opens both f1.leo and f2.leo. Pasting v2 with
paste-retaining-clones from f2 to f1 will cause data loss. Leo will
consider that v2 and v3 are clones, so the contents of one of them
will be lost.
Yes, this will happen rarely, but it was supposed *never* to happen.
The post script discusses two solutions. But first, let's step back
and consider the big picture...
===== How serious are gnx clashes?
Remember that this whole issue arose because Bob *automatically*
invoked Leo twice in such a way that two distinct invocation of Leo
started with the same timestamp. This happens about once every four
invocations, in my tests.
Without the automatic invocation of Leo, problems can occur only in
the following *extremely rare* scenario:
- Two different people share the same user id. This will happen
fairly often, say with probability P1.
- These two people each create separately a node that just happens to
have the same timestamp. This will happen rarely, but it *can*
happen: probability P2.
- These two people share data by sharing a .leo file that contains one
of the nodes: probability P3.
- The recipient does a past-retaining-clones a part of the shared .leo
file that contains the clashing vnodes. This is extremely unlikely,
but it *could* happen: probability P4.
The probability of data loss is P1*P2*P3*P4. The product of small
probabilities is extremely small. Imo, we can ignore this scenario
for now.
===== Summary
Aside from Bob's automated collision process (TM), the probability of
clashing gnx's is negligible. There is no urgent need to use uuids
now.
We must solve Bob's problem, but the present "solution" is not good.
The post-pass is a ticking time bomb because it's implications are so
subtle. I'm confused, and every other Leo developer will be too.
Hacking on ni.getNewIndex would be a band-aid. Imo, the post pass
must go.
If comments are favorable, I'll write a unique_timestamps plugin. This
plugin will repackage Bob's original timestamp adjustment. See the
post script for details.
Yes, Bob will have to enable this plugin when running his automated unit tests.
Your comments please, Amigos. I won't do anything until I've heard from you.
Edward
P.S. This post script discusses two solutions to the present gnx difficulties.
===== Solution 1. Use uuid's for all new gnxs.
This may not be as odious as I first thought. At present, node
sentinels have the form::
#@+node:<gnx>:<headline>
Instead, they could have the form::
#@+node::<headline>:<gnx>
The second form is better because the headline is first, which is what
humans want to see. The opening :: distinguishes the second form from
the first. The trailing gnx will be scanned *backward*, starting from
the end of the line. This ensures that headlines may contain any text
whatever.
Lengthening sentinel comments is not pleasant, but using uuid's in
sentinels appears to be inevitable at some point.
===== Solution 2: Create a plugin that ensures unique timestamps.
This plugin would repackage Bob's timestamp hack. Unless I am
severely mistaken, ensuring that all invocations of Leo are based on
separate timestamps will solve all the present gnx problems.
I like this solution:
1. It requires no nerdy command-line option.
2. Only those who have Bob's particular use-case need activate the plugin.
3. It simplifies Leo's code and *much more importantly* simplifies the
underlying assumptions behind Leo's code.
Otoh, this solution resuscitates but #35
Happily, I still have the tests lying around. I spent enough time with
those tests that I should be able to tell whether they fail or not.
It's a statistical thing whether the two invocations actually share
the same timestamp: one must run the test until they do.
EKR