How do I use 'NullSaver'?

0 views
Skip to first unread message

Antoine Latter

unread,
Nov 27, 2009, 2:33:50 PM11/27/09
to ha...@googlegroups.com
Folks,

I'm trying the following with happstack-state 0.4 (from darcs a few
weeks back, I think):

>>>>>
<various language pragmas>
<various imports>

data State1 = State1 { unState1 :: String }
deriving Typeable

instance Version State1
$(deriveSerialize ''State1)

instance Component State1 where
type Dependencies State1 = End
initialValue = State1 ""

$(mkMethods ''State1 [])

startState1 :: IO (MVar TxControl)
startState1
= runTxSystem NullSaver (Proxy :: Proxy State1)
<<<<

if I then execute:

> tx <- startState1

in GHCi, I get the following error: *** Exception: user error
(NullSaver: readerGetUncut)

Is this expected? Am I going about this the wrong way? Should I be
trying this on a previous version?

The haddocks aren't terribly useful. Happstack.State appears to export
a lot of things I don't care about - it's hard to separate the
internals from the externals.

Thanks,
Antoine

tphyahoo

unread,
Nov 27, 2009, 3:16:47 PM11/27/09
to HAppS
It's true, the documentation sucks, I have only been able to work with
state by following successful sample applications, of which the main
one is probably the guestbook app that comes bundled with happstack.
have you tried following along with that?

thomas.

Antoine Latter

unread,
Nov 27, 2009, 5:04:50 PM11/27/09
to ha...@googlegroups.com
On Fri, Nov 27, 2009 at 2:16 PM, tphyahoo <tphy...@gmail.com> wrote:
> It's true, the documentation sucks, I have only been able to work with
> state by following successful sample applications, of which the main
> one is probably the guestbook app that comes bundled with happstack.
> have you tried following along with that?
>
> thomas.
>

Yep, if I do what the tutorial does everything works great.

>>>>>
startState1 :: IO (MVar TxControl)
startState1
= do
saver <- stdSaver
runTxSystem saver (Proxy :: Proxy State1)
<<<<<

But then I'm not using the NullSaver, which was what I wanted.

Antoine

stepcut

unread,
Nov 27, 2009, 5:08:38 PM11/27/09
to HAppS
Hello,

What did you expect to happen / what are you trying to achieve?

The error occurs because runTxSystem tries to restore the previous
state, and NullSaver didn't save anything, so it has no way to do
that...

As you suggest, NullSaver is more of an internal thing than an
external thing. The only saver you are likely to want to use for a
single-server setup is:

(Queue (FileSaver "path"))

One of the goals for 0.5 is to try to reorganize some modules and
improve the haddock documentation so it is a lot clearer what
functions you are likely to want to use as a normal user.

- jeremy

Antoine Latter

unread,
Nov 27, 2009, 5:41:43 PM11/27/09
to ha...@googlegroups.com
On Fri, Nov 27, 2009 at 4:08 PM, stepcut <jer...@n-heptane.com> wrote:
> Hello,
>
> What did you expect to happen / what are you trying to achieve?
>
> The error occurs because runTxSystem tries to restore the previous
> state, and NullSaver didn't save anything, so it has no way to do
> that...
>
> As you suggest, NullSaver is more of an internal thing than an
> external thing. The only saver you are likely to want to use for a
> single-server setup is:
>
>  (Queue (FileSaver "path"))
>
> One of the goals for 0.5 is to try to reorganize some modules and
> improve the haddock documentation so it is a lot clearer what
> functions you are likely to want to use as a normal user.
>

From reading prior email threads it sounded like NullSaver was
supposed to be useful to create a transactional store that doesn't
write to disk:

http://groups.google.com/group/HAppS/browse_thread/thread/bf9e11e08043db88

Maybe things have changed since then, or maybe I'm supposed to use it
in a different way.

Antoine

Jeremy Shaw

unread,
Nov 27, 2009, 6:17:46 PM11/27/09
to ha...@googlegroups.com

On Nov 27, 2009, at 4:41 PM, Antoine Latter wrote:

From reading prior email threads it sounded like NullSaver was
supposed to be useful to create a transactional store that doesn't
write to disk:

http://groups.google.com/group/HAppS/browse_thread/thread/bf9e11e08043db88

Maybe things have changed since then, or maybe I'm supposed to use it
in a different way.

If you are not writing to disk, then how will you restore after a restart? Or do you not plan on restoring after a restart?

The runTxSystem function assumes you want to restore the state using the same Saver that was used to save the state. If this is not the case, then you will need to write your own runTxSystem like function that restores the state some other way.

By way of example, darcs head now has experimental code for using central logging servers. 

If you look at runTxSystem, you will see that it calls, 

  enableLogging <- Checkpoint.restoreState ctl

But, if you look at the runTxSystemAmazon function you will see that it uses NullSaver, and instead of restoring the state by calling 'Checkpoint.restoreStore', it instead connects to the central logging server.

So, to figure out what is right for your case, we would need more information about what you are trying to achieve. Do you only have one server? Do you care about restoring state when the server restarts? If so, where will that state be stored?

- jeremy

Antoine Latter

unread,
Nov 27, 2009, 6:37:06 PM11/27/09
to ha...@googlegroups.com
On Fri, Nov 27, 2009 at 5:17 PM, Jeremy Shaw <jer...@n-heptane.com> wrote:
> If you look at runTxSystem, you will see that it calls,
>   enableLogging <- Checkpoint.restoreState ctl
> But, if you look at the runTxSystemAmazon function you will see that it uses
> NullSaver, and instead of restoring the state by calling
> 'Checkpoint.restoreStore', it instead connects to the central logging
> server.
> So, to figure out what is right for your case, we would need more
> information about what you are trying to achieve. Do you only have one
> server? Do you care about restoring state when the server restarts? If so,
> where will that state be stored?

Nothing so serious is going on, I'm just trying to find my way around,
and I thought I'd try the NullSaver while developing to avoid stray
locks and versioning headaches.

rm-rf works just as well.

Thanks,
Antoine
Reply all
Reply to author
Forward
0 new messages