Issue #1300
This commit is contained in:
parent
e01636d109
commit
7bc0ae57ca
|
@ -422,9 +422,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
if (!_dsProvided)
|
if (!_dsProvided)
|
||||||
{
|
{
|
||||||
if (!StringUtil.isBlank(getNamespace()))
|
if (!StringUtil.isBlank(getNamespace()))
|
||||||
_datastore = DatastoreOptions.builder().namespace(getNamespace()).build().service();
|
_datastore = DatastoreOptions.newBuilder().setNamespace(getNamespace()).build().getService();
|
||||||
else
|
else
|
||||||
_datastore = DatastoreOptions.defaultInstance().service();
|
_datastore = DatastoreOptions.getDefaultInstance().getService();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_model == null)
|
if (_model == null)
|
||||||
|
@ -433,7 +433,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
addBean(_model,true);
|
addBean(_model,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_keyFactory = _datastore.newKeyFactory().kind(_model.getKind());
|
_keyFactory = _datastore.newKeyFactory().setKind(_model.getKind());
|
||||||
|
|
||||||
_indexesPresent = checkIndexes();
|
_indexesPresent = checkIndexes();
|
||||||
if (!_indexesPresent)
|
if (!_indexesPresent)
|
||||||
|
@ -566,9 +566,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Query<Key> q = Query.keyQueryBuilder()
|
Query<Key> q = Query.newKeyQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.filter(PropertyFilter.eq(_model.getId(), s))
|
.setFilter(PropertyFilter.eq(_model.getId(), s))
|
||||||
.build();
|
.build();
|
||||||
QueryResults<Key> res = _datastore.run(q);
|
QueryResults<Key> res = _datastore.run(q);
|
||||||
if (!res.hasNext())
|
if (!res.hasNext())
|
||||||
|
@ -604,10 +604,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
Set<ExpiryInfo> info = new HashSet<>();
|
Set<ExpiryInfo> info = new HashSet<>();
|
||||||
|
|
||||||
//get up to maxResult number of sessions that have expired
|
//get up to maxResult number of sessions that have expired
|
||||||
Query<Entity> query = Query.entityQueryBuilder()
|
Query<Entity> query = Query.newEntityQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
|
.setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
|
||||||
.limit(_maxResults)
|
.setLimit(_maxResults)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
QueryResults<Entity> results;
|
QueryResults<Entity> results;
|
||||||
|
@ -637,11 +637,11 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
protected Set<ExpiryInfo> queryExpiryByIndex () throws Exception
|
protected Set<ExpiryInfo> queryExpiryByIndex () throws Exception
|
||||||
{
|
{
|
||||||
Set<ExpiryInfo> info = new HashSet<>();
|
Set<ExpiryInfo> info = new HashSet<>();
|
||||||
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
|
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.projection(_model.getId(), _model.getLastNode(), _model.getExpiry())
|
.setProjection(_model.getId(), _model.getLastNode(), _model.getExpiry())
|
||||||
.filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
|
.setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
|
||||||
.limit(_maxResults)
|
.setLimit(_maxResults)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
QueryResults<ProjectionEntity> presults;
|
QueryResults<ProjectionEntity> presults;
|
||||||
|
@ -674,10 +674,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
if (_indexesPresent)
|
if (_indexesPresent)
|
||||||
{
|
{
|
||||||
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
|
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.projection(_model.getExpiry())
|
.setProjection(_model.getExpiry())
|
||||||
.filter(PropertyFilter.eq(_model.getId(), id))
|
.setFilter(PropertyFilter.eq(_model.getId(), id))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
QueryResults<ProjectionEntity> presults;
|
QueryResults<ProjectionEntity> presults;
|
||||||
|
@ -700,9 +700,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Query<Entity> query = Query.entityQueryBuilder()
|
Query<Entity> query = Query.newEntityQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.filter(PropertyFilter.eq(_model.getId(), id))
|
.setFilter(PropertyFilter.eq(_model.getId(), id))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
QueryResults<Entity> results;
|
QueryResults<Entity> results;
|
||||||
|
@ -761,7 +761,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
}
|
}
|
||||||
catch (DatastoreException e)
|
catch (DatastoreException e)
|
||||||
{
|
{
|
||||||
if (e.retryable())
|
if (e.isRetryable())
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("Datastore put retry {} waiting {}ms", attempts, backoff);
|
if (LOG.isDebugEnabled()) LOG.debug("Datastore put retry {} waiting {}ms", attempts, backoff);
|
||||||
|
|
||||||
|
@ -814,18 +814,26 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
*/
|
*/
|
||||||
protected boolean checkIndexes ()
|
protected boolean checkIndexes ()
|
||||||
{
|
{
|
||||||
|
long start =0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
|
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
|
||||||
.kind(_model.getKind())
|
.setKind(_model.getKind())
|
||||||
.projection(_model.getExpiry())
|
.setProjection(_model.getExpiry())
|
||||||
.filter(PropertyFilter.eq(_model.getId(), "-"))
|
.setFilter(PropertyFilter.eq(_model.getId(), "-"))
|
||||||
.build();
|
.build();
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
System.err.println("Checking indexes at "+start);
|
||||||
_datastore.run(query);
|
_datastore.run(query);
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.err.println("Done checking, elapsed "+(end-start));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (DatastoreException e)
|
catch (DatastoreException e)
|
||||||
{
|
{
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.err.println("Done checking, no indexes, elapsed="+(end-start));
|
||||||
//need to assume that the problem is the index doesn't exist, because there
|
//need to assume that the problem is the index doesn't exist, because there
|
||||||
//is no specific code for that
|
//is no specific code for that
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
|
@ -855,7 +863,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
oos.flush();
|
oos.flush();
|
||||||
|
|
||||||
//turn a session into an entity
|
//turn a session into an entity
|
||||||
entity = Entity.builder(key)
|
entity = Entity.newBuilder(key)
|
||||||
.set(_model.getId(), session.getId())
|
.set(_model.getId(), session.getId())
|
||||||
.set(_model.getContextPath(), session.getContextPath())
|
.set(_model.getContextPath(), session.getContextPath())
|
||||||
.set(_model.getVhost(), session.getVhost())
|
.set(_model.getVhost(), session.getVhost())
|
||||||
|
@ -866,7 +874,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
|
||||||
.set(_model.getLastNode(),session.getLastNode())
|
.set(_model.getLastNode(),session.getLastNode())
|
||||||
.set(_model.getExpiry(), session.getExpiry())
|
.set(_model.getExpiry(), session.getExpiry())
|
||||||
.set(_model.getMaxInactive(), session.getMaxInactiveMs())
|
.set(_model.getMaxInactive(), session.getMaxInactiveMs())
|
||||||
.set(_model.getAttributes(), BlobValue.builder(Blob.copyFrom(baos.toByteArray())).excludeFromIndexes(true).build()).build();
|
.set(_model.getAttributes(), BlobValue.newBuilder(Blob.copyFrom(baos.toByteArray())).setExcludeFromIndexes(true).build()).build();
|
||||||
|
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<name>Jetty :: GCloud</name>
|
<name>Jetty :: GCloud</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<gcloud.version>0.7.0</gcloud.version>
|
<gcloud.version>0.8.2-beta</gcloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
|
|
@ -27,6 +27,8 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
import com.google.cloud.datastore.Datastore;
|
import com.google.cloud.datastore.Datastore;
|
||||||
import com.google.cloud.datastore.DatastoreOptions;
|
import com.google.cloud.datastore.DatastoreOptions;
|
||||||
import com.google.cloud.datastore.Entity;
|
import com.google.cloud.datastore.Entity;
|
||||||
|
@ -73,7 +75,7 @@ public class GCloudSessionTestSupport
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
_helper.stop();
|
_helper.stop(Duration.millis(5)); //wait up to 5ms for shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue