merlimat commented on a change in pull request #12776:
URL: https://github.com/apache/pulsar/pull/12776#discussion_r748529775



##########
File path: 
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/RocksdbMetadataStore.java
##########
@@ -0,0 +1,428 @@
+/**
+ * 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.impl;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.common.util.FutureUtil;
+import org.apache.pulsar.metadata.api.GetResult;
+import org.apache.pulsar.metadata.api.MetadataStoreConfig;
+import org.apache.pulsar.metadata.api.MetadataStoreException;
+import org.apache.pulsar.metadata.api.Notification;
+import org.apache.pulsar.metadata.api.NotificationType;
+import org.apache.pulsar.metadata.api.Stat;
+import org.apache.pulsar.metadata.api.extended.CreateOption;
+import org.rocksdb.InfoLogLevel;
+import org.rocksdb.Options;
+import org.rocksdb.ReadOptions;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.rocksdb.RocksIterator;
+import org.rocksdb.Transaction;
+import org.rocksdb.TransactionDB;
+import org.rocksdb.TransactionDBOptions;
+import org.rocksdb.WriteBatch;
+import org.rocksdb.WriteOptions;
+
+/**
+ *
+ */
+@Slf4j
+public class RocksdbMetadataStore extends AbstractMetadataStore {
+    private static final byte[] SEQUENTIAL_ID_KEY = 
toBytes("__metadata_sequentialId_key");
+    private static final byte[] INSTANCE_ID_KEY = 
toBytes("__metadata_instanceId_key");
+
+    private final long instanceId;
+    private final AtomicLong sequentialIdGenerator;
+
+    private final TransactionDB db;
+
+    private final WriteOptions optionSync;
+    private final WriteOptions optionDontSync;
+
+    private final ReadOptions optionCache;
+    private final ReadOptions optionDontCache;
+
+    private final WriteBatch emptyBatch;
+
+    @Data
+    @AllArgsConstructor
+    @NoArgsConstructor
+    private static class MetaValue {
+        private static final int HEADER_SIZE = 8 + 8 + 8 + 8 + 1;
+
+        long version;
+        long owner;
+        long createdTimestamp;
+        long modifiedTimestamp;
+        boolean ephemeral;
+        byte[] data;
+
+        public byte[] serialize() {
+            byte[] result = new byte[HEADER_SIZE + data.length];
+            ByteBuffer buffer = ByteBuffer.wrap(result);
+            buffer.putLong(version);
+            buffer.putLong(owner);
+            buffer.putLong(createdTimestamp);
+            buffer.putLong(modifiedTimestamp);
+            buffer.put((byte) (ephemeral ? 1 : 0));
+            buffer.put(data);
+            return result;

Review comment:
       Since this is not going to change very often, I agree we don't need to 
use Protobuf or similar, though we should leave the door open for future 
modifications. 
   
   I would add: 
    * `header-size` field as the first field
    *  `format-version` identifier to understand which format was used for a 
given value
    * Add a note that we can only add new fields, but not change or remove 
existing fields
    * When deserializing, stop reading at the current known HEADER size, 
ignoring newer unknown fields.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to