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 2018/03/10 05:55:07 UTC

[GitHub] merlimat commented on a change in pull request #1363: Schema registry 3/N

merlimat commented on a change in pull request #1363: Schema registry 3/N
URL: https://github.com/apache/incubator-pulsar/pull/1363#discussion_r173612296
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java
 ##########
 @@ -0,0 +1,477 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.broker.service.schema;
+
+import static com.google.common.collect.Iterables.concat;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.protobuf.ByteString.copyFrom;
+import static java.util.Collections.emptyMap;
+import static java.util.Objects.isNull;
+import static java.util.Objects.nonNull;
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.pulsar.broker.service.schema.BookkeeperSchemaStorage.Functions.newSchemaEntry;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.protobuf.ByteString;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import javax.validation.constraints.NotNull;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeper.DigestType;
+import org.apache.bookkeeper.client.LedgerEntry;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.util.ZkUtils;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.common.schema.SchemaVersion;
+import org.apache.pulsar.zookeeper.ZooKeeperCache;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.Code;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.ACL;
+
+public class BookkeeperSchemaStorage implements SchemaStorage {
+    private static final String SchemaPath = "/schemas";
+    private static final List<ACL> Acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+
+    private final PulsarService pulsar;
+    private final ZooKeeper zooKeeper;
+    private final ZooKeeperCache localZkCache;
+    private BookKeeper bookKeeper;
+
+    @VisibleForTesting
+    BookkeeperSchemaStorage(PulsarService pulsar) {
+        this.pulsar = pulsar;
+        this.localZkCache = pulsar.getLocalZkCache();
+        this.zooKeeper = localZkCache.getZooKeeper();
+    }
+
+    @VisibleForTesting
+    public void init() throws KeeperException, InterruptedException {
+        try {
+            zooKeeper.create(SchemaPath, new byte[]{}, Acl, CreateMode.PERSISTENT);
 
 Review comment:
   Every time we do this it will actually do the write the operation on journal and then log something in zk server that it failed. 
   
   If it's very unlikely that the condition is true (just the very first time), we do and `exists()` call to avoid the write.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services