You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/01/15 20:18:26 UTC

[GitHub] [pulsar] merlimat opened a new pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

merlimat opened a new pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221


   ### Motivation
   
   Added `CoordinationService` abstraction implemented on top of `MetadataStore`. 
    
   CoordinationService provides: 
    * Locks management
    * Leader election
    * Unique numbers generator
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat merged pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
merlimat merged pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat commented on a change in pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221#discussion_r558970801



##########
File path: pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java
##########
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.metadata.coordination.impl;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.pulsar.metadata.api.MetadataStore;
+import org.apache.pulsar.metadata.api.coordination.ResourceLock;
+import org.apache.pulsar.metadata.cache.impl.MetadataSerde;
+
+public class ResourceLockImpl<T> implements ResourceLock<T> {
+
+    private final MetadataStore store;
+    private final MetadataSerde<T> serde;
+    private final String path;
+
+    private volatile T value;
+    private long version;
+    private final CompletableFuture<Void> expiredFuture;
+
+    private static enum State {
+        Valid, Released
+    }
+
+    private State state;
+
+    public ResourceLockImpl(MetadataStore store, MetadataSerde<T> serde, String path, T value, long version) {
+        this.store = store;
+        this.serde = serde;
+        this.path = path;
+        this.value = value;
+        this.version = version;
+        this.expiredFuture = new CompletableFuture<>();
+        this.state = State.Valid;
+    }
+
+    @Override
+    public synchronized T getValue() {
+        return value;
+    }
+
+    @Override
+    public synchronized CompletableFuture<Void> updateValue(T newValue) {

Review comment:
       We need the `synchronized` for reading the `version` field




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221#discussion_r558826576



##########
File path: pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java
##########
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.metadata.coordination.impl;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.pulsar.metadata.api.MetadataStore;
+import org.apache.pulsar.metadata.api.coordination.ResourceLock;
+import org.apache.pulsar.metadata.cache.impl.MetadataSerde;
+
+public class ResourceLockImpl<T> implements ResourceLock<T> {
+
+    private final MetadataStore store;
+    private final MetadataSerde<T> serde;
+    private final String path;
+
+    private volatile T value;
+    private long version;
+    private final CompletableFuture<Void> expiredFuture;
+
+    private static enum State {
+        Valid, Released
+    }
+
+    private State state;
+
+    public ResourceLockImpl(MetadataStore store, MetadataSerde<T> serde, String path, T value, long version) {
+        this.store = store;
+        this.serde = serde;
+        this.path = path;
+        this.value = value;
+        this.version = version;
+        this.expiredFuture = new CompletableFuture<>();
+        this.state = State.Valid;
+    }
+
+    @Override
+    public synchronized T getValue() {
+        return value;
+    }
+
+    @Override
+    public synchronized CompletableFuture<Void> updateValue(T newValue) {

Review comment:
       Probably we do  not need 'synchonized' here, the real critical section is executed in another thread




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221#discussion_r558991288



##########
File path: pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java
##########
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.metadata.coordination.impl;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.bookkeeper.common.concurrent.FutureUtils;
+import org.apache.pulsar.metadata.api.MetadataStore;
+import org.apache.pulsar.metadata.api.coordination.ResourceLock;
+import org.apache.pulsar.metadata.cache.impl.MetadataSerde;
+
+public class ResourceLockImpl<T> implements ResourceLock<T> {
+
+    private final MetadataStore store;
+    private final MetadataSerde<T> serde;
+    private final String path;
+
+    private volatile T value;
+    private long version;
+    private final CompletableFuture<Void> expiredFuture;
+
+    private static enum State {
+        Valid, Released
+    }
+
+    private State state;
+
+    public ResourceLockImpl(MetadataStore store, MetadataSerde<T> serde, String path, T value, long version) {
+        this.store = store;
+        this.serde = serde;
+        this.path = path;
+        this.value = value;
+        this.version = version;
+        this.expiredFuture = new CompletableFuture<>();
+        this.state = State.Valid;
+    }
+
+    @Override
+    public synchronized T getValue() {
+        return value;
+    }
+
+    @Override
+    public synchronized CompletableFuture<Void> updateValue(T newValue) {

Review comment:
       Right. Thanks for the clarification 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] jiazhai commented on pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
jiazhai commented on pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221#issuecomment-761957243


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie commented on pull request #9221: PIP-45: Implement CoordinationService on top of MetadataStore

Posted by GitBox <gi...@apache.org>.
sijie commented on pull request #9221:
URL: https://github.com/apache/pulsar/pull/9221#issuecomment-761980666


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org