سؤال

I'm experiencing a bug which seems to be related to the memcache.

java.lang.IllegalArgumentException: Key is incomplete.
    at com.google.appengine.api.datastore.KeyFactory.keyToString(KeyFactory.java:164)
    at com.googlecode.objectify.cache.KeyMemcacheService.stringify(KeyMemcacheService.java:62)
    at com.googlecode.objectify.cache.KeyMemcacheService.putAll(KeyMemcacheService.java:91)
    at com.googlecode.objectify.cache.EntityMemcache.empty(EntityMemcache.java:319)
    at com.googlecode.objectify.cache.CachingAsyncDatastoreService$5.trigger(CachingAsyncDatastoreService.java:445)
    at com.googlecode.objectify.cache.TriggerFuture.isDone(TriggerFuture.java:89)
    at com.googlecode.objectify.cache.TriggerFuture.get(TriggerFuture.java:104)
    at com.googlecode.objectify.impl.ResultAdapter.now(ResultAdapter.java:34)
    at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:22)
    at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:10)
    at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
    at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:22)
    at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:10)
    at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)

The objects I'm trying to persist are extending the following, and have @Parent Key someclass;

public abstract class AbstractVO<T> implements iVO<T> {
private static final Logger log = Logger.getLogger(AbstractVO.class.getName());

@Id
private Long id;

@Index
private Date lastModified;

public Long getId() {
    return id;
}

public Date getLastModified() {
    return lastModified;
}

public void setId(Long id) {
    this.id = id;
}

public void setLastModified(Date lastModified) {
    this.lastModified = lastModified;
}

public Key<?> getKey() {
    return Key.create(this);
}

@OnSave
public void onSaveFunction(){
    setLastModified(new Date());
}



@SuppressWarnings("unchecked")
public T save(){
    try {
        ofy().save().entity(this).now();
    } catch (IllegalArgumentException e){
        log.log(Level.SEVERE, "boom, key was incomplete", e);
    }
    return (T) this;
}

public Result<Void> delete(){
    return ofy().delete().entity(this);
}

@SuppressWarnings("unchecked")
public T refresh(){
    if (getId() != null){
        return (T) ofy().load().entity(this).now();
    }
    else {
        return (T) this;
    }
}

Logs are showing that the data required to save the entities are what you'd expect them to be:

parent id:5813790675304448
parent key:ag5zfnRlY2gtZXNzZW5jZXJZCxIHQ29tcGFueRiAgIDAyK2fCAwLEghDYW1wYWlnbhiAgICA0pCXCwwLEgpBY3Rpb25UeXBlGICAgICS5-gJDAsSDFNlbGxlckFjdGlvbhiAgICAyvOpCgw
entity id: null

Have anyone experienced this problem before and how could I resolve it? I've written test cases to attempt to reproduce on my dev servers, but they are all passing. It only appears to be a problem on production.

Edit:

I have removed the cache on the affected entities, which resulted in the saving of the entity taking 10 seconds (I'm guessing this is the timeout?) and high contention making it blow up..

هل كانت مفيدة؟

المحلول

I think i have identified the problem, it's simply contention.. I have rewritten much of my application to verify - I'm in the middle of migration now and will let you know

  • This was indeed the problem, my resolution was to remove the entity from the hierarchy and add the parents as indexed fields.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top