One question that's been bugging me the last couple of days vis-a-vis
swarm is: when I've sent my serialized continuation from server A to
server B, how is the restarted continuation to access data on server
B? It's not like a class which gets deserialized and into which we can
inject some state when it arrives on server B. If the point is for the
continuation to move to where the data is, we have to have some way of
locating the data and working with it...
I'm probably missing something here.
Thanks
Patrick
> Swarm uses the "Ref" class see [1] to refer to data which may reside
> on a remote computer. Within Ref, this data is indexed by a long
> integer uid.
>
> If you try to retrieve the data from a Ref class (see Ref.apply()),
> and the data is on a remote computer, then the continuation will be
> moved automatically such that the data is now local, and it can be
> retrieved via the integer uid from the Store [2].
Your Scala-foo is more advanced than mine. What I'm missing in Ref is
"...and the data is on a remote computer". What I see in the sources
is that apply() , without a location, uses Swarm.myLocation, which is
the local server, correct? Where do we maintain the reference from a
Ref id to a node?
I can wait until you've written a demo for it, though, that may clear it up.
Thanks
Patrick
> Swarm uses the "Ref" class see [1] to refer to data which may resideYour Scala-foo is more advanced than mine. What I'm missing in Ref is
> on a remote computer. Within Ref, this data is indexed by a long
> integer uid.
>
> If you try to retrieve the data from a Ref class (see Ref.apply()),
> and the data is on a remote computer, then the continuation will be
> moved automatically such that the data is now local, and it can be
> retrieved via the integer uid from the Store [2].
"...and the data is on a remote computer". What I see in the sources
is that apply() , without a location, uses Swarm.myLocation, which is
the local server, correct?
Where do we maintain the reference from a
Ref id to a node?
I can wait until you've written a demo for it, though, that may clear it up.
Then a Ref would (internally) know the location to which the users.dat
or uid 12345 was mapped, or would know how to look the location up
from somewhere else.
By demo I mean--there are no demos for either Ref or TreeMap at the
moment, so I'm not sure what this would look like in client code.
Given that a Ref must be given a location, I assume a TreeMap will be
have hard-coded ref-location entries, or would download a TreeMap from
another server to know what refs were available from that server?
Thanks
Patrick
Thanks for the clarification. I misunderstood your earlier
explanation: I thought that, given
Ref("users.dat")
or
Ref("users.dat", 12345)
Then a Ref would (internally) know the location to which the users.dat
or uid 12345 was mapped, or would know how to look the location up
from somewhere else.
By demo I mean--there are no demos for either Ref or TreeMap at the
moment, so I'm not sure what this would look like in client code.
Given that a Ref must be given a location, I assume a TreeMap will be
have hard-coded ref-location entries, or would download a TreeMap from
another server to know what refs were available from that server?
This does help. I had actually seen ForceRemoteRef before, but I
thought it was a non-working demo or stub, since I didn't get how Refs
worked.
That demo is pretty mind-blowing; impressive how much it shows in so
little code. Kudos.
A Ref is still a bit conceptually confusing, though, or rather,
there's a feature I wasn't expecting.
val vLoc = Ref("test local string");
Creates a ref with location = this server.
vRem = Ref(new Location(myLocation.address, 9997), "test remote string");
Creates a ref with location = remote server, then serializes itself to
the remote server, saves the content of the ref on the remote server,
and continues executing on the remote server.
I'm not sure why just creating a ref with a remote location would
cause the transfer, and why server A should be able to push data into
the Store in server B. Like all of this, it's interesting, but what
are you aiming at with this functionality?
Also, to what extent should Swarm expose or make clear operations
which may cause a move, and to what extent should it be hidden (though
possibly easier to use)?
Adding this line
println(format("%s:%s:%s:%s:%s",vRem(), vLoc(), vRem(), vLoc(),vRem()))
to the demo causes multiple hops between servers; imagine iterating
Refs inside a list.
Very interesting stuff, though. Hope I am closer to grokking it.
Patrick
vRem = Ref(new Location(myLocation.address, 9997), "test remote string");
Creates a ref with location = remote server, then serializes itself to
the remote server, saves the content of the ref on the remote server,
and continues executing on the remote server.
I'm not sure why just creating a ref with a remote location would
cause the transfer,
and why server A should be able to push data into
the Store in server B.
Also, to what extent should Swarm expose or make clear operations
which may cause a move, and to what extent should it be hidden (though
possibly easier to use)?
Adding this line
println(format("%s:%s:%s:%s:%s",vRem(), vLoc(), vRem(), vLoc(),vRem()))
to the demo causes multiple hops between servers; imagine iterating
Refs inside a list.
Very interesting stuff, though. Hope I am closer to grokking it.
One comment about the serialization aspect--when a field is not
serializable, my experience is that you will typically receive a null
on the receiving end, possibly without any exception being thrown in
the process. The Serializable interface doesn't demand transitivity,
although I believe a number of code-checkers will warn you if you have
non-serializable fields inside a class marked serializable. But if you
receive data from someone else, all bets are off--you just won't know
if you can transport it across the wire.
I mention this because it will be a design issue for people working
with Swarm, and it's one thing I've had to worry about in working with
serialization over the last couple of years.
Patrick
That's a good question; maybe I misspoke. I will see if I can come up
with a scenario where no exception is thrown. I thought I had seen
that happen before, but I may be confusing two different issue.
Please file this in the "I didn't mean to say that" category. The
first part is wrong (you will cause an exception if you try to
serialize a non-serializable class, or one with a non-serializable
field). You won't end up with a serialized object but a null field for
the value that couldn't be serialized. I was thinking about nulls when
I wrote that because of the error I ran into with JavaSpaces, where
the serialization code for JS ignores any non-public fields. I feel
stupid :).
What I meant to say :) was that the problem is that first, when
receiving an object from someone else, or even one of your own, you
can't know, without examining the object graph, whether it's actually
serializable or not. You can declare a class Serializable and include
in it non-transient fields for object types that are not
serializable--that will compile. It will fail on serialization,
though. So if you receive some type of reference from a method call
you can't know if you can actually send it across the wire or not. You
would have to use reflection (I think) to check the graph all the way
down.
I think that everyone knows that is an issue when working with
something like RMI or Jini, that the method calls must take parameters
and return values that are serializable. But if we are working in
Swarm, we need to know that the data we are accessing on any given
server is serializable, otherwise, if we assign it to a "local"
variable (e.g. local to the continuation, in the method or block we
are serializing), when we try to hop over to the next server, it will
fail. That would imply that the data sets we work with in Swarm can't
be any old data set available in our applications, right? We would
have to separate out the part that may not be serializable, and should
not be referenced from within a continuation, from the part we can use
within a continuation.
Am I thinking about this correctly?
Patrick