re: Changing State / State Migrations

0 views
Skip to first unread message

tphyahoo

unread,
Nov 29, 2008, 1:12:58 PM11/29/08
to HAppS, ee...@lempsink.nl
My comments below reference thread

http://groups.google.com/group/HAppS/browse_thread/thread/c23101b258d337d0/261e3a871853b0e8?lnk=gst&q=migration+example#261e3a871853b0e8

which is closed to reply.

In the last message in this thread, eelco lempsink presented some code
for doing happs migrations. I found that this code doesn't behave in a
reasonable way when I tried to do state modifications using
State2.hs.

After staring at this from some time, I concluded that this is because
the state type in State2 doesn't make sense. Map key should be page,
not page content. I fixed accoridngly and reattached the tar.gz.

To demonstrate the fix (and generally improve the demo) I modified the
code so that the main function in MigrateToState2.hs does an insert as
well as a query. Both MigrateToState2 and CreateState1 now insert
three records rather than just 1. (see attached.) Also I use
System.Environment.withProgName so that both programs use the same
state storage directory under _local.

I'll try to include this demo in an upcoming major release of
happstutorial.

***********

state migration demo output:

thartman@thartman-laptop:~/happs-migrations/example>rm -rf _local/

(wipe state storage directory)

thartman@thartman-laptop:~/happs-migrations/example>runghc
CreateState1.hs
[("index",Page {title = "Home3 ", body = "hello, world 3"}),
("index",Page {title = "Home 2", body = "hello, world 2"}),
("index",Page {title = "Home", body = "hello, world"})]

state is a list

thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState2.hs
fromList [(Page {title = "Home", body = "hello, world"},"index"),(Page
{title = "Home 2", body = "hello, world 2"},"index"),(Page {title =
"Home3 ", body = "hello, world 3"},"index")]

state migration. notice that the insertion called for in main
doesn't take place.
I am guessing that the rule is that when startSystemState detects
there's a migration in progress it exits immediately so the app owners
can verify that the migration was successful. This seems reasonable to
me, but should be documented. (Or is it already?)

thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState2.hs
fromList [(Page {title = "Home 6", body = "hello, world 6"},"index"),
(Page {title = "Home 5", body = "hello, world 5"},"index"),(Page
{title = "Home 4", body = "hello, world 4"},"index"),(Page {title =
"Home", body = "hello, world"},"index"),(Page {title = "Home 2", body
= "hello, world 2"},"index"),(Page {title = "Home3 ", body = "hello,
world 3"},"index")]

No change when run again, which makes sense since we're using a map
now.

thartman@thartman-laptop:~/happs-migrations/example>runghc
CreateState1.hs
CreateState1.hs: Couldn't find handler for event of type:
State2.InsertPage

app is now incompatible with State1, which also makes sense.

tphyahoo

unread,
Nov 29, 2008, 1:18:54 PM11/29/08
to HAppS
now with tar attached. I believe eelco's patches have already been
integrated into the latest hackaged happs, so I merely attached the
example directory.

http://groups.google.com/group/HAppS/web/happs-migration.tar.gz

On Nov 29, 7:12 pm, tphyahoo <thomashartm...@googlemail.com> wrote:
> My comments below reference thread
>
> http://groups.google.com/group/HAppS/browse_thread/thread/c23101b258d...

tphyahoo

unread,
Dec 1, 2008, 4:33:21 PM12/1/08
to HAppS
1) On second thought, Eelco's map did make sense.

2) I played some more with migrations, and ran into a problem,
attached at

http://groups.google.com/group/HAppS/web/happs-migration2.tar.gz

Can someone help me fix this?

Thomas.

thartman@thartman-laptop:~/happs-migrations/example>rm -rf _local/
thartman@thartman-laptop:~/happs-migrations/example>runghc
CreateState1.hs
[("index",Page {title = Title "Home3 ", body = Body "hello, world 3"}),
("index",Page {title = Title "Home 2", body = Body \
"hello, world 2"}),("index",Page {title = Title "Home", body = Body
"hello, world"})]
thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState2.hs
fromList [("index",Page {title = Title "Home", body = Body "hello,
world"}),("index2",Page {title = Title "Home 2", body =\
Body "hello, world 2"}),("index3",Page {title = Title "Home 3", body
= Body "hello, world 3"}),("index4",Page {title = Ti\
tle "Home 4", body = Body "hello, world 4"})]
thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState3.hs
MigrateToState3.hs: Couldn't find handler for event of type:
StateVersions.AppState2.InsertPage

tphyahoo

unread,
Dec 1, 2008, 4:33:30 PM12/1/08
to HAppS
1) On second thought, Eelco's map did make sense.

