Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-366

Document CAS-like operations in Hot Rod clearly

    XMLWordPrintable

Details

    • Task
    • Resolution: Done
    • Minor
    • 4.1.0.CR2
    • None
    • Remote Protocols
    • None

    Description

      <mmarkus_> galderz: ping
      <mmarkus_> what is the meaning of "replaceIfUnmodified"?

      • amontenegro_ (~amonteneg@200.111.187.74) has joined #infinispan
      • amontenegro_ is now known as aamonten
      • clebert (~clebert@redhat/jboss/clebert) has joined #infinispan
      • baileyje (~baileyje@redhat/jboss/baileyje) has joined #infinispan
      • clebert (~clebert@redhat/jboss/clebert) has left #infinispan
        <galderz> manik_, hi mmarkus
        <galderz> replaceIfUnmodified ?
        <galderz> one sec
        <galderz> mmarkus_, manik_, r u planning to produce diff jars for server and client?
        <galderz> if so, it'd make sense for the client to be a separate module
        <galderz> wouldn't it?
        <manik_> galderz: yes, I think diff jars would make sense
        <mmarkus_> galderz: i think yes, because I'd like the client to be light
        <galderz> same here
        <manik_> no one would want server code (+ server deps) on their client
        <galderz> exactly
        <galderz> so, the client should be in server/hotrod-client or similar module
        <mmarkus_> not sure we need another module for that, only different packaging
        <galderz> mmarkus_, u're lucky i don't have java classes
        <galderz> and u can use src/java
        <galderz> while I use main/scala
        <galderz> i mean, u use main/java
        <galderz> but once u give a maven module scala nature
        <galderz> i think it ignores main/java
        <galderz> at least that's what I found out doing some testing
        <mmarkus_> even so, can't we produce two jars for the same module?
        <galderz> mmarkus_, u prob can but u have to start filtering classes./..etc
        <manik_> mmarkus_: thats a real PITA
        <galderz> iow, it's a probably a PITA
        <manik_> try wrestling with maven assemblies to do that !
        <sannegrinovero> hi all; nice to see activity here hi galderz recovered from all the walking?
        <galderz> sannegrinovero, yup, fully recovered now
        <sannegrinovero> nice
        <manik_> mmarkus_: much easier to just use a separate maven module
        <mmarkus_> manik_: I don't want to do that for sure. Not a big fan o mvn (not to say more)
        <galderz> mmarkus_, replaceIfUnmodified is all about the cas
        <sannegrinovero> can't build the snapshot currently as I'm missing a jgroups:jar:2.10.0.Alpha2
        <galderz> it's a way to do a replace remotely
        <galderz> u want to replace, only if no one changed the value
        <galderz> so what do u do?
        <galderz> each modification has a unique value associated to it
        <galderz> so, when u want to mayeb replace, u get the cas first with: getWithCas
        <galderz> and then use the cas to make the modification
        <sannegrinovero> galderz is this "replaceIfUnmodified" already in trunk? sounds very useful
        <galderz> if the cas values do not match, someone has changed the value and replace is not execited
        <galderz> sannegrinovero, not yet
        <sannegrinovero> ok
        <galderz> mmarkus_, it's the same technique used by memcached: see http://github.com/trondn/memcached/blob/master/doc/protocol.txt
        <galderz> see cas command in that document
        <galderz> cas is our replaceIfUnmodified
        <galderz> mmarkus_, is it clear?
        <mmarkus_> what is cas?
        <galderz> Compare And Swap
        <galderz> used all over java.util.concurrent
        <mmarkus_> I know that one, just I don't see how it maps in hotrod
        <mmarkus_> e.g. getWithCas?
        <galderz> mmarkus_, each modification has a unique value associated:
        <galderz> for example:
        <galderz> if u key=k value=v1, let's say the unique value is 12345
        <galderz> get with cas returns that 12345
        <galderz> 12345 and v1 of course
        <galderz> now, u call replaceIfUnmodified on key=k with value=v2 and cas 12345
        <galderz> key=k will only be replaced by v2 if, and only if, the cas in that node is still 12345
        <galderz> if someone else had made a modification in the mean time, the unique value would have changed
        <galderz> hence, replaceIfUnmodified call would not have succeded
        <galderz> mmarkus_, does it make sense now?
        <galderz> it's a way to do a remote CAS
        <galderz> as memcached says: " "cas" is a check and set operation which means "store this data but
        <galderz> only if no one else has updated since I last fetched it.""
        <mmarkus_> so cas is generated on the server, each modification to the cache (cluster) resulting in a new cas value?
        <galderz> that cas operation does exactly the same as replaceIfUnmodified
        <galderz> indeed mmarkus_
        <galderz> see the memcached module for an example
        <galderz> we discussed this in the list as well
        <mmarkus_> is the cache set per key or per whole cache?
        <galderz> cas u mean?
        <galderz> it's associated with each value, so is per key
        <mmarkus_> cas, sorry
        <galderz> mmarkus_, see http://anonsvn.jboss.org/repos/infinispan/trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/Value.java
        <galderz> and
        <galderz> AddCommand
        <galderz> or SetCommand
        <galderz> in memcached, we set it to current time millis
        <galderz> and we increment it for each modification
        <mmarkus_> yep, makes sense. And it's not returned by default, the only way to retrieve it is through getWithCas, right?
        <galderz> mmarkus_, indeed
        <mmarkus_> galderz: I'm just thinking, is there a way to do a put AND obtain the cas value atomically?
      • mmarkus_ i.e. the way I understand it. if one does a 1.put (k1,v1)
        <galderz> not at the moment
        <mmarkus_> then he will need to to a getWithCas(k1) to get this value back
        <galderz> i wonder how often this would be needed
        <galderz> indeed
        <galderz> by making getWithCas a separate command and not using cas anywhere, i'm assuming this is rare occurrence
        <galderz> but maybe it's not that rar
        <galderz> rare
        <mmarkus_> now, the cas he gets on getWithCas(k1), might be the cas of a different put that happened after put(k1,v1), e.g. put(k1,v2)
        <galderz> mmarkus_, well, that means someone has changed it then
        <galderz> i think i know what u mean though
        <galderz> if u have a put and replaceIfUnmodified one after the other, put returning the cas would cut one network call
        <mmarkus_> not necesarelly
        <mmarkus_> (that also)
        <galderz> i'm all ears
        <mmarkus_> considering your example with cas= 12345 (see few lines bellow)
        <mmarkus_> I do a put that results in cas 12345
        <mmarkus_> then immediately after, one does another put(k), resulting in cas 54321
        <mmarkus_> then you do an getWithCas and obtain cas=54321 on the server
        <mmarkus_> now you do a replaceIfUnmodified(k, 54321)
        <mmarkus_> the cas will match, and the replace operation will take place. But you really wanted it not to take place, as per your example, isn't it?
        <galderz> well, depends who does the getWithCas
        <galderz> or more specifically, who did the other put
        <galderz> what u know is that since u called getWithCas till u do replace, no one else has modified it
        <galderz> and that's what u do with cas
        <galderz> u get something, u check the value
        <mmarkus_> ah, you want to use cas for getting the following gurante: you read data, and based on what you read you want to modify it. Now you only modify it if it hasn't changed in between, correct?
        <galderz> it matches
        <galderz> indeed
        <galderz> that's what a cas does
        <galderz> u get something
        <galderz> u assume that it has X
        <mmarkus_> I see it now!
        <galderz>
        <mmarkus_> I was thinking at a different scenario.
        <mmarkus_> you put data, and at a further point you want to modify it only if it hasn't changed
        <mmarkus_> but, yeah, this doesn't sound as common as the other scenario, with read
      • aslak has quit (Quit: Ex-Chat)
        <mmarkus_> I got it now - thanks for the explanation!
      • manik_ has quit (Quit: manik_)
        <galderz> mmarkus_, u're welcome
        <galderz> we'll have to make sure this is explained properly in the docu
        <galderz> i'll add a jira

      Attachments

        Activity

          People

            rh-ee-galder Galder ZamarreƱo
            rh-ee-galder Galder ZamarreƱo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: