I have a composite index (prop0 asc, prop1 asc). To verify whether it is updated even if prop0 and prop1 aren't indexed, I have made a test. The test has several requests as shown in the AppStats screenshot below.
Request 1: Composite filter query (same as Request 4).
Request 2: Creation of the same DataStore of Request 5, but with all properties unindexed.
Request 3: DataStore cleanup.
Request 4: Composite filter query.
Request 5: DataStore creation with all properties indexed.
Request 6: memcache cleanup.
Request 1 is returning no results, which is expected if the composite index is not being updated in Request 2. My question is: that's the case?
The related code is below.
// DataStore creation.
public ReturnCodes operate() {
DatastoreService dataStore = DatastoreServiceFactory.getDatastoreService();
Entity testEntity = new Entity(ENTITY_NAME, ROOT_NAME);
Key rootKey = KeyFactory.createKey(DataStoreCreation.ENTITY_NAME, ROOT_NAME);
setProps(testEntity, 0);
dataStore.put(testEntity);
for(int i = 1; i < numEntities; ++i) {
// Chave = nome da entidade + i
testEntity = new Entity(ENTITY_NAME, ENTITY_NAME + i, rootKey);
setProps(testEntity, i);
dataStore.put(testEntity);
}
return ReturnCodes.SUCCESS;
}
private void setProps(Entity entity, int value) {
for(int j = 0; j < numProps; ++j) {
if(indexed) {
entity.setProperty(PROPERTY_NAME_PREFIX + j, value);
}
else {
entity.setUnindexedProperty(PROPERTY_NAME_PREFIX + j, value);
}
}
}
// DataStore cleanup.
private ReturnCodes clean() {
Key rootKey = KeyFactory.createKey(DataStoreCreation.ENTITY_NAME, DataStoreCreation.ROOT_NAME);
DatastoreService dataStore = DatastoreServiceFactory.getDatastoreService();
Query query = new Query(DataStoreCreation.ENTITY_NAME).setKeysOnly();
PreparedQuery prepQuery = dataStore.prepare(query);
Iterable<Entity> entities = prepQuery.asIterable();
ArrayList<Key> keys = new ArrayList<Key>();
for(Entity entity : entities) {
keys.add(entity.getKey());
}
dataStore.delete(keys);
return ReturnCodes.SUCCESS;
}
// Composite filter query.
public ReturnCodes doQuery() {
DatastoreService dataStore = DatastoreServiceFactory.getDatastoreService();
for(int i = 0; i < numIters; ++i) {
Query.FilterPredicate filter0 = new Query.FilterPredicate(DataStoreCreation.PROPERTY_NAME_PREFIX + 0,
Query.FilterOperator.NOT_EQUAL, 0);
Query.FilterPredicate filter1 = new Query.FilterPredicate(DataStoreCreation.PROPERTY_NAME_PREFIX + 0,
Query.FilterOperator.GREATER_THAN_OR_EQUAL, 0);
CompositeFilter finalFilter = Query.CompositeFilterOperator.or(filter0, filter1);
Query query = new Query(DataStoreCreation.ENTITY_NAME/*, key*/).setFilter(finalFilter);
query.addProjection(new PropertyProjection(DataStoreCreation.PROPERTY_NAME_PREFIX + 0, Integer.class));
query.addProjection(new PropertyProjection(DataStoreCreation.PROPERTY_NAME_PREFIX + 1, Integer.class));
PreparedQuery prepQuery = dataStore.prepare(query);
Iterable<Entity> results = prepQuery.asIterable();
if(!results.iterator().hasNext()) {
return ReturnCodes.ERROR;
}
for(Entity result : results) {
//log.info(result.toString());
}
}
return ReturnCodes.SUCCESS;
}