2) I played some more with migrations, and ran into a problem,
attached at

http://groups.google.com/group/HAppS/web/happs-migration2.tar.gz

Can someone help me fix this?

Thomas.

thartman@thartman-laptop:~/happs-migrations/example>rm -rf _local/
thartman@thartman-laptop:~/happs-migrations/example>runghc
CreateState1.hs
[("index",Page {title = Title "Home3 ", body = Body "hello, world 3"}),
("index",Page {title = Title "Home 2", body = Body \
"hello, world 2"}),("index",Page {title = Title "Home", body = Body
"hello, world"})]
thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState2.hs
fromList [("index",Page {title = Title "Home", body = Body "hello,
world"}),("index2",Page {title = Title "Home 2", body =\
Body "hello, world 2"}),("index3",Page {title = Title "Home 3", body
= Body "hello, world 3"}),("index4",Page {title = Ti\
tle "Home 4", body = Body "hello, world 4"})]
thartman@thartman-laptop:~/happs-migrations/example>runghc
MigrateToState3.hs
MigrateToState3.hs: Couldn't find handler for event of type:
StateVersions.AppState2.InsertPage


On Nov 29, 7:18 pm, tphyahoo <thomashartm...@googlemail.com> wrote:

Joachim Breitner

unread,
Dec 1, 2008, 5:18:18 PM12/1/08
to HA...@googlegroups.com
Hi,

Am Montag, den 01.12.2008, 13:33 -0800 schrieb tphyahoo:
> 1) On second thought, Eelco's map did make sense.
>
> 2) I played some more with migrations, and ran into a problem,
> attached at
>
> http://groups.google.com/group/HAppS/web/happs-migration2.tar.gz
>
> Can someone help me fix this?

> thartman@thartman-laptop:~/happs-migrations/example>runghc


> MigrateToState3.hs
> MigrateToState3.hs: Couldn't find handler for event of type:
> StateVersions.AppState2.InsertPage

I think the problem is that the module containing your current state
changes names with each state version, which confuses HAppS.

What I do is that I alwas have src/State.hs with the current state, and
src/Old/State<n>.hs for the old states. So when I need a new state, I
move src/State.hs to src/State3.hs, and put the new stuff in
src/State.hs.

OTOH, if changing state modules are supposed to be supported, than this
looks like a HAppS bug to me (but I’m not sure, maybe there is a
subtlety I’m missing)

BTW, it works if you add
> createCheckpoint control
at the end of MigrateToState2.hs, and it breaks earlier if you remove
that line from CreateState1.hs

Greetings,
Joachim
--
Joachim "nomeata" Breitner
mail: ma...@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
JID: nom...@joachim-breitner.de | http://www.joachim-breitner.de/
Debian Developer: nom...@debian.org

signature.asc

tphyahoo

unread,
Dec 1, 2008, 6:10:33 PM12/1/08
to HAppS
Thanks!
>   mail: m...@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
>   JID: nome...@joachim-breitner.de |http://www.joachim-breitner.de/
>   Debian Developer: nome...@debian.org
>
>  signature.asc
> < 1KViewDownload

