KVM put operation override true or false

Not applicable

Hello team,

I was using KVM facility, while I was doing PUT process.

According to documentation,override is true then will override the value of key else it will not.

So tried this but it seems that it is not working properly.

I have created proxy API "KVM-create-update-demo", in this proxy the problem is occurred.

I am passing key & value through query-params.

If I set override to "true", it is overriding which is good;

but if I set it to "false", it should give some exception or error,

but it don't give any error or exception, in fact simply the value of key will updated.

So I have handle the exception or error in my code? if yes then how?

If no then this is might a be bug.Thank You.

3 10 867
10 REPLIES 10

Hi @NIkhil Madal, I can reproduce your issue. It is most probably a bug in Apigee Public Cloud.

Even when we use override=false in KVM Policy, in Trace I can see that it uses true, so it is updating.

Which Apigee account are you working on? Apigee Public Cloud/Private/on-prem?

override = false should not update/override existing key value.

I have used below KVM policy, check override line,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-1" mapIdentifier="sid-put">
    <DisplayName>Key Value Map Operations-1</DisplayName>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>300</ExpiryTimeInSecs>
    <Put override="false">  <!-- false here, but in trace i can see it as true-->
        <Key>
            <Parameter ref="request.queryparam.name"/>
        </Key>
        <Value ref="request.queryparam.value"/>
    </Put>
    <Scope>environment</Scope>
</KeyValueMapOperations>

7600-apigee-cloud.jpg

Same KVM Policy on our on-prem setup works as expected,

7601-apigee-on-prem.png

Is this a bug? Please look into this @Dino-at-Google @Sai Saran Vaidyanathan @Anil Sagar @ Google

@Siddharth Barahalikar Thank You. I am using trial version.

And in response every time it gives as TRUE.

So is it the limitation use of trial version apigee?

It does work on Apigee Trail/Eval accounts, may be it just a bug.

Lets wait for Apigee folks to look into it & raise a ticket if required.

Not a bug. See my answer.

Siddharth - also: eliminate <ExclusiveCache> from your KVM policy config.

The expected and documented behavior is working for me.

When the cache is warm, and when override="false", then the PUT operation does not occur, and the variable like

keyvaluemapoperations.POLICYNAME.KEYVALUE

...is set to false.

For example, when I invoke a KeyValueMapOperations/PUT with override = false, with a key and value pair, like this:

curl -i https://$ORG-$ENV.apigee.net/kvm-put-override/override-false?key=key1\&value=value2

..the result is, I get the previously cached value.

HTTP/1.1 200 OK
Date: Wed, 24 Oct 2018 17:33:06 GMT
Content-Type: application/json
Content-Length: 56
Connection: keep-alive
{
    "status" : "ok",
    "retrieved_data" : "value1"
}

Notice the value in the output is "value1", not "value2".

I think you may have a misunderstanding of the expected behavior. The lack of detail in the documentation on this particular attribute contributes to your misunderstanding. I'll flag this for the doc team and maybe we can sharpen it up.

Here's the story: The override=false will apply if and only if the cache for the given key is warm. There is a cache for the KVM. This logic causes a check of the cache! not the KVM that backs the cache! When override=true, the state of the cache is not considered. the KVM PUT always occurs and the variable named like keyvaluemapoperations.POLICYNAME.KEYVALUE is set to true.


Suppose you insert a key/value pair of xyz/abc into your KVM. Then you use a KVM PUT operation, with override=false, and with k/v pair of xyz/123. The value inserted into the KVM will be 123. The cache is not warm, so the KVM PUT actually occurs. Suppose you call KVM PUT again, with xyz/456. The KVM PUT will actually occur again, and the value will be 456. The KVM key exists, but it gets overwritten, because the cache is not warm.

This is what you are seeing in your case. The KVM PUT is happening because the cache is not warm. If you want to force the cache to be warm, you can do so by performing a KVM GET on the same key, prior to calling the KVM PUT. Keep in mind: you can perform a GET and a PUT within the same KeyValueMapOperations policy. They are performed in the order they appear in the policy configuration. For example:

<KeyValueMapOperations name="KVM-Put-override-false" mapIdentifier="settings1">
  <Scope>environment</Scope>
  <!--
      <ExclusiveCache>false</ExclusiveCache>
      this element is deprecated. Don't use it.
  -->
  <ExpiryTimeInSecs>30</ExpiryTimeInSecs>
  <!-- The GET  will populate the cache, if the entry exists -->
  <Get assignTo='retrieved_data'> 
    <Key>
      <Parameter ref='request.queryparam.key'/>
    </Key>
  </Get>
  <!-- The PUT will write a value only if the entry did not previously exist -->
  <Put override="false">
    <Key>
      <Parameter ref="request.queryparam.key"/>
    </Key>
    <Value ref="request.queryparam.value"/>
  </Put>
</KeyValueMapOperations>

The override=false will apply if and only if the cache for the given key is warm.

Thanks for the clarification Dino, I never knew about this point. A good point to remember 🙂

Hi @Dino-at-Google, Can you please make sure this has been updated in docs as well as i dont see this is updated

So, if a kvm value happens to be in a cache because someone run GET right before PUT, with PUT/override=false a new value is not updated. But if it is not in cache, then PUT will update the KVM value... 
Doesn't it makes the result of KVM/PUT operation unpredictable based on a cached value expiration?

May I ask what is a use case for this behaviour?

Also, while override=false is default? I would assume most of the times we what the PUT to happen, the cache to be invalidated then re-populated on a next GET? (aka overrides=true). 

Hey @Dino-at-Google et al. I'd like to clarify the docs on this, but quite frankly I'm still confused. 🙂

My experience suggests that when I put something to a cache, the thing is put to the cache -- without needing to set an attribute to override. So is this attribute intended to allow puts that don't actually put? Is it just the value's presence (or importance) in the KVM cache that's overridden?

What's a use case?

Thanks!

Steve

Any luck in updates documentation for put/override attribute? It still is confusing