Hi Karthi,
Well, as it turns out, you need to do your validation before the configuration gets committed at all! Your problem has nothing do with subscriptions or commit order or command order, it is a validation issue. The situation you describe is actually quite common. What you need to do is define a constraint using a yang "must" statement. This will get evaluated before ConfD even tries to commit it. For example, in the yang model for server you'd have a leaf called "key" of some type, e.g. serverKeyType or int or something. In that leaf you'd put the following must statement (I am using assumed names for some items because I do't have your yang models):
import key { <== guessing
prefix key;
}
list server {
key index; <=== guessing
leaf index {...
leaf key {
type int;
must "/key:key[key:index=current()])" {
error-message "key must exist";
tailf:dependency "/key:key";
tailf:dependency ".";
}
What this says is "for the proposed value of server/key, there must be an instance of key{n} where n = the value of this server/key, which the current() function gives." Behold the power of yang! All this gets evaluated by Confd when you type "validate" or "commit." It occurs in the pending transaction. If it doesn't evaluate to true, it won't commit until you correct it or revert. A disclaimer - the syntax I gave might be inexact, but it illustrates the point. We've written countless statements like this in our code.
To debug this stuff, configure your confdConfig/logs/xpathTraceLog enabled, set a file name, and watch the file output when you try to commit or validate. You may have to refine the expressions with some trial and error, it takes a while to get the hang of it.
I don't know the namespaces or names of your indices (list keys or server) so I am using placeholders.
in general, you should avoid validation in a subscription in less it is unavoidable. If something is invalid in a subscription phase 1 (prepare), you can roll back the transaction. In phase 2, the data is already committed to CDB so even if you reject it in a subscription callback, it's too late, your system is out of balance because you've got data committed which cannot be consumed by the system. Always avoid letting data get committed which is not acceptable.