
Log-structured storage - ingve
https://jvns.ca/blog/2017/06/11/log-structured-storage/
======
glandium

      > grep "^$1," database | sed -e "s/^$1,//" | tail -n 1
    

FWIW.

Shell pipelines are very useful, but sometimes, you don't need them.

Case in point: \- sed can do the matching:

    
    
      sed -n -e "/^$1,/s/^$1,//p" | tail -1
    

\- sed can just take the last match:

    
    
      sed -n -e "/^$1,/h;\${g;s/^$1,//p}"
    

\- sed can be cryptic, so you might prefer awk:

    
    
      awk -F, '$1 == "'"$1"'" { val=$2 } END { print val }'
    

although the fact that it's in a shell function makes the "'"$1"'" thing kind
of confusing. It would be less confusing if using a named environment
variable...

maybe less bad with explicit escapes...

    
    
      awk -F, "\$1 == \"$1\" { val=\$2 } END { print val }"

------
jorams
> I seriously thought atomicity in databases was the same idea as atomicity in
> concurrent programs like an “atomic instruction” and it’s a TOTALLY
> DIFFERENT THING

I don't see how it's a totally different thing.

When a change to a database is atomic, it can never be observed to be in
progress by others. Either it has occurred or it hasn't. To the observer this
means it appears to happen instantly.

When an instruction in a concurrent program is atomic, it can never be
observed to be in progress by others. Either it has occurred or it hasn't. To
the observer this means it appears to happen instantly.

Is either of these descriptions wrong?

~~~
twic
Yes, your description of database atomicity is wrong (i think!).

In ACID, atomicity doesn't mean that a set of writes in one transaction become
visible to other transactions all at the same time; it means that after the
writing transaction is finished, they are either all applied, or none are
applied.

In practice, that means if you successfully commit, all your data is saved,
and if you successfully roll back, none of your data is saved. EDIT: I'm not
sure what the guarantees are if either fail.

The property that the writes don't become visible to other transactions is
isolation. This is where the infamous transaction isolation levels come in;
with a weak level of isolation, writes in one transaction may be visible to
others before they are committed.

~~~
jorams
Alright, so the non-database definition of atomicity combines the Atomicity
and Isolation of ACID. Thanks for helping clear that up.

I don't think that makes it a "TOTALLY DIFFERENT THING", but it's definitely
important to understand the difference.