Lemmih

unread,
Dec 2, 2008, 6:12:00 AM12/2/08
to HA...@googlegroups.com
On Mon, Dec 1, 2008 at 11:18 PM, Joachim Breitner
<ma...@joachim-breitner.de> wrote:
> Hi,
>
> Am Montag, den 01.12.2008, 13:33 -0800 schrieb tphyahoo:
>> 1) On second thought, Eelco's map did make sense.
>>
>> 2) I played some more with migrations, and ran into a problem,
>> attached at
>>
>> http://groups.google.com/group/HAppS/web/happs-migration2.tar.gz
>>
>> Can someone help me fix this?
>
>> thartman@thartman-laptop:~/happs-migrations/example>runghc
>> MigrateToState3.hs
>> MigrateToState3.hs: Couldn't find handler for event of type:
>> StateVersions.AppState2.InsertPage
>
> I think the problem is that the module containing your current state
> changes names with each state version, which confuses HAppS.
>
> What I do is that I alwas have src/State.hs with the current state, and
> src/Old/State<n>.hs for the old states. So when I need a new state, I
> move src/State.hs to src/State3.hs, and put the new stuff in
> src/State.hs.
>
> OTOH, if changing state modules are supposed to be supported, than this
> looks like a HAppS bug to me (but I'm not sure, maybe there is a
> subtlety I'm missing)

There is indeed a reason for this. If you change the module name then
you can't take advantage of the built-in scalability features. That
is, you will not be able to do replication or partitioning.

HAppS-0.9.3 is able to deal with changing module names but /only/
after a clean checkpoint. It /will/ fail if the state is changed after
the checkpoint. I would not recommend using this feature for a
production application.

--
Cheers,
Lemmih

tphyahoo

unread,
Dec 3, 2008, 7:25:00 AM12/3/08
to HAppS
Replication and partitioning are still future-features though, right?
Not yet implememented in what's on hackage.

Lemmih

unread,
Dec 3, 2008, 7:46:46 AM12/3/08
to HA...@googlegroups.com
On Wed, Dec 3, 2008 at 1:25 PM, tphyahoo <thomash...@googlemail.com> wrote:
>
> Replication and partitioning are still future-features though, right?
> Not yet implememented in what's on hackage.

Partitioning isn't complete but replication is.

--
Cheers,
Lemmih

tphyahoo

unread,
Dec 3, 2008, 2:40:53 PM12/3/08
to HAppS
Is there documentation, demo, or a blog on the replication bit?

On Dec 3, 1:46 pm, Lemmih <lem...@gmail.com> wrote:

Lemmih

unread,
Dec 3, 2008, 3:08:18 PM12/3/08
to HA...@googlegroups.com
On Wed, Dec 3, 2008 at 8:40 PM, tphyahoo <thomash...@googlemail.com> wrote:
>
> Is there documentation, demo, or a blog on the replication bit?

http://happs.org/repos/HAppS-Server/Examples/MultimasterTest1.hs
http://happs.org/repos/HAppS-Server/Examples/MultimasterTest2.hs

It requires spread to be configured and running.

--
Cheers,
Lemmih

tphyahoo

unread,
Dec 13, 2008, 10:48:20 AM12/13/08
to HAppS
I have worked to consolidate wisdom concerning macid migrations into
happstutorial:

http://happstutorial.com/tutorial/macid-migration

On Dec 3, 9:08 pm, Lemmih <lem...@gmail.com> wrote:
> On Wed, Dec 3, 2008 at 8:40 PM, tphyahoo <thomashartm...@googlemail.com> wrote:
>
> > Is there documentation, demo, or a blog on the replication bit?
>
> http://happs.org/repos/HAppS-Server/Examples/MultimasterTest1.hshttp://happs.org/repos/HAppS-Server/Examples/MultimasterTest2.hs
Reply all
Reply to author
Forward
0 new messages