From: Brian Candler Date: 2003-08-08T05:30:07+09:00 Subject: Re: [DRb] Using DRb to implement object database --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 08, 2003 at 04:36:42AM +0900, Steve Tuckner wrote: > I had some trouble understanding your solution, so I will attempt to explain > how PStore works and what the exact problem is. PStore is just a set of > marshalled objects on the server's local disk. To store the objects on disk, > just create the pstore > > require "pstore" > > store = PStore.new("test.db") > store.transaction do > store["objects"] = object_list # where object_list is the array of objects > in the database Sorry if I wasn't clear :-) So 'store' looks like a hash? store[key] = some_object If you update store[] or one of the objects it refers to, is there anything you need to do to write it back to disk? Hmm, probably that's what the transaction syntax achieves. OK, I've had a play. The attached code hopefully demonstrates what I was trying to say. DRb provides a remote 'facade' to a single object on a particular port, 9000 in this case. So you create a single object which contains a set of methods which do all the different work parcels you want - including invoking methods on other objects if necessary. That's unless you want a separate DRb front-end to each individual Foo object, which would mean binding them to separate TCP ports. That's not an approach I would recommend unless you've only got two or three objects you want to access remotely. If you decided to make the PStore object itself available by DRb, then the only methods you would get would be those methods which PStore itself provides - such as [] and []= to fetch and set the contained objects. And running over DRb, in its normal operation, you would get *copies* of those objects. Updating state on a local copy of an object will do nothing on the server side of course; you would have to explicitly overwrite the old object with the new one using []=. > When I do that however foo can't be dumped because its _dump function has > been replaced by a function that raises a TypeError exception (and produces > the following output). I don't know anything about DRbUndumped (have you got a reference to a description? [*]) Standard DRb just marshals a method call and its arguments across a TCP stream, and marshals the method result back over the stream. So it's like a local method call except the arguments and the result are 'dup'ed (deep-copied, actually) I don't know anything about 'Linda' or Java either, so Rinda doesn't mean much to me. If DRbUndumped automatically puts in some kind of proxy-object for each remote object on the server, then that would be very cool indeed. But then I see your problem with PStore, which relies on being able to dump objects to get them to disk. Have you tried just commenting out the _dump function? It looks like DRb only tests whether the module has been included: obj = DRbObject.new(obj) if obj.kind_of? DRbUndumped Hence it probably doesn't actually need _dump to be overridden. Regards, Brian. [*] In the source tarball there's a reference in doc/drb-ref.rd.ja , but the text in that file looks like it has been marshaled in a strange binary format that I'm not able to read :-) --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="foo.rb" class Foo attr_accessor :x,:y def initialize(x,y) @x, @y = x,y end end --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="server.rb" require 'pstore' require 'drb' require 'foo' # Note: this is probably not thread-safe as written (unless # PStore#transaction has a serialisation mechanism of its own) class StoreApplication def initialize @store = PStore.new("test.db") @store.transaction do @store["objects"] = [Foo.new(1,2), Foo.new(3,4), Foo.new(5,6)] end end def setx(index, xval) @store.transaction do o = @store["objects"] o[index].x = xval end end def getx(index) @store.transaction do @store["objects"][index].x end end end app = StoreApplication.new DRb.start_service('druby://0.0.0.0:9000', app) DRb.thread.join --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="client.rb" require 'drb' require 'pstore' # so any pstore exceptions are reported correctly require 'foo' DRb.start_service app = DRbObject.new(nil, 'druby://localhost:9000') p app.getx(0) app.setx(0,99) p app.getx(0) app.setx(0,33) p app.getx(0) --xHFwDpU9dbj6ez1V--