diff --git a/README.md b/README.md index f1856d9e..3f6780b9 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,16 @@ Gradle: ```kotlin dependencies { // Datastore Storage support library. - implementation("io.spine.gcloud:spine-datastore:1.7.0") + implementation("io.spine.gcloud:spine-datastore:1.8.0") // Pub/Sub messaging support library. - implementation("io.spine.gcloud:spine-pubsub:1.7.0") + implementation("io.spine.gcloud:spine-pubsub:1.8.0") // Stackdriver Trace support library. - implementation("io.spine.gcloud:spine-stackdriver-trace:1.7.0") + implementation("io.spine.gcloud:spine-stackdriver-trace:1.8.0") // Datastore-related test utilities (if needed). - implementation("io.spine.gcloud:testutil-gcloud:1.7.0") + implementation("io.spine.gcloud:testutil-gcloud:1.8.0") } ``` diff --git a/datastore/src/main/java/io/spine/server/storage/datastore/DsSessionStorage.java b/datastore/src/main/java/io/spine/server/storage/datastore/DsSessionStorage.java index ff3dd8c9..4f8d60bd 100644 --- a/datastore/src/main/java/io/spine/server/storage/datastore/DsSessionStorage.java +++ b/datastore/src/main/java/io/spine/server/storage/datastore/DsSessionStorage.java @@ -34,6 +34,7 @@ import com.google.cloud.datastore.TimestampValue; import io.spine.server.delivery.ShardIndex; import io.spine.server.delivery.ShardSessionRecord; +import io.spine.server.delivery.WorkerId; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Iterator; @@ -165,9 +166,11 @@ private enum Column implements MessageColumn { .getOfTotal()); }), - node((m) -> { - return StringValue.of(m.getPickedBy() - .getValue()); + worker((m) -> { + WorkerId worker = m.getWorker(); + String value = worker.getNodeId().getValue() + '-' + worker.getValue(); + return StringValue.of(value); + }), when_last_picked((m) -> { diff --git a/datastore/src/main/java/io/spine/server/storage/datastore/DsShardedWorkRegistry.java b/datastore/src/main/java/io/spine/server/storage/datastore/DsShardedWorkRegistry.java index 81be534a..9b39241f 100644 --- a/datastore/src/main/java/io/spine/server/storage/datastore/DsShardedWorkRegistry.java +++ b/datastore/src/main/java/io/spine/server/storage/datastore/DsShardedWorkRegistry.java @@ -33,6 +33,7 @@ import io.spine.server.delivery.ShardIndex; import io.spine.server.delivery.ShardProcessingSession; import io.spine.server.delivery.ShardSessionRecord; +import io.spine.server.delivery.WorkerId; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Iterator; @@ -79,11 +80,26 @@ public DsShardedWorkRegistry(DatastoreStorageFactory factory) { public synchronized Optional pickUp(ShardIndex index, NodeId nodeId) { checkNotNull(index); checkNotNull(nodeId); + + WorkerId worker = currentWorkerFor(nodeId); Optional result = - storage.updateTransactionally(index, new UpdateNodeIfAbsent(index, nodeId)); + storage.updateTransactionally(index, new UpdateWorkerIfAbsent(index, worker)); return result.map(this::asSession); } + /** + * Creates a worker ID by combining the given node ID with the ID of the current Java thread, + * in which the execution in performed. + */ + @Override + protected WorkerId currentWorkerFor(NodeId id) { + long threadId = Thread.currentThread().getId(); + return WorkerId.newBuilder() + .setNodeId(id) + .setValue(Long.toString(threadId)) + .vBuild(); + } + @Override public synchronized Iterable releaseExpiredSessions(Duration inactivityPeriod) { return super.releaseExpiredSessions(inactivityPeriod); @@ -123,24 +139,24 @@ protected DsSessionStorage storage() { } /** - * Updates the {@code nodeId} for the {@link ShardSessionRecord} with the specified + * Updates the {@code workerId} for the {@link ShardSessionRecord} with the specified * {@link ShardIndex} if the record has not been picked by anyone. * *

If there is no such a record, creates a new record. */ - private static class UpdateNodeIfAbsent implements DsSessionStorage.RecordUpdate { + private static class UpdateWorkerIfAbsent implements DsSessionStorage.RecordUpdate { private final ShardIndex index; - private final NodeId nodeToSet; + private final WorkerId workerToSet; - private UpdateNodeIfAbsent(ShardIndex index, NodeId set) { + private UpdateWorkerIfAbsent(ShardIndex index, WorkerId worker) { this.index = index; - nodeToSet = set; + workerToSet = worker; } @Override public Optional createOrUpdate(@Nullable ShardSessionRecord previous) { - if (previous != null && previous.hasPickedBy()) { + if (previous != null && previous.hasWorker()) { return Optional.empty(); } ShardSessionRecord.Builder builder = @@ -150,7 +166,7 @@ public Optional createOrUpdate(@Nullable ShardSessionRecord : previous.toBuilder(); ShardSessionRecord updated = - builder.setPickedBy(nodeToSet) + builder.setWorker(workerToSet) .setWhenLastPicked(currentTime()) .vBuild(); return Optional.of(updated); diff --git a/datastore/src/test/java/io/spine/server/storage/datastore/DsShardedWorkRegistryTest.java b/datastore/src/test/java/io/spine/server/storage/datastore/DsShardedWorkRegistryTest.java index 1995dcb3..e96147fa 100644 --- a/datastore/src/test/java/io/spine/server/storage/datastore/DsShardedWorkRegistryTest.java +++ b/datastore/src/test/java/io/spine/server/storage/datastore/DsShardedWorkRegistryTest.java @@ -36,6 +36,7 @@ import io.spine.server.delivery.ShardSessionRecord; import io.spine.server.delivery.ShardedWorkRegistry; import io.spine.server.delivery.ShardedWorkRegistryTest; +import io.spine.server.delivery.WorkerId; import io.spine.testing.server.storage.datastore.TestDatastoreStorageFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -47,8 +48,6 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth8.assertThat; import static io.spine.server.storage.datastore.given.TestShardIndex.newIndex; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; @DisplayName("`DsShardedWorkRegistry` should") class DsShardedWorkRegistryTest extends ShardedWorkRegistryTest { @@ -82,13 +81,14 @@ protected ShardedWorkRegistry registry() { @DisplayName("pick up the shard and write a corresponding record to the storage") void pickUp() { Optional session = registry.pickUp(index, nodeId); - assertTrue(session.isPresent()); + WorkerId expectedWorker = registry.currentWorkerFor(nodeId); + assertThat(session).isPresent(); assertThat(session.get() .shardIndex()).isEqualTo(index); ShardSessionRecord record = readSingleRecord(index); assertThat(record.getIndex()).isEqualTo(index); - assertThat(record.getPickedBy()).isEqualTo(nodeId); + assertThat(record.getWorker()).isEqualTo(expectedWorker); } @Test @@ -96,28 +96,28 @@ void pickUp() { void cannotPickUpIfTaken() { Optional session = registry.pickUp(index, nodeId); - assertTrue(session.isPresent()); + assertThat(session).isPresent(); Optional sameIdxSameNode = registry.pickUp(index, nodeId); - assertFalse(sameIdxSameNode.isPresent()); + assertThat(sameIdxSameNode).isEmpty(); Optional sameIdxAnotherNode = registry.pickUp(index, newNode()); - assertFalse(sameIdxAnotherNode.isPresent()); + assertThat(sameIdxAnotherNode).isEmpty(); ShardIndex anotherIdx = newIndex(24, 100); Optional anotherIdxSameNode = registry.pickUp(anotherIdx, nodeId); - assertTrue(anotherIdxSameNode.isPresent()); + assertThat(anotherIdxSameNode).isPresent(); Optional anotherIdxAnotherNode = registry.pickUp(anotherIdx, newNode()); - assertFalse(anotherIdxAnotherNode.isPresent()); + assertThat(anotherIdxAnotherNode).isEmpty(); } @Test @DisplayName("complete the shard session (once picked up) and make it available for picking up") void completeSessionAndMakeItAvailable() { Optional optional = registry.pickUp(index, nodeId); - assertTrue(optional.isPresent()); + assertThat(optional).isPresent(); Timestamp whenPickedFirst = readSingleRecord(index).getWhenLastPicked(); @@ -125,17 +125,18 @@ void completeSessionAndMakeItAvailable() { session.complete(); ShardSessionRecord completedRecord = readSingleRecord(index); - assertFalse(completedRecord.hasPickedBy()); + assertThat(completedRecord.hasWorker()).isFalse(); NodeId anotherNode = newNode(); + WorkerId anotherWorker = registry.currentWorkerFor(anotherNode); Optional anotherOptional = registry.pickUp(index, anotherNode); - assertTrue(anotherOptional.isPresent()); + assertThat(anotherOptional).isPresent(); ShardSessionRecord secondSessionRecord = readSingleRecord(index); - assertThat(secondSessionRecord.getPickedBy()).isEqualTo(anotherNode); + assertThat(secondSessionRecord.getWorker()).isEqualTo(anotherWorker); Timestamp whenPickedSecond = secondSessionRecord.getWhenLastPicked(); - assertTrue(Timestamps.compare(whenPickedFirst, whenPickedSecond) < 0); + assertThat(Timestamps.compare(whenPickedFirst, whenPickedSecond) < 0).isTrue(); } @Test diff --git a/license-report.md b/license-report.md index 5d3e2885..030a46b4 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.gcloud:spine-datastore:1.7.0` +# Dependencies of `io.spine.gcloud:spine-datastore:1.8.0` ## Runtime 1. **Group:** com.fasterxml.jackson **Name:** jackson-bom **Version:** 2.12.0 **No license information found** @@ -592,12 +592,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Dec 15 12:20:09 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Dec 16 16:38:53 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.gcloud:spine-pubsub:1.7.0` +# Dependencies of `io.spine.gcloud:spine-pubsub:1.8.0` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -1003,12 +1003,12 @@ This report was generated on **Tue Dec 15 12:20:09 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Dec 15 12:20:20 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Dec 16 16:38:57 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.gcloud:spine-stackdriver-trace:1.7.0` +# Dependencies of `io.spine.gcloud:spine-stackdriver-trace:1.8.0` ## Runtime 1. **Group:** com.fasterxml.jackson **Name:** jackson-bom **Version:** 2.12.0 **No license information found** @@ -1594,12 +1594,12 @@ This report was generated on **Tue Dec 15 12:20:20 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Dec 15 12:20:43 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Dec 16 16:39:04 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.gcloud:spine-testutil-gcloud:1.7.0` +# Dependencies of `io.spine.gcloud:spine-testutil-gcloud:1.8.0` ## Runtime 1. **Group:** com.fasterxml.jackson **Name:** jackson-bom **Version:** 2.12.0 **No license information found** @@ -2191,4 +2191,4 @@ This report was generated on **Tue Dec 15 12:20:43 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Dec 15 12:20:48 EET 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file +This report was generated on **Thu Dec 16 16:39:07 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/pom.xml b/pom.xml index b0e0bb0a..8866b144 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject. io.spine.gcloud spine-gcloud-java -1.7.0 +1.8.0 2015 @@ -46,7 +46,7 @@ all modules and does not describe the project structure per-subproject. io.spine spine-server - 1.7.0 + 1.8.0 compile @@ -70,7 +70,7 @@ all modules and does not describe the project structure per-subproject. io.spine spine-testutil-server - 1.7.0 + 1.8.0 test @@ -98,44 +98,28 @@ all modules and does not describe the project structure per-subproject. test - com.google.errorprone - error_prone_core - 2.4.0 + com.google.code.findbugs + jsr305 + 3.0.2 + provided com.google.errorprone - javac - 9+181-r4173-1 - - - com.google.protobuf - protoc - 3.13.0 - - - io.grpc - protoc-gen-grpc-java - 1.28.1 - - - io.spine.tools - spine-protoc-plugin - 1.7.0 - - - net.sourceforge.pmd - pmd-java - 6.24.0 + error_prone_annotations + 2.4.0 + provided - org.jacoco - org.jacoco.agent - 0.8.5 + com.google.errorprone + error_prone_type_annotations + 2.4.0 + provided - org.jacoco - org.jacoco.ant - 0.8.5 + org.checkerframework + checker-qual + 3.7.1 + provided diff --git a/version.gradle.kts b/version.gradle.kts index 3f9a78d2..fe6e8e48 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -31,6 +31,6 @@ * `.config/gradle/dependencies.gradle`. */ -val spineBaseVersion: String by extra("1.7.0") -val spineCoreVersion: String by extra("1.7.0") -val versionToPublish: String by extra("1.7.0") +val spineBaseVersion: String by extra("1.8.0") +val spineCoreVersion: String by extra("1.8.0") +val versionToPublish: String by extra("1.8.0")