1
我有一個複合索引(prop0 asc,prop1 asc)。要驗證它是否更新,即使prop0和prop1沒有編入索引,我也做了一個測試。該測試有幾個請求,如下面的AppStats截圖所示。做一個屬性必須索引的關聯複合索引更新put()?
請求1:複合過濾器查詢(與請求4相同)。
請求2:創建請求5的同一個DataStore,但所有屬性都是未索引的。
請求3:DataStore清理。
請求4:複合過濾器查詢。
請求5:使用索引的所有屬性創建DataStore。
請求6:memcache清理。
要求1返回沒有結果,如果指數沒有被要求在2我的問題更新的預計是:是這樣的話?
相關代碼如下。
// 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;
}