views:

42

answers:

2

How can I check if datastore Indexes as defined in index.yaml are serving in the python code?

I am using Python 1.3.6 AppEngine SDK.

A: 

I don't think there's a way to check without adding some logging to the SDK code. If you're using the SQLite stub, __FindIndexForQuery, lines 1114-1140, is the part that looks for applicable indices to a query, and (at line 1140), returns, and I quote:

An entity_pb.CompositeIndex PB, if a suitable index exists; otherwise None

A little logging at that point (and when it's about to fall off the end having exhausted the loop -- that's how it returns None) will give you a trace of all your indices that are actually used, as part of the logs of course. The protocol buffer it returns is an instance of the class defined in this file, starting at line 2576.

If you can explain why you want to know this, it would, I think, be quite reasonable to open a feature request on the App Engine tracker, asking Google to add the logging that I'm suggesting, so you don't have to keep maintaining your edited version of the file!

(If you use the file stub, the relevant file is here, and the part to instrument is around line 824 and following; of course, this part will be used only if you're running the SDK in "require indices" mode, AKA "strict mode", otherwise, indices are created in, not used by, the SDK;-)

Alex Martelli
+1  A: 

Attempt to perform a query that requires that index. If it raises a NeedIndexError, it's not uploaded or not yet serving.

Nick Johnson
Is their no other AppEngine API call which can give me all the currently served indices?
GeekTantra
Not currently, no. Why do you need them?
Nick Johnson
Because indexing delays leaves the application unusable for hours.
GeekTantra
In that case, what is wrong with the solution above, of catching NeedIndexError? You don't even need to explicitly do sample queries - just catch that error when thrown by regular queries.
Nick Johnson
You can delay making a new version the default if it introduces new indices and those indices have not yet been built.
mahmoud