From 7bc0ae57cacad1fec7e1d17b9e48c3e55e3fc479 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 8 Feb 2017 09:23:32 +1100 Subject: [PATCH] Issue #1300 --- .../session/GCloudSessionDataStore.java | 66 +++++++++++-------- jetty-gcloud/pom.xml | 2 +- .../session/GCloudSessionTestSupport.java | 4 +- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java index c7e5d039959..689f1cdd26d 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java @@ -422,9 +422,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore if (!_dsProvided) { if (!StringUtil.isBlank(getNamespace())) - _datastore = DatastoreOptions.builder().namespace(getNamespace()).build().service(); + _datastore = DatastoreOptions.newBuilder().setNamespace(getNamespace()).build().getService(); else - _datastore = DatastoreOptions.defaultInstance().service(); + _datastore = DatastoreOptions.getDefaultInstance().getService(); } if (_model == null) @@ -433,7 +433,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore addBean(_model,true); } - _keyFactory = _datastore.newKeyFactory().kind(_model.getKind()); + _keyFactory = _datastore.newKeyFactory().setKind(_model.getKind()); _indexesPresent = checkIndexes(); if (!_indexesPresent) @@ -566,9 +566,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore { try { - Query q = Query.keyQueryBuilder() - .kind(_model.getKind()) - .filter(PropertyFilter.eq(_model.getId(), s)) + Query q = Query.newKeyQueryBuilder() + .setKind(_model.getKind()) + .setFilter(PropertyFilter.eq(_model.getId(), s)) .build(); QueryResults res = _datastore.run(q); if (!res.hasNext()) @@ -604,10 +604,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore Set info = new HashSet<>(); //get up to maxResult number of sessions that have expired - Query query = Query.entityQueryBuilder() - .kind(_model.getKind()) - .filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis()))) - .limit(_maxResults) + Query query = Query.newEntityQueryBuilder() + .setKind(_model.getKind()) + .setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis()))) + .setLimit(_maxResults) .build(); QueryResults results; @@ -637,11 +637,11 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore protected Set queryExpiryByIndex () throws Exception { Set info = new HashSet<>(); - Query query = Query.projectionEntityQueryBuilder() - .kind(_model.getKind()) - .projection(_model.getId(), _model.getLastNode(), _model.getExpiry()) - .filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis()))) - .limit(_maxResults) + Query query = Query.newProjectionEntityQueryBuilder() + .setKind(_model.getKind()) + .setProjection(_model.getId(), _model.getLastNode(), _model.getExpiry()) + .setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis()))) + .setLimit(_maxResults) .build(); QueryResults presults; @@ -674,10 +674,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore { if (_indexesPresent) { - Query query = Query.projectionEntityQueryBuilder() - .kind(_model.getKind()) - .projection(_model.getExpiry()) - .filter(PropertyFilter.eq(_model.getId(), id)) + Query query = Query.newProjectionEntityQueryBuilder() + .setKind(_model.getKind()) + .setProjection(_model.getExpiry()) + .setFilter(PropertyFilter.eq(_model.getId(), id)) .build(); QueryResults presults; @@ -700,9 +700,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore } else { - Query query = Query.entityQueryBuilder() - .kind(_model.getKind()) - .filter(PropertyFilter.eq(_model.getId(), id)) + Query query = Query.newEntityQueryBuilder() + .setKind(_model.getKind()) + .setFilter(PropertyFilter.eq(_model.getId(), id)) .build(); QueryResults results; @@ -761,7 +761,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore } catch (DatastoreException e) { - if (e.retryable()) + if (e.isRetryable()) { if (LOG.isDebugEnabled()) LOG.debug("Datastore put retry {} waiting {}ms", attempts, backoff); @@ -814,18 +814,26 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore */ protected boolean checkIndexes () { + long start =0; + try { - Query query = Query.projectionEntityQueryBuilder() - .kind(_model.getKind()) - .projection(_model.getExpiry()) - .filter(PropertyFilter.eq(_model.getId(), "-")) + Query query = Query.newProjectionEntityQueryBuilder() + .setKind(_model.getKind()) + .setProjection(_model.getExpiry()) + .setFilter(PropertyFilter.eq(_model.getId(), "-")) .build(); + start = System.currentTimeMillis(); + System.err.println("Checking indexes at "+start); _datastore.run(query); + long end = System.currentTimeMillis(); + System.err.println("Done checking, elapsed "+(end-start)); return true; } 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 //is no specific code for that if (LOG.isDebugEnabled()) @@ -855,7 +863,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore oos.flush(); //turn a session into an entity - entity = Entity.builder(key) + entity = Entity.newBuilder(key) .set(_model.getId(), session.getId()) .set(_model.getContextPath(), session.getContextPath()) .set(_model.getVhost(), session.getVhost()) @@ -866,7 +874,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore .set(_model.getLastNode(),session.getLastNode()) .set(_model.getExpiry(), session.getExpiry()) .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; diff --git a/jetty-gcloud/pom.xml b/jetty-gcloud/pom.xml index cb220caa7e6..403684e66df 100644 --- a/jetty-gcloud/pom.xml +++ b/jetty-gcloud/pom.xml @@ -13,7 +13,7 @@ Jetty :: GCloud - 0.7.0 + 0.8.2-beta diff --git a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java index 514c660892b..626d6c36271 100644 --- a/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java +++ b/tests/test-sessions/test-gcloud-sessions/src/test/java/org/eclipse/jetty/gcloud/session/GCloudSessionTestSupport.java @@ -27,6 +27,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.joda.time.Duration; + import com.google.cloud.datastore.Datastore; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.datastore.Entity; @@ -73,7 +75,7 @@ public class GCloudSessionTestSupport public void tearDown() throws Exception { - _helper.stop(); + _helper.stop(Duration.millis(5)); //wait up to 5ms for shutdown }