Fix indexes for gcloudatastore; make initial retry backoff 1s as per SLA

This commit is contained in:
Jan Bartel 2016-06-02 16:40:51 +10:00
parent e1b551c2ae
commit 0578d15813
4 changed files with 33 additions and 17 deletions

View File

@ -0,0 +1,21 @@
indexes:
# AUTOGENERATED
# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
- kind: "GCloudSession"
properties:
- name: "expiry"
- name: "id"
- name: "lastNode"
- kind: "GCloudSession"
properties:
- name: "id"
- name: "expiry"

View File

@ -13,7 +13,7 @@
<Set name="gCloudConfiguration"><Ref id="gconf"/></Set>
<Set name="gracePeriodSec"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
<Set name="maxRetries"><Property name="jetty.gcloudSession.maxRetries" default="5"/></Set>
<Set name="backoffMs"><Property name="jetty.gcloudSession.backoffMs" default="50"/></Set>
<Set name="backoffMs"><Property name="jetty.gcloudSession.backoffMs" default="1000"/></Set>
</New>
</Arg>
</Call>

View File

@ -20,6 +20,7 @@
package org.eclipse.jetty.gcloud.session;
import com.google.gcloud.datastore.Blob;
import com.google.gcloud.datastore.BlobValue;
import com.google.gcloud.datastore.Datastore;
import com.google.gcloud.datastore.DatastoreException;
import com.google.gcloud.datastore.DatastoreFactory;
@ -77,7 +78,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
public static final String KIND = "GCloudSession";
public static final int DEFAULT_MAX_QUERY_RESULTS = 100;
public static final int DEFAULT_MAX_RETRIES = 5;
public static final int DEFAULT_BACKOFF_MS = 50;
public static final int DEFAULT_BACKOFF_MS = 1000;
private GCloudConfiguration _config;
private Datastore _datastore;
@ -209,7 +210,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
{
//get up to maxResult number of sessions that have expired
ProjectionEntityQueryBuilder pbuilder = Query.projectionEntityQueryBuilder();
pbuilder.addProjection(Projection.property(ID), Projection.property(LASTNODE), Projection.property(EXPIRY));
pbuilder.projection(Projection.property(ID), Projection.property(LASTNODE), Projection.property(EXPIRY));
pbuilder.filter(CompositeFilter.and(PropertyFilter.gt(EXPIRY, 0), PropertyFilter.le(EXPIRY, now)));
pbuilder.limit(_maxResults);
pbuilder.kind(KIND);
@ -295,11 +296,12 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
*/
@Override
public boolean exists(String id) throws Exception
{
{
ProjectionEntityQueryBuilder pbuilder = Query.projectionEntityQueryBuilder();
pbuilder.addProjection(Projection.property(EXPIRY));
pbuilder.filter(PropertyFilter.eq(ID, id));
pbuilder.kind(KIND);
pbuilder.projection(Projection.property(EXPIRY));
pbuilder.filter(PropertyFilter.eq(ID, id));
StructuredQuery<ProjectionEntity> pquery = pbuilder.build();
QueryResults<ProjectionEntity> presults = _datastore.run(pquery);
@ -404,9 +406,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
oos.writeObject(session.getAllAttributes());
oos.flush();
try
{
//turn a session into an entity
//turn a session into an entity
entity = Entity.builder(key)
.set(ID, session.getId())
.set(CONTEXTPATH, session.getContextPath())
@ -418,13 +418,8 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
.set(LASTNODE,session.getLastNode())
.set(EXPIRY, session.getExpiry())
.set(MAXINACTIVE, session.getMaxInactiveMs())
.set(ATTRIBUTES, Blob.copyFrom(baos.toByteArray())).build();
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
.set(ATTRIBUTES, BlobValue.builder(Blob.copyFrom(baos.toByteArray())).indexed(false).build()).build();
return entity;
}

View File

@ -309,7 +309,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
}
catch (Exception e)
{
LOG.warn("Problem checking if id {} is in use", e);
LOG.warn("Problem checking if id {} is in use", id, e);
return false;
}
}