Re: [Prevayler-coders] The PrevaylerJr Game
Brought to you by:
jsampson,
klauswuestefeld
From: Justin T. S. <ju...@kr...> - 2008-07-03 19:52:42
|
Well, queries aren't supposed to modify the prevalent system at all, so it's actually okay for a query to throw an Error. The system can keep on running without experiencing inconsistency. The only exception might be if you're doing some kind of lazy computations inside queries -- conceptually read-only, but actually read-write. In that case, queries must not run concurrently with each other anyway. -Justin On Wed, Jul 2, 2008 at 11:57 PM, Klaus Wuestefeld <kla...@gm...> wrote: > Justin, > > Do you see any way of extending this "no inconsistency" guarantee for > queries running in parallel when one of them throws an Error? > > Will some sort of gate (AtomicReference<Boolean>?), just before the > queries return, work? Or might the scheduler play tricks on us? > > Klaus. > > > On Thu, Jul 3, 2008 at 3:50 AM, Klaus Wuestefeld > <kla...@gm...> wrote: >>> There's a remaining bug -- while transactions will now be prevented >>> from executing since the journal has been closed, queries are still >>> allowed to execute against the corrupted prevalent system. >> >> Yup. Fixed below. >> >> Anything else? Is that it? >> >> Is this what 90% of all apps (that fit in RAM) out there need in terms >> of persistence? >> >> Klaus >> >> -------------------- >> >> import java.io.EOFException; >> import java.io.IOException; >> >> public class PrevaylerJr { >> private final Object _system; >> private final AcidOutputStream _journal; >> >> public PrevaylerJr(Object initialState, String storageFile) throws Exception { >> AcidInputStream input = new AcidInputStream(storageFile); >> try { >> initialState = input.readObject(); >> >> while (true) >> ((Command)input.readObject()).executeOn(initialState); >> >> } catch (EOFException expected) {} >> >> _system = initialState; >> _journal = new AcidOutputStream(storageFile, _system); >> } >> >> synchronized public Object executeTransaction(Command transaction) >> throws Exception { >> checkSystemConsistency(); >> _journal.append(transaction); >> return tryToExecute(transaction); >> } >> >> synchronized public Object executeQuery(Command query) { >> checkSystemConsistency(); >> return tryToExecute(query); >> } >> >> private Object tryToExecute(Command command) { >> try { >> return command.executeOn(_system); >> } catch (Error err) { >> _journal.close(); >> throw err; >> } >> } >> >> private void checkSystemConsistency() { >> if (_journal.isClosed()) >> throw new IllegalStateException("An Error such as OutOfMemoryError >> or StackOverflowError was thrown while executing some previous >> transaction or query. The system might be in an inconsistent state."); >> } >> >> public static interface Command { >> Object executeOn(Object system); >> } >> } >> >> class AcidInputStream { >> >> public AcidInputStream(String fileName) throws IOException {} >> public Object readObject() throws IOException {return null;} >> >> } >> >> class AcidOutputStream { >> >> /** Atomically and durably replaces the previous journal file with >> the new entry using file rename manoeuvres.*/ >> public AcidOutputStream(String fileName, Object firstEntry) throws >> IOException {} >> public void append(Object entry) throws IOException {} >> public void close() {} >> public boolean isClosed() {return false;} >> >> } >> > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > Prevayler-coders mailing list > Pre...@li... > https://lists.sourceforge.net/lists/listinfo/prevayler-coders > |