Skip to content

Instantly share code, notes, and snippets.

@curtislinden
Last active August 29, 2015 14:07

Revisions

  1. curtislinden revised this gist Oct 9, 2014. 1 changed file with 29 additions and 83 deletions.
    112 changes: 29 additions & 83 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,102 +1,48 @@
    class set

    (still test-set transactional memory semantics)

    /http?store/{resource.atom}/{version}/{value}
    /http?get/{resource.atom}/{version}
    /http?next_version/{resource.atom}
    [200, 400]


    -- I went back to drawing board and asked the question - what if the resource version whas just a transparent mechanism of the resource - IE: model this as direct operations on remote resource...

    writing part of a resource

    /http?store/resource.atom/0/value
    => OK
    I get the purchase

    Increment version of field
    /http?next_version/resource.atam
    => 1
    /http?get/my/inventory
    => { inventory:[{id:1, name:'old boot'}], txn_version: 7 }
    /http?post/my/inventory
    <= { inventory:[{id:1, name:'old boot'}, {id:36,name:'new boots'}], txn_version: 7 }
    => (OK|ERROR)
    --- OK would bump txn_version such that any successive get would return txn_version:8

    I loose 1000 cents for my purchase

    /http?store/resource.name/1/ 'the coatsman'
    => OK
    /http?get/my/wallet
    => { wallet:{id:1, amount_in_cents: 9000}, txn_version:18}
    /http?post/my/wallet
    <= { wallet:{id:1, amount_in_cents: 8000}, txn_version:18}

    /http?next_version/resource.name
    => 2

    linden gets 5 cents

    /http?get/resource.name/0
    => value'
    /http?get/linden/wallet
    => { wallet:{id:1, amount_in_cents: 1000000}, txn_version:1812}
    /http?post/my/wallet
    <= { wallet:{id:1, amount_in_cents: 1000005}, txn_version:1812}

    /http?get/resource.name/1
    => 'the coastman'

    /http?store/resource.name/2/ 'the coatsman'
    => OK
    sue gets 995 Cents

    /http?next_version/resource.name
    => 3
    /http?get/sue/wallet
    => { wallet:{id:1, amount_in_cents: 1000}, txn_version:1914}
    /http?post/my/wallet
    <= { wallet:{id:1, amount_in_cents: 1995}, txn_version:1914}

    /http?get/resource.name/1/'the coatsman'
    => ERROR

    /http?get/resource.name/2/'the coatsman'
    => ERROR
    ROLLBACK ALL STATE:

    /http?get/resource.name/3/'the COASTman'
    => OK
    http?post/my/inventory/rollback/txn_version=7
    http?post/my/wallet/rollback/txn_version=18
    http?post/linden/wallet/rollback/txn_version=1812
    http?post/sue/wallet/rollback/txn_version=1914


    --- after here is just me formatting my thoughts.



    (update{ var, ver, value} ->
    error
    )

    (update{ var, 0, value} ->
    store{var,1,value}
    get{var, 1}
    )

    (store{var,ver,value} ->
    if db:get{var}.ver == ver + 1
    db:put{var.'.version',ver}
    db:put{var,ver,value}

    else
    error{var, ver}
    )

    (get{var,ver} ->
    db:get{var,ver}
    )

    (next-verion{var} ->
    db:get{var.'.version'}
    )
    (update{var,value}
    ver = (next-version var)
    store{var,ver,value}
    )


    (transaction ;
    update('adam.name','the coatsman')
    update('adam.wall.deduct',10)
    update('eve.wall.credit',7)
    update('master.wall.credit',3)

    retry 3, ->
    error

    )








  2. curtislinden created this gist Oct 8, 2014.
    102 changes: 102 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,102 @@
    class set


    /http?store/{resource.atom}/{version}/{value}
    /http?get/{resource.atom}/{version}
    /http?next_version/{resource.atom}
    [200, 400]



    writing part of a resource

    /http?store/resource.atom/0/value
    => OK

    Increment version of field
    /http?next_version/resource.atam
    => 1


    /http?store/resource.name/1/ 'the coatsman'
    => OK

    /http?next_version/resource.name
    => 2


    /http?get/resource.name/0
    => value'

    /http?get/resource.name/1
    => 'the coastman'

    /http?store/resource.name/2/ 'the coatsman'
    => OK

    /http?next_version/resource.name
    => 3

    /http?get/resource.name/1/'the coatsman'
    => ERROR

    /http?get/resource.name/2/'the coatsman'
    => ERROR

    /http?get/resource.name/3/'the COASTman'
    => OK


    --- after here is just me formatting my thoughts.



    (update{ var, ver, value} ->
    error
    )

    (update{ var, 0, value} ->
    store{var,1,value}
    get{var, 1}
    )

    (store{var,ver,value} ->
    if db:get{var}.ver == ver + 1
    db:put{var.'.version',ver}
    db:put{var,ver,value}

    else
    error{var, ver}
    )

    (get{var,ver} ->
    db:get{var,ver}
    )

    (next-verion{var} ->
    db:get{var.'.version'}
    )
    (update{var,value}
    ver = (next-version var)
    store{var,ver,value}
    )


    (transaction ;
    update('adam.name','the coatsman')
    update('adam.wall.deduct',10)
    update('eve.wall.credit',7)
    update('master.wall.credit',3)

    retry 3, ->
    error

    